aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2018-03-16 16:51:22 +0100
committerHiltjo Posthuma <hiltjo@codemadness.org>2018-04-22 14:09:05 +0200
commitb6d2cc9aea979cb3557db39dbe65a2870d13e597 (patch)
treee19f4eb0f0639aedfcc5744ef6e7e957ac25333a
parent2f398981feb562285b0a96cd315bf2b3244c7309 (diff)
Fix handling of input strings
-rw-r--r--dmenu.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/dmenu.c b/dmenu.c
index 5e9c367..c852e92 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -308,13 +308,21 @@ keypress(XKeyEvent *ev)
308{ 308{
309 char buf[32]; 309 char buf[32];
310 int len; 310 int len;
311 KeySym ksym = NoSymbol; 311 KeySym ksym;
312 Status status; 312 Status status;
313 313
314 len = XmbLookupString(xic, ev, buf, sizeof buf, &ksym, &status); 314 len = XmbLookupString(xic, ev, buf, sizeof buf, &ksym, &status);
315 if (status == XBufferOverflow) 315 switch (status) {
316 default: /* XLookupNone, XBufferOverflow */
316 return; 317 return;
317 if (ev->state & ControlMask) 318 case XLookupChars:
319 goto insert;
320 case XLookupKeySym:
321 case XLookupBoth:
322 break;
323 }
324
325 if (ev->state & ControlMask) {
318 switch(ksym) { 326 switch(ksym) {
319 case XK_a: ksym = XK_Home; break; 327 case XK_a: ksym = XK_Home; break;
320 case XK_b: ksym = XK_Left; break; 328 case XK_b: ksym = XK_Left; break;
@@ -352,12 +360,10 @@ keypress(XKeyEvent *ev)
352 return; 360 return;
353 case XK_Left: 361 case XK_Left:
354 movewordedge(-1); 362 movewordedge(-1);
355 ksym = NoSymbol; 363 goto draw;
356 break;
357 case XK_Right: 364 case XK_Right:
358 movewordedge(+1); 365 movewordedge(+1);
359 ksym = NoSymbol; 366 goto draw;
360 break;
361 case XK_Return: 367 case XK_Return:
362 case XK_KP_Enter: 368 case XK_KP_Enter:
363 break; 369 break;
@@ -367,16 +373,14 @@ keypress(XKeyEvent *ev)
367 default: 373 default:
368 return; 374 return;
369 } 375 }
370 else if (ev->state & Mod1Mask) 376 } else if (ev->state & Mod1Mask) {
371 switch(ksym) { 377 switch(ksym) {
372 case XK_b: 378 case XK_b:
373 movewordedge(-1); 379 movewordedge(-1);
374 ksym = NoSymbol; 380 goto draw;
375 break;
376 case XK_f: 381 case XK_f:
377 movewordedge(+1); 382 movewordedge(+1);
378 ksym = NoSymbol; 383 goto draw;
379 break;
380 case XK_g: ksym = XK_Home; break; 384 case XK_g: ksym = XK_Home; break;
381 case XK_G: ksym = XK_End; break; 385 case XK_G: ksym = XK_End; break;
382 case XK_h: ksym = XK_Up; break; 386 case XK_h: ksym = XK_Up; break;
@@ -386,13 +390,14 @@ keypress(XKeyEvent *ev)
386 default: 390 default:
387 return; 391 return;
388 } 392 }
393 }
394
389 switch(ksym) { 395 switch(ksym) {
390 default: 396 default:
397insert:
391 if (!iscntrl(*buf)) 398 if (!iscntrl(*buf))
392 insert(buf, len); 399 insert(buf, len);
393 break; 400 break;
394 case NoSymbol:
395 break;
396 case XK_Delete: 401 case XK_Delete:
397 if (text[cursor] == '\0') 402 if (text[cursor] == '\0')
398 return; 403 return;
@@ -489,6 +494,8 @@ keypress(XKeyEvent *ev)
489 match(); 494 match();
490 break; 495 break;
491 } 496 }
497
498draw:
492 drawmenu(); 499 drawmenu();
493} 500}
494 501