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

1.28    ! nicm        1: /* $OpenBSD: cmd-select-pane.c,v 1.27 2015/12/13 14:32:38 nicm Exp $ */
1.1       nicm        2:
                      3: /*
                      4:  * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
                      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 "tmux.h"
                     22:
                     23: /*
                     24:  * Select pane.
                     25:  */
                     26:
1.15      nicm       27: enum cmd_retval         cmd_select_pane_exec(struct cmd *, struct cmd_q *);
1.1       nicm       28:
                     29: const struct cmd_entry cmd_select_pane_entry = {
1.28    ! nicm       30:        .name = "select-pane",
        !            31:        .alias = "selectp",
        !            32:
        !            33:        .args = { "DdegLlMmP:Rt:U", 0, 0 },
        !            34:        .usage = "[-DdegLlMmRU] [-P style] " CMD_TARGET_PANE_USAGE,
        !            35:
        !            36:        .flags = CMD_PANE_T,
        !            37:        .exec = cmd_select_pane_exec
1.1       nicm       38: };
                     39:
1.12      nicm       40: const struct cmd_entry cmd_last_pane_entry = {
1.28    ! nicm       41:        .name = "last-pane",
        !            42:        .alias = "lastp",
        !            43:
        !            44:        .args = { "det:", 0, 0 },
        !            45:        .usage = "[-de] " CMD_TARGET_WINDOW_USAGE,
        !            46:
        !            47:        .flags = CMD_WINDOW_T,
        !            48:        .exec = cmd_select_pane_exec
1.12      nicm       49: };
1.10      nicm       50:
1.14      nicm       51: enum cmd_retval
1.15      nicm       52: cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq)
1.1       nicm       53: {
1.11      nicm       54:        struct args             *args = self->args;
1.27      nicm       55:        struct winlink          *wl = cmdq->state.tflag.wl;
                     56:        struct window           *w = wl->window;
                     57:        struct session          *s = cmdq->state.tflag.s;
                     58:        struct window_pane      *wp = cmdq->state.tflag.wp, *lastwp, *markedwp;
1.21      nicm       59:        const char              *style;
1.12      nicm       60:
                     61:        if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) {
                     62:
1.27      nicm       63:                if (wl->window->last == NULL) {
1.15      nicm       64:                        cmdq_error(cmdq, "no last pane");
1.14      nicm       65:                        return (CMD_RETURN_ERROR);
1.12      nicm       66:                }
1.13      nicm       67:
1.18      nicm       68:                if (args_has(self->args, 'e'))
1.25      nicm       69:                        w->last->flags &= ~PANE_INPUTOFF;
1.18      nicm       70:                else if (args_has(self->args, 'd'))
1.25      nicm       71:                        w->last->flags |= PANE_INPUTOFF;
1.18      nicm       72:                else {
1.25      nicm       73:                        server_unzoom_window(w);
                     74:                        window_redraw_active_switch(w, w->last);
                     75:                        if (window_set_active_pane(w, w->last)) {
                     76:                                server_status_window(w);
                     77:                                server_redraw_window_borders(w);
                     78:                        }
1.18      nicm       79:                }
1.13      nicm       80:
1.14      nicm       81:                return (CMD_RETURN_NORMAL);
1.12      nicm       82:        }
1.1       nicm       83:
1.27      nicm       84:        server_unzoom_window(wp->window);
                     85:        if (!window_pane_visible(wp)) {
                     86:                cmdq_error(cmdq, "pane not visible");
1.14      nicm       87:                return (CMD_RETURN_ERROR);
1.27      nicm       88:        }
1.24      nicm       89:
                     90:        if (args_has(args, 'm') || args_has(args, 'M')) {
                     91:                if (args_has(args, 'm') && !window_pane_visible(wp))
                     92:                        return (CMD_RETURN_NORMAL);
                     93:                lastwp = marked_window_pane;
                     94:
                     95:                if (args_has(args, 'M') || server_is_marked(s, wl, wp))
                     96:                        server_clear_marked();
                     97:                else
                     98:                        server_set_marked(s, wl, wp);
                     99:                markedwp = marked_window_pane;
                    100:
                    101:                if (lastwp != NULL) {
                    102:                        server_redraw_window_borders(lastwp->window);
                    103:                        server_status_window(lastwp->window);
                    104:                }
                    105:                if (markedwp != NULL) {
                    106:                        server_redraw_window_borders(markedwp->window);
                    107:                        server_status_window(markedwp->window);
                    108:                }
                    109:                return (CMD_RETURN_NORMAL);
                    110:        }
1.1       nicm      111:
1.21      nicm      112:        if (args_has(self->args, 'P') || args_has(self->args, 'g')) {
                    113:                if (args_has(args, 'P')) {
                    114:                        style = args_get(args, 'P');
                    115:                        if (style_parse(&grid_default_cell, &wp->colgc,
                    116:                            style) == -1) {
                    117:                                cmdq_error(cmdq, "bad style: %s", style);
                    118:                                return (CMD_RETURN_ERROR);
                    119:                        }
                    120:                        wp->flags |= PANE_REDRAW;
                    121:                }
                    122:                if (args_has(self->args, 'g'))
                    123:                        cmdq_print(cmdq, "%s", style_tostring(&wp->colgc));
                    124:                return (CMD_RETURN_NORMAL);
1.1       nicm      125:        }
1.10      nicm      126:
1.26      nicm      127:        if (args_has(self->args, 'L')) {
                    128:                server_unzoom_window(wp->window);
1.10      nicm      129:                wp = window_pane_find_left(wp);
1.26      nicm      130:        } else if (args_has(self->args, 'R')) {
                    131:                server_unzoom_window(wp->window);
1.10      nicm      132:                wp = window_pane_find_right(wp);
1.26      nicm      133:        } else if (args_has(self->args, 'U')) {
                    134:                server_unzoom_window(wp->window);
1.10      nicm      135:                wp = window_pane_find_up(wp);
1.26      nicm      136:        } else if (args_has(self->args, 'D')) {
                    137:                server_unzoom_window(wp->window);
1.10      nicm      138:                wp = window_pane_find_down(wp);
1.26      nicm      139:        }
1.23      nicm      140:        if (wp == NULL)
                    141:                return (CMD_RETURN_NORMAL);
1.10      nicm      142:
1.22      nicm      143:        if (args_has(self->args, 'e')) {
1.18      nicm      144:                wp->flags &= ~PANE_INPUTOFF;
1.22      nicm      145:                return (CMD_RETURN_NORMAL);
                    146:        }
                    147:        if (args_has(self->args, 'd')) {
1.18      nicm      148:                wp->flags |= PANE_INPUTOFF;
1.22      nicm      149:                return (CMD_RETURN_NORMAL);
                    150:        }
                    151:
1.25      nicm      152:        if (wp == w->active)
1.22      nicm      153:                return (CMD_RETURN_NORMAL);
                    154:        server_unzoom_window(wp->window);
                    155:        if (!window_pane_visible(wp)) {
                    156:                cmdq_error(cmdq, "pane not visible");
                    157:                return (CMD_RETURN_ERROR);
                    158:        }
1.25      nicm      159:        window_redraw_active_switch(w, wp);
                    160:        if (window_set_active_pane(w, wp)) {
                    161:                server_status_window(w);
                    162:                server_redraw_window_borders(w);
1.18      nicm      163:        }
1.1       nicm      164:
1.14      nicm      165:        return (CMD_RETURN_NORMAL);
1.1       nicm      166: }