[BACK]Return to cmd-select-pane.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Annotation of src/usr.bin/tmux/cmd-select-pane.c, Revision 1.44

1.44    ! nicm        1: /* $OpenBSD: cmd-select-pane.c,v 1.43 2018/05/20 11:48:34 nicm Exp $ */
1.1       nicm        2:
                      3: /*
1.32      nicm        4:  * Copyright (c) 2009 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:
1.42      nicm       21: #include <stdlib.h>
                     22:
1.1       nicm       23: #include "tmux.h"
                     24:
                     25: /*
                     26:  * Select pane.
                     27:  */
                     28:
1.34      nicm       29: static enum cmd_retval cmd_select_pane_exec(struct cmd *, struct cmdq_item *);
1.1       nicm       30:
                     31: const struct cmd_entry cmd_select_pane_entry = {
1.28      nicm       32:        .name = "select-pane",
                     33:        .alias = "selectp",
                     34:
1.41      nicm       35:        .args = { "DdegLlMmP:RT:t:U", 0, 0 },
                     36:        .usage = "[-DdegLlMmRU] [-P style] [-T title] " CMD_TARGET_PANE_USAGE,
1.28      nicm       37:
1.38      nicm       38:        .target = { 't', CMD_FIND_PANE, 0 },
1.29      nicm       39:
                     40:        .flags = 0,
1.28      nicm       41:        .exec = cmd_select_pane_exec
1.1       nicm       42: };
                     43:
1.12      nicm       44: const struct cmd_entry cmd_last_pane_entry = {
1.28      nicm       45:        .name = "last-pane",
                     46:        .alias = "lastp",
                     47:
                     48:        .args = { "det:", 0, 0 },
                     49:        .usage = "[-de] " CMD_TARGET_WINDOW_USAGE,
                     50:
1.38      nicm       51:        .target = { 't', CMD_FIND_WINDOW, 0 },
1.29      nicm       52:
                     53:        .flags = 0,
1.28      nicm       54:        .exec = cmd_select_pane_exec
1.12      nicm       55: };
1.10      nicm       56:
1.33      nicm       57: static enum cmd_retval
1.34      nicm       58: cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
1.1       nicm       59: {
1.11      nicm       60:        struct args             *args = self->args;
1.37      nicm       61:        struct cmd_find_state   *current = &item->shared->current;
1.42      nicm       62:        struct client           *c = cmd_find_client(item, NULL, 1);
1.38      nicm       63:        struct winlink          *wl = item->target.wl;
1.27      nicm       64:        struct window           *w = wl->window;
1.38      nicm       65:        struct session          *s = item->target.s;
                     66:        struct window_pane      *wp = item->target.wp, *lastwp, *markedwp;
1.42      nicm       67:        char                    *pane_title;
1.21      nicm       68:        const char              *style;
1.12      nicm       69:
                     70:        if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) {
1.36      nicm       71:                lastwp = w->last;
1.44    ! nicm       72:                if (lastwp == NULL && window_count_panes(w) == 2) {
        !            73:                        lastwp = TAILQ_PREV(w->active, window_panes, entry);
        !            74:                        if (lastwp == NULL)
        !            75:                                lastwp = TAILQ_NEXT(w->active, entry);
        !            76:                }
1.36      nicm       77:                if (lastwp == NULL) {
1.34      nicm       78:                        cmdq_error(item, "no last pane");
1.14      nicm       79:                        return (CMD_RETURN_ERROR);
1.12      nicm       80:                }
1.18      nicm       81:                if (args_has(self->args, 'e'))
1.36      nicm       82:                        lastwp->flags &= ~PANE_INPUTOFF;
1.18      nicm       83:                else if (args_has(self->args, 'd'))
1.36      nicm       84:                        lastwp->flags |= PANE_INPUTOFF;
1.18      nicm       85:                else {
1.25      nicm       86:                        server_unzoom_window(w);
1.36      nicm       87:                        window_redraw_active_switch(w, lastwp);
                     88:                        if (window_set_active_pane(w, lastwp)) {
1.40      nicm       89:                                cmd_find_from_winlink(current, wl, 0);
1.25      nicm       90:                                server_status_window(w);
                     91:                                server_redraw_window_borders(w);
                     92:                        }
1.18      nicm       93:                }
1.14      nicm       94:                return (CMD_RETURN_NORMAL);
1.27      nicm       95:        }
1.24      nicm       96:
                     97:        if (args_has(args, 'm') || args_has(args, 'M')) {
                     98:                if (args_has(args, 'm') && !window_pane_visible(wp))
                     99:                        return (CMD_RETURN_NORMAL);
1.30      nicm      100:                lastwp = marked_pane.wp;
1.24      nicm      101:
                    102:                if (args_has(args, 'M') || server_is_marked(s, wl, wp))
                    103:                        server_clear_marked();
                    104:                else
                    105:                        server_set_marked(s, wl, wp);
1.30      nicm      106:                markedwp = marked_pane.wp;
1.24      nicm      107:
                    108:                if (lastwp != NULL) {
                    109:                        server_redraw_window_borders(lastwp->window);
                    110:                        server_status_window(lastwp->window);
                    111:                }
                    112:                if (markedwp != NULL) {
                    113:                        server_redraw_window_borders(markedwp->window);
                    114:                        server_status_window(markedwp->window);
                    115:                }
                    116:                return (CMD_RETURN_NORMAL);
                    117:        }
1.1       nicm      118:
1.21      nicm      119:        if (args_has(self->args, 'P') || args_has(self->args, 'g')) {
                    120:                if (args_has(args, 'P')) {
                    121:                        style = args_get(args, 'P');
                    122:                        if (style_parse(&grid_default_cell, &wp->colgc,
                    123:                            style) == -1) {
1.34      nicm      124:                                cmdq_error(item, "bad style: %s", style);
1.21      nicm      125:                                return (CMD_RETURN_ERROR);
                    126:                        }
                    127:                        wp->flags |= PANE_REDRAW;
                    128:                }
                    129:                if (args_has(self->args, 'g'))
1.34      nicm      130:                        cmdq_print(item, "%s", style_tostring(&wp->colgc));
1.21      nicm      131:                return (CMD_RETURN_NORMAL);
1.1       nicm      132:        }
1.10      nicm      133:
1.26      nicm      134:        if (args_has(self->args, 'L')) {
                    135:                server_unzoom_window(wp->window);
1.10      nicm      136:                wp = window_pane_find_left(wp);
1.26      nicm      137:        } else if (args_has(self->args, 'R')) {
                    138:                server_unzoom_window(wp->window);
1.10      nicm      139:                wp = window_pane_find_right(wp);
1.26      nicm      140:        } else if (args_has(self->args, 'U')) {
                    141:                server_unzoom_window(wp->window);
1.10      nicm      142:                wp = window_pane_find_up(wp);
1.26      nicm      143:        } else if (args_has(self->args, 'D')) {
                    144:                server_unzoom_window(wp->window);
1.10      nicm      145:                wp = window_pane_find_down(wp);
1.26      nicm      146:        }
1.23      nicm      147:        if (wp == NULL)
                    148:                return (CMD_RETURN_NORMAL);
1.10      nicm      149:
1.22      nicm      150:        if (args_has(self->args, 'e')) {
1.18      nicm      151:                wp->flags &= ~PANE_INPUTOFF;
1.22      nicm      152:                return (CMD_RETURN_NORMAL);
                    153:        }
                    154:        if (args_has(self->args, 'd')) {
1.18      nicm      155:                wp->flags |= PANE_INPUTOFF;
1.22      nicm      156:                return (CMD_RETURN_NORMAL);
1.41      nicm      157:        }
                    158:
                    159:        if (args_has(self->args, 'T')) {
1.42      nicm      160:                pane_title = format_single(item, args_get(self->args, 'T'),
                    161:                    c, s, wl, wp);
                    162:                screen_set_title(&wp->base, pane_title);
                    163:                server_status_window(wp->window);
                    164:                free(pane_title);
1.43      nicm      165:                return (CMD_RETURN_NORMAL);
1.22      nicm      166:        }
                    167:
1.25      nicm      168:        if (wp == w->active)
1.22      nicm      169:                return (CMD_RETURN_NORMAL);
                    170:        server_unzoom_window(wp->window);
                    171:        if (!window_pane_visible(wp)) {
1.34      nicm      172:                cmdq_error(item, "pane not visible");
1.22      nicm      173:                return (CMD_RETURN_ERROR);
                    174:        }
1.25      nicm      175:        window_redraw_active_switch(w, wp);
                    176:        if (window_set_active_pane(w, wp)) {
1.40      nicm      177:                cmd_find_from_winlink_pane(current, wl, wp, 0);
1.39      nicm      178:                hooks_insert(s->hooks, item, current, "after-select-pane");
1.25      nicm      179:                server_status_window(w);
                    180:                server_redraw_window_borders(w);
1.18      nicm      181:        }
1.1       nicm      182:
1.14      nicm      183:        return (CMD_RETURN_NORMAL);
1.1       nicm      184: }