[hackers] [dmenu] Fix handling of input strings || Hiltjo Posthuma

From: <git_AT_suckless.org>
Date: Sun, 22 Apr 2018 14:34:23 +0200 (CEST)

commit b6d2cc9aea979cb3557db39dbe65a2870d13e597
Author: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
AuthorDate: Fri Mar 16 16:51:22 2018 +0100
Commit: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
CommitDate: Sun Apr 22 14:09:05 2018 +0200

    Fix handling of input strings

diff --git a/dmenu.c b/dmenu.c
index 5e9c367..c852e92 100644
--- a/dmenu.c
+++ b/dmenu.c
_AT_@ -308,13 +308,21 @@ keypress(XKeyEvent *ev)
 {
         char buf[32];
         int len;
- KeySym ksym = NoSymbol;
+ KeySym ksym;
         Status status;
 
         len = XmbLookupString(xic, ev, buf, sizeof buf, &ksym, &status);
- if (status == XBufferOverflow)
+ switch (status) {
+ default: /* XLookupNone, XBufferOverflow */
                 return;
- if (ev->state & ControlMask)
+ case XLookupChars:
+ goto insert;
+ case XLookupKeySym:
+ case XLookupBoth:
+ break;
+ }
+
+ if (ev->state & ControlMask) {
                 switch(ksym) {
                 case XK_a: ksym = XK_Home; break;
                 case XK_b: ksym = XK_Left; break;
_AT_@ -352,12 +360,10 @@ keypress(XKeyEvent *ev)
                         return;
                 case XK_Left:
                         movewordedge(-1);
- ksym = NoSymbol;
- break;
+ goto draw;
                 case XK_Right:
                         movewordedge(+1);
- ksym = NoSymbol;
- break;
+ goto draw;
                 case XK_Return:
                 case XK_KP_Enter:
                         break;
_AT_@ -367,16 +373,14 @@ keypress(XKeyEvent *ev)
                 default:
                         return;
                 }
- else if (ev->state & Mod1Mask)
+ } else if (ev->state & Mod1Mask) {
                 switch(ksym) {
                 case XK_b:
                         movewordedge(-1);
- ksym = NoSymbol;
- break;
+ goto draw;
                 case XK_f:
                         movewordedge(+1);
- ksym = NoSymbol;
- break;
+ goto draw;
                 case XK_g: ksym = XK_Home; break;
                 case XK_G: ksym = XK_End; break;
                 case XK_h: ksym = XK_Up; break;
_AT_@ -386,13 +390,14 @@ keypress(XKeyEvent *ev)
                 default:
                         return;
                 }
+ }
+
         switch(ksym) {
         default:
+insert:
                 if (!iscntrl(*buf))
                         insert(buf, len);
                 break;
- case NoSymbol:
- break;
         case XK_Delete:
                 if (text[cursor] == '\0')
                         return;
_AT_@ -489,6 +494,8 @@ keypress(XKeyEvent *ev)
                 match();
                 break;
         }
+
+draw:
         drawmenu();
 }
 
Received on Sun Apr 22 2018 - 14:34:23 CEST

This archive was generated by hypermail 2.3.0 : Sun Apr 22 2018 - 14:36:35 CEST