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