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

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