1
0
Fork 0

Fix handling of input strings

This commit is contained in:
Hiltjo Posthuma 2018-03-16 16:51:22 +01:00
parent 2f398981fe
commit b6d2cc9aea

35
dmenu.c
View file

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