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);
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
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;
(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);
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);
}
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) {