aboutsummaryrefslogtreecommitdiff
path: root/dmenu.c
diff options
context:
space:
mode:
authorQuentin Rameau <quinq@fifth.space>2018-03-13 17:15:09 +0100
committerHiltjo Posthuma <hiltjo@codemadness.org>2018-03-13 20:10:46 +0100
commite2a280541eab62717d6a9a72d047c832e5cb1edc (patch)
tree5cdfb7c03fc76d7024e009dc3d9617cb5db48520 /dmenu.c
parent889512811d7ae410eb4ab60be3568278b3e23f2e (diff)
downloaddmenu-e2a280541eab62717d6a9a72d047c832e5cb1edc.tar.gz
dmenu-e2a280541eab62717d6a9a72d047c832e5cb1edc.tar.bz2
dmenu-e2a280541eab62717d6a9a72d047c832e5cb1edc.zip
add key bindings for moving to the word start or end
Mod1+b/^Left and Mod1+f/^Right
Diffstat (limited to 'dmenu.c')
-rw-r--r--dmenu.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/dmenu.c b/dmenu.c
index a246111..5e9c367 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -288,6 +288,22 @@ nextrune(int inc)
}
static void
+movewordedge(int dir)
+{
+ if (dir < 0) { /* move cursor to the start of the word*/
+ while (cursor > 0 && strchr(worddelimiters, text[nextrune(-1)]))
+ cursor = nextrune(-1);
+ while (cursor > 0 && !strchr(worddelimiters, text[nextrune(-1)]))
+ cursor = nextrune(-1);
+ } else { /* move cursor to the end of the word */
+ while (text[cursor] && strchr(worddelimiters, text[cursor]))
+ cursor = nextrune(+1);
+ while (text[cursor] && !strchr(worddelimiters, text[cursor]))
+ cursor = nextrune(+1);
+ }
+}
+
+static void
keypress(XKeyEvent *ev)
{
char buf[32];
@@ -334,6 +350,14 @@ keypress(XKeyEvent *ev)
XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY,
utf8, utf8, win, CurrentTime);
return;
+ case XK_Left:
+ movewordedge(-1);
+ ksym = NoSymbol;
+ break;
+ case XK_Right:
+ movewordedge(+1);
+ ksym = NoSymbol;
+ break;
case XK_Return:
case XK_KP_Enter:
break;
@@ -345,6 +369,14 @@ keypress(XKeyEvent *ev)
}
else if (ev->state & Mod1Mask)
switch(ksym) {
+ case XK_b:
+ movewordedge(-1);
+ ksym = NoSymbol;
+ break;
+ case XK_f:
+ movewordedge(+1);
+ ksym = NoSymbol;
+ break;
case XK_g: ksym = XK_Home; break;
case XK_G: ksym = XK_End; break;
case XK_h: ksym = XK_Up; break;
@@ -359,6 +391,8 @@ keypress(XKeyEvent *ev)
if (!iscntrl(*buf))
insert(buf, len);
break;
+ case NoSymbol:
+ break;
case XK_Delete:
if (text[cursor] == '\0')
return;