Annotation of src/usr.bin/tmux/key-bindings.c, Revision 1.106
1.106 ! nicm 1: /* $OpenBSD: key-bindings.c,v 1.105 2019/12/19 09:22:33 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 \
37: " 'Swap Left' 'l' {swap-window -t:-1}" \
38: " 'Swap Right' 'r' {swap-window -t:+1}" \
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 \
49: " '#{?mouse_word,Search For #[underscore]#{=/9/...:mouse_word},}' 'C-r' {copy-mode -t=; send -Xt= search-backward \"#{q:mouse_word}\"}" \
50: " '#{?mouse_word,Type #[underscore]#{=/9/...:mouse_word},}' 'C-y' {send-keys -l -- \"#{q:mouse_word}\"}" \
51: " '#{?mouse_word,Copy #[underscore]#{=/9/...:mouse_word},}' 'c' {set-buffer -- \"#{q:mouse_word}\"}" \
52: " '#{?mouse_line,Copy Line,}' 'l' {set-buffer -- \"#{q:mouse_line}\"}" \
53: " ''" \
54: " 'Horizontal Split' 'h' {split-window -h}" \
55: " 'Vertical Split' 'v' {split-window -v}" \
56: " ''" \
57: " 'Swap Up' 'u' {swap-pane -U}" \
58: " 'Swap Down' 'd' {swap-pane -D}" \
59: " '#{?pane_marked_set,,-}Swap Marked' 's' {swap-pane}" \
60: " ''" \
61: " 'Kill' 'X' {kill-pane}" \
62: " 'Respawn' 'R' {respawn-pane -k}" \
63: " '#{?pane_marked,Unmark,Mark}' 'm' {select-pane -m}" \
64: " '#{?window_zoomed_flag,Unzoom,Zoom}' 'z' {resize-pane -Z}"
65:
1.86 nicm 66: static int key_bindings_cmp(struct key_binding *, struct key_binding *);
67: RB_GENERATE_STATIC(key_bindings, key_binding, entry, key_bindings_cmp);
68: static int key_table_cmp(struct key_table *, struct key_table *);
69: RB_GENERATE_STATIC(key_tables, key_table, entry, key_table_cmp);
70: static struct key_tables key_tables = RB_INITIALIZER(&key_tables);
1.1 nicm 71:
1.86 nicm 72: static int
73: key_table_cmp(struct key_table *table1, struct key_table *table2)
1.45 nicm 74: {
1.86 nicm 75: return (strcmp(table1->name, table2->name));
1.45 nicm 76: }
1.1 nicm 77:
1.86 nicm 78: static int
1.1 nicm 79: key_bindings_cmp(struct key_binding *bd1, struct key_binding *bd2)
80: {
1.55 nicm 81: if (bd1->key < bd2->key)
82: return (-1);
83: if (bd1->key > bd2->key)
84: return (1);
85: return (0);
1.45 nicm 86: }
87:
1.106 ! nicm 88: static void
! 89: key_bindings_free(struct key_table *table, struct key_binding *bd)
! 90: {
! 91: RB_REMOVE(key_bindings, &table->key_bindings, bd);
! 92: cmd_list_free(bd->cmdlist);
! 93: free(bd);
! 94: }
! 95:
1.45 nicm 96: struct key_table *
97: key_bindings_get_table(const char *name, int create)
98: {
99: struct key_table table_find, *table;
100:
101: table_find.name = name;
102: table = RB_FIND(key_tables, &key_tables, &table_find);
103: if (table != NULL || !create)
104: return (table);
1.8 nicm 105:
1.45 nicm 106: table = xmalloc(sizeof *table);
107: table->name = xstrdup(name);
108: RB_INIT(&table->key_bindings);
1.8 nicm 109:
1.45 nicm 110: table->references = 1; /* one reference in key_tables */
111: RB_INSERT(key_tables, &key_tables, table);
112:
113: return (table);
1.1 nicm 114: }
115:
1.86 nicm 116: struct key_table *
117: key_bindings_first_table(void)
118: {
119: return (RB_MIN(key_tables, &key_tables));
120: }
121:
122: struct key_table *
123: key_bindings_next_table(struct key_table *table)
124: {
125: return (RB_NEXT(key_tables, &key_tables, table));
126: }
127:
1.45 nicm 128: void
129: key_bindings_unref_table(struct key_table *table)
1.1 nicm 130: {
1.45 nicm 131: struct key_binding *bd;
1.57 nicm 132: struct key_binding *bd1;
1.45 nicm 133:
134: if (--table->references != 0)
135: return;
136:
1.106 ! nicm 137: RB_FOREACH_SAFE(bd, key_bindings, &table->key_bindings, bd1)
! 138: key_bindings_free(table, bd);
1.1 nicm 139:
1.45 nicm 140: free((void *)table->name);
141: free(table);
1.86 nicm 142: }
143:
144: struct key_binding *
145: key_bindings_get(struct key_table *table, key_code key)
146: {
147: struct key_binding bd;
148:
149: bd.key = key;
150: return (RB_FIND(key_bindings, &table->key_bindings, &bd));
151: }
152:
153: struct key_binding *
154: key_bindings_first(struct key_table *table)
155: {
156: return (RB_MIN(key_bindings, &table->key_bindings));
157: }
158:
159: struct key_binding *
160: key_bindings_next(__unused struct key_table *table, struct key_binding *bd)
161: {
162: return (RB_NEXT(key_bindings, &table->key_bindings, bd));
1.1 nicm 163: }
164:
165: void
1.75 nicm 166: key_bindings_add(const char *name, key_code key, int repeat,
1.45 nicm 167: struct cmd_list *cmdlist)
1.1 nicm 168: {
1.45 nicm 169: struct key_table *table;
1.106 ! nicm 170: struct key_binding *bd;
1.45 nicm 171:
172: table = key_bindings_get_table(name, 1);
1.1 nicm 173:
1.106 ! nicm 174: bd = key_bindings_get(table, key & ~KEYC_XTERM);
! 175: if (bd != NULL)
! 176: key_bindings_free(table, bd);
1.15 nicm 177:
1.76 nicm 178: bd = xcalloc(1, sizeof *bd);
1.2 nicm 179: bd->key = key;
1.45 nicm 180: RB_INSERT(key_bindings, &table->key_bindings, bd);
1.15 nicm 181:
1.75 nicm 182: if (repeat)
183: bd->flags |= KEY_BINDING_REPEAT;
1.1 nicm 184: bd->cmdlist = cmdlist;
185: }
186:
187: void
1.55 nicm 188: key_bindings_remove(const char *name, key_code key)
1.1 nicm 189: {
1.45 nicm 190: struct key_table *table;
1.106 ! nicm 191: struct key_binding *bd;
1.45 nicm 192:
193: table = key_bindings_get_table(name, 0);
194: if (table == NULL)
195: return;
1.1 nicm 196:
1.106 ! nicm 197: bd = key_bindings_get(table, key & ~KEYC_XTERM);
1.45 nicm 198: if (bd == NULL)
1.1 nicm 199: return;
1.106 ! nicm 200: key_bindings_free(table, bd);
1.45 nicm 201:
202: if (RB_EMPTY(&table->key_bindings)) {
203: RB_REMOVE(key_tables, &key_tables, table);
204: key_bindings_unref_table(table);
205: }
206: }
207:
208: void
209: key_bindings_remove_table(const char *name)
210: {
211: struct key_table *table;
1.82 nicm 212: struct client *c;
1.45 nicm 213:
214: table = key_bindings_get_table(name, 0);
215: if (table != NULL) {
216: RB_REMOVE(key_tables, &key_tables, table);
217: key_bindings_unref_table(table);
1.82 nicm 218: }
219: TAILQ_FOREACH(c, &clients, entry) {
220: if (c->keytable == table)
221: server_client_set_key_table(c, NULL);
1.45 nicm 222: }
1.1 nicm 223: }
224:
225: void
226: key_bindings_init(void)
227: {
1.47 nicm 228: static const char *defaults[] = {
1.42 nicm 229: "bind C-b send-prefix",
230: "bind C-o rotate-window",
231: "bind C-z suspend-client",
232: "bind Space next-layout",
233: "bind ! break-pane",
234: "bind '\"' split-window",
235: "bind '#' list-buffers",
1.83 nicm 236: "bind '$' command-prompt -I'#S' \"rename-session -- '%%'\"",
1.42 nicm 237: "bind % split-window -h",
238: "bind & confirm-before -p\"kill-window #W? (y/n)\" kill-window",
239: "bind \"'\" command-prompt -pindex \"select-window -t ':%%'\"",
240: "bind ( switch-client -p",
241: "bind ) switch-client -n",
1.83 nicm 242: "bind , command-prompt -I'#W' \"rename-window -- '%%'\"",
1.42 nicm 243: "bind - delete-buffer",
244: "bind . command-prompt \"move-window -t '%%'\"",
1.50 nicm 245: "bind 0 select-window -t:=0",
246: "bind 1 select-window -t:=1",
247: "bind 2 select-window -t:=2",
248: "bind 3 select-window -t:=3",
249: "bind 4 select-window -t:=4",
250: "bind 5 select-window -t:=5",
251: "bind 6 select-window -t:=6",
252: "bind 7 select-window -t:=7",
253: "bind 8 select-window -t:=8",
254: "bind 9 select-window -t:=9",
1.42 nicm 255: "bind : command-prompt",
256: "bind \\; last-pane",
1.85 nicm 257: "bind = choose-buffer -Z",
1.42 nicm 258: "bind ? list-keys",
1.85 nicm 259: "bind D choose-client -Z",
1.84 nicm 260: "bind E select-layout -E",
1.42 nicm 261: "bind L switch-client -l",
1.49 nicm 262: "bind M select-pane -M",
1.42 nicm 263: "bind [ copy-mode",
264: "bind ] paste-buffer",
265: "bind c new-window",
266: "bind d detach-client",
1.87 nicm 267: "bind f command-prompt \"find-window -Z -- '%%'\"",
1.42 nicm 268: "bind i display-message",
269: "bind l last-window",
1.49 nicm 270: "bind m select-pane -m",
1.42 nicm 271: "bind n next-window",
272: "bind o select-pane -t:.+",
273: "bind p previous-window",
274: "bind q display-panes",
275: "bind r refresh-client",
1.85 nicm 276: "bind s choose-tree -Zs",
1.42 nicm 277: "bind t clock-mode",
1.85 nicm 278: "bind w choose-tree -Zw",
1.42 nicm 279: "bind x confirm-before -p\"kill-pane #P? (y/n)\" kill-pane",
280: "bind z resize-pane -Z",
1.94 nicm 281: "bind '{' swap-pane -U",
282: "bind '}' swap-pane -D",
1.42 nicm 283: "bind '~' show-messages",
284: "bind PPage copy-mode -u",
285: "bind -r Up select-pane -U",
286: "bind -r Down select-pane -D",
287: "bind -r Left select-pane -L",
288: "bind -r Right select-pane -R",
289: "bind M-1 select-layout even-horizontal",
290: "bind M-2 select-layout even-vertical",
291: "bind M-3 select-layout main-horizontal",
292: "bind M-4 select-layout main-vertical",
293: "bind M-5 select-layout tiled",
294: "bind M-n next-window -a",
295: "bind M-o rotate-window -D",
296: "bind M-p previous-window -a",
1.88 nicm 297: "bind -r S-Up refresh-client -U 10",
298: "bind -r S-Down refresh-client -D 10",
299: "bind -r S-Left refresh-client -L 10",
300: "bind -r S-Right refresh-client -R 10",
301: "bind -r DC refresh-client -c",
1.42 nicm 302: "bind -r M-Up resize-pane -U 5",
303: "bind -r M-Down resize-pane -D 5",
304: "bind -r M-Left resize-pane -L 5",
305: "bind -r M-Right resize-pane -R 5",
306: "bind -r C-Up resize-pane -U",
307: "bind -r C-Down resize-pane -D",
308: "bind -r C-Left resize-pane -L",
309: "bind -r C-Right resize-pane -R",
1.91 nicm 310:
1.44 nicm 311: "bind -n MouseDown1Pane select-pane -t=\\; send-keys -M",
312: "bind -n MouseDrag1Border resize-pane -M",
313: "bind -n MouseDown1Status select-window -t=",
1.52 nicm 314: "bind -n WheelDownStatus next-window",
315: "bind -n WheelUpStatus previous-window",
1.46 nicm 316: "bind -n MouseDrag1Pane if -Ft= '#{mouse_any_flag}' 'if -Ft= \"#{pane_in_mode}\" \"copy-mode -M\" \"send-keys -M\"' 'copy-mode -M'",
1.92 nicm 317: "bind -n WheelUpPane if -Ft= '#{mouse_any_flag}' 'send-keys -M' 'if -Ft= \"#{pane_in_mode}\" \"send-keys -M\" \"copy-mode -et=\"'",
1.95 nicm 318:
1.97 nicm 319: "bind -n MouseDown3StatusLeft display-menu -t= -xM -yS -T \"#[align=centre]#{session_name}\" " DEFAULT_SESSION_MENU,
320: "bind -n MouseDown3Status display-menu -t= -xW -yS -T \"#[align=centre]#{window_index}:#{window_name}\" " DEFAULT_WINDOW_MENU,
1.101 nicm 321: "bind < display-menu -xW -yS -T \"#[align=centre]#{window_index}:#{window_name}\" " DEFAULT_WINDOW_MENU,
1.98 nicm 322: "bind -n MouseDown3Pane if -Ft= '#{||:#{mouse_any_flag},#{pane_in_mode}}' 'select-pane -t=; send-keys -M' {display-menu -t= -xM -yM -T \"#[align=centre]#{pane_index} (#{pane_id})\" " DEFAULT_PANE_MENU "}",
1.97 nicm 323: "bind -n M-MouseDown3Pane display-menu -t= -xM -yM -T \"#[align=centre]#{pane_index} (#{pane_id})\" " DEFAULT_PANE_MENU,
1.101 nicm 324: "bind > display-menu -xP -yP -T \"#[align=centre]#{pane_index} (#{pane_id})\" " DEFAULT_PANE_MENU,
1.58 nicm 325:
326: "bind -Tcopy-mode C-Space send -X begin-selection",
327: "bind -Tcopy-mode C-a send -X start-of-line",
328: "bind -Tcopy-mode C-c send -X cancel",
329: "bind -Tcopy-mode C-e send -X end-of-line",
330: "bind -Tcopy-mode C-f send -X cursor-right",
1.67 nicm 331: "bind -Tcopy-mode C-b send -X cursor-left",
1.58 nicm 332: "bind -Tcopy-mode C-g send -X clear-selection",
333: "bind -Tcopy-mode C-k send -X copy-end-of-line",
334: "bind -Tcopy-mode C-n send -X cursor-down",
335: "bind -Tcopy-mode C-p send -X cursor-up",
1.81 nicm 336: "bind -Tcopy-mode C-r command-prompt -ip'(search up)' -I'#{pane_search_string}' 'send -X search-backward-incremental \"%%%\"'",
337: "bind -Tcopy-mode C-s command-prompt -ip'(search down)' -I'#{pane_search_string}' 'send -X search-forward-incremental \"%%%\"'",
1.58 nicm 338: "bind -Tcopy-mode C-v send -X page-down",
339: "bind -Tcopy-mode C-w send -X copy-selection-and-cancel",
340: "bind -Tcopy-mode Escape send -X cancel",
341: "bind -Tcopy-mode Space send -X page-down",
342: "bind -Tcopy-mode , send -X jump-reverse",
343: "bind -Tcopy-mode \\; send -X jump-again",
1.81 nicm 344: "bind -Tcopy-mode F command-prompt -1p'(jump backward)' 'send -X jump-backward \"%%%\"'",
1.58 nicm 345: "bind -Tcopy-mode N send -X search-reverse",
346: "bind -Tcopy-mode R send -X rectangle-toggle",
1.81 nicm 347: "bind -Tcopy-mode T command-prompt -1p'(jump to backward)' 'send -X jump-to-backward \"%%%\"'",
348: "bind -Tcopy-mode f command-prompt -1p'(jump forward)' 'send -X jump-forward \"%%%\"'",
349: "bind -Tcopy-mode g command-prompt -p'(goto line)' 'send -X goto-line \"%%%\"'",
1.58 nicm 350: "bind -Tcopy-mode n send -X search-again",
351: "bind -Tcopy-mode q send -X cancel",
1.81 nicm 352: "bind -Tcopy-mode t command-prompt -1p'(jump to forward)' 'send -X jump-to-forward \"%%%\"'",
1.74 nicm 353: "bind -Tcopy-mode Home send -X start-of-line",
354: "bind -Tcopy-mode End send -X end-of-line",
1.66 nicm 355: "bind -Tcopy-mode MouseDown1Pane select-pane",
356: "bind -Tcopy-mode MouseDrag1Pane select-pane\\; send -X begin-selection",
1.58 nicm 357: "bind -Tcopy-mode MouseDragEnd1Pane send -X copy-selection-and-cancel",
1.66 nicm 358: "bind -Tcopy-mode WheelUpPane select-pane\\; send -N5 -X scroll-up",
359: "bind -Tcopy-mode WheelDownPane select-pane\\; send -N5 -X scroll-down",
360: "bind -Tcopy-mode DoubleClick1Pane select-pane\\; send -X select-word",
361: "bind -Tcopy-mode TripleClick1Pane select-pane\\; send -X select-line",
1.58 nicm 362: "bind -Tcopy-mode NPage send -X page-down",
363: "bind -Tcopy-mode PPage send -X page-up",
364: "bind -Tcopy-mode Up send -X cursor-up",
365: "bind -Tcopy-mode Down send -X cursor-down",
366: "bind -Tcopy-mode Left send -X cursor-left",
367: "bind -Tcopy-mode Right send -X cursor-right",
1.81 nicm 368: "bind -Tcopy-mode M-1 command-prompt -Np'(repeat)' -I1 'send -N \"%%%\"'",
369: "bind -Tcopy-mode M-2 command-prompt -Np'(repeat)' -I2 'send -N \"%%%\"'",
370: "bind -Tcopy-mode M-3 command-prompt -Np'(repeat)' -I3 'send -N \"%%%\"'",
371: "bind -Tcopy-mode M-4 command-prompt -Np'(repeat)' -I4 'send -N \"%%%\"'",
372: "bind -Tcopy-mode M-5 command-prompt -Np'(repeat)' -I5 'send -N \"%%%\"'",
373: "bind -Tcopy-mode M-6 command-prompt -Np'(repeat)' -I6 'send -N \"%%%\"'",
374: "bind -Tcopy-mode M-7 command-prompt -Np'(repeat)' -I7 'send -N \"%%%\"'",
375: "bind -Tcopy-mode M-8 command-prompt -Np'(repeat)' -I8 'send -N \"%%%\"'",
376: "bind -Tcopy-mode M-9 command-prompt -Np'(repeat)' -I9 'send -N \"%%%\"'",
1.58 nicm 377: "bind -Tcopy-mode M-< send -X history-top",
378: "bind -Tcopy-mode M-> send -X history-bottom",
379: "bind -Tcopy-mode M-R send -X top-line",
380: "bind -Tcopy-mode M-b send -X previous-word",
1.89 nicm 381: "bind -Tcopy-mode C-M-b send -X previous-matching-bracket",
1.58 nicm 382: "bind -Tcopy-mode M-f send -X next-word-end",
1.89 nicm 383: "bind -Tcopy-mode C-M-f send -X next-matching-bracket",
1.58 nicm 384: "bind -Tcopy-mode M-m send -X back-to-indentation",
385: "bind -Tcopy-mode M-r send -X middle-line",
386: "bind -Tcopy-mode M-v send -X page-up",
387: "bind -Tcopy-mode M-w send -X copy-selection-and-cancel",
1.94 nicm 388: "bind -Tcopy-mode 'M-{' send -X previous-paragraph",
389: "bind -Tcopy-mode 'M-}' send -X next-paragraph",
1.58 nicm 390: "bind -Tcopy-mode M-Up send -X halfpage-up",
391: "bind -Tcopy-mode M-Down send -X halfpage-down",
392: "bind -Tcopy-mode C-Up send -X scroll-up",
393: "bind -Tcopy-mode C-Down send -X scroll-down",
394:
1.103 nicm 395: "bind -Tcopy-mode-vi '#' send -FX search-backward '#{copy_cursor_word}'",
396: "bind -Tcopy-mode-vi * send -FX search-forward '#{copy_cursor_word}'",
1.58 nicm 397: "bind -Tcopy-mode-vi C-c send -X cancel",
398: "bind -Tcopy-mode-vi C-d send -X halfpage-down",
399: "bind -Tcopy-mode-vi C-e send -X scroll-down",
1.67 nicm 400: "bind -Tcopy-mode-vi C-b send -X page-up",
1.58 nicm 401: "bind -Tcopy-mode-vi C-f send -X page-down",
402: "bind -Tcopy-mode-vi C-h send -X cursor-left",
403: "bind -Tcopy-mode-vi C-j send -X copy-selection-and-cancel",
404: "bind -Tcopy-mode-vi Enter send -X copy-selection-and-cancel",
405: "bind -Tcopy-mode-vi C-u send -X halfpage-up",
406: "bind -Tcopy-mode-vi C-v send -X rectangle-toggle",
407: "bind -Tcopy-mode-vi C-y send -X scroll-up",
408: "bind -Tcopy-mode-vi Escape send -X clear-selection",
409: "bind -Tcopy-mode-vi Space send -X begin-selection",
410: "bind -Tcopy-mode-vi '$' send -X end-of-line",
411: "bind -Tcopy-mode-vi , send -X jump-reverse",
1.81 nicm 412: "bind -Tcopy-mode-vi / command-prompt -p'(search down)' 'send -X search-forward \"%%%\"'",
1.58 nicm 413: "bind -Tcopy-mode-vi 0 send -X start-of-line",
1.81 nicm 414: "bind -Tcopy-mode-vi 1 command-prompt -Np'(repeat)' -I1 'send -N \"%%%\"'",
415: "bind -Tcopy-mode-vi 2 command-prompt -Np'(repeat)' -I2 'send -N \"%%%\"'",
416: "bind -Tcopy-mode-vi 3 command-prompt -Np'(repeat)' -I3 'send -N \"%%%\"'",
417: "bind -Tcopy-mode-vi 4 command-prompt -Np'(repeat)' -I4 'send -N \"%%%\"'",
418: "bind -Tcopy-mode-vi 5 command-prompt -Np'(repeat)' -I5 'send -N \"%%%\"'",
419: "bind -Tcopy-mode-vi 6 command-prompt -Np'(repeat)' -I6 'send -N \"%%%\"'",
420: "bind -Tcopy-mode-vi 7 command-prompt -Np'(repeat)' -I7 'send -N \"%%%\"'",
421: "bind -Tcopy-mode-vi 8 command-prompt -Np'(repeat)' -I8 'send -N \"%%%\"'",
422: "bind -Tcopy-mode-vi 9 command-prompt -Np'(repeat)' -I9 'send -N \"%%%\"'",
423: "bind -Tcopy-mode-vi : command-prompt -p'(goto line)' 'send -X goto-line \"%%%\"'",
1.60 nicm 424: "bind -Tcopy-mode-vi \\; send -X jump-again",
1.81 nicm 425: "bind -Tcopy-mode-vi ? command-prompt -p'(search up)' 'send -X search-backward \"%%%\"'",
1.58 nicm 426: "bind -Tcopy-mode-vi A send -X append-selection-and-cancel",
427: "bind -Tcopy-mode-vi B send -X previous-space",
428: "bind -Tcopy-mode-vi D send -X copy-end-of-line",
429: "bind -Tcopy-mode-vi E send -X next-space-end",
1.81 nicm 430: "bind -Tcopy-mode-vi F command-prompt -1p'(jump backward)' 'send -X jump-backward \"%%%\"'",
1.58 nicm 431: "bind -Tcopy-mode-vi G send -X history-bottom",
432: "bind -Tcopy-mode-vi H send -X top-line",
433: "bind -Tcopy-mode-vi J send -X scroll-down",
434: "bind -Tcopy-mode-vi K send -X scroll-up",
435: "bind -Tcopy-mode-vi L send -X bottom-line",
436: "bind -Tcopy-mode-vi M send -X middle-line",
437: "bind -Tcopy-mode-vi N send -X search-reverse",
1.81 nicm 438: "bind -Tcopy-mode-vi T command-prompt -1p'(jump to backward)' 'send -X jump-to-backward \"%%%\"'",
1.58 nicm 439: "bind -Tcopy-mode-vi V send -X select-line",
440: "bind -Tcopy-mode-vi W send -X next-space",
441: "bind -Tcopy-mode-vi ^ send -X back-to-indentation",
442: "bind -Tcopy-mode-vi b send -X previous-word",
443: "bind -Tcopy-mode-vi e send -X next-word-end",
1.81 nicm 444: "bind -Tcopy-mode-vi f command-prompt -1p'(jump forward)' 'send -X jump-forward \"%%%\"'",
1.58 nicm 445: "bind -Tcopy-mode-vi g send -X history-top",
446: "bind -Tcopy-mode-vi h send -X cursor-left",
447: "bind -Tcopy-mode-vi j send -X cursor-down",
448: "bind -Tcopy-mode-vi k send -X cursor-up",
449: "bind -Tcopy-mode-vi l send -X cursor-right",
450: "bind -Tcopy-mode-vi n send -X search-again",
451: "bind -Tcopy-mode-vi o send -X other-end",
452: "bind -Tcopy-mode-vi q send -X cancel",
1.81 nicm 453: "bind -Tcopy-mode-vi t command-prompt -1p'(jump to forward)' 'send -X jump-to-forward \"%%%\"'",
1.58 nicm 454: "bind -Tcopy-mode-vi v send -X rectangle-toggle",
455: "bind -Tcopy-mode-vi w send -X next-word",
1.94 nicm 456: "bind -Tcopy-mode-vi '{' send -X previous-paragraph",
457: "bind -Tcopy-mode-vi '}' send -X next-paragraph",
1.89 nicm 458: "bind -Tcopy-mode-vi % send -X next-matching-bracket",
1.66 nicm 459: "bind -Tcopy-mode-vi MouseDown1Pane select-pane",
460: "bind -Tcopy-mode-vi MouseDrag1Pane select-pane\\; send -X begin-selection",
1.58 nicm 461: "bind -Tcopy-mode-vi MouseDragEnd1Pane send -X copy-selection-and-cancel",
1.66 nicm 462: "bind -Tcopy-mode-vi WheelUpPane select-pane\\; send -N5 -X scroll-up",
463: "bind -Tcopy-mode-vi WheelDownPane select-pane\\; send -N5 -X scroll-down",
464: "bind -Tcopy-mode-vi DoubleClick1Pane select-pane\\; send -X select-word",
465: "bind -Tcopy-mode-vi TripleClick1Pane select-pane\\; send -X select-line",
1.58 nicm 466: "bind -Tcopy-mode-vi BSpace send -X cursor-left",
467: "bind -Tcopy-mode-vi NPage send -X page-down",
468: "bind -Tcopy-mode-vi PPage send -X page-up",
469: "bind -Tcopy-mode-vi Up send -X cursor-up",
470: "bind -Tcopy-mode-vi Down send -X cursor-down",
471: "bind -Tcopy-mode-vi Left send -X cursor-left",
472: "bind -Tcopy-mode-vi Right send -X cursor-right",
473: "bind -Tcopy-mode-vi C-Up send -X scroll-up",
474: "bind -Tcopy-mode-vi C-Down send -X scroll-down",
1.1 nicm 475: };
1.93 nicm 476: u_int i;
477: struct cmd_parse_result *pr;
1.1 nicm 478:
1.42 nicm 479: for (i = 0; i < nitems(defaults); i++) {
1.93 nicm 480: pr = cmd_parse_from_string(defaults[i], NULL);
481: if (pr->status != CMD_PARSE_SUCCESS)
1.72 nicm 482: fatalx("bad default key: %s", defaults[i]);
1.93 nicm 483: cmdq_append(NULL, cmdq_get_command(pr->cmdlist, NULL, NULL, 0));
484: cmd_list_free(pr->cmdlist);
1.1 nicm 485: }
1.61 nicm 486: }
487:
488: static enum cmd_retval
1.62 nicm 489: key_bindings_read_only(struct cmdq_item *item, __unused void *data)
1.61 nicm 490: {
1.62 nicm 491: cmdq_error(item, "client is read-only");
1.61 nicm 492: return (CMD_RETURN_ERROR);
1.1 nicm 493: }
494:
1.90 nicm 495: struct cmdq_item *
1.78 nicm 496: key_bindings_dispatch(struct key_binding *bd, struct cmdq_item *item,
497: struct client *c, struct mouse_event *m, struct cmd_find_state *fs)
1.1 nicm 498: {
1.73 nicm 499: struct cmd *cmd;
1.78 nicm 500: struct cmdq_item *new_item;
1.73 nicm 501: int readonly;
1.1 nicm 502:
1.102 nicm 503: if (c == NULL || (~c->flags & CLIENT_READONLY))
504: readonly = 1;
505: else {
506: readonly = 1;
507: TAILQ_FOREACH(cmd, &bd->cmdlist->list, qentry) {
508: if (~cmd->entry->flags & CMD_READONLY)
509: readonly = 0;
510: }
1.17 nicm 511: }
1.102 nicm 512: if (!readonly)
1.78 nicm 513: new_item = cmdq_get_callback(key_bindings_read_only, NULL);
1.73 nicm 514: else {
1.78 nicm 515: new_item = cmdq_get_command(bd->cmdlist, fs, m, 0);
1.75 nicm 516: if (bd->flags & KEY_BINDING_REPEAT)
1.78 nicm 517: new_item->shared->flags |= CMDQ_SHARED_REPEAT;
1.73 nicm 518: }
1.78 nicm 519: if (item != NULL)
1.105 nicm 520: new_item = cmdq_insert_after(item, new_item);
1.78 nicm 521: else
1.105 nicm 522: new_item = cmdq_append(c, new_item);
1.90 nicm 523: return (new_item);
1.1 nicm 524: }