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