Remove now unused cmd_get_default_path.
[tmux-openbsd.git] / cmd-select-layout.c
blob26d8538ec4d822793f03bcbe947d1ddc570b5f9d
1 /* $OpenBSD$ */
3 /*
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>
21 #include "tmux.h"
24 * Switch window to selected layout.
27 void cmd_select_layout_key_binding(struct cmd *, int);
28 enum cmd_retval cmd_select_layout_exec(struct cmd *, struct cmd_q *);
30 const struct cmd_entry cmd_select_layout_entry = {
31 "select-layout", "selectl",
32 "npt:", 0, 1,
33 "[-np] " CMD_TARGET_WINDOW_USAGE " [layout-name]",
35 cmd_select_layout_key_binding,
36 cmd_select_layout_exec
39 const struct cmd_entry cmd_next_layout_entry = {
40 "next-layout", "nextl",
41 "t:", 0, 0,
42 CMD_TARGET_WINDOW_USAGE,
44 NULL,
45 cmd_select_layout_exec
48 const struct cmd_entry cmd_previous_layout_entry = {
49 "previous-layout", "prevl",
50 "t:", 0, 0,
51 CMD_TARGET_WINDOW_USAGE,
53 NULL,
54 cmd_select_layout_exec
57 void
58 cmd_select_layout_key_binding(struct cmd *self, int key)
60 switch (key) {
61 case '1' | KEYC_ESCAPE:
62 self->args = args_create(1, "even-horizontal");
63 break;
64 case '2' | KEYC_ESCAPE:
65 self->args = args_create(1, "even-vertical");
66 break;
67 case '3' | KEYC_ESCAPE:
68 self->args = args_create(1, "main-horizontal");
69 break;
70 case '4' | KEYC_ESCAPE:
71 self->args = args_create(1, "main-vertical");
72 break;
73 case '5' | KEYC_ESCAPE:
74 self->args = args_create(1, "tiled");
75 break;
76 default:
77 self->args = args_create(0);
78 break;
82 enum cmd_retval
83 cmd_select_layout_exec(struct cmd *self, struct cmd_q *cmdq)
85 struct args *args = self->args;
86 struct winlink *wl;
87 const char *layoutname;
88 int next, previous, layout;
90 if ((wl = cmd_find_window(cmdq, args_get(args, 't'), NULL)) == NULL)
91 return (CMD_RETURN_ERROR);
92 server_unzoom_window(wl->window);
94 next = self->entry == &cmd_next_layout_entry;
95 if (args_has(self->args, 'n'))
96 next = 1;
97 previous = self->entry == &cmd_previous_layout_entry;
98 if (args_has(self->args, 'p'))
99 previous = 1;
101 if (next || previous) {
102 if (next)
103 layout = layout_set_next(wl->window);
104 else
105 layout = layout_set_previous(wl->window);
106 server_redraw_window(wl->window);
107 cmdq_info(cmdq, "arranging in: %s", layout_set_name(layout));
108 return (CMD_RETURN_NORMAL);
111 if (args->argc == 0)
112 layout = wl->window->lastlayout;
113 else
114 layout = layout_set_lookup(args->argv[0]);
115 if (layout != -1) {
116 layout = layout_set_select(wl->window, layout);
117 server_redraw_window(wl->window);
118 cmdq_info(cmdq, "arranging in: %s", layout_set_name(layout));
119 return (CMD_RETURN_NORMAL);
122 if (args->argc != 0) {
123 layoutname = args->argv[0];
124 if (layout_parse(wl->window, layoutname) == -1) {
125 cmdq_error(cmdq, "can't set layout: %s", layoutname);
126 return (CMD_RETURN_ERROR);
128 server_redraw_window(wl->window);
129 cmdq_info(cmdq, "arranging in: %s", layoutname);
131 return (CMD_RETURN_NORMAL);