[BACK]Return to key-bindings.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Annotation of src/usr.bin/tmux/key-bindings.c, Revision 1.104

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