From 9a33a72c6afd9042c8395f4318bf5d21e235694d Mon Sep 17 00:00:00 2001
From: Connor Lane Smith <cls@lubutu.com>
Date: Sun, 20 Jun 2010 15:04:15 +0100
Subject: [PATCH] updated manpage, changed keybinds M- binds tend to be wm
 level, and there were up to 3 binds for the same action M-{hjkl} also no
 longer made sense in vlist mode

---
 dmenu.1 | 46 ++++++++++++++-----------------
 dmenu.c | 84 +++++++++++++++++++++++++++------------------------------
 2 files changed, 59 insertions(+), 71 deletions(-)

diff --git a/dmenu.1 b/dmenu.1
index 03ebda8..c994ad7 100644
--- a/dmenu.1
+++ b/dmenu.1
@@ -14,12 +14,22 @@ dmenu \- dynamic menu
 .RB [ \-sb " <color>]"
 .RB [ \-sf " <color>]"
 .RB [ \-v ]
+
+.B dmenu_run
+[<options...>]
+
+.BR dmenu_path
 .SH DESCRIPTION
 .SS Overview
 dmenu is a generic menu for X, originally designed for
 .BR dwm (1).
 It manages huge amounts (up to 10.000 and more) of user defined menu items
 efficiently.
+
+dmenu_run is a dmenu script used by dwm which lists executables in the user's PATH
+and executes the selected item.
+
+dmenu_path is a script used by dmenu_run to find and cache a list of executables.
 .SS Options
 .TP
 .B \-i
@@ -33,7 +43,7 @@ reparents dmenu to the window specified by xid.
 .TP
 .B \-l <lines>
 activates vertical list mode.
-The given number of lines will be displayed. Window height will get adjusted.
+The given number of lines will be displayed. Window height will be adjusted.
 .TP
 .B \-fn <font>
 defines the font.
@@ -60,20 +70,9 @@ dmenu reads a list of newline-separated items from standard input and creates a
 menu.  When the user selects an item or enters any text and presses Return, his/her
 choice is printed to standard output and dmenu terminates.
 .P
-dmenu is completely controlled by the keyboard. The following keys are recognized:
-.TP
-.B Any printable character
-Appends the character to the text in the input field.  This works as a filter:
-only items containing this text will be displayed.
-.TP
-.B Left/Right (Up/Down) (Mod1\-h/Mod1\-l)
-Select the previous/next item.
-.TP
-.B PageUp/PageDown (Mod1\-k/Mod1\-j)
-Select the first item of the previous/next 'page' of items.
-.TP
-.B Home/End (Mod1\-g/Mod1\-G)
-Select the first/last item.
+dmenu is completely controlled by the keyboard. Besides standard Unix line editing,
+and item selection (Up/Down or Left/Right, PageUp/PageDown, Home/End), the following
+keys are recognized:
 .TP
 .B Tab (Control\-i)
 Copy the selected item to the input field.
@@ -84,24 +83,19 @@ Confirm selection and quit (print the selected item to standard output). Returns
 on termination.
 .TP
 .B Shift\-Return (Control\-Shift\-j)
-Confirm selection and quit (print the text in the input field to standard output).
+Confirm input and quit (print the text in the input field to standard output).
 Returns
 .B 0
 on termination.
 .TP
-.B Escape (Control\-bracketleft)
+.B Escape (Control\-c)
 Quit without selecting an item. Returns
 .B 1
 on termination.
 .TP
-.B Backspace (Control\-h)
-Remove a character from the input field.
-.TP
-.B Control\-u
-Remove all characters from the input field.
-.TP
-.B Control\-w
-Remove all characters of current word from the input field.
+.B Control\-y
+Pastes the X selection into the input field. This requires
+.BR sselp (1).
 .SH SEE ALSO
 .BR dwm (1),
-.BR wmii (1) .
+.BR wmii (1).
diff --git a/dmenu.c b/dmenu.c
index ec62602..15ce8c7 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -355,17 +355,23 @@ kpress(XKeyEvent * e) {
 	/* first check if a control mask is omitted */
 	if(e->state & ControlMask) {
 		switch(tolower(ksym)) {
-		default:	/* ignore other control sequences */
+		default:
 			return;
 		case XK_a:
 			ksym = XK_Home;
 			break;
+		case XK_b:
+			ksym = XK_Left;
+			break;
 		case XK_c:
 			ksym = XK_Escape;
 			break;
 		case XK_e:
 			ksym = XK_End;
 			break;
+		case XK_f:
+			ksym = XK_Right;
+			break;
 		case XK_h:
 			ksym = XK_BackSpace;
 			break;
@@ -378,6 +384,12 @@ kpress(XKeyEvent * e) {
 		case XK_k:
 			text[cursor] = '\0';
 			break;
+		case XK_n:
+			ksym = XK_Down;
+			break;
+		case XK_p:
+			ksym = XK_Up;
+			break;
 		case XK_u:
 			memmove(text, text + cursor, sizeof text - cursor + 1);
 			cursor = 0;
@@ -393,31 +405,7 @@ kpress(XKeyEvent * e) {
 				match(text);
 			}
 			break;
-		}
-	}
-	if(CLEANMASK(e->state) & Mod1Mask) {
-		switch(ksym) {
-		default:
-			return;
-		case XK_h:
-			ksym = XK_Left;
-			break;
-		case XK_l:
-			ksym = XK_Right;
-			break;
-		case XK_j:
-			ksym = XK_Next;
-			break;
-		case XK_k:
-			ksym = XK_Prior;
-			break;
-		case XK_g:
-			ksym = XK_Home;
-			break;
-		case XK_G:
-			ksym = XK_End;
-			break;
-		case XK_p:
+		case XK_y:
 			{
 				FILE *fp;
 				char *s;
@@ -453,6 +441,8 @@ kpress(XKeyEvent * e) {
 		match(text);
 		break;
 	case XK_Delete:
+		if(cursor == len)
+			return;
 		for(i = 1; cursor + i < len && !IS_UTF8_1ST_CHAR(text[cursor + i]); i++);
 		memmove(text + cursor, text + cursor + i, sizeof text - cursor);
 		match(text);
@@ -482,18 +472,20 @@ kpress(XKeyEvent * e) {
 		calcoffsets();
 		break;
 	case XK_Left:
-	case XK_Up:
-		if(sel && sel->left){
-			sel = sel->left;
-			if(sel->right == curr) {
-				curr = prev;
-				calcoffsets();
-			}
-		}
-		else if(cursor > 0)
+		if(cursor > 0 && (!sel || !sel->left)) {
 			while(cursor-- > 0 && !IS_UTF8_1ST_CHAR(text[cursor]));
-		else
+			break;
+		}
+		if(lines > 0)
 			return;
+	case XK_Up:
+		if(!sel || !sel->left)
+			return;
+		sel = sel->left;
+		if(sel->right == curr) {
+			curr = prev;
+			calcoffsets();
+		}
 		break;
 	case XK_Next:
 		if(!next)
@@ -516,18 +508,20 @@ kpress(XKeyEvent * e) {
 		running = False;
 		return;
 	case XK_Right:
-	case XK_Down:
-		if(cursor < len)
+		if(cursor < len) {
 			while(cursor++ < len && !IS_UTF8_1ST_CHAR(text[cursor]));
-		else if(sel && sel->right) {
-			sel = sel->right;
-			if(sel == next) {
-				curr = next;
-				calcoffsets();
-			}
+			break;
 		}
-		else
+		if(lines > 0)
 			return;
+	case XK_Down:
+		if(!sel || !sel->right)
+			return;
+		sel = sel->right;
+		if(sel == next) {
+			curr = next;
+			calcoffsets();
+		}
 		break;
 	case XK_Tab:
 		if(!sel)