diff options
-rw-r--r-- | dmenu.1 | 8 | ||||
-rw-r--r-- | main.c | 89 |
2 files changed, 64 insertions, 33 deletions
@@ -40,7 +40,7 @@ defines the seconds to wait for standard input, before exiting (default is 3). | |||
40 | prints version information to standard output, then exits. | 40 | prints version information to standard output, then exits. |
41 | .SH USAGE | 41 | .SH USAGE |
42 | dmenu reads a list of newline-separated items from standard input and creates a | 42 | dmenu reads a list of newline-separated items from standard input and creates a |
43 | menu. When the user selects an item or enters any text and presses Return, his | 43 | menu. When the user selects an item or enters any text and presses Return, his/her |
44 | choice is printed to standard output and dmenu terminates. | 44 | choice is printed to standard output and dmenu terminates. |
45 | .P | 45 | .P |
46 | dmenu is completely controlled by the keyboard. The following keys are recognized: | 46 | dmenu is completely controlled by the keyboard. The following keys are recognized: |
@@ -52,6 +52,12 @@ only items containing this text will be displayed. | |||
52 | .B Left/Right | 52 | .B Left/Right |
53 | Select the previous/next item. | 53 | Select the previous/next item. |
54 | .TP | 54 | .TP |
55 | .B PageUp/PageDown | ||
56 | Select the first item of the previous/next 'page' of items. | ||
57 | .TP | ||
58 | .B Home/End | ||
59 | Select the first/last item. | ||
60 | .TP | ||
55 | .B Tab | 61 | .B Tab |
56 | Copy the selected item to the input field. | 62 | Copy the selected item to the input field. |
57 | .TP | 63 | .TP |
@@ -170,6 +170,42 @@ kpress(XKeyEvent * e) { | |||
170 | } | 170 | } |
171 | } | 171 | } |
172 | switch(ksym) { | 172 | switch(ksym) { |
173 | default: | ||
174 | if(num && !iscntrl((int) buf[0])) { | ||
175 | buf[num] = 0; | ||
176 | if(len > 0) | ||
177 | strncat(text, buf, sizeof text); | ||
178 | else | ||
179 | strncpy(text, buf, sizeof text); | ||
180 | match(text); | ||
181 | } | ||
182 | break; | ||
183 | case XK_BackSpace: | ||
184 | if((i = len)) { | ||
185 | prev_nitem = nitem; | ||
186 | do { | ||
187 | text[--i] = 0; | ||
188 | match(text); | ||
189 | } while(i && nitem && prev_nitem == nitem); | ||
190 | match(text); | ||
191 | } | ||
192 | break; | ||
193 | case XK_End: | ||
194 | while(next) { | ||
195 | sel = curr = next; | ||
196 | calcoffsets(); | ||
197 | } | ||
198 | while(sel->right) | ||
199 | sel = sel->right; | ||
200 | break; | ||
201 | case XK_Escape: | ||
202 | ret = 1; | ||
203 | running = False; | ||
204 | break; | ||
205 | case XK_Home: | ||
206 | sel = curr = item; | ||
207 | calcoffsets(); | ||
208 | break; | ||
173 | case XK_Left: | 209 | case XK_Left: |
174 | if(!(sel && sel->left)) | 210 | if(!(sel && sel->left)) |
175 | return; | 211 | return; |
@@ -179,18 +215,15 @@ kpress(XKeyEvent * e) { | |||
179 | calcoffsets(); | 215 | calcoffsets(); |
180 | } | 216 | } |
181 | break; | 217 | break; |
182 | case XK_Tab: | 218 | case XK_Next: |
183 | if(!sel) | 219 | if(next) { |
184 | return; | 220 | sel = curr = next; |
185 | strncpy(text, sel->text, sizeof text); | 221 | calcoffsets(); |
186 | match(text); | 222 | } |
187 | break; | 223 | break; |
188 | case XK_Right: | 224 | case XK_Prior: |
189 | if(!(sel && sel->right)) | 225 | if(prev) { |
190 | return; | 226 | sel = curr = prev; |
191 | sel=sel->right; | ||
192 | if(sel == next) { | ||
193 | curr = next; | ||
194 | calcoffsets(); | 227 | calcoffsets(); |
195 | } | 228 | } |
196 | break; | 229 | break; |
@@ -204,29 +237,21 @@ kpress(XKeyEvent * e) { | |||
204 | fflush(stdout); | 237 | fflush(stdout); |
205 | running = False; | 238 | running = False; |
206 | break; | 239 | break; |
207 | case XK_Escape: | 240 | case XK_Right: |
208 | ret = 1; | 241 | if(!(sel && sel->right)) |
209 | running = False; | 242 | return; |
210 | break; | 243 | sel=sel->right; |
211 | case XK_BackSpace: | 244 | if(sel == next) { |
212 | if((i = len)) { | 245 | curr = next; |
213 | prev_nitem = nitem; | 246 | calcoffsets(); |
214 | do { | ||
215 | text[--i] = 0; | ||
216 | match(text); | ||
217 | } while(i && nitem && prev_nitem == nitem); | ||
218 | match(text); | ||
219 | } | 247 | } |
220 | break; | 248 | break; |
221 | default: | 249 | case XK_Tab: |
222 | if(num && !iscntrl((int) buf[0])) { | 250 | if(!sel) |
223 | buf[num] = 0; | 251 | return; |
224 | if(len > 0) | 252 | strncpy(text, sel->text, sizeof text); |
225 | strncat(text, buf, sizeof text); | 253 | match(text); |
226 | else | 254 | break; |
227 | strncpy(text, buf, sizeof text); | ||
228 | match(text); | ||
229 | } | ||
230 | } | 255 | } |
231 | drawmenu(); | 256 | drawmenu(); |
232 | } | 257 | } |