diff options
author | Anselm R Garbe <anselm@garbe.us> | 2010-05-29 12:55:38 +0100 |
---|---|---|
committer | Anselm R Garbe <anselm@garbe.us> | 2010-05-29 12:55:38 +0100 |
commit | 504b797be8ed4535a038974355a301fbf82e2509 (patch) | |
tree | 0eef4e815a0d36e3153d6e52d3f9c1591da5fbad | |
parent | 503ca75af46d7b2756cad03b546f9570a1b57850 (diff) |
applied Ramils patch
-rw-r--r-- | dmenu.c | 31 |
1 files changed, 21 insertions, 10 deletions
@@ -19,6 +19,7 @@ | |||
19 | #define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH)) | 19 | #define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH)) |
20 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) | 20 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) |
21 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) | 21 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) |
22 | #define IS_UTF8_1ST_CHAR(c) ((((c) & 0xc0) == 0xc0) || !((c) & 0x80)) | ||
22 | 23 | ||
23 | /* enums */ | 24 | /* enums */ |
24 | enum { ColFG, ColBG, ColLast }; | 25 | enum { ColFG, ColBG, ColLast }; |
@@ -360,7 +361,7 @@ initfont(const char *fontstr) { | |||
360 | void | 361 | void |
361 | kpress(XKeyEvent * e) { | 362 | kpress(XKeyEvent * e) { |
362 | char buf[sizeof text]; | 363 | char buf[sizeof text]; |
363 | int i, num; | 364 | int i, num, off; |
364 | unsigned int len; | 365 | unsigned int len; |
365 | KeySym ksym; | 366 | KeySym ksym; |
366 | 367 | ||
@@ -475,13 +476,19 @@ kpress(XKeyEvent * e) { | |||
475 | break; | 476 | break; |
476 | case XK_BackSpace: | 477 | case XK_BackSpace: |
477 | if(cursor > 0) { | 478 | if(cursor > 0) { |
478 | memmove(text + cursor - 1, text + cursor, sizeof text - cursor + 1); | 479 | off = 1; |
479 | cursor--; | 480 | while(cursor > off && !IS_UTF8_1ST_CHAR(text[cursor - off])) |
481 | off++; | ||
482 | memmove(text + cursor - off, text + cursor, sizeof text - cursor + off); | ||
483 | cursor -= off; | ||
480 | match(text); | 484 | match(text); |
481 | } | 485 | } |
482 | break; | 486 | break; |
483 | case XK_Delete: | 487 | case XK_Delete: |
484 | memmove(text + cursor, text + cursor + 1, sizeof text - cursor); | 488 | off = 1; |
489 | while(cursor + off < sizeof text - 1 && !IS_UTF8_1ST_CHAR(text[cursor + off])) | ||
490 | off++; | ||
491 | memmove(text + cursor, text + cursor + off, sizeof text - cursor); | ||
485 | match(text); | 492 | match(text); |
486 | break; | 493 | break; |
487 | case XK_End: | 494 | case XK_End: |
@@ -517,9 +524,11 @@ kpress(XKeyEvent * e) { | |||
517 | calcoffsets(); | 524 | calcoffsets(); |
518 | } | 525 | } |
519 | } | 526 | } |
520 | else if(cursor > 0) | 527 | else if(cursor > 0) { |
521 | cursor--; | 528 | do { |
522 | else | 529 | cursor--; |
530 | } while(cursor > 0 && !IS_UTF8_1ST_CHAR(text[cursor])); | ||
531 | } else | ||
523 | return; | 532 | return; |
524 | break; | 533 | break; |
525 | case XK_Next: | 534 | case XK_Next: |
@@ -544,9 +553,11 @@ kpress(XKeyEvent * e) { | |||
544 | break; | 553 | break; |
545 | case XK_Right: | 554 | case XK_Right: |
546 | case XK_Down: | 555 | case XK_Down: |
547 | if(cursor < len) | 556 | if(cursor < len) { |
548 | cursor++; | 557 | do { |
549 | else if(sel && sel->right) { | 558 | cursor++; |
559 | } while(cursor < len && !IS_UTF8_1ST_CHAR(text[cursor])); | ||
560 | } else if(sel && sel->right) { | ||
550 | sel=sel->right; | 561 | sel=sel->right; |
551 | if(sel == next) { | 562 | if(sel == next) { |
552 | curr = next; | 563 | curr = next; |