diff options
-rw-r--r-- | main.c | 33 | ||||
-rw-r--r-- | xlib.c | 16 | ||||
-rw-r--r-- | xlib.h | 1 |
3 files changed, 48 insertions, 2 deletions
@@ -1,3 +1,4 @@ +#include <locale.h> #include <stdio.h> #include "runes.h" @@ -5,6 +6,9 @@ int main (int argc, char *argv[]) { RunesTerm *t; + unsigned long mask; + + setlocale(LC_ALL, ""); t = runes_term_create(); @@ -13,15 +17,40 @@ int main (int argc, char *argv[]) cairo_set_source_rgb(t->cr, 0.0, 0.0, 1.0); cairo_move_to(t->cr, 0.0, 14.0); - XSelectInput(t->w->dpy, t->w->w, KeyPressMask|KeyReleaseMask); + XGetICValues(t->w->ic, XNFilterEvents, &mask, NULL); + XSelectInput(t->w->dpy, t->w->w, mask|KeyPressMask); + XSetICFocus(t->w->ic); for (;;) { XEvent e; char buf[10]; XNextEvent(t->w->dpy, &e); + if (XFilterEvent(&e, None)) { + continue; + } if (e.type == KeyPress) { - XLookupString(&e, buf, 10, NULL, NULL); + Status s; + KeySym sym; + int chars; + + chars = Xutf8LookupString(t->w->ic, &e.xkey, buf, 9, &sym, &s); + buf[chars] = '\0'; + switch (s) { + case XLookupKeySym: + fprintf(stderr, "keysym: %d\n", sym); + break; + case XLookupBoth: + case XLookupChars: + fprintf(stderr, "chars: %10s\n", buf); + break; + case XLookupNone: + fprintf(stderr, "none\n"); + break; + default: + fprintf(stderr, "???\n"); + break; + } } else { continue; @@ -1,4 +1,5 @@ #include <cairo-xlib.h> +#include <stdio.h> #include <stdlib.h> #include <X11/Xlib.h> @@ -8,6 +9,7 @@ RunesWindow *runes_window_create() { RunesWindow *w; unsigned long white; + XIM im; w = malloc(sizeof(RunesWindow)); @@ -32,6 +34,20 @@ RunesWindow *runes_window_create() } } + XSetLocaleModifiers(""); + im = XOpenIM(w->dpy, NULL, NULL, NULL); + w->ic = XCreateIC( + im, + XNInputStyle, XIMPreeditNothing | XIMStatusNothing, + XNClientWindow, w->w, + XNFocusWindow, w->w, + NULL + ); + if (w->ic == NULL) { + fprintf(stderr, "failed\n"); + exit(1); + } + return w; } @@ -7,6 +7,7 @@ typedef struct { Display *dpy; Window w; GC gc; + XIC ic; } RunesWindow; RunesWindow *runes_window_create(); |