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

1.69    ! nicm        1: /* $OpenBSD: cmd-select-pane.c,v 1.68 2021/08/21 10:22:39 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.68      nicm       36:        .args = { "DdegLlMmP:RT:t:UZ", 0, 0, NULL }, /* -P and -g deprecated */
1.52      nicm       37:        .usage = "[-DdeLlMmRUZ] [-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:
1.68      nicm       49:        .args = { "det:Z", 0, 0, NULL },
1.52      nicm       50:        .usage = "[-deZ] " CMD_TARGET_WINDOW_USAGE,
1.28      nicm       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) {
1.50      nicm       69:                if (c->session == NULL || (c->flags & CLIENT_CONTROL))
1.45      nicm       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.55      nicm       86:        struct args             *args = cmd_get_args(self);
                     87:        const struct cmd_entry  *entry = cmd_get_entry(self);
1.58      nicm       88:        struct cmd_find_state   *current = cmdq_get_current(item);
1.56      nicm       89:        struct cmd_find_state   *target = cmdq_get_target(item);
1.61      nicm       90:        struct client           *c = cmdq_get_client(item);
1.56      nicm       91:        struct winlink          *wl = target->wl;
1.27      nicm       92:        struct window           *w = wl->window;
1.56      nicm       93:        struct session          *s = target->s;
1.61      nicm       94:        struct window_pane      *wp = target->wp, *activewp, *lastwp, *markedwp;
1.60      nicm       95:        struct options          *oo = wp->options;
1.59      nicm       96:        char                    *title;
1.21      nicm       97:        const char              *style;
1.51      nicm       98:        struct options_entry    *o;
1.12      nicm       99:
1.55      nicm      100:        if (entry == &cmd_last_pane_entry || args_has(args, 'l')) {
1.69    ! nicm      101:                /*
        !           102:                 * Check for no last pane found in case the other pane was
        !           103:                 * spawned without being visited (for example split-window -d).
        !           104:                 */
        !           105:                lastwp = TAILQ_FIRST(&w->last_panes);
1.44      nicm      106:                if (lastwp == NULL && window_count_panes(w) == 2) {
                    107:                        lastwp = TAILQ_PREV(w->active, window_panes, entry);
                    108:                        if (lastwp == NULL)
                    109:                                lastwp = TAILQ_NEXT(w->active, entry);
                    110:                }
1.36      nicm      111:                if (lastwp == NULL) {
1.34      nicm      112:                        cmdq_error(item, "no last pane");
1.14      nicm      113:                        return (CMD_RETURN_ERROR);
1.12      nicm      114:                }
1.65      nicm      115:                if (args_has(args, 'e')) {
1.36      nicm      116:                        lastwp->flags &= ~PANE_INPUTOFF;
1.65      nicm      117:                        server_redraw_window_borders(lastwp->window);
                    118:                        server_status_window(lastwp->window);
                    119:                } else if (args_has(args, 'd')) {
1.36      nicm      120:                        lastwp->flags |= PANE_INPUTOFF;
1.65      nicm      121:                        server_redraw_window_borders(lastwp->window);
                    122:                        server_status_window(lastwp->window);
                    123:                } else {
1.66      nicm      124:                        if (window_push_zoom(w, 0, args_has(args, 'Z')))
1.52      nicm      125:                                server_redraw_window(w);
1.36      nicm      126:                        window_redraw_active_switch(w, lastwp);
1.48      nicm      127:                        if (window_set_active_pane(w, lastwp, 1)) {
1.40      nicm      128:                                cmd_find_from_winlink(current, wl, 0);
1.45      nicm      129:                                cmd_select_pane_redraw(w);
1.25      nicm      130:                        }
1.52      nicm      131:                        if (window_pop_zoom(w))
                    132:                                server_redraw_window(w);
1.18      nicm      133:                }
1.14      nicm      134:                return (CMD_RETURN_NORMAL);
1.27      nicm      135:        }
1.24      nicm      136:
                    137:        if (args_has(args, 'm') || args_has(args, 'M')) {
                    138:                if (args_has(args, 'm') && !window_pane_visible(wp))
                    139:                        return (CMD_RETURN_NORMAL);
1.62      nicm      140:                if (server_check_marked())
                    141:                        lastwp = marked_pane.wp;
                    142:                else
                    143:                        lastwp = NULL;
1.24      nicm      144:
                    145:                if (args_has(args, 'M') || server_is_marked(s, wl, wp))
                    146:                        server_clear_marked();
                    147:                else
                    148:                        server_set_marked(s, wl, wp);
1.30      nicm      149:                markedwp = marked_pane.wp;
1.24      nicm      150:
                    151:                if (lastwp != NULL) {
1.67      nicm      152:                        lastwp->flags |= (PANE_REDRAW|PANE_STYLECHANGED);
1.24      nicm      153:                        server_redraw_window_borders(lastwp->window);
                    154:                        server_status_window(lastwp->window);
                    155:                }
                    156:                if (markedwp != NULL) {
1.67      nicm      157:                        markedwp->flags |= (PANE_REDRAW|PANE_STYLECHANGED);
1.24      nicm      158:                        server_redraw_window_borders(markedwp->window);
                    159:                        server_status_window(markedwp->window);
                    160:                }
                    161:                return (CMD_RETURN_NORMAL);
                    162:        }
1.1       nicm      163:
1.60      nicm      164:        style = args_get(args, 'P');
                    165:        if (style != NULL) {
                    166:                o = options_set_string(oo, "window-style", 0, "%s", style);
                    167:                if (o == NULL) {
                    168:                        cmdq_error(item, "bad style: %s", style);
                    169:                        return (CMD_RETURN_ERROR);
1.51      nicm      170:                }
1.60      nicm      171:                options_set_string(oo, "window-active-style", 0, "%s", style);
                    172:                wp->flags |= (PANE_REDRAW|PANE_STYLECHANGED);
                    173:        }
                    174:        if (args_has(args, 'g')) {
                    175:                cmdq_print(item, "%s", options_get_string(oo, "window-style"));
1.21      nicm      176:                return (CMD_RETURN_NORMAL);
1.1       nicm      177:        }
1.10      nicm      178:
1.55      nicm      179:        if (args_has(args, 'L')) {
1.66      nicm      180:                window_push_zoom(w, 0, 1);
1.10      nicm      181:                wp = window_pane_find_left(wp);
1.52      nicm      182:                window_pop_zoom(w);
1.55      nicm      183:        } else if (args_has(args, 'R')) {
1.66      nicm      184:                window_push_zoom(w, 0, 1);
1.10      nicm      185:                wp = window_pane_find_right(wp);
1.52      nicm      186:                window_pop_zoom(w);
1.55      nicm      187:        } else if (args_has(args, 'U')) {
1.66      nicm      188:                window_push_zoom(w, 0, 1);
1.10      nicm      189:                wp = window_pane_find_up(wp);
1.52      nicm      190:                window_pop_zoom(w);
1.55      nicm      191:        } else if (args_has(args, 'D')) {
1.66      nicm      192:                window_push_zoom(w, 0, 1);
1.10      nicm      193:                wp = window_pane_find_down(wp);
1.52      nicm      194:                window_pop_zoom(w);
1.26      nicm      195:        }
1.23      nicm      196:        if (wp == NULL)
                    197:                return (CMD_RETURN_NORMAL);
1.10      nicm      198:
1.55      nicm      199:        if (args_has(args, 'e')) {
1.18      nicm      200:                wp->flags &= ~PANE_INPUTOFF;
1.65      nicm      201:                server_redraw_window_borders(wp->window);
                    202:                server_status_window(wp->window);
1.22      nicm      203:                return (CMD_RETURN_NORMAL);
                    204:        }
1.55      nicm      205:        if (args_has(args, 'd')) {
1.18      nicm      206:                wp->flags |= PANE_INPUTOFF;
1.65      nicm      207:                server_redraw_window_borders(wp->window);
                    208:                server_status_window(wp->window);
1.22      nicm      209:                return (CMD_RETURN_NORMAL);
1.41      nicm      210:        }
                    211:
1.55      nicm      212:        if (args_has(args, 'T')) {
1.59      nicm      213:                title = format_single_from_target(item, args_get(args, 'T'));
1.60      nicm      214:                if (screen_set_title(&wp->base, title)) {
1.64      nicm      215:                        notify_pane("pane-title-changed", wp);
1.60      nicm      216:                        server_redraw_window_borders(wp->window);
1.54      nicm      217:                        server_status_window(wp->window);
1.60      nicm      218:                }
1.59      nicm      219:                free(title);
1.43      nicm      220:                return (CMD_RETURN_NORMAL);
1.22      nicm      221:        }
                    222:
1.63      nicm      223:        if (c != NULL && c->session != NULL && (c->flags & CLIENT_ACTIVEPANE))
1.61      nicm      224:                activewp = server_client_get_pane(c);
                    225:        else
                    226:                activewp = w->active;
                    227:        if (wp == activewp)
1.22      nicm      228:                return (CMD_RETURN_NORMAL);
1.66      nicm      229:        if (window_push_zoom(w, 0, args_has(args, 'Z')))
1.52      nicm      230:                server_redraw_window(w);
1.25      nicm      231:        window_redraw_active_switch(w, wp);
1.63      nicm      232:        if (c != NULL && c->session != NULL && (c->flags & CLIENT_ACTIVEPANE))
1.61      nicm      233:                server_client_set_pane(c, wp);
                    234:        else if (window_set_active_pane(w, wp, 1))
1.40      nicm      235:                cmd_find_from_winlink_pane(current, wl, wp, 0);
1.61      nicm      236:        cmdq_insert_hook(s, item, current, "after-select-pane");
                    237:        cmd_select_pane_redraw(w);
1.52      nicm      238:        if (window_pop_zoom(w))
                    239:                server_redraw_window(w);
1.1       nicm      240:
1.14      nicm      241:        return (CMD_RETURN_NORMAL);
1.1       nicm      242: }