Annotation of src/usr.bin/tmux/cmd-select-pane.c, Revision 1.41
1.41 ! nicm 1: /* $OpenBSD: cmd-select-pane.c,v 1.40 2017/08/30 10:33:57 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:
21: #include "tmux.h"
22:
23: /*
24: * Select pane.
25: */
26:
1.34 nicm 27: static enum cmd_retval cmd_select_pane_exec(struct cmd *, struct cmdq_item *);
1.1 nicm 28:
29: const struct cmd_entry cmd_select_pane_entry = {
1.28 nicm 30: .name = "select-pane",
31: .alias = "selectp",
32:
1.41 ! nicm 33: .args = { "DdegLlMmP:RT:t:U", 0, 0 },
! 34: .usage = "[-DdegLlMmRU] [-P style] [-T title] " CMD_TARGET_PANE_USAGE,
1.28 nicm 35:
1.38 nicm 36: .target = { 't', CMD_FIND_PANE, 0 },
1.29 nicm 37:
38: .flags = 0,
1.28 nicm 39: .exec = cmd_select_pane_exec
1.1 nicm 40: };
41:
1.12 nicm 42: const struct cmd_entry cmd_last_pane_entry = {
1.28 nicm 43: .name = "last-pane",
44: .alias = "lastp",
45:
46: .args = { "det:", 0, 0 },
47: .usage = "[-de] " CMD_TARGET_WINDOW_USAGE,
48:
1.38 nicm 49: .target = { 't', CMD_FIND_WINDOW, 0 },
1.29 nicm 50:
51: .flags = 0,
1.28 nicm 52: .exec = cmd_select_pane_exec
1.12 nicm 53: };
1.10 nicm 54:
1.33 nicm 55: static enum cmd_retval
1.34 nicm 56: cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
1.1 nicm 57: {
1.11 nicm 58: struct args *args = self->args;
1.37 nicm 59: struct cmd_find_state *current = &item->shared->current;
1.38 nicm 60: struct winlink *wl = item->target.wl;
1.27 nicm 61: struct window *w = wl->window;
1.38 nicm 62: struct session *s = item->target.s;
63: struct window_pane *wp = item->target.wp, *lastwp, *markedwp;
1.21 nicm 64: const char *style;
1.12 nicm 65:
66: if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) {
1.36 nicm 67: lastwp = w->last;
68: if (lastwp == NULL) {
1.34 nicm 69: cmdq_error(item, "no last pane");
1.14 nicm 70: return (CMD_RETURN_ERROR);
1.12 nicm 71: }
1.18 nicm 72: if (args_has(self->args, 'e'))
1.36 nicm 73: lastwp->flags &= ~PANE_INPUTOFF;
1.18 nicm 74: else if (args_has(self->args, 'd'))
1.36 nicm 75: lastwp->flags |= PANE_INPUTOFF;
1.18 nicm 76: else {
1.25 nicm 77: server_unzoom_window(w);
1.36 nicm 78: window_redraw_active_switch(w, lastwp);
79: if (window_set_active_pane(w, lastwp)) {
1.40 nicm 80: cmd_find_from_winlink(current, wl, 0);
1.25 nicm 81: server_status_window(w);
82: server_redraw_window_borders(w);
83: }
1.18 nicm 84: }
1.14 nicm 85: return (CMD_RETURN_NORMAL);
1.27 nicm 86: }
1.24 nicm 87:
88: if (args_has(args, 'm') || args_has(args, 'M')) {
89: if (args_has(args, 'm') && !window_pane_visible(wp))
90: return (CMD_RETURN_NORMAL);
1.30 nicm 91: lastwp = marked_pane.wp;
1.24 nicm 92:
93: if (args_has(args, 'M') || server_is_marked(s, wl, wp))
94: server_clear_marked();
95: else
96: server_set_marked(s, wl, wp);
1.30 nicm 97: markedwp = marked_pane.wp;
1.24 nicm 98:
99: if (lastwp != NULL) {
100: server_redraw_window_borders(lastwp->window);
101: server_status_window(lastwp->window);
102: }
103: if (markedwp != NULL) {
104: server_redraw_window_borders(markedwp->window);
105: server_status_window(markedwp->window);
106: }
107: return (CMD_RETURN_NORMAL);
108: }
1.1 nicm 109:
1.21 nicm 110: if (args_has(self->args, 'P') || args_has(self->args, 'g')) {
111: if (args_has(args, 'P')) {
112: style = args_get(args, 'P');
113: if (style_parse(&grid_default_cell, &wp->colgc,
114: style) == -1) {
1.34 nicm 115: cmdq_error(item, "bad style: %s", style);
1.21 nicm 116: return (CMD_RETURN_ERROR);
117: }
118: wp->flags |= PANE_REDRAW;
119: }
120: if (args_has(self->args, 'g'))
1.34 nicm 121: cmdq_print(item, "%s", style_tostring(&wp->colgc));
1.21 nicm 122: return (CMD_RETURN_NORMAL);
1.1 nicm 123: }
1.10 nicm 124:
1.26 nicm 125: if (args_has(self->args, 'L')) {
126: server_unzoom_window(wp->window);
1.10 nicm 127: wp = window_pane_find_left(wp);
1.26 nicm 128: } else if (args_has(self->args, 'R')) {
129: server_unzoom_window(wp->window);
1.10 nicm 130: wp = window_pane_find_right(wp);
1.26 nicm 131: } else if (args_has(self->args, 'U')) {
132: server_unzoom_window(wp->window);
1.10 nicm 133: wp = window_pane_find_up(wp);
1.26 nicm 134: } else if (args_has(self->args, 'D')) {
135: server_unzoom_window(wp->window);
1.10 nicm 136: wp = window_pane_find_down(wp);
1.26 nicm 137: }
1.23 nicm 138: if (wp == NULL)
139: return (CMD_RETURN_NORMAL);
1.10 nicm 140:
1.22 nicm 141: if (args_has(self->args, 'e')) {
1.18 nicm 142: wp->flags &= ~PANE_INPUTOFF;
1.22 nicm 143: return (CMD_RETURN_NORMAL);
144: }
145: if (args_has(self->args, 'd')) {
1.18 nicm 146: wp->flags |= PANE_INPUTOFF;
1.22 nicm 147: return (CMD_RETURN_NORMAL);
1.41 ! nicm 148: }
! 149:
! 150: if (args_has(self->args, 'T')) {
! 151: screen_set_title(&wp->base, args_get(self->args, 'T'));
! 152: server_status_window(wp->window);
1.22 nicm 153: }
154:
1.25 nicm 155: if (wp == w->active)
1.22 nicm 156: return (CMD_RETURN_NORMAL);
157: server_unzoom_window(wp->window);
158: if (!window_pane_visible(wp)) {
1.34 nicm 159: cmdq_error(item, "pane not visible");
1.22 nicm 160: return (CMD_RETURN_ERROR);
161: }
1.25 nicm 162: window_redraw_active_switch(w, wp);
163: if (window_set_active_pane(w, wp)) {
1.40 nicm 164: cmd_find_from_winlink_pane(current, wl, wp, 0);
1.39 nicm 165: hooks_insert(s->hooks, item, current, "after-select-pane");
1.25 nicm 166: server_status_window(w);
167: server_redraw_window_borders(w);
1.18 nicm 168: }
1.1 nicm 169:
1.14 nicm 170: return (CMD_RETURN_NORMAL);
1.1 nicm 171: }