aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dmenu.112
-rw-r--r--dmenu.c34
2 files changed, 46 insertions, 0 deletions
diff --git a/dmenu.1 b/dmenu.1
index 9eab758..fbb3f76 100644
--- a/dmenu.1
+++ b/dmenu.1
@@ -100,6 +100,12 @@ Confirm input. Prints the input text to stdout and exits, returning success.
100.B Escape 100.B Escape
101Exit without selecting an item, returning failure. 101Exit without selecting an item, returning failure.
102.TP 102.TP
103.B Ctrl-Left
104Move cursor to the start of the current word
105.TP
106.B Ctrl-Right
107Move cursor to the end of the current word
108.TP
103C\-a 109C\-a
104Home 110Home
105.TP 111.TP
@@ -160,6 +166,12 @@ Paste from primary X selection
160C\-Y 166C\-Y
161Paste from X clipboard 167Paste from X clipboard
162.TP 168.TP
169M\-b
170Move cursor to the start of the current word
171.TP
172M\-f
173Move cursor to the end of the current word
174.TP
163M\-g 175M\-g
164Home 176Home
165.TP 177.TP
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)
288} 288}
289 289
290static void 290static void
291movewordedge(int dir)
292{
293 if (dir < 0) { /* move cursor to the start of the word*/
294 while (cursor > 0 && strchr(worddelimiters, text[nextrune(-1)]))
295 cursor = nextrune(-1);
296 while (cursor > 0 && !strchr(worddelimiters, text[nextrune(-1)]))
297 cursor = nextrune(-1);
298 } else { /* move cursor to the end of the word */
299 while (text[cursor] && strchr(worddelimiters, text[cursor]))
300 cursor = nextrune(+1);
301 while (text[cursor] && !strchr(worddelimiters, text[cursor]))
302 cursor = nextrune(+1);
303 }
304}
305
306static void
291keypress(XKeyEvent *ev) 307keypress(XKeyEvent *ev)
292{ 308{
293 char buf[32]; 309 char buf[32];
@@ -334,6 +350,14 @@ keypress(XKeyEvent *ev)
334 XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY, 350 XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY,
335 utf8, utf8, win, CurrentTime); 351 utf8, utf8, win, CurrentTime);
336 return; 352 return;
353 case XK_Left:
354 movewordedge(-1);
355 ksym = NoSymbol;
356 break;
357 case XK_Right:
358 movewordedge(+1);
359 ksym = NoSymbol;
360 break;
337 case XK_Return: 361 case XK_Return:
338 case XK_KP_Enter: 362 case XK_KP_Enter:
339 break; 363 break;
@@ -345,6 +369,14 @@ keypress(XKeyEvent *ev)
345 } 369 }
346 else if (ev->state & Mod1Mask) 370 else if (ev->state & Mod1Mask)
347 switch(ksym) { 371 switch(ksym) {
372 case XK_b:
373 movewordedge(-1);
374 ksym = NoSymbol;
375 break;
376 case XK_f:
377 movewordedge(+1);
378 ksym = NoSymbol;
379 break;
348 case XK_g: ksym = XK_Home; break; 380 case XK_g: ksym = XK_Home; break;
349 case XK_G: ksym = XK_End; break; 381 case XK_G: ksym = XK_End; break;
350 case XK_h: ksym = XK_Up; break; 382 case XK_h: ksym = XK_Up; break;
@@ -359,6 +391,8 @@ keypress(XKeyEvent *ev)
359 if (!iscntrl(*buf)) 391 if (!iscntrl(*buf))
360 insert(buf, len); 392 insert(buf, len);
361 break; 393 break;
394 case NoSymbol:
395 break;
362 case XK_Delete: 396 case XK_Delete:
363 if (text[cursor] == '\0') 397 if (text[cursor] == '\0')
364 return; 398 return;