cleaned up

This commit is contained in:
Connor Lane Smith 2010-06-16 15:36:17 +01:00
parent 6366f94e36
commit b27ffbd78b
1 changed files with 21 additions and 31 deletions

52
dmenu.c
View File

@ -93,7 +93,7 @@ static Item *next = NULL;
static Item *prev = NULL; static Item *prev = NULL;
static Item *curr = NULL; static Item *curr = NULL;
static Window parent, win; static Window parent, win;
static int (*fstrncmp)(const char *, const char *, size_t n) = strncmp; static int (*fstrncmp)(const char *, const char *, size_t) = strncmp;
static char *(*fstrstr)(const char *, const char *) = strstr; static char *(*fstrstr)(const char *, const char *) = strstr;
static unsigned int lines = 0; static unsigned int lines = 0;
static void (*calcoffsets)(void) = calcoffsetsh; static void (*calcoffsets)(void) = calcoffsetsh;
@ -144,8 +144,7 @@ cistrstr(const char *s, const char *sub) {
if(!sub) if(!sub)
return (char *)s; return (char *)s;
if((c = *sub++) != '\0') { if((c = tolower(*sub++)) != '\0') {
c = tolower(c);
len = strlen(sub); len = strlen(sub);
do { do {
do { do {
@ -199,7 +198,7 @@ drawmenu(void) {
/* print command */ /* print command */
if(cmdw && item && lines == 0) if(cmdw && item && lines == 0)
dc.w = cmdw; dc.w = cmdw;
drawtext(text[0] ? text : NULL, dc.norm); drawtext(*text ? text : NULL, dc.norm);
drawcursor(); drawcursor();
if(curr) { if(curr) {
if(lines > 0) if(lines > 0)
@ -345,15 +344,13 @@ kpress(XKeyEvent * e) {
len = strlen(text); len = strlen(text);
num = XLookupString(e, buf, sizeof buf, &ksym, NULL); num = XLookupString(e, buf, sizeof buf, &ksym, NULL);
if(IsKeypadKey(ksym)) { if(ksym == XK_KP_Enter)
if(ksym == XK_KP_Enter) ksym = XK_Return;
ksym = XK_Return; else if(ksym >= XK_KP_0 && ksym <= XK_KP_9)
else if(ksym >= XK_KP_0 && ksym <= XK_KP_9) ksym = (ksym - XK_KP_0) + XK_0;
ksym = (ksym - XK_KP_0) + XK_0; else if(IsFunctionKey(ksym) || IsKeypadKey(ksym)
} || IsMiscFunctionKey(ksym) || IsPFKey(ksym)
if(IsFunctionKey(ksym) || IsKeypadKey(ksym) || IsPrivateKeypadKey(ksym))
|| IsMiscFunctionKey(ksym) || IsPFKey(ksym)
|| IsPrivateKeypadKey(ksym))
return; return;
/* first check if a control mask is omitted */ /* first check if a control mask is omitted */
if(e->state & ControlMask) { if(e->state & ControlMask) {
@ -405,7 +402,8 @@ kpress(XKeyEvent * e) {
} }
if(CLEANMASK(e->state) & Mod1Mask) { if(CLEANMASK(e->state) & Mod1Mask) {
switch(ksym) { switch(ksym) {
default: return; default:
return;
case XK_h: case XK_h:
ksym = XK_Left; ksym = XK_Left;
break; break;
@ -491,17 +489,15 @@ kpress(XKeyEvent * e) {
case XK_Left: case XK_Left:
case XK_Up: case XK_Up:
if(sel && sel->left){ if(sel && sel->left){
sel=sel->left; sel = sel->left;
if(sel->right == curr) { if(sel->right == curr) {
curr = prev; curr = prev;
calcoffsets(); calcoffsets();
} }
} }
else if(cursor > 0) { else if(cursor > 0)
do { while(cursor-- > 0 && !IS_UTF8_1ST_CHAR(text[cursor]));
cursor--; else
} while(cursor > 0 && !IS_UTF8_1ST_CHAR(text[cursor]));
} else
return; return;
break; break;
case XK_Next: case XK_Next:
@ -526,12 +522,10 @@ kpress(XKeyEvent * e) {
break; break;
case XK_Right: case XK_Right:
case XK_Down: case XK_Down:
if(cursor < len) { if(cursor < len)
do { while(cursor++ < len && !IS_UTF8_1ST_CHAR(text[cursor]));
cursor++; else if(sel && sel->right) {
} while(cursor < len && !IS_UTF8_1ST_CHAR(text[cursor])); sel = sel->right;
} else if(sel && sel->right) {
sel=sel->right;
if(sel == next) { if(sel == next) {
curr = next; curr = next;
calcoffsets(); calcoffsets();
@ -605,10 +599,8 @@ readstdin(void) {
buf[--len] = '\0'; buf[--len] = '\0';
if(!(p = strdup(buf))) if(!(p = strdup(buf)))
eprint("dmenu: cannot strdup %u bytes\n", len); eprint("dmenu: cannot strdup %u bytes\n", len);
if(max < len || !maxname) { if((max = MAX(max, len)) == len)
maxname = p; maxname = p;
max = len;
}
if(!(new = malloc(sizeof *new))) if(!(new = malloc(sizeof *new)))
eprint("dmenu: cannot malloc %u bytes\n", sizeof *new); eprint("dmenu: cannot malloc %u bytes\n", sizeof *new);
new->next = new->left = new->right = NULL; new->next = new->left = new->right = NULL;
@ -628,8 +620,6 @@ run(void) {
/* main event loop */ /* main event loop */
while(running && !XNextEvent(dpy, &ev)) while(running && !XNextEvent(dpy, &ev))
switch (ev.type) { switch (ev.type) {
default: /* ignore all crap */
break;
case KeyPress: case KeyPress:
kpress(&ev.xkey); kpress(&ev.xkey);
break; break;