1
0
Fork 0

added ^K, optimisations

This commit is contained in:
Connor Lane Smith 2010-06-20 00:44:26 +01:00
parent 4229fb7b78
commit 4983707c70

26
dmenu.c
View file

@ -79,9 +79,9 @@ static char text[4096];
static int cmdw = 0; static int cmdw = 0;
static int promptw = 0; static int promptw = 0;
static int ret = 0; static int ret = 0;
static int cursor = 0;
static int screen; static int screen;
static unsigned int mw, mh; static unsigned int mw, mh;
static unsigned int cursor = 0;
static unsigned int numlockmask = 0; static unsigned int numlockmask = 0;
static Bool running = True; static Bool running = True;
static Display *dpy; static Display *dpy;
@ -338,8 +338,8 @@ initfont(const char *fontstr) {
void void
kpress(XKeyEvent * e) { kpress(XKeyEvent * e) {
char buf[sizeof text]; char buf[sizeof text];
int i, num; int num;
unsigned int len; unsigned int i, len;
KeySym ksym; KeySym ksym;
len = strlen(text); len = strlen(text);
@ -381,6 +381,10 @@ kpress(XKeyEvent * e) {
case XK_J: case XK_J:
ksym = XK_Return; ksym = XK_Return;
break; break;
case XK_k:
case XK_K:
text[cursor] = '\0';
break;
case XK_u: case XK_u:
case XK_U: case XK_U:
memmove(text, text + cursor, sizeof text - cursor + 1); memmove(text, text + cursor, sizeof text - cursor + 1);
@ -450,12 +454,12 @@ kpress(XKeyEvent * e) {
} }
break; break;
case XK_BackSpace: case XK_BackSpace:
if(cursor > 0) { if(cursor == 0)
for(i = 1; cursor - i > 0 && !IS_UTF8_1ST_CHAR(text[cursor - i]); i++); return;
memmove(text + cursor - i, text + cursor, sizeof text - cursor + i); for(i = 1; cursor - i > 0 && !IS_UTF8_1ST_CHAR(text[cursor - i]); i++);
cursor -= i; memmove(text + cursor - i, text + cursor, sizeof text - cursor + i);
match(text); cursor -= i;
} match(text);
break; break;
case XK_Delete: case XK_Delete:
for(i = 1; cursor + i < len && !IS_UTF8_1ST_CHAR(text[cursor + i]); i++); for(i = 1; cursor + i < len && !IS_UTF8_1ST_CHAR(text[cursor + i]); i++);
@ -477,7 +481,7 @@ kpress(XKeyEvent * e) {
case XK_Escape: case XK_Escape:
ret = 1; ret = 1;
running = False; running = False;
break; return;
case XK_Home: case XK_Home:
if(sel == item) { if(sel == item) {
cursor = 0; cursor = 0;
@ -519,7 +523,7 @@ kpress(XKeyEvent * e) {
fprintf(stdout, "%s", sel->text); fprintf(stdout, "%s", sel->text);
fflush(stdout); fflush(stdout);
running = False; running = False;
break; return;
case XK_Right: case XK_Right:
case XK_Down: case XK_Down:
if(cursor < len) if(cursor < len)