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

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