strip out keypress stuff
This commit is contained in:
parent
df016717ca
commit
12325c692d
204
dmenubar/dmenu.c
204
dmenubar/dmenu.c
@ -171,6 +171,7 @@ drawmenu(void)
|
||||
static void
|
||||
grabfocus(void)
|
||||
{
|
||||
return;
|
||||
struct timespec ts = { .tv_sec = 0, .tv_nsec = 10000000 };
|
||||
Window focuswin;
|
||||
int i, revertwin;
|
||||
@ -188,6 +189,7 @@ grabfocus(void)
|
||||
static void
|
||||
grabkeyboard(void)
|
||||
{
|
||||
return;
|
||||
struct timespec ts = { .tv_sec = 0, .tv_nsec = 1000000 };
|
||||
int i;
|
||||
|
||||
@ -297,198 +299,6 @@ movewordedge(int dir)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
keypress(XKeyEvent *ev)
|
||||
{
|
||||
char buf[32];
|
||||
int len;
|
||||
KeySym ksym;
|
||||
Status status;
|
||||
|
||||
len = XmbLookupString(xic, ev, buf, sizeof buf, &ksym, &status);
|
||||
switch (status) {
|
||||
default: /* XLookupNone, XBufferOverflow */
|
||||
return;
|
||||
case XLookupChars:
|
||||
goto insert;
|
||||
case XLookupKeySym:
|
||||
case XLookupBoth:
|
||||
break;
|
||||
}
|
||||
|
||||
if (ev->state & ControlMask) {
|
||||
switch(ksym) {
|
||||
case XK_a: ksym = XK_Home; break;
|
||||
case XK_b: ksym = XK_Left; break;
|
||||
case XK_c: ksym = XK_Escape; break;
|
||||
case XK_d: ksym = XK_Delete; break;
|
||||
case XK_e: ksym = XK_End; break;
|
||||
case XK_f: ksym = XK_Right; break;
|
||||
case XK_g: ksym = XK_Escape; break;
|
||||
case XK_h: ksym = XK_BackSpace; break;
|
||||
case XK_i: ksym = XK_Tab; break;
|
||||
case XK_j: /* fallthrough */
|
||||
case XK_J: /* fallthrough */
|
||||
case XK_m: /* fallthrough */
|
||||
case XK_M: ksym = XK_Return; ev->state &= ~ControlMask; break;
|
||||
case XK_n: ksym = XK_Down; break;
|
||||
case XK_p: ksym = XK_Up; break;
|
||||
|
||||
case XK_k: /* delete right */
|
||||
text[cursor] = '\0';
|
||||
match();
|
||||
break;
|
||||
case XK_u: /* delete left */
|
||||
insert(NULL, 0 - cursor);
|
||||
break;
|
||||
case XK_w: /* delete word */
|
||||
while (cursor > 0 && strchr(worddelimiters, text[nextrune(-1)]))
|
||||
insert(NULL, nextrune(-1) - cursor);
|
||||
while (cursor > 0 && !strchr(worddelimiters, text[nextrune(-1)]))
|
||||
insert(NULL, nextrune(-1) - cursor);
|
||||
break;
|
||||
case XK_y: /* paste selection */
|
||||
case XK_Y:
|
||||
XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY,
|
||||
utf8, utf8, win, CurrentTime);
|
||||
return;
|
||||
case XK_Left:
|
||||
movewordedge(-1);
|
||||
goto draw;
|
||||
case XK_Right:
|
||||
movewordedge(+1);
|
||||
goto draw;
|
||||
case XK_Return:
|
||||
case XK_KP_Enter:
|
||||
break;
|
||||
case XK_bracketleft:
|
||||
cleanup();
|
||||
exit(1);
|
||||
default:
|
||||
return;
|
||||
}
|
||||
} else if (ev->state & Mod1Mask) {
|
||||
switch(ksym) {
|
||||
case XK_b:
|
||||
movewordedge(-1);
|
||||
goto draw;
|
||||
case XK_f:
|
||||
movewordedge(+1);
|
||||
goto draw;
|
||||
case XK_g: ksym = XK_Home; break;
|
||||
case XK_G: ksym = XK_End; break;
|
||||
case XK_h: ksym = XK_Up; break;
|
||||
case XK_j: ksym = XK_Next; break;
|
||||
case XK_k: ksym = XK_Prior; break;
|
||||
case XK_l: ksym = XK_Down; break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
switch(ksym) {
|
||||
default:
|
||||
insert:
|
||||
if (!iscntrl(*buf))
|
||||
insert(buf, len);
|
||||
break;
|
||||
case XK_Delete:
|
||||
if (text[cursor] == '\0')
|
||||
return;
|
||||
cursor = nextrune(+1);
|
||||
/* fallthrough */
|
||||
case XK_BackSpace:
|
||||
if (cursor == 0)
|
||||
return;
|
||||
insert(NULL, nextrune(-1) - cursor);
|
||||
break;
|
||||
case XK_End:
|
||||
if (text[cursor] != '\0') {
|
||||
cursor = strlen(text);
|
||||
break;
|
||||
}
|
||||
if (next) {
|
||||
/* jump to end of list and position items in reverse */
|
||||
curr = matchend;
|
||||
calcoffsets();
|
||||
curr = prev;
|
||||
calcoffsets();
|
||||
while (next && (curr = curr->right))
|
||||
calcoffsets();
|
||||
}
|
||||
sel = matchend;
|
||||
break;
|
||||
case XK_Escape:
|
||||
cleanup();
|
||||
exit(1);
|
||||
case XK_Home:
|
||||
if (sel == matches) {
|
||||
cursor = 0;
|
||||
break;
|
||||
}
|
||||
sel = curr = matches;
|
||||
calcoffsets();
|
||||
break;
|
||||
case XK_Left:
|
||||
if (cursor > 0 && (!sel || !sel->left)) {
|
||||
cursor = nextrune(-1);
|
||||
break;
|
||||
}
|
||||
/* fallthrough */
|
||||
case XK_Up:
|
||||
if (sel && sel->left && (sel = sel->left)->right == curr) {
|
||||
curr = prev;
|
||||
calcoffsets();
|
||||
}
|
||||
break;
|
||||
case XK_Next:
|
||||
if (!next)
|
||||
return;
|
||||
sel = curr = next;
|
||||
calcoffsets();
|
||||
break;
|
||||
case XK_Prior:
|
||||
if (!prev)
|
||||
return;
|
||||
sel = curr = prev;
|
||||
calcoffsets();
|
||||
break;
|
||||
case XK_Return:
|
||||
case XK_KP_Enter:
|
||||
puts((sel && !(ev->state & ShiftMask)) ? sel->text : text);
|
||||
if (!(ev->state & ControlMask)) {
|
||||
cleanup();
|
||||
exit(0);
|
||||
}
|
||||
if (sel)
|
||||
sel->out = 1;
|
||||
break;
|
||||
case XK_Right:
|
||||
if (text[cursor] != '\0') {
|
||||
cursor = nextrune(+1);
|
||||
break;
|
||||
}
|
||||
/* fallthrough */
|
||||
case XK_Down:
|
||||
if (sel && sel->right && (sel = sel->right) == next) {
|
||||
curr = next;
|
||||
calcoffsets();
|
||||
}
|
||||
break;
|
||||
case XK_Tab:
|
||||
if (!sel)
|
||||
return;
|
||||
strncpy(text, sel->text, sizeof text - 1);
|
||||
text[sizeof text - 1] = '\0';
|
||||
cursor = strlen(text);
|
||||
match();
|
||||
break;
|
||||
}
|
||||
|
||||
draw:
|
||||
drawmenu();
|
||||
}
|
||||
|
||||
static void
|
||||
paste(void)
|
||||
{
|
||||
@ -558,9 +368,6 @@ run(void)
|
||||
if (ev.xfocus.window != win)
|
||||
grabfocus();
|
||||
break;
|
||||
case KeyPress:
|
||||
keypress(&ev.xkey);
|
||||
break;
|
||||
case SelectionNotify:
|
||||
if (ev.xselection.property == utf8)
|
||||
paste();
|
||||
@ -694,12 +501,7 @@ main(int argc, char *argv[])
|
||||
exit(0);
|
||||
} else if (!strcmp(argv[i], "-b")) /* appears at the bottom of the screen */
|
||||
topbar = 0;
|
||||
else if (!strcmp(argv[i], "-f")) /* grabs keyboard before reading stdin */
|
||||
fast = 1;
|
||||
else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
|
||||
fstrncmp = strncasecmp;
|
||||
fstrstr = cistrstr;
|
||||
} else if (i + 1 == argc)
|
||||
else if (i + 1 == argc)
|
||||
usage();
|
||||
/* these options take one argument */
|
||||
else if (!strcmp(argv[i], "-m"))
|
||||
|
Loading…
Reference in New Issue
Block a user