]> git.mdlowis.com Git - projs/tide.git/commitdiff
added key input processing
authorMichael D. Lowis <mike@mdlowis.com>
Sat, 22 Dec 2018 03:51:47 +0000 (22:51 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Sat, 22 Dec 2018 03:51:47 +0000 (22:51 -0500)
inc/x11.h
src/lib/x11.c
src/pick.c

index e2693fc03c1113d3457553ee6a7b5303f46c330c..33fbcee8a4f33c6a19004ea3f66034c10028e3f7 100644 (file)
--- a/inc/x11.h
+++ b/inc/x11.h
@@ -120,7 +120,7 @@ static void x11_show(XConf* x) {
 
 static void x11_event_loop(XConf* x, void (*redraw)(XConf* x)) {
     if (redraw) redraw(x);
-    for (XEvent e;;) {
+    for (XEvent e; x->running;) {
         XNextEvent(x->display, &e);
         if (x->eventfns[e.type])
             x->eventfns[e.type](x, &e);
@@ -173,4 +173,16 @@ static void x11_flip(XConf* x) {
     XFlush(x->display);
 }
 
+static KeySym x11_getkey(XConf* x, XEvent* e) {
+    char buf[8];
+    KeySym key;
+    Status status;
+    /* Read the key string */
+    if (x->xic)
+        Xutf8LookupString(x->xic, &(e->xkey), buf, sizeof(buf), &key, &status);
+    else
+        XLookupString(&(e->xkey), buf, sizeof(buf), &key, 0);
+    return key;
+}
+
 #pragma GCC diagnostic pop
index bccc0b0f969f4ac73e20c0fd59c3add54a92b2db..4e58603626924f77150479e0dd754fdbc8cb2d6d 100644 (file)
@@ -108,15 +108,8 @@ static uint32_t special_keys(uint32_t key) {
     return (!key ? RUNE_ERR : key);
 }
 
-static uint32_t getkey(XEvent* e) {
-    char buf[8];
-    KeySym key;
-    Status status;
-    /* Read the key string */
-    if (X.xic)
-        Xutf8LookupString(X.xic, &(e->xkey), buf, sizeof(buf), &key, &status);
-    else
-        XLookupString(&(e->xkey), buf, sizeof(buf), &key, 0);
+static uint32_t getkey(XConf* x, XEvent* e) {
+    KeySym key = x11_getkey(x, e);
     /* if it's ascii, just return it */
     if (key >= 0x20 && key <= 0x7F)
         return (uint32_t)key;
@@ -300,7 +293,7 @@ static void xkeypress(XConf* x, XEvent* e) {
     (void)x;
     Now = e->xkey.time;
     Focused = (e->xkey.y <= Divider ? TAGS : EDIT);
-    uint32_t key = getkey(e);
+    uint32_t key = getkey(x, e);
     if (key == RUNE_ERR) return;
     KeyBtnState = e->xkey.state;
     int mods = KeyBtnState & (ModCtrl|ModShift|ModAlt);
@@ -439,7 +432,7 @@ static void xupdate(Job* job) {
         for (int status; waitpid(-1, &status, WNOHANG) > 0;);
     }
     if (nqueued || !job) {
-            /* force update the title */
+        /* force update the title */
         win_title(NULL);
         /* determine the size of the regions */
         size_t maxtagrows = ((X.height/4) / X.tagfont->height);
index 2113b6525fa712d8efa032620826564246f9dea3..5f5049b5a53a0d2d3ec35ad6d526b83769f99a55 100644 (file)
@@ -108,8 +108,26 @@ static void score(void) {
 }
 
 static void xkeypress(XConf* x, XEvent* e) {
-    (void)x, (void)e;
-    score();
+    KeySym key = x11_getkey(x, e);
+    if (key == XK_Return) {
+        x->running = false;
+    } else if (key == XK_Escape) {
+        x->running = false;
+        ChoiceIdx = SIZE_MAX;
+    } else if (key == XK_Up) {
+        if (ChoiceIdx <= vec_size(&Choices))
+            ChoiceIdx++;
+    } else if (key == XK_Down) {
+        if (ChoiceIdx > 0)
+            ChoiceIdx--;
+    } else if (key == XK_BackSpace) {
+        if (QueryIdx > 0)
+            Query[--QueryIdx] = '\0';
+    } else if (key >= 0x20 && key <= 0x7F) {
+        if (QueryIdx < sizeof(Query)-1)
+            Query[QueryIdx++] = key;
+        score();
+    }
 }
 
 static void xbtnpress(XConf* x, XEvent* e) {