ratpoison-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RP] Digraphs in ratpoison


From: Nikolai Weibull
Subject: [RP] Digraphs in ratpoison
Date: Tue, 23 Jan 2007 23:50:08 +0100

Screen has digraph support.  It would be sweet if ratpoison would have
it as well.  It can be simulated somewhat with the use of keymaps and
the meta command (with an argument), but it's not very useful, as only
the most basic of keys is in the keymap at the time meta is called
(i.e., the keys you could generate yourself by pressing a key on the
keyboard).

Here's my solution to it, using code I found on some GNOME mailing-list:

#include <stdio.h>
#include <X11/X.h>
#include <X11/Xlib.h>

int
main(int argc, char **argv)
{
       Display *display;
       display = XOpenDisplay(NULL);

       if (argc != 2) {
               printf("This program takes a single keysym name (such
as A or U0041) as an argument\n");
               return 1;
       }

       KeySym sym = XStringToKeysym(argv[1]);

       int min, max, numcodes;
       KeySym *keysyms;
       XDisplayKeycodes(display, &min, &max);
       keysyms = XGetKeyboardMapping(display, min, max - min + 1, &numcodes);
       keysyms[(max - min - 1) * numcodes] = sym;
       XChangeKeyboardMapping(display, min, numcodes, keysyms, max - min);
       XFree(keysyms);
       XFlush(display);

       KeyCode code = XKeysymToKeycode(display, sym);

       Window window;
       int revert_to_return;
       XGetInputFocus(display, &window, &revert_to_return);

       XEvent event;
       event.xkey.type = KeyPress;
       event.xkey.display = display;
       event.xkey.window = window;
       event.xkey.state = 0;
       event.xkey.keycode = code;
       XSendEvent(display, event.xkey.window, False, KeyPressMask, &event);

       XFlush(display);

       XCloseDisplay(display);

       return 0;
}

And here are my keymaps:

newkmap digraphs
definekey digraphs a readkey digraph-a
definekey digraphs o readkey digraph-o
bind C-v readkey digraphs

newkmap digraph-a
definekey digraph-a colon exec ratpoison-send-key U00e4
definekey digraph-a a exec ratpoison-send-key U00e5

newkmap digraph-o
definekey digraph-o colon exec ratpoison-send-key U00f6

However, that will become unsightly quite fast and it would be a lot
sweeter if this was implemented internally in ratpoison.  I suppose
it's up to me to write the code if I want this feature, but I'd be
more than willing to let someone else write it for me.  Any takers?

It could easily be implemented using a two-level lookup table after
having read two characters of input from the user, like readkey does.
Then the code above could be used to generate the keypress event with
the Unicode character that was found in the table.

Anyway, just a thought.

 nikolai




reply via email to

[Prev in Thread] Current Thread [Next in Thread]