4 * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
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.
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.
19 #include <sys/types.h>
27 void cmd_select_pane_key_binding(struct cmd
*, int);
28 int cmd_select_pane_exec(struct cmd
*, struct cmd_ctx
*);
30 const struct cmd_entry cmd_select_pane_entry
= {
31 "select-pane", "selectp",
33 "[-lDLRU] " CMD_TARGET_PANE_USAGE
,
35 cmd_select_pane_key_binding
,
40 const struct cmd_entry cmd_last_pane_entry
= {
43 CMD_TARGET_WINDOW_USAGE
,
51 cmd_select_pane_key_binding(struct cmd
*self
, int key
)
53 self
->args
= args_create(0);
55 args_set(self
->args
, 'U', NULL
);
57 args_set(self
->args
, 'D', NULL
);
59 args_set(self
->args
, 'L', NULL
);
60 if (key
== KEYC_RIGHT
)
61 args_set(self
->args
, 'R', NULL
);
63 args_set(self
->args
, 't', ":.+");
67 cmd_select_pane_exec(struct cmd
*self
, struct cmd_ctx
*ctx
)
69 struct args
*args
= self
->args
;
71 struct window_pane
*wp
;
73 if (self
->entry
== &cmd_last_pane_entry
|| args_has(args
, 'l')) {
74 wl
= cmd_find_window(ctx
, args_get(args
, 't'), NULL
);
78 if (wl
->window
->last
== NULL
) {
79 ctx
->error(ctx
, "no last pane");
83 window_set_active_pane(wl
->window
, wl
->window
->last
);
84 server_status_window(wl
->window
);
85 server_redraw_window_borders(wl
->window
);
90 if ((wl
= cmd_find_pane(ctx
, args_get(args
, 't'), NULL
, &wp
)) == NULL
)
93 if (!window_pane_visible(wp
)) {
94 ctx
->error(ctx
, "pane not visible");
98 if (args_has(self
->args
, 'L'))
99 wp
= window_pane_find_left(wp
);
100 else if (args_has(self
->args
, 'R'))
101 wp
= window_pane_find_right(wp
);
102 else if (args_has(self
->args
, 'U'))
103 wp
= window_pane_find_up(wp
);
104 else if (args_has(self
->args
, 'D'))
105 wp
= window_pane_find_down(wp
);
107 ctx
->error(ctx
, "pane not found");
111 window_set_active_pane(wl
->window
, wp
);
112 server_status_window(wl
->window
);
113 server_redraw_window_borders(wl
->window
);