Annotation of src/usr.bin/tmux/cmd-select-pane.c, Revision 1.35
1.35 ! nicm 1: /* $OpenBSD: cmd-select-pane.c,v 1.34 2016/10/16 19:04:05 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:
33: .args = { "DdegLlMmP:Rt:U", 0, 0 },
34: .usage = "[-DdegLlMmRU] [-P style] " CMD_TARGET_PANE_USAGE,
35:
1.29 nicm 36: .tflag = CMD_PANE,
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.29 nicm 49: .tflag = CMD_WINDOW,
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.34 nicm 59: struct winlink *wl = item->state.tflag.wl;
1.27 nicm 60: struct window *w = wl->window;
1.34 nicm 61: struct session *s = item->state.tflag.s;
62: struct window_pane *wp = item->state.tflag.wp, *lastwp, *markedwp;
1.21 nicm 63: const char *style;
1.12 nicm 64:
65: if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) {
1.27 nicm 66: if (wl->window->last == NULL) {
1.34 nicm 67: cmdq_error(item, "no last pane");
1.14 nicm 68: return (CMD_RETURN_ERROR);
1.12 nicm 69: }
1.13 nicm 70:
1.18 nicm 71: if (args_has(self->args, 'e'))
1.25 nicm 72: w->last->flags &= ~PANE_INPUTOFF;
1.18 nicm 73: else if (args_has(self->args, 'd'))
1.25 nicm 74: w->last->flags |= PANE_INPUTOFF;
1.18 nicm 75: else {
1.25 nicm 76: server_unzoom_window(w);
77: window_redraw_active_switch(w, w->last);
78: if (window_set_active_pane(w, w->last)) {
79: server_status_window(w);
80: server_redraw_window_borders(w);
81: }
1.18 nicm 82: }
1.13 nicm 83:
1.14 nicm 84: return (CMD_RETURN_NORMAL);
1.27 nicm 85: }
1.24 nicm 86:
87: if (args_has(args, 'm') || args_has(args, 'M')) {
88: if (args_has(args, 'm') && !window_pane_visible(wp))
89: return (CMD_RETURN_NORMAL);
1.30 nicm 90: lastwp = marked_pane.wp;
1.24 nicm 91:
92: if (args_has(args, 'M') || server_is_marked(s, wl, wp))
93: server_clear_marked();
94: else
95: server_set_marked(s, wl, wp);
1.30 nicm 96: markedwp = marked_pane.wp;
1.24 nicm 97:
98: if (lastwp != NULL) {
99: server_redraw_window_borders(lastwp->window);
100: server_status_window(lastwp->window);
101: }
102: if (markedwp != NULL) {
103: server_redraw_window_borders(markedwp->window);
104: server_status_window(markedwp->window);
105: }
106: return (CMD_RETURN_NORMAL);
107: }
1.1 nicm 108:
1.21 nicm 109: if (args_has(self->args, 'P') || args_has(self->args, 'g')) {
110: if (args_has(args, 'P')) {
111: style = args_get(args, 'P');
112: if (style_parse(&grid_default_cell, &wp->colgc,
113: style) == -1) {
1.34 nicm 114: cmdq_error(item, "bad style: %s", style);
1.21 nicm 115: return (CMD_RETURN_ERROR);
116: }
117: wp->flags |= PANE_REDRAW;
118: }
119: if (args_has(self->args, 'g'))
1.34 nicm 120: cmdq_print(item, "%s", style_tostring(&wp->colgc));
1.21 nicm 121: return (CMD_RETURN_NORMAL);
1.1 nicm 122: }
1.10 nicm 123:
1.26 nicm 124: if (args_has(self->args, 'L')) {
125: server_unzoom_window(wp->window);
1.10 nicm 126: wp = window_pane_find_left(wp);
1.26 nicm 127: } else if (args_has(self->args, 'R')) {
128: server_unzoom_window(wp->window);
1.10 nicm 129: wp = window_pane_find_right(wp);
1.26 nicm 130: } else if (args_has(self->args, 'U')) {
131: server_unzoom_window(wp->window);
1.10 nicm 132: wp = window_pane_find_up(wp);
1.26 nicm 133: } else if (args_has(self->args, 'D')) {
134: server_unzoom_window(wp->window);
1.10 nicm 135: wp = window_pane_find_down(wp);
1.26 nicm 136: }
1.23 nicm 137: if (wp == NULL)
138: return (CMD_RETURN_NORMAL);
1.10 nicm 139:
1.22 nicm 140: if (args_has(self->args, 'e')) {
1.18 nicm 141: wp->flags &= ~PANE_INPUTOFF;
1.22 nicm 142: return (CMD_RETURN_NORMAL);
143: }
144: if (args_has(self->args, 'd')) {
1.18 nicm 145: wp->flags |= PANE_INPUTOFF;
1.22 nicm 146: return (CMD_RETURN_NORMAL);
147: }
148:
1.25 nicm 149: if (wp == w->active)
1.22 nicm 150: return (CMD_RETURN_NORMAL);
151: server_unzoom_window(wp->window);
152: if (!window_pane_visible(wp)) {
1.34 nicm 153: cmdq_error(item, "pane not visible");
1.22 nicm 154: return (CMD_RETURN_ERROR);
155: }
1.25 nicm 156: window_redraw_active_switch(w, wp);
157: if (window_set_active_pane(w, wp)) {
158: server_status_window(w);
159: server_redraw_window_borders(w);
1.18 nicm 160: }
1.1 nicm 161:
1.14 nicm 162: return (CMD_RETURN_NORMAL);
1.1 nicm 163: }