Annotation of src/usr.bin/tmux/key-bindings.c, Revision 1.124
1.124 ! nicm 1: /* $OpenBSD: key-bindings.c,v 1.123 2020/04/17 08:03:22 nicm Exp $ */
1.1 nicm 2:
3: /*
1.56 nicm 4: * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
1.1 nicm 5: *
6: * Permission to use, copy, modify, and distribute this software for any
7: * purpose with or without fee is hereby granted, provided that the above
8: * copyright notice and this permission notice appear in all copies.
9: *
10: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14: * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15: * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16: * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17: */
18:
19: #include <sys/types.h>
20:
21: #include <ctype.h>
22: #include <stdlib.h>
23: #include <string.h>
24:
25: #include "tmux.h"
26:
1.97 nicm 27: #define DEFAULT_SESSION_MENU \
28: " 'Next' 'n' {switch-client -n}" \
29: " 'Previous' 'p' {switch-client -p}" \
30: " ''" \
31: " 'Renumber' 'N' {move-window -r}" \
32: " 'Rename' 'n' {command-prompt -I \"#S\" \"rename-session -- '%%'\"}" \
33: " ''" \
34: " 'New Session' 's' {new-session}" \
35: " 'New Window' 'w' {new-window}"
36: #define DEFAULT_WINDOW_MENU \
1.112 nicm 37: " '#{?#{>:#{session_windows},1},,-}Swap Left' 'l' {swap-window -t:-1}" \
38: " '#{?#{>:#{session_windows},1},,-}Swap Right' 'r' {swap-window -t:+1}" \
1.97 nicm 39: " '#{?pane_marked_set,,-}Swap Marked' 's' {swap-window}" \
40: " ''" \
41: " 'Kill' 'X' {kill-window}" \
42: " 'Respawn' 'R' {respawn-window -k}" \
43: " '#{?pane_marked,Unmark,Mark}' 'm' {select-pane -m}" \
44: " 'Rename' 'n' {command-prompt -I \"#W\" \"rename-window -- '%%'\"}" \
45: " ''" \
46: " 'New After' 'w' {new-window -a}" \
47: " 'New At End' 'W' {new-window}"
48: #define DEFAULT_PANE_MENU \
1.115 nicm 49: " '#{?#{m/r:(copy|view)-mode,#{pane_mode}},Go To Top,}' '<' {send -X history-top}" \
50: " '#{?#{m/r:(copy|view)-mode,#{pane_mode}},Go To Bottom,}' '>' {send -X history-bottom}" \
1.109 nicm 51: " ''" \
1.115 nicm 52: " '#{?mouse_word,Search For #[underscore]#{=/9/...:mouse_word},}' 'C-r' {if -F '#{?#{m/r:(copy|view)-mode,#{pane_mode}},0,1}' 'copy-mode -t='; send -Xt= search-backward \"#{q:mouse_word}\"}" \
1.109 nicm 53: " '#{?mouse_word,Type #[underscore]#{=/9/...:mouse_word},}' 'C-y' {copy-mode -q; send-keys -l -- \"#{q:mouse_word}\"}" \
54: " '#{?mouse_word,Copy #[underscore]#{=/9/...:mouse_word},}' 'c' {copy-mode -q; set-buffer -- \"#{q:mouse_word}\"}" \
55: " '#{?mouse_line,Copy Line,}' 'l' {copy-mode -q; set-buffer -- \"#{q:mouse_line}\"}" \
1.97 nicm 56: " ''" \
57: " 'Horizontal Split' 'h' {split-window -h}" \
58: " 'Vertical Split' 'v' {split-window -v}" \
59: " ''" \
1.112 nicm 60: " '#{?#{>:#{window_panes},1},,-}Swap Up' 'u' {swap-pane -U}" \
1.113 nicm 61: " '#{?#{>:#{window_panes},1},,-}Swap Down' 'd' {swap-pane -D}" \
1.97 nicm 62: " '#{?pane_marked_set,,-}Swap Marked' 's' {swap-pane}" \
63: " ''" \
64: " 'Kill' 'X' {kill-pane}" \
65: " 'Respawn' 'R' {respawn-pane -k}" \
66: " '#{?pane_marked,Unmark,Mark}' 'm' {select-pane -m}" \
1.114 nicm 67: " '#{?#{>:#{window_panes},1},,-}#{?window_zoomed_flag,Unzoom,Zoom}' 'z' {resize-pane -Z}"
1.97 nicm 68:
1.86 nicm 69: static int key_bindings_cmp(struct key_binding *, struct key_binding *);
70: RB_GENERATE_STATIC(key_bindings, key_binding, entry, key_bindings_cmp);
71: static int key_table_cmp(struct key_table *, struct key_table *);
72: RB_GENERATE_STATIC(key_tables, key_table, entry, key_table_cmp);
73: static struct key_tables key_tables = RB_INITIALIZER(&key_tables);
1.1 nicm 74:
1.86 nicm 75: static int
76: key_table_cmp(struct key_table *table1, struct key_table *table2)
1.45 nicm 77: {
1.86 nicm 78: return (strcmp(table1->name, table2->name));
1.45 nicm 79: }
1.1 nicm 80:
1.86 nicm 81: static int
1.1 nicm 82: key_bindings_cmp(struct key_binding *bd1, struct key_binding *bd2)
83: {
1.55 nicm 84: if (bd1->key < bd2->key)
85: return (-1);
86: if (bd1->key > bd2->key)
87: return (1);
88: return (0);
1.45 nicm 89: }
90:
1.106 nicm 91: static void
92: key_bindings_free(struct key_table *table, struct key_binding *bd)
93: {
94: RB_REMOVE(key_bindings, &table->key_bindings, bd);
95: cmd_list_free(bd->cmdlist);
1.107 nicm 96: free((void *)bd->note);
1.106 nicm 97: free(bd);
98: }
99:
1.45 nicm 100: struct key_table *
101: key_bindings_get_table(const char *name, int create)
102: {
103: struct key_table table_find, *table;
104:
105: table_find.name = name;
106: table = RB_FIND(key_tables, &key_tables, &table_find);
107: if (table != NULL || !create)
108: return (table);
1.8 nicm 109:
1.45 nicm 110: table = xmalloc(sizeof *table);
111: table->name = xstrdup(name);
112: RB_INIT(&table->key_bindings);
1.8 nicm 113:
1.45 nicm 114: table->references = 1; /* one reference in key_tables */
115: RB_INSERT(key_tables, &key_tables, table);
116:
117: return (table);
1.1 nicm 118: }
119:
1.86 nicm 120: struct key_table *
121: key_bindings_first_table(void)
122: {
123: return (RB_MIN(key_tables, &key_tables));
124: }
125:
126: struct key_table *
127: key_bindings_next_table(struct key_table *table)
128: {
129: return (RB_NEXT(key_tables, &key_tables, table));
130: }
131:
1.45 nicm 132: void
133: key_bindings_unref_table(struct key_table *table)
1.1 nicm 134: {
1.45 nicm 135: struct key_binding *bd;
1.57 nicm 136: struct key_binding *bd1;
1.45 nicm 137:
138: if (--table->references != 0)
139: return;
140:
1.106 nicm 141: RB_FOREACH_SAFE(bd, key_bindings, &table->key_bindings, bd1)
142: key_bindings_free(table, bd);
1.1 nicm 143:
1.45 nicm 144: free((void *)table->name);
145: free(table);
1.86 nicm 146: }
147:
148: struct key_binding *
149: key_bindings_get(struct key_table *table, key_code key)
150: {
151: struct key_binding bd;
152:
153: bd.key = key;
154: return (RB_FIND(key_bindings, &table->key_bindings, &bd));
155: }
156:
157: struct key_binding *
158: key_bindings_first(struct key_table *table)
159: {
160: return (RB_MIN(key_bindings, &table->key_bindings));
161: }
162:
163: struct key_binding *
164: key_bindings_next(__unused struct key_table *table, struct key_binding *bd)
165: {
166: return (RB_NEXT(key_bindings, &table->key_bindings, bd));
1.1 nicm 167: }
168:
169: void
1.107 nicm 170: key_bindings_add(const char *name, key_code key, const char *note, int repeat,
1.45 nicm 171: struct cmd_list *cmdlist)
1.1 nicm 172: {
1.45 nicm 173: struct key_table *table;
1.106 nicm 174: struct key_binding *bd;
1.45 nicm 175:
176: table = key_bindings_get_table(name, 1);
1.1 nicm 177:
1.106 nicm 178: bd = key_bindings_get(table, key & ~KEYC_XTERM);
179: if (bd != NULL)
180: key_bindings_free(table, bd);
1.15 nicm 181:
1.76 nicm 182: bd = xcalloc(1, sizeof *bd);
1.2 nicm 183: bd->key = key;
1.107 nicm 184: if (note != NULL)
185: bd->note = xstrdup(note);
1.45 nicm 186: RB_INSERT(key_bindings, &table->key_bindings, bd);
1.15 nicm 187:
1.75 nicm 188: if (repeat)
189: bd->flags |= KEY_BINDING_REPEAT;
1.1 nicm 190: bd->cmdlist = cmdlist;
191: }
192:
193: void
1.55 nicm 194: key_bindings_remove(const char *name, key_code key)
1.1 nicm 195: {
1.45 nicm 196: struct key_table *table;
1.106 nicm 197: struct key_binding *bd;
1.45 nicm 198:
199: table = key_bindings_get_table(name, 0);
200: if (table == NULL)
201: return;
1.1 nicm 202:
1.106 nicm 203: bd = key_bindings_get(table, key & ~KEYC_XTERM);
1.45 nicm 204: if (bd == NULL)
1.1 nicm 205: return;
1.106 nicm 206: key_bindings_free(table, bd);
1.45 nicm 207:
208: if (RB_EMPTY(&table->key_bindings)) {
209: RB_REMOVE(key_tables, &key_tables, table);
210: key_bindings_unref_table(table);
211: }
212: }
213:
214: void
215: key_bindings_remove_table(const char *name)
216: {
217: struct key_table *table;
1.82 nicm 218: struct client *c;
1.45 nicm 219:
220: table = key_bindings_get_table(name, 0);
221: if (table != NULL) {
222: RB_REMOVE(key_tables, &key_tables, table);
223: key_bindings_unref_table(table);
1.82 nicm 224: }
225: TAILQ_FOREACH(c, &clients, entry) {
226: if (c->keytable == table)
227: server_client_set_key_table(c, NULL);
1.45 nicm 228: }
1.1 nicm 229: }
230:
231: void
232: key_bindings_init(void)
233: {
1.47 nicm 234: static const char *defaults[] = {
1.108 nicm 235: /* Prefix keys. */
1.107 nicm 236: "bind -N 'Send the prefix key' C-b send-prefix",
237: "bind -N 'Rotate through the panes' C-o rotate-window",
238: "bind -N 'Suspend the current client' C-z suspend-client",
239: "bind -N 'Select next layout' Space next-layout",
240: "bind -N 'Break pane to a new window' ! break-pane",
241: "bind -N 'Split window vertically' '\"' split-window",
242: "bind -N 'List all paste buffers' '#' list-buffers",
243: "bind -N 'Rename current session' '$' command-prompt -I'#S' \"rename-session -- '%%'\"",
244: "bind -N 'Split window horizontally' % split-window -h",
245: "bind -N 'Kill current window' & confirm-before -p\"kill-window #W? (y/n)\" kill-window",
1.124 ! nicm 246: "bind -N 'Prompt for window index to select' \"'\" command-prompt -Wpindex \"select-window -t ':%%'\"",
1.107 nicm 247: "bind -N 'Switch to previous client' ( switch-client -p",
248: "bind -N 'Switch to next client' ) switch-client -n",
249: "bind -N 'Rename current window' , command-prompt -I'#W' \"rename-window -- '%%'\"",
250: "bind -N 'Delete the most recent paste buffer' - delete-buffer",
1.124 ! nicm 251: "bind -N 'Move the current window' . command-prompt -T \"move-window -t '%%'\"",
1.107 nicm 252: "bind -N 'Describe key binding' '/' command-prompt -kpkey 'list-keys -1N \"%%%\"'",
253: "bind -N 'Select window 0' 0 select-window -t:=0",
254: "bind -N 'Select window 1' 1 select-window -t:=1",
255: "bind -N 'Select window 2' 2 select-window -t:=2",
256: "bind -N 'Select window 3' 3 select-window -t:=3",
257: "bind -N 'Select window 4' 4 select-window -t:=4",
258: "bind -N 'Select window 5' 5 select-window -t:=5",
259: "bind -N 'Select window 6' 6 select-window -t:=6",
260: "bind -N 'Select window 7' 7 select-window -t:=7",
261: "bind -N 'Select window 8' 8 select-window -t:=8",
262: "bind -N 'Select window 9' 9 select-window -t:=9",
263: "bind -N 'Prompt for a command' : command-prompt",
264: "bind -N 'Move to the previously active pane' \\; last-pane",
265: "bind -N 'Choose a paste buffer from a list' = choose-buffer -Z",
266: "bind -N 'List key bindings' ? list-keys -N",
267: "bind -N 'Choose a client from a list' D choose-client -Z",
268: "bind -N 'Spread panes out evenly' E select-layout -E",
269: "bind -N 'Switch to the last client' L switch-client -l",
270: "bind -N 'Clear the marked pane' M select-pane -M",
271: "bind -N 'Enter copy mode' [ copy-mode",
272: "bind -N 'Paste the most recent paste buffer' ] paste-buffer",
273: "bind -N 'Create a new window' c new-window",
274: "bind -N 'Detach the current client' d detach-client",
275: "bind -N 'Search for a pane' f command-prompt \"find-window -Z -- '%%'\"",
276: "bind -N 'Display window information' i display-message",
277: "bind -N 'Select the previously current window' l last-window",
278: "bind -N 'Toggle the marked pane' m select-pane -m",
279: "bind -N 'Select the next window' n next-window",
280: "bind -N 'Select the next pane' o select-pane -t:.+",
281: "bind -N 'Select the previous pane' p previous-window",
282: "bind -N 'Display pane numbers' q display-panes",
283: "bind -N 'Redraw the current client' r refresh-client",
284: "bind -N 'Choose a session from a list' s choose-tree -Zs",
285: "bind -N 'Show a clock' t clock-mode",
286: "bind -N 'Choose a window from a list' w choose-tree -Zw",
287: "bind -N 'Kill the active pane' x confirm-before -p\"kill-pane #P? (y/n)\" kill-pane",
288: "bind -N 'Zoom the active pane' z resize-pane -Z",
289: "bind -N 'Swap the active pane with the pane above' '{' swap-pane -U",
290: "bind -N 'Swap the active pane with the pane below' '}' swap-pane -D",
291: "bind -N 'Show messages' '~' show-messages",
292: "bind -N 'Enter copy mode and scroll up' PPage copy-mode -u",
293: "bind -N 'Select the pane above the active pane' -r Up select-pane -U",
294: "bind -N 'Select the pane below the active pane' -r Down select-pane -D",
295: "bind -N 'Select the pane to the left of the active pane' -r Left select-pane -L",
296: "bind -N 'Select the pane to the right of the active pane' -r Right select-pane -R",
297: "bind -N 'Set the even-horizontal layout' M-1 select-layout even-horizontal",
298: "bind -N 'Set the even-vertical layout' M-2 select-layout even-vertical",
299: "bind -N 'Set the main-horizontal layout' M-3 select-layout main-horizontal",
300: "bind -N 'Set the main-vertical layout' M-4 select-layout main-vertical",
301: "bind -N 'Select the tiled layout' M-5 select-layout tiled",
302: "bind -N 'Select the next window with an alert' M-n next-window -a",
303: "bind -N 'Rotate through the panes in reverse' M-o rotate-window -D",
304: "bind -N 'Select the previous window with an alert' M-p previous-window -a",
305: "bind -N 'Move the visible part of the window up' -r S-Up refresh-client -U 10",
306: "bind -N 'Move the visible part of the window down' -r S-Down refresh-client -D 10",
307: "bind -N 'Move the visible part of the window left' -r S-Left refresh-client -L 10",
308: "bind -N 'Move the visible part of the window right' -r S-Right refresh-client -R 10",
309: "bind -N 'Reset so the visible part of the window follows the cursor' -r DC refresh-client -c",
310: "bind -N 'Resize the pane up by 5' -r M-Up resize-pane -U 5",
311: "bind -N 'Resize the pane down by 5' -r M-Down resize-pane -D 5",
312: "bind -N 'Resize the pane left by 5' -r M-Left resize-pane -L 5",
313: "bind -N 'Resize the pane right by 5' -r M-Right resize-pane -R 5",
314: "bind -N 'Resize the pane up' -r C-Up resize-pane -U",
315: "bind -N 'Resize the pane down' -r C-Down resize-pane -D",
316: "bind -N 'Resize the pane left' -r C-Left resize-pane -L",
317: "bind -N 'Resize the pane right' -r C-Right resize-pane -R",
1.91 nicm 318:
1.108 nicm 319: /* Menu keys */
1.116 nicm 320: "bind < display-menu -xW -yW -T '#[align=centre]#{window_index}:#{window_name}' " DEFAULT_WINDOW_MENU,
1.108 nicm 321: "bind > display-menu -xP -yP -T '#[align=centre]#{pane_index} (#{pane_id})' " DEFAULT_PANE_MENU,
322:
323: /* Mouse button 1 down on pane. */
324: "bind -n MouseDown1Pane select-pane -t=\\; send -M",
325:
326: /* Mouse button 1 drag on pane. */
327: "bind -n MouseDrag1Pane if -F '#{||:#{pane_in_mode},#{mouse_any_flag}}' { send -M } { copy-mode -M }",
328:
329: /* Mouse wheel up on pane. */
330: "bind -n WheelUpPane if -F '#{||:#{pane_in_mode},#{mouse_any_flag}}' { send -M } { copy-mode -e }",
331:
332: /* Mouse button 2 down on pane. */
333: "bind -n MouseDown2Pane select-pane -t=\\; if -F '#{||:#{pane_in_mode},#{mouse_any_flag}}' { send -M } { paste -p }",
334:
335: /* Mouse button 1 double click on pane. */
1.123 nicm 336: "bind -n DoubleClick1Pane select-pane -t=\\; if -F '#{||:#{pane_in_mode},#{mouse_any_flag}}' { send -M } { copy-mode -H; send -X select-word; run -d0.3; send -X copy-pipe-and-cancel }",
1.108 nicm 337:
338: /* Mouse button 1 triple click on pane. */
1.123 nicm 339: "bind -n TripleClick1Pane select-pane -t=\\; if -F '#{||:#{pane_in_mode},#{mouse_any_flag}}' { send -M } { copy-mode -H; send -X select-line; run -d0.3; send -X copy-pipe-and-cancel }",
1.108 nicm 340:
341: /* Mouse button 1 drag on border. */
1.44 nicm 342: "bind -n MouseDrag1Border resize-pane -M",
1.108 nicm 343:
344: /* Mouse button 1 down on status line. */
1.44 nicm 345: "bind -n MouseDown1Status select-window -t=",
1.108 nicm 346:
347: /* Mouse wheel down on status line. */
1.52 nicm 348: "bind -n WheelDownStatus next-window",
1.108 nicm 349:
350: /* Mouse wheel up on status line. */
1.52 nicm 351: "bind -n WheelUpStatus previous-window",
1.95 nicm 352:
1.108 nicm 353: /* Mouse button 3 down on status left. */
1.116 nicm 354: "bind -n MouseDown3StatusLeft display-menu -t= -xM -yW -T '#[align=centre]#{session_name}' " DEFAULT_SESSION_MENU,
1.108 nicm 355:
356: /* Mouse button 3 down on status line. */
1.116 nicm 357: "bind -n MouseDown3Status display-menu -t= -xW -yW -T '#[align=centre]#{window_index}:#{window_name}' " DEFAULT_WINDOW_MENU,
1.108 nicm 358:
359: /* Mouse button 3 down on pane. */
1.115 nicm 360: "bind -n MouseDown3Pane if -Ft= '#{||:#{mouse_any_flag},#{&&:#{pane_in_mode},#{?#{m/r:(copy|view)-mode,#{pane_mode}},0,1}}}' { select-pane -t=; send -M } { display-menu -t= -xM -yM -T '#[align=centre]#{pane_index} (#{pane_id})' " DEFAULT_PANE_MENU " }",
1.108 nicm 361: "bind -n M-MouseDown3Pane display-menu -t= -xM -yM -T '#[align=centre]#{pane_index} (#{pane_id})' " DEFAULT_PANE_MENU,
1.58 nicm 362:
1.108 nicm 363: /* Copy mode (emacs) keys. */
1.58 nicm 364: "bind -Tcopy-mode C-Space send -X begin-selection",
365: "bind -Tcopy-mode C-a send -X start-of-line",
366: "bind -Tcopy-mode C-c send -X cancel",
367: "bind -Tcopy-mode C-e send -X end-of-line",
368: "bind -Tcopy-mode C-f send -X cursor-right",
1.67 nicm 369: "bind -Tcopy-mode C-b send -X cursor-left",
1.58 nicm 370: "bind -Tcopy-mode C-g send -X clear-selection",
371: "bind -Tcopy-mode C-k send -X copy-end-of-line",
372: "bind -Tcopy-mode C-n send -X cursor-down",
373: "bind -Tcopy-mode C-p send -X cursor-up",
1.81 nicm 374: "bind -Tcopy-mode C-r command-prompt -ip'(search up)' -I'#{pane_search_string}' 'send -X search-backward-incremental \"%%%\"'",
375: "bind -Tcopy-mode C-s command-prompt -ip'(search down)' -I'#{pane_search_string}' 'send -X search-forward-incremental \"%%%\"'",
1.58 nicm 376: "bind -Tcopy-mode C-v send -X page-down",
1.123 nicm 377: "bind -Tcopy-mode C-w send -X copy-pipe-and-cancel",
1.58 nicm 378: "bind -Tcopy-mode Escape send -X cancel",
379: "bind -Tcopy-mode Space send -X page-down",
380: "bind -Tcopy-mode , send -X jump-reverse",
381: "bind -Tcopy-mode \\; send -X jump-again",
1.81 nicm 382: "bind -Tcopy-mode F command-prompt -1p'(jump backward)' 'send -X jump-backward \"%%%\"'",
1.58 nicm 383: "bind -Tcopy-mode N send -X search-reverse",
384: "bind -Tcopy-mode R send -X rectangle-toggle",
1.81 nicm 385: "bind -Tcopy-mode T command-prompt -1p'(jump to backward)' 'send -X jump-to-backward \"%%%\"'",
386: "bind -Tcopy-mode f command-prompt -1p'(jump forward)' 'send -X jump-forward \"%%%\"'",
387: "bind -Tcopy-mode g command-prompt -p'(goto line)' 'send -X goto-line \"%%%\"'",
1.58 nicm 388: "bind -Tcopy-mode n send -X search-again",
389: "bind -Tcopy-mode q send -X cancel",
1.117 nicm 390: "bind -Tcopy-mode r send -X refresh-from-pane",
1.81 nicm 391: "bind -Tcopy-mode t command-prompt -1p'(jump to forward)' 'send -X jump-to-forward \"%%%\"'",
1.74 nicm 392: "bind -Tcopy-mode Home send -X start-of-line",
393: "bind -Tcopy-mode End send -X end-of-line",
1.66 nicm 394: "bind -Tcopy-mode MouseDown1Pane select-pane",
395: "bind -Tcopy-mode MouseDrag1Pane select-pane\\; send -X begin-selection",
1.123 nicm 396: "bind -Tcopy-mode MouseDragEnd1Pane send -X copy-pipe-and-cancel",
1.66 nicm 397: "bind -Tcopy-mode WheelUpPane select-pane\\; send -N5 -X scroll-up",
398: "bind -Tcopy-mode WheelDownPane select-pane\\; send -N5 -X scroll-down",
1.123 nicm 399: "bind -Tcopy-mode DoubleClick1Pane select-pane\\; send -X select-word\\; run -d0.3\\; send -X copy-pipe-and-cancel",
400: "bind -Tcopy-mode TripleClick1Pane select-pane\\; send -X select-line\\; run -d0.3\\; send -X copy-pipe-and-cancel",
1.58 nicm 401: "bind -Tcopy-mode NPage send -X page-down",
402: "bind -Tcopy-mode PPage send -X page-up",
403: "bind -Tcopy-mode Up send -X cursor-up",
404: "bind -Tcopy-mode Down send -X cursor-down",
405: "bind -Tcopy-mode Left send -X cursor-left",
406: "bind -Tcopy-mode Right send -X cursor-right",
1.81 nicm 407: "bind -Tcopy-mode M-1 command-prompt -Np'(repeat)' -I1 'send -N \"%%%\"'",
408: "bind -Tcopy-mode M-2 command-prompt -Np'(repeat)' -I2 'send -N \"%%%\"'",
409: "bind -Tcopy-mode M-3 command-prompt -Np'(repeat)' -I3 'send -N \"%%%\"'",
410: "bind -Tcopy-mode M-4 command-prompt -Np'(repeat)' -I4 'send -N \"%%%\"'",
411: "bind -Tcopy-mode M-5 command-prompt -Np'(repeat)' -I5 'send -N \"%%%\"'",
412: "bind -Tcopy-mode M-6 command-prompt -Np'(repeat)' -I6 'send -N \"%%%\"'",
413: "bind -Tcopy-mode M-7 command-prompt -Np'(repeat)' -I7 'send -N \"%%%\"'",
414: "bind -Tcopy-mode M-8 command-prompt -Np'(repeat)' -I8 'send -N \"%%%\"'",
415: "bind -Tcopy-mode M-9 command-prompt -Np'(repeat)' -I9 'send -N \"%%%\"'",
1.58 nicm 416: "bind -Tcopy-mode M-< send -X history-top",
417: "bind -Tcopy-mode M-> send -X history-bottom",
418: "bind -Tcopy-mode M-R send -X top-line",
419: "bind -Tcopy-mode M-b send -X previous-word",
1.89 nicm 420: "bind -Tcopy-mode C-M-b send -X previous-matching-bracket",
1.58 nicm 421: "bind -Tcopy-mode M-f send -X next-word-end",
1.89 nicm 422: "bind -Tcopy-mode C-M-f send -X next-matching-bracket",
1.58 nicm 423: "bind -Tcopy-mode M-m send -X back-to-indentation",
424: "bind -Tcopy-mode M-r send -X middle-line",
425: "bind -Tcopy-mode M-v send -X page-up",
1.123 nicm 426: "bind -Tcopy-mode M-w send -X copy-pipe-and-cancel",
1.94 nicm 427: "bind -Tcopy-mode 'M-{' send -X previous-paragraph",
428: "bind -Tcopy-mode 'M-}' send -X next-paragraph",
1.58 nicm 429: "bind -Tcopy-mode M-Up send -X halfpage-up",
430: "bind -Tcopy-mode M-Down send -X halfpage-down",
431: "bind -Tcopy-mode C-Up send -X scroll-up",
432: "bind -Tcopy-mode C-Down send -X scroll-down",
433:
1.108 nicm 434: /* Copy mode (vi) keys. */
1.103 nicm 435: "bind -Tcopy-mode-vi '#' send -FX search-backward '#{copy_cursor_word}'",
436: "bind -Tcopy-mode-vi * send -FX search-forward '#{copy_cursor_word}'",
1.58 nicm 437: "bind -Tcopy-mode-vi C-c send -X cancel",
438: "bind -Tcopy-mode-vi C-d send -X halfpage-down",
439: "bind -Tcopy-mode-vi C-e send -X scroll-down",
1.67 nicm 440: "bind -Tcopy-mode-vi C-b send -X page-up",
1.58 nicm 441: "bind -Tcopy-mode-vi C-f send -X page-down",
442: "bind -Tcopy-mode-vi C-h send -X cursor-left",
1.123 nicm 443: "bind -Tcopy-mode-vi C-j send -X copy-pipe-and-cancel",
444: "bind -Tcopy-mode-vi Enter send -X copy-pipe-and-cancel",
1.58 nicm 445: "bind -Tcopy-mode-vi C-u send -X halfpage-up",
446: "bind -Tcopy-mode-vi C-v send -X rectangle-toggle",
447: "bind -Tcopy-mode-vi C-y send -X scroll-up",
448: "bind -Tcopy-mode-vi Escape send -X clear-selection",
449: "bind -Tcopy-mode-vi Space send -X begin-selection",
450: "bind -Tcopy-mode-vi '$' send -X end-of-line",
451: "bind -Tcopy-mode-vi , send -X jump-reverse",
1.81 nicm 452: "bind -Tcopy-mode-vi / command-prompt -p'(search down)' 'send -X search-forward \"%%%\"'",
1.58 nicm 453: "bind -Tcopy-mode-vi 0 send -X start-of-line",
1.81 nicm 454: "bind -Tcopy-mode-vi 1 command-prompt -Np'(repeat)' -I1 'send -N \"%%%\"'",
455: "bind -Tcopy-mode-vi 2 command-prompt -Np'(repeat)' -I2 'send -N \"%%%\"'",
456: "bind -Tcopy-mode-vi 3 command-prompt -Np'(repeat)' -I3 'send -N \"%%%\"'",
457: "bind -Tcopy-mode-vi 4 command-prompt -Np'(repeat)' -I4 'send -N \"%%%\"'",
458: "bind -Tcopy-mode-vi 5 command-prompt -Np'(repeat)' -I5 'send -N \"%%%\"'",
459: "bind -Tcopy-mode-vi 6 command-prompt -Np'(repeat)' -I6 'send -N \"%%%\"'",
460: "bind -Tcopy-mode-vi 7 command-prompt -Np'(repeat)' -I7 'send -N \"%%%\"'",
461: "bind -Tcopy-mode-vi 8 command-prompt -Np'(repeat)' -I8 'send -N \"%%%\"'",
462: "bind -Tcopy-mode-vi 9 command-prompt -Np'(repeat)' -I9 'send -N \"%%%\"'",
463: "bind -Tcopy-mode-vi : command-prompt -p'(goto line)' 'send -X goto-line \"%%%\"'",
1.60 nicm 464: "bind -Tcopy-mode-vi \\; send -X jump-again",
1.81 nicm 465: "bind -Tcopy-mode-vi ? command-prompt -p'(search up)' 'send -X search-backward \"%%%\"'",
1.58 nicm 466: "bind -Tcopy-mode-vi A send -X append-selection-and-cancel",
467: "bind -Tcopy-mode-vi B send -X previous-space",
468: "bind -Tcopy-mode-vi D send -X copy-end-of-line",
469: "bind -Tcopy-mode-vi E send -X next-space-end",
1.81 nicm 470: "bind -Tcopy-mode-vi F command-prompt -1p'(jump backward)' 'send -X jump-backward \"%%%\"'",
1.58 nicm 471: "bind -Tcopy-mode-vi G send -X history-bottom",
472: "bind -Tcopy-mode-vi H send -X top-line",
473: "bind -Tcopy-mode-vi J send -X scroll-down",
474: "bind -Tcopy-mode-vi K send -X scroll-up",
475: "bind -Tcopy-mode-vi L send -X bottom-line",
476: "bind -Tcopy-mode-vi M send -X middle-line",
477: "bind -Tcopy-mode-vi N send -X search-reverse",
1.81 nicm 478: "bind -Tcopy-mode-vi T command-prompt -1p'(jump to backward)' 'send -X jump-to-backward \"%%%\"'",
1.58 nicm 479: "bind -Tcopy-mode-vi V send -X select-line",
480: "bind -Tcopy-mode-vi W send -X next-space",
481: "bind -Tcopy-mode-vi ^ send -X back-to-indentation",
482: "bind -Tcopy-mode-vi b send -X previous-word",
483: "bind -Tcopy-mode-vi e send -X next-word-end",
1.81 nicm 484: "bind -Tcopy-mode-vi f command-prompt -1p'(jump forward)' 'send -X jump-forward \"%%%\"'",
1.58 nicm 485: "bind -Tcopy-mode-vi g send -X history-top",
486: "bind -Tcopy-mode-vi h send -X cursor-left",
487: "bind -Tcopy-mode-vi j send -X cursor-down",
488: "bind -Tcopy-mode-vi k send -X cursor-up",
489: "bind -Tcopy-mode-vi l send -X cursor-right",
490: "bind -Tcopy-mode-vi n send -X search-again",
491: "bind -Tcopy-mode-vi o send -X other-end",
492: "bind -Tcopy-mode-vi q send -X cancel",
1.117 nicm 493: "bind -Tcopy-mode-vi r send -X refresh-from-pane",
1.81 nicm 494: "bind -Tcopy-mode-vi t command-prompt -1p'(jump to forward)' 'send -X jump-to-forward \"%%%\"'",
1.58 nicm 495: "bind -Tcopy-mode-vi v send -X rectangle-toggle",
496: "bind -Tcopy-mode-vi w send -X next-word",
1.94 nicm 497: "bind -Tcopy-mode-vi '{' send -X previous-paragraph",
498: "bind -Tcopy-mode-vi '}' send -X next-paragraph",
1.89 nicm 499: "bind -Tcopy-mode-vi % send -X next-matching-bracket",
1.66 nicm 500: "bind -Tcopy-mode-vi MouseDown1Pane select-pane",
501: "bind -Tcopy-mode-vi MouseDrag1Pane select-pane\\; send -X begin-selection",
1.123 nicm 502: "bind -Tcopy-mode-vi MouseDragEnd1Pane send -X copy-pipe-and-cancel",
1.66 nicm 503: "bind -Tcopy-mode-vi WheelUpPane select-pane\\; send -N5 -X scroll-up",
504: "bind -Tcopy-mode-vi WheelDownPane select-pane\\; send -N5 -X scroll-down",
1.123 nicm 505: "bind -Tcopy-mode-vi DoubleClick1Pane select-pane\\; send -X select-word\\; run -d0.3\\; send -X copy-pipe-and-cancel",
506: "bind -Tcopy-mode-vi TripleClick1Pane select-pane\\; send -X select-line\\; run -d0.3\\; send -X copy-pipe-and-cancel",
1.58 nicm 507: "bind -Tcopy-mode-vi BSpace send -X cursor-left",
508: "bind -Tcopy-mode-vi NPage send -X page-down",
509: "bind -Tcopy-mode-vi PPage send -X page-up",
510: "bind -Tcopy-mode-vi Up send -X cursor-up",
511: "bind -Tcopy-mode-vi Down send -X cursor-down",
512: "bind -Tcopy-mode-vi Left send -X cursor-left",
513: "bind -Tcopy-mode-vi Right send -X cursor-right",
514: "bind -Tcopy-mode-vi C-Up send -X scroll-up",
515: "bind -Tcopy-mode-vi C-Down send -X scroll-down",
1.1 nicm 516: };
1.93 nicm 517: u_int i;
518: struct cmd_parse_result *pr;
1.1 nicm 519:
1.42 nicm 520: for (i = 0; i < nitems(defaults); i++) {
1.93 nicm 521: pr = cmd_parse_from_string(defaults[i], NULL);
522: if (pr->status != CMD_PARSE_SUCCESS)
1.72 nicm 523: fatalx("bad default key: %s", defaults[i]);
1.122 nicm 524: cmdq_append(NULL, cmdq_get_command(pr->cmdlist, NULL));
1.93 nicm 525: cmd_list_free(pr->cmdlist);
1.1 nicm 526: }
1.61 nicm 527: }
528:
529: static enum cmd_retval
1.62 nicm 530: key_bindings_read_only(struct cmdq_item *item, __unused void *data)
1.61 nicm 531: {
1.62 nicm 532: cmdq_error(item, "client is read-only");
1.61 nicm 533: return (CMD_RETURN_ERROR);
1.1 nicm 534: }
535:
1.90 nicm 536: struct cmdq_item *
1.78 nicm 537: key_bindings_dispatch(struct key_binding *bd, struct cmdq_item *item,
1.121 nicm 538: struct client *c, struct key_event *event, struct cmd_find_state *fs)
1.1 nicm 539: {
1.78 nicm 540: struct cmdq_item *new_item;
1.122 nicm 541: struct cmdq_state *new_state;
1.121 nicm 542: int readonly, flags = 0;
1.1 nicm 543:
1.102 nicm 544: if (c == NULL || (~c->flags & CLIENT_READONLY))
545: readonly = 1;
1.118 nicm 546: else
547: readonly = cmd_list_all_have(bd->cmdlist, CMD_READONLY);
1.102 nicm 548: if (!readonly)
1.78 nicm 549: new_item = cmdq_get_callback(key_bindings_read_only, NULL);
1.73 nicm 550: else {
1.75 nicm 551: if (bd->flags & KEY_BINDING_REPEAT)
1.121 nicm 552: flags |= CMDQ_STATE_REPEAT;
1.122 nicm 553: new_state = cmdq_new_state(fs, event, flags);
554: new_item = cmdq_get_command(bd->cmdlist, new_state);
555: cmdq_free_state(new_state);
1.73 nicm 556: }
1.78 nicm 557: if (item != NULL)
1.105 nicm 558: new_item = cmdq_insert_after(item, new_item);
1.78 nicm 559: else
1.105 nicm 560: new_item = cmdq_append(c, new_item);
1.90 nicm 561: return (new_item);
1.1 nicm 562: }