Annotation of src/usr.bin/tmux/cmd-select-pane.c, Revision 1.29
1.29 ! nicm 1: /* $OpenBSD: cmd-select-pane.c,v 1.28 2015/12/13 21:53:57 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:
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.14 nicm 55: enum cmd_retval
1.15 nicm 56: cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq)
1.1 nicm 57: {
1.11 nicm 58: struct args *args = self->args;
1.27 nicm 59: struct winlink *wl = cmdq->state.tflag.wl;
60: struct window *w = wl->window;
61: struct session *s = cmdq->state.tflag.s;
62: struct window_pane *wp = cmdq->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')) {
66:
1.27 nicm 67: if (wl->window->last == NULL) {
1.15 nicm 68: cmdq_error(cmdq, "no last pane");
1.14 nicm 69: return (CMD_RETURN_ERROR);
1.12 nicm 70: }
1.13 nicm 71:
1.18 nicm 72: if (args_has(self->args, 'e'))
1.25 nicm 73: w->last->flags &= ~PANE_INPUTOFF;
1.18 nicm 74: else if (args_has(self->args, 'd'))
1.25 nicm 75: w->last->flags |= PANE_INPUTOFF;
1.18 nicm 76: else {
1.25 nicm 77: server_unzoom_window(w);
78: window_redraw_active_switch(w, w->last);
79: if (window_set_active_pane(w, w->last)) {
80: server_status_window(w);
81: server_redraw_window_borders(w);
82: }
1.18 nicm 83: }
1.13 nicm 84:
1.14 nicm 85: return (CMD_RETURN_NORMAL);
1.12 nicm 86: }
1.1 nicm 87:
1.27 nicm 88: server_unzoom_window(wp->window);
89: if (!window_pane_visible(wp)) {
90: cmdq_error(cmdq, "pane not visible");
1.14 nicm 91: return (CMD_RETURN_ERROR);
1.27 nicm 92: }
1.24 nicm 93:
94: if (args_has(args, 'm') || args_has(args, 'M')) {
95: if (args_has(args, 'm') && !window_pane_visible(wp))
96: return (CMD_RETURN_NORMAL);
97: lastwp = marked_window_pane;
98:
99: if (args_has(args, 'M') || server_is_marked(s, wl, wp))
100: server_clear_marked();
101: else
102: server_set_marked(s, wl, wp);
103: markedwp = marked_window_pane;
104:
105: if (lastwp != NULL) {
106: server_redraw_window_borders(lastwp->window);
107: server_status_window(lastwp->window);
108: }
109: if (markedwp != NULL) {
110: server_redraw_window_borders(markedwp->window);
111: server_status_window(markedwp->window);
112: }
113: return (CMD_RETURN_NORMAL);
114: }
1.1 nicm 115:
1.21 nicm 116: if (args_has(self->args, 'P') || args_has(self->args, 'g')) {
117: if (args_has(args, 'P')) {
118: style = args_get(args, 'P');
119: if (style_parse(&grid_default_cell, &wp->colgc,
120: style) == -1) {
121: cmdq_error(cmdq, "bad style: %s", style);
122: return (CMD_RETURN_ERROR);
123: }
124: wp->flags |= PANE_REDRAW;
125: }
126: if (args_has(self->args, 'g'))
127: cmdq_print(cmdq, "%s", style_tostring(&wp->colgc));
128: return (CMD_RETURN_NORMAL);
1.1 nicm 129: }
1.10 nicm 130:
1.26 nicm 131: if (args_has(self->args, 'L')) {
132: server_unzoom_window(wp->window);
1.10 nicm 133: wp = window_pane_find_left(wp);
1.26 nicm 134: } else if (args_has(self->args, 'R')) {
135: server_unzoom_window(wp->window);
1.10 nicm 136: wp = window_pane_find_right(wp);
1.26 nicm 137: } else if (args_has(self->args, 'U')) {
138: server_unzoom_window(wp->window);
1.10 nicm 139: wp = window_pane_find_up(wp);
1.26 nicm 140: } else if (args_has(self->args, 'D')) {
141: server_unzoom_window(wp->window);
1.10 nicm 142: wp = window_pane_find_down(wp);
1.26 nicm 143: }
1.23 nicm 144: if (wp == NULL)
145: return (CMD_RETURN_NORMAL);
1.10 nicm 146:
1.22 nicm 147: if (args_has(self->args, 'e')) {
1.18 nicm 148: wp->flags &= ~PANE_INPUTOFF;
1.22 nicm 149: return (CMD_RETURN_NORMAL);
150: }
151: if (args_has(self->args, 'd')) {
1.18 nicm 152: wp->flags |= PANE_INPUTOFF;
1.22 nicm 153: return (CMD_RETURN_NORMAL);
154: }
155:
1.25 nicm 156: if (wp == w->active)
1.22 nicm 157: return (CMD_RETURN_NORMAL);
158: server_unzoom_window(wp->window);
159: if (!window_pane_visible(wp)) {
160: cmdq_error(cmdq, "pane not visible");
161: return (CMD_RETURN_ERROR);
162: }
1.25 nicm 163: window_redraw_active_switch(w, wp);
164: if (window_set_active_pane(w, wp)) {
165: server_status_window(w);
166: server_redraw_window_borders(w);
1.18 nicm 167: }
1.1 nicm 168:
1.14 nicm 169: return (CMD_RETURN_NORMAL);
1.1 nicm 170: }