[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.97

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