Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 134 lines (117 sloc) 3.364 kb
7216c39 Karl Ferdinand Ebert Imported Upstream version 1.5
kfebert authored
1 /* $Id: cmd-select-layout.c 2553 2011-07-09 09:42:33Z tcunha $ */
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
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 * Switch window to selected layout.
25 */
26
7216c39 Karl Ferdinand Ebert Imported Upstream version 1.5
kfebert authored
27 void cmd_select_layout_key_binding(struct cmd *, int);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
28 int cmd_select_layout_exec(struct cmd *, struct cmd_ctx *);
29
30 const struct cmd_entry cmd_select_layout_entry = {
31 "select-layout", "selectl",
7216c39 Karl Ferdinand Ebert Imported Upstream version 1.5
kfebert authored
32 "npt:", 0, 1,
33 "[-np] " CMD_TARGET_WINDOW_USAGE " [layout-name]",
34 0,
35 cmd_select_layout_key_binding,
36 NULL,
37 cmd_select_layout_exec
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
38 };
39
7216c39 Karl Ferdinand Ebert Imported Upstream version 1.5
kfebert authored
40 const struct cmd_entry cmd_next_layout_entry = {
41 "next-layout", "nextl",
42 "t:", 0, 0,
43 CMD_TARGET_WINDOW_USAGE,
44 0,
45 NULL,
46 NULL,
47 cmd_select_layout_exec
48 };
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
49
7216c39 Karl Ferdinand Ebert Imported Upstream version 1.5
kfebert authored
50 const struct cmd_entry cmd_previous_layout_entry = {
51 "previous-layout", "prevl",
52 "t:", 0, 0,
53 CMD_TARGET_WINDOW_USAGE,
54 0,
55 NULL,
56 NULL,
57 cmd_select_layout_exec
58 };
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
59
7216c39 Karl Ferdinand Ebert Imported Upstream version 1.5
kfebert authored
60 void
61 cmd_select_layout_key_binding(struct cmd *self, int key)
62 {
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
63 switch (key) {
7216c39 Karl Ferdinand Ebert Imported Upstream version 1.5
kfebert authored
64 case '1' | KEYC_ESCAPE:
65 self->args = args_create(1, "even-horizontal");
66 break;
67 case '2' | KEYC_ESCAPE:
68 self->args = args_create(1, "even-vertical");
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
69 break;
7216c39 Karl Ferdinand Ebert Imported Upstream version 1.5
kfebert authored
70 case '3' | KEYC_ESCAPE:
71 self->args = args_create(1, "main-horizontal");
dda8e8e Karl Ferdinand Ebert Imported Upstream version 1.2
kfebert authored
72 break;
7216c39 Karl Ferdinand Ebert Imported Upstream version 1.5
kfebert authored
73 case '4' | KEYC_ESCAPE:
74 self->args = args_create(1, "main-vertical");
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
75 break;
7216c39 Karl Ferdinand Ebert Imported Upstream version 1.5
kfebert authored
76 case '5' | KEYC_ESCAPE:
77 self->args = args_create(1, "tiled");
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
78 break;
7216c39 Karl Ferdinand Ebert Imported Upstream version 1.5
kfebert authored
79 default:
80 self->args = args_create(0);
fb53a63 Karl Ferdinand Ebert Imported Upstream version 1.3
kfebert authored
81 break;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
82 }
83 }
84
85 int
86 cmd_select_layout_exec(struct cmd *self, struct cmd_ctx *ctx)
87 {
7216c39 Karl Ferdinand Ebert Imported Upstream version 1.5
kfebert authored
88 struct args *args = self->args;
89 struct winlink *wl;
90 const char *layoutname;
91 int next, previous, layout;
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
92
7216c39 Karl Ferdinand Ebert Imported Upstream version 1.5
kfebert authored
93 if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
94 return (-1);
95
7216c39 Karl Ferdinand Ebert Imported Upstream version 1.5
kfebert authored
96 next = self->entry == &cmd_next_layout_entry;
97 if (args_has(self->args, 'n'))
98 next = 1;
99 previous = self->entry == &cmd_previous_layout_entry;
100 if (args_has(self->args, 'p'))
101 previous = 1;
102
103 if (next || previous) {
104 if (next)
105 layout = layout_set_next(wl->window);
106 else
107 layout = layout_set_previous(wl->window);
108 ctx->info(ctx, "arranging in: %s", layout_set_name(layout));
109 return (0);
110 }
111
112 if (args->argc == 0)
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
113 layout = wl->window->lastlayout;
7216c39 Karl Ferdinand Ebert Imported Upstream version 1.5
kfebert authored
114 else
115 layout = layout_set_lookup(args->argv[0]);
116 if (layout != -1) {
fb53a63 Karl Ferdinand Ebert Imported Upstream version 1.3
kfebert authored
117 layout = layout_set_select(wl->window, layout);
118 ctx->info(ctx, "arranging in: %s", layout_set_name(layout));
7216c39 Karl Ferdinand Ebert Imported Upstream version 1.5
kfebert authored
119 return (0);
120 }
121
122 if (args->argc != 0) {
123 layoutname = args->argv[0];
124 if (layout_parse(wl->window, layoutname) == -1) {
125 ctx->error(ctx, "can't set layout: %s", layoutname);
fb53a63 Karl Ferdinand Ebert Imported Upstream version 1.3
kfebert authored
126 return (-1);
127 }
7216c39 Karl Ferdinand Ebert Imported Upstream version 1.5
kfebert authored
128 ctx->info(ctx, "arranging in: %s", layoutname);
129 return (0);
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
130 }
dda8e8e Karl Ferdinand Ebert Imported Upstream version 1.2
kfebert authored
131
8fade26 Imported Upstream version 1.1
Karl Ferdinand Ebert authored
132 return (0);
133 }
Something went wrong with that request. Please try again.