diff options
Diffstat (limited to 'dmenu.c')
-rw-r--r-- | dmenu.c | 21 |
1 files changed, 12 insertions, 9 deletions
@@ -3,6 +3,7 @@ | |||
3 | #include <stdio.h> | 3 | #include <stdio.h> |
4 | #include <stdlib.h> | 4 | #include <stdlib.h> |
5 | #include <string.h> | 5 | #include <string.h> |
6 | #include <strings.h> | ||
6 | #include <unistd.h> | 7 | #include <unistd.h> |
7 | #include <X11/Xlib.h> | 8 | #include <X11/Xlib.h> |
8 | #include <X11/Xatom.h> | 9 | #include <X11/Xatom.h> |
@@ -231,13 +232,14 @@ insert(const char *str, ssize_t n) { | |||
231 | void | 232 | void |
232 | keypress(XKeyEvent *ev) { | 233 | keypress(XKeyEvent *ev) { |
233 | char buf[32]; | 234 | char buf[32]; |
234 | size_t len; | ||
235 | KeySym ksym; | 235 | KeySym ksym; |
236 | 236 | ||
237 | len = strlen(text); | ||
238 | XLookupString(ev, buf, sizeof buf, &ksym, NULL); | 237 | XLookupString(ev, buf, sizeof buf, &ksym, NULL); |
239 | if(ev->state & ControlMask) | 238 | if(ev->state & ControlMask) { |
240 | switch(tolower(ksym)) { | 239 | KeySym lower, upper; |
240 | |||
241 | XConvertCase(ksym, &lower, &upper); | ||
242 | switch(lower) { | ||
241 | default: | 243 | default: |
242 | return; | 244 | return; |
243 | case XK_a: | 245 | case XK_a: |
@@ -290,13 +292,14 @@ keypress(XKeyEvent *ev) { | |||
290 | XConvertSelection(dc->dpy, XA_PRIMARY, utf8, utf8, win, CurrentTime); | 292 | XConvertSelection(dc->dpy, XA_PRIMARY, utf8, utf8, win, CurrentTime); |
291 | return; | 293 | return; |
292 | } | 294 | } |
295 | } | ||
293 | switch(ksym) { | 296 | switch(ksym) { |
294 | default: | 297 | default: |
295 | if(!iscntrl(*buf)) | 298 | if(!iscntrl(*buf)) |
296 | insert(buf, strlen(buf)); | 299 | insert(buf, strlen(buf)); |
297 | break; | 300 | break; |
298 | case XK_Delete: | 301 | case XK_Delete: |
299 | if(cursor == len) | 302 | if(text[cursor] == '\0') |
300 | return; | 303 | return; |
301 | cursor = nextrune(+1); | 304 | cursor = nextrune(+1); |
302 | case XK_BackSpace: | 305 | case XK_BackSpace: |
@@ -304,8 +307,8 @@ keypress(XKeyEvent *ev) { | |||
304 | insert(NULL, nextrune(-1) - cursor); | 307 | insert(NULL, nextrune(-1) - cursor); |
305 | break; | 308 | break; |
306 | case XK_End: | 309 | case XK_End: |
307 | if(cursor < len) { | 310 | if(text[cursor] != '\0') { |
308 | cursor = len; | 311 | cursor = strlen(text); |
309 | break; | 312 | break; |
310 | } | 313 | } |
311 | if(next) { | 314 | if(next) { |
@@ -358,7 +361,7 @@ keypress(XKeyEvent *ev) { | |||
358 | fputs((sel && !(ev->state & ShiftMask)) ? sel->text : text, stdout); | 361 | fputs((sel && !(ev->state & ShiftMask)) ? sel->text : text, stdout); |
359 | exit(EXIT_SUCCESS); | 362 | exit(EXIT_SUCCESS); |
360 | case XK_Right: | 363 | case XK_Right: |
361 | if(cursor < len) { | 364 | if(text[cursor] != '\0') { |
362 | cursor = nextrune(+1); | 365 | cursor = nextrune(+1); |
363 | break; | 366 | break; |
364 | } | 367 | } |
@@ -385,7 +388,7 @@ void | |||
385 | match(Bool sub) { | 388 | match(Bool sub) { |
386 | size_t len = strlen(text); | 389 | size_t len = strlen(text); |
387 | Item *lexact, *lprefix, *lsubstr, *exactend, *prefixend, *substrend; | 390 | Item *lexact, *lprefix, *lsubstr, *exactend, *prefixend, *substrend; |
388 | Item *item, *next = NULL; | 391 | Item *item, *next; |
389 | 392 | ||
390 | lexact = lprefix = lsubstr = exactend = prefixend = substrend = NULL; | 393 | lexact = lprefix = lsubstr = exactend = prefixend = substrend = NULL; |
391 | for(item = sub ? matches : items; item && item->text; item = next) { | 394 | for(item = sub ? matches : items; item && item->text; item = next) { |