aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main.c33
-rw-r--r--xlib.c16
-rw-r--r--xlib.h1
3 files changed, 48 insertions, 2 deletions
diff --git a/main.c b/main.c
index a3a57a0..01a27df 100644
--- a/main.c
+++ b/main.c
@@ -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;
diff --git a/xlib.c b/xlib.c
index 76b3b55..2a29c0d 100644
--- a/xlib.c
+++ b/xlib.c
@@ -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;
}
diff --git a/xlib.h b/xlib.h
index 083bfb6..f462743 100644
--- a/xlib.h
+++ b/xlib.h
@@ -7,6 +7,7 @@ typedef struct {
Display *dpy;
Window w;
GC gc;
+ XIC ic;
} RunesWindow;
RunesWindow *runes_window_create();