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