aboutsummaryrefslogtreecommitdiffstats
path: root/xlib.c
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-04-05 10:17:19 -0400
committerJesse Luehrs <doy@tozt.net>2014-04-05 10:17:19 -0400
commitd63232774dae78b0ee270a47671be9fd70d99969 (patch)
tree7f282f0cd8845f49934246ab7629583f636b7eac /xlib.c
parentb97c939bdc404cb38a82f2d425a3ab1812c68f05 (diff)
downloadrunes-d63232774dae78b0ee270a47671be9fd70d99969.tar.gz
runes-d63232774dae78b0ee270a47671be9fd70d99969.zip
move the input processing into the backend
Diffstat (limited to 'xlib.c')
-rw-r--r--xlib.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/xlib.c b/xlib.c
index 6578ca7..4d8d039 100644
--- a/xlib.c
+++ b/xlib.c
@@ -59,6 +59,49 @@ cairo_surface_t *runes_surface_create(RunesWindow *w)
return cairo_xlib_surface_create(w->dpy, w->w, vis, 240, 80);
}
+void runes_window_prepare_input(RunesWindow *w)
+{
+ unsigned long mask;
+
+ XGetICValues(w->ic, XNFilterEvents, &mask, NULL);
+ XSelectInput(w->dpy, w->w, mask|KeyPressMask);
+ XSetICFocus(w->ic);
+}
+
+void runes_window_read_key(RunesWindow *w, char **outbuf, size_t *outlen)
+{
+ static char *buf = NULL;
+ static size_t len = 8;
+ XEvent e;
+ Status s;
+ KeySym sym;
+ size_t chars;
+
+ if (!buf) {
+ buf = malloc(len);
+ }
+
+ XNextEvent(w->dpy, &e);
+ if (XFilterEvent(&e, None) || e.type != KeyPress) {
+ *outlen = 0;
+ *outbuf = buf;
+ return;
+ }
+
+ for (;;) {
+ chars = Xutf8LookupString(w->ic, &e.xkey, buf, len - 1, &sym, &s);
+ if (s == XBufferOverflow) {
+ len = chars + 1;
+ buf = realloc(buf, len);
+ continue;
+ }
+ break;
+ }
+
+ *outlen = chars;
+ *outbuf = buf;
+}
+
void runes_window_destroy(RunesWindow *w)
{
XDestroyWindow(w->dpy, w->w);