Annotation of src/usr.bin/tmux/cmd-select-pane.c, Revision 1.19
1.19 ! nicm 1: /* $OpenBSD: cmd-select-pane.c,v 1.18 2014/08/11 22:14:30 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.18 nicm 31: "DdeLlRt:U", 0, 0,
32: "[-DdeLlRU] " CMD_TARGET_PANE_USAGE,
1.11 nicm 33: 0,
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.12 nicm 41: 0,
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.1 nicm 49: struct winlink *wl;
50: struct window_pane *wp;
1.12 nicm 51:
52: if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) {
1.15 nicm 53: wl = cmd_find_window(cmdq, args_get(args, 't'), NULL);
1.12 nicm 54: if (wl == NULL)
1.14 nicm 55: return (CMD_RETURN_ERROR);
1.12 nicm 56:
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'))
63: wl->window->last->flags &= ~PANE_INPUTOFF;
64: else if (args_has(self->args, 'd'))
65: wl->window->last->flags |= PANE_INPUTOFF;
66: else {
67: server_unzoom_window(wl->window);
68: window_set_active_pane(wl->window, wl->window->last);
69: server_status_window(wl->window);
70: server_redraw_window_borders(wl->window);
71: }
1.13 nicm 72:
1.14 nicm 73: return (CMD_RETURN_NORMAL);
1.12 nicm 74: }
1.1 nicm 75:
1.15 nicm 76: if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp)) == NULL)
1.14 nicm 77: return (CMD_RETURN_ERROR);
1.1 nicm 78:
1.16 nicm 79: server_unzoom_window(wp->window);
1.3 nicm 80: if (!window_pane_visible(wp)) {
1.15 nicm 81: cmdq_error(cmdq, "pane not visible");
1.14 nicm 82: return (CMD_RETURN_ERROR);
1.1 nicm 83: }
1.10 nicm 84:
1.11 nicm 85: if (args_has(self->args, 'L'))
1.10 nicm 86: wp = window_pane_find_left(wp);
1.11 nicm 87: else if (args_has(self->args, 'R'))
1.10 nicm 88: wp = window_pane_find_right(wp);
1.11 nicm 89: else if (args_has(self->args, 'U'))
1.10 nicm 90: wp = window_pane_find_up(wp);
1.11 nicm 91: else if (args_has(self->args, 'D'))
1.10 nicm 92: wp = window_pane_find_down(wp);
93: if (wp == NULL) {
1.15 nicm 94: cmdq_error(cmdq, "pane not found");
1.14 nicm 95: return (CMD_RETURN_ERROR);
1.10 nicm 96: }
97:
1.18 nicm 98: if (args_has(self->args, 'e'))
99: wp->flags &= ~PANE_INPUTOFF;
100: else if (args_has(self->args, 'd'))
101: wp->flags |= PANE_INPUTOFF;
102: else {
103: window_set_active_pane(wl->window, wp);
104: server_status_window(wl->window);
105: server_redraw_window_borders(wl->window);
106: }
1.1 nicm 107:
1.14 nicm 108: return (CMD_RETURN_NORMAL);
1.1 nicm 109: }