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