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

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