X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=dmenu.c;h=5e9c36735152d883d00df4cc21eaad5b3172ce40;hb=e2a280541eab62717d6a9a72d047c832e5cb1edc;hp=eae56850e37d6cf78b570a46b1f5abe57e3df563;hpb=1cabeda5505dcc35d4d2ca2a09151a7c449fb401;p=dmenu.git diff --git a/dmenu.c b/dmenu.c index eae5685..5e9c367 100644 --- a/dmenu.c +++ b/dmenu.c @@ -287,6 +287,22 @@ nextrune(int inc) return n; } +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) { @@ -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; @@ -541,7 +575,7 @@ run(void) static void setup(void) { - int x, y, i = 0; + int x, y, i, j; unsigned int du; XSetWindowAttributes swa; XIM xim; @@ -551,9 +585,8 @@ setup(void) #ifdef XINERAMA XineramaScreenInfo *info; Window pw; - int a, j, di, n, area = 0; + int a, di, n, area = 0; #endif - /* init appearance */ for (j = 0; j < SchemeLast; j++) scheme[j] = drw_scm_create(drw, colors[j], 2); @@ -566,6 +599,7 @@ setup(void) lines = MAX(lines, 0); mh = (lines + 1) * bh; #ifdef XINERAMA + i = 0; if (parentwin == root && (info = XineramaQueryScreens(dpy, &n))) { XGetInputFocus(dpy, &w, &di); if (mon >= 0 && mon < n)