diff options
Diffstat (limited to 'sway/commands')
-rw-r--r-- | sway/commands/bar/binding_mode_indicator.c | 6 | ||||
-rw-r--r-- | sway/commands/gaps.c | 306 | ||||
-rw-r--r-- | sway/commands/hide_edge_borders.c | 16 | ||||
-rw-r--r-- | sway/commands/input.c | 1 | ||||
-rw-r--r-- | sway/commands/input/drag.c | 26 | ||||
-rw-r--r-- | sway/commands/layout.c | 3 | ||||
-rw-r--r-- | sway/commands/output/background.c | 18 | ||||
-rw-r--r-- | sway/commands/resize.c | 30 | ||||
-rw-r--r-- | sway/commands/smart_borders.c | 25 | ||||
-rw-r--r-- | sway/commands/workspace.c | 74 |
10 files changed, 305 insertions, 200 deletions
diff --git a/sway/commands/bar/binding_mode_indicator.c b/sway/commands/bar/binding_mode_indicator.c index 0c48bee9..f18b8d7c 100644 --- a/sway/commands/bar/binding_mode_indicator.c +++ b/sway/commands/bar/binding_mode_indicator.c | |||
@@ -21,7 +21,9 @@ struct cmd_results *bar_cmd_binding_mode_indicator(int argc, char **argv) { | |||
21 | config->current_bar->binding_mode_indicator = false; | 21 | config->current_bar->binding_mode_indicator = false; |
22 | wlr_log(WLR_DEBUG, "Disabling binding mode indicator on bar: %s", | 22 | wlr_log(WLR_DEBUG, "Disabling binding mode indicator on bar: %s", |
23 | config->current_bar->id); | 23 | config->current_bar->id); |
24 | } else { | ||
25 | return cmd_results_new(CMD_INVALID, "binding_mode_indicator", | ||
26 | "Invalid value %s", argv[0]); | ||
24 | } | 27 | } |
25 | return cmd_results_new(CMD_INVALID, "binding_mode_indicator", | 28 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
26 | "Invalid value %s", argv[0]); | ||
27 | } | 29 | } |
diff --git a/sway/commands/gaps.c b/sway/commands/gaps.c index d676e475..2e0876a9 100644 --- a/sway/commands/gaps.c +++ b/sway/commands/gaps.c | |||
@@ -1,4 +1,5 @@ | |||
1 | #include <string.h> | 1 | #include <string.h> |
2 | #include <strings.h> | ||
2 | #include "sway/commands.h" | 3 | #include "sway/commands.h" |
3 | #include "sway/config.h" | 4 | #include "sway/config.h" |
4 | #include "sway/tree/arrange.h" | 5 | #include "sway/tree/arrange.h" |
@@ -13,172 +14,173 @@ enum gaps_op { | |||
13 | GAPS_OP_SUBTRACT | 14 | GAPS_OP_SUBTRACT |
14 | }; | 15 | }; |
15 | 16 | ||
16 | enum gaps_scope { | 17 | struct gaps_data { |
17 | GAPS_SCOPE_ALL, | 18 | bool inner; |
18 | GAPS_SCOPE_WORKSPACE, | 19 | enum gaps_op operation; |
19 | GAPS_SCOPE_CURRENT | 20 | int amount; |
20 | }; | 21 | }; |
21 | 22 | ||
22 | struct cmd_results *cmd_gaps(int argc, char **argv) { | 23 | // gaps edge_gaps on|off|toggle |
23 | struct cmd_results *error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1); | 24 | static struct cmd_results *gaps_edge_gaps(int argc, char **argv) { |
24 | if (error) { | 25 | struct cmd_results *error; |
26 | if ((error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 2))) { | ||
25 | return error; | 27 | return error; |
26 | } | 28 | } |
27 | 29 | ||
28 | if (strcmp(argv[0], "edge_gaps") == 0) { | 30 | if (strcmp(argv[1], "on") == 0) { |
29 | if ((error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 2))) { | 31 | config->edge_gaps = true; |
30 | return error; | 32 | } else if (strcmp(argv[1], "off") == 0) { |
31 | } | 33 | config->edge_gaps = false; |
32 | 34 | } else if (strcmp(argv[1], "toggle") == 0) { | |
33 | if (strcmp(argv[1], "on") == 0) { | 35 | if (!config->active) { |
34 | config->edge_gaps = true; | ||
35 | } else if (strcmp(argv[1], "off") == 0) { | ||
36 | config->edge_gaps = false; | ||
37 | } else if (strcmp(argv[1], "toggle") == 0) { | ||
38 | if (!config->active) { | ||
39 | return cmd_results_new(CMD_INVALID, "gaps", | ||
40 | "Cannot toggle gaps while not running."); | ||
41 | } | ||
42 | config->edge_gaps = !config->edge_gaps; | ||
43 | } else { | ||
44 | return cmd_results_new(CMD_INVALID, "gaps", | 36 | return cmd_results_new(CMD_INVALID, "gaps", |
45 | "gaps edge_gaps on|off|toggle"); | 37 | "Cannot toggle gaps while not running."); |
46 | } | 38 | } |
47 | arrange_root(); | 39 | config->edge_gaps = !config->edge_gaps; |
48 | } else { | 40 | } else { |
49 | int amount_idx = 0; // the current index in argv | 41 | return cmd_results_new(CMD_INVALID, "gaps", |
50 | enum gaps_op op = GAPS_OP_SET; | 42 | "gaps edge_gaps on|off|toggle"); |
51 | enum gaps_scope scope = GAPS_SCOPE_ALL; | 43 | } |
52 | bool inner = true; | 44 | arrange_root(); |
53 | 45 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | |
54 | if (strcmp(argv[0], "inner") == 0) { | 46 | } |
55 | amount_idx++; | ||
56 | inner = true; | ||
57 | } else if (strcmp(argv[0], "outer") == 0) { | ||
58 | amount_idx++; | ||
59 | inner = false; | ||
60 | } | ||
61 | 47 | ||
62 | // If one of the long variants of the gaps command is used | 48 | // gaps inner|outer <px> |
63 | // (which starts with inner|outer) check the number of args | 49 | static struct cmd_results *gaps_set_defaults(int argc, char **argv) { |
64 | if (amount_idx > 0) { // if we've seen inner|outer | 50 | struct cmd_results *error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 2); |
65 | if (argc > 2) { // check the longest variant | 51 | if (error) { |
66 | error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 4); | 52 | return error; |
67 | if (error) { | 53 | } |
68 | return error; | ||
69 | } | ||
70 | } else { // check the next longest format | ||
71 | error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 2); | ||
72 | if (error) { | ||
73 | return error; | ||
74 | } | ||
75 | } | ||
76 | } else { | ||
77 | error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 1); | ||
78 | if (error) { | ||
79 | return error; | ||
80 | } | ||
81 | } | ||
82 | 54 | ||
83 | if (argc == 4) { | 55 | bool inner; |
84 | // Long format: all|workspace|current. | 56 | if (strcasecmp(argv[0], "inner") == 0) { |
85 | if (strcmp(argv[amount_idx], "all") == 0) { | 57 | inner = true; |
86 | amount_idx++; | 58 | } else if (strcasecmp(argv[0], "outer") == 0) { |
87 | scope = GAPS_SCOPE_ALL; | 59 | inner = false; |
88 | } else if (strcmp(argv[amount_idx], "workspace") == 0) { | 60 | } else { |
89 | amount_idx++; | 61 | return cmd_results_new(CMD_INVALID, "gaps", |
90 | scope = GAPS_SCOPE_WORKSPACE; | 62 | "Expected 'gaps inner|outer <px>'"); |
91 | } else if (strcmp(argv[amount_idx], "current") == 0) { | 63 | } |
92 | amount_idx++; | ||
93 | scope = GAPS_SCOPE_CURRENT; | ||
94 | } | ||
95 | |||
96 | // Long format: set|plus|minus | ||
97 | if (strcmp(argv[amount_idx], "set") == 0) { | ||
98 | amount_idx++; | ||
99 | op = GAPS_OP_SET; | ||
100 | } else if (strcmp(argv[amount_idx], "plus") == 0) { | ||
101 | amount_idx++; | ||
102 | op = GAPS_OP_ADD; | ||
103 | } else if (strcmp(argv[amount_idx], "minus") == 0) { | ||
104 | amount_idx++; | ||
105 | op = GAPS_OP_SUBTRACT; | ||
106 | } | ||
107 | } | ||
108 | 64 | ||
109 | char *end; | 65 | char *end; |
110 | double val = strtod(argv[amount_idx], &end); | 66 | int amount = strtol(argv[1], &end, 10); |
111 | 67 | if (strlen(end) && strcasecmp(end, "px") != 0) { | |
112 | if (strlen(end) && val == 0.0) { // invalid <amount> | 68 | return cmd_results_new(CMD_INVALID, "gaps", |
113 | // guess which variant of the command was attempted | 69 | "Expected 'gaps inner|outer <px>'"); |
114 | if (argc == 1) { | 70 | } |
115 | return cmd_results_new(CMD_INVALID, "gaps", "gaps <amount>"); | 71 | if (amount < 0) { |
116 | } | 72 | amount = 0; |
117 | if (argc == 2) { | 73 | } |
118 | return cmd_results_new(CMD_INVALID, "gaps", | ||
119 | "gaps inner|outer <amount>"); | ||
120 | } | ||
121 | return cmd_results_new(CMD_INVALID, "gaps", | ||
122 | "gaps inner|outer all|workspace|current set|plus|minus <amount>"); | ||
123 | } | ||
124 | 74 | ||
125 | if (amount_idx == 0) { // gaps <amount> | 75 | if (inner) { |
126 | config->gaps_inner = val; | 76 | config->gaps_inner = amount; |
127 | config->gaps_outer = val; | 77 | } else { |
128 | arrange_root(); | 78 | config->gaps_outer = amount; |
129 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 79 | } |
130 | } | 80 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
131 | // Other variants. The middle-length variant (gaps inner|outer <amount>) | 81 | } |
132 | // just defaults the scope to "all" and defaults the op to "set". | ||
133 | |||
134 | double total; | ||
135 | switch (op) { | ||
136 | case GAPS_OP_SUBTRACT: { | ||
137 | total = (inner ? config->gaps_inner : config->gaps_outer) - val; | ||
138 | if (total < 0) { | ||
139 | total = 0; | ||
140 | } | ||
141 | break; | ||
142 | } | ||
143 | case GAPS_OP_ADD: { | ||
144 | total = (inner ? config->gaps_inner : config->gaps_outer) + val; | ||
145 | break; | ||
146 | } | ||
147 | case GAPS_OP_SET: { | ||
148 | total = val; | ||
149 | break; | ||
150 | } | ||
151 | } | ||
152 | 82 | ||
153 | if (scope == GAPS_SCOPE_ALL) { | 83 | static void configure_gaps(struct sway_workspace *ws, void *_data) { |
154 | if (inner) { | 84 | struct gaps_data *data = _data; |
155 | config->gaps_inner = total; | 85 | int *prop = data->inner ? &ws->gaps_inner : &ws->gaps_outer; |
156 | } else { | 86 | |
157 | config->gaps_outer = total; | 87 | switch (data->operation) { |
158 | } | 88 | case GAPS_OP_SET: |
159 | arrange_root(); | 89 | *prop = data->amount; |
160 | } else { | 90 | break; |
161 | if (scope == GAPS_SCOPE_WORKSPACE) { | 91 | case GAPS_OP_ADD: |
162 | struct sway_workspace *ws = config->handler_context.workspace; | 92 | *prop += data->amount; |
163 | ws->has_gaps = true; | 93 | break; |
164 | if (inner) { | 94 | case GAPS_OP_SUBTRACT: |
165 | ws->gaps_inner = total; | 95 | *prop -= data->amount; |
166 | } else { | 96 | break; |
167 | ws->gaps_outer = total; | 97 | } |
168 | } | 98 | if (*prop < 0) { |
169 | arrange_workspace(ws); | 99 | *prop = 0; |
170 | } else { | 100 | } |
171 | struct sway_container *c = config->handler_context.container; | 101 | arrange_workspace(ws); |
172 | c->has_gaps = true; | 102 | } |
173 | if (inner) { | 103 | |
174 | c->gaps_inner = total; | 104 | // gaps inner|outer current|all set|plus|minus <px> |
175 | } else { | 105 | static struct cmd_results *gaps_set_runtime(int argc, char **argv) { |
176 | c->gaps_outer = total; | 106 | struct cmd_results *error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 4); |
177 | } | 107 | if (error) { |
178 | arrange_workspace(c->workspace); | 108 | return error; |
179 | } | 109 | } |
180 | } | 110 | |
111 | struct gaps_data data; | ||
112 | |||
113 | if (strcasecmp(argv[0], "inner") == 0) { | ||
114 | data.inner = true; | ||
115 | } else if (strcasecmp(argv[0], "outer") == 0) { | ||
116 | data.inner = false; | ||
117 | } else { | ||
118 | return cmd_results_new(CMD_INVALID, "gaps", | ||
119 | "Expected 'gaps inner|outer current|all set|plus|minus <px>'"); | ||
120 | } | ||
121 | |||
122 | bool all; | ||
123 | if (strcasecmp(argv[1], "current") == 0) { | ||
124 | all = false; | ||
125 | } else if (strcasecmp(argv[1], "all") == 0) { | ||
126 | all = true; | ||
127 | } else { | ||
128 | return cmd_results_new(CMD_INVALID, "gaps", | ||
129 | "Expected 'gaps inner|outer current|all set|plus|minus <px>'"); | ||
130 | } | ||
131 | |||
132 | if (strcasecmp(argv[2], "set") == 0) { | ||
133 | data.operation = GAPS_OP_SET; | ||
134 | } else if (strcasecmp(argv[2], "plus") == 0) { | ||
135 | data.operation = GAPS_OP_ADD; | ||
136 | } else if (strcasecmp(argv[2], "minus") == 0) { | ||
137 | data.operation = GAPS_OP_SUBTRACT; | ||
138 | } else { | ||
139 | return cmd_results_new(CMD_INVALID, "gaps", | ||
140 | "Expected 'gaps inner|outer current|all set|plus|minus <px>'"); | ||
141 | } | ||
142 | |||
143 | char *end; | ||
144 | data.amount = strtol(argv[3], &end, 10); | ||
145 | if (strlen(end) && strcasecmp(end, "px") != 0) { | ||
146 | return cmd_results_new(CMD_INVALID, "gaps", | ||
147 | "Expected 'gaps inner|outer current|all set|plus|minus <px>'"); | ||
148 | } | ||
149 | |||
150 | if (all) { | ||
151 | root_for_each_workspace(configure_gaps, &data); | ||
152 | } else { | ||
153 | configure_gaps(config->handler_context.workspace, &data); | ||
181 | } | 154 | } |
182 | 155 | ||
183 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 156 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
184 | } | 157 | } |
158 | |||
159 | // gaps edge_gaps on|off|toggle | ||
160 | // gaps inner|outer <px> - sets defaults for workspaces | ||
161 | // gaps inner|outer current|all set|plus|minus <px> - runtime only | ||
162 | struct cmd_results *cmd_gaps(int argc, char **argv) { | ||
163 | struct cmd_results *error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 2); | ||
164 | if (error) { | ||
165 | return error; | ||
166 | } | ||
167 | |||
168 | if (strcmp(argv[0], "edge_gaps") == 0) { | ||
169 | return gaps_edge_gaps(argc, argv); | ||
170 | } | ||
171 | |||
172 | if (argc == 2) { | ||
173 | return gaps_set_defaults(argc, argv); | ||
174 | } | ||
175 | if (argc == 4) { | ||
176 | if (config->active) { | ||
177 | return gaps_set_runtime(argc, argv); | ||
178 | } else { | ||
179 | return cmd_results_new(CMD_INVALID, "gaps", | ||
180 | "This syntax can only be used when sway is running"); | ||
181 | } | ||
182 | } | ||
183 | return cmd_results_new(CMD_INVALID, "gaps", | ||
184 | "Expected 'gaps inner|outer <px>' or " | ||
185 | "'gaps inner|outer current|all set|plus|minus <px>'"); | ||
186 | } | ||
diff --git a/sway/commands/hide_edge_borders.c b/sway/commands/hide_edge_borders.c index 0a5c7f28..ea261fb1 100644 --- a/sway/commands/hide_edge_borders.c +++ b/sway/commands/hide_edge_borders.c | |||
@@ -1,15 +1,8 @@ | |||
1 | #include "sway/commands.h" | 1 | #include "sway/commands.h" |
2 | #include "sway/config.h" | 2 | #include "sway/config.h" |
3 | #include "sway/tree/container.h" | 3 | #include "sway/tree/arrange.h" |
4 | #include "sway/tree/root.h" | ||
5 | #include "sway/tree/view.h" | 4 | #include "sway/tree/view.h" |
6 | 5 | ||
7 | static void _configure_view(struct sway_container *con, void *data) { | ||
8 | if (con->view) { | ||
9 | view_autoconfigure(con->view); | ||
10 | } | ||
11 | } | ||
12 | |||
13 | struct cmd_results *cmd_hide_edge_borders(int argc, char **argv) { | 6 | struct cmd_results *cmd_hide_edge_borders(int argc, char **argv) { |
14 | struct cmd_results *error = NULL; | 7 | struct cmd_results *error = NULL; |
15 | if ((error = checkarg(argc, "hide_edge_borders", EXPECTED_EQUAL_TO, 1))) { | 8 | if ((error = checkarg(argc, "hide_edge_borders", EXPECTED_EQUAL_TO, 1))) { |
@@ -26,13 +19,16 @@ struct cmd_results *cmd_hide_edge_borders(int argc, char **argv) { | |||
26 | config->hide_edge_borders = E_BOTH; | 19 | config->hide_edge_borders = E_BOTH; |
27 | } else if (strcmp(argv[0], "smart") == 0) { | 20 | } else if (strcmp(argv[0], "smart") == 0) { |
28 | config->hide_edge_borders = E_SMART; | 21 | config->hide_edge_borders = E_SMART; |
22 | } else if (strcmp(argv[0], "smart_no_gaps") == 0) { | ||
23 | config->hide_edge_borders = E_SMART_NO_GAPS; | ||
29 | } else { | 24 | } else { |
30 | return cmd_results_new(CMD_INVALID, "hide_edge_borders", | 25 | return cmd_results_new(CMD_INVALID, "hide_edge_borders", |
31 | "Expected 'hide_edge_borders " | 26 | "Expected 'hide_edge_borders " |
32 | "<none|vertical|horizontal|both|smart>'"); | 27 | "<none|vertical|horizontal|both|smart|smart_no_gaps>'"); |
33 | } | 28 | } |
29 | config->saved_edge_borders = config->hide_edge_borders; | ||
34 | 30 | ||
35 | root_for_each_container(_configure_view, NULL); | 31 | arrange_root(); |
36 | 32 | ||
37 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 33 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
38 | } | 34 | } |
diff --git a/sway/commands/input.c b/sway/commands/input.c index 9091da2a..2889d47d 100644 --- a/sway/commands/input.c +++ b/sway/commands/input.c | |||
@@ -9,6 +9,7 @@ | |||
9 | static struct cmd_handler input_handlers[] = { | 9 | static struct cmd_handler input_handlers[] = { |
10 | { "accel_profile", input_cmd_accel_profile }, | 10 | { "accel_profile", input_cmd_accel_profile }, |
11 | { "click_method", input_cmd_click_method }, | 11 | { "click_method", input_cmd_click_method }, |
12 | { "drag", input_cmd_drag }, | ||
12 | { "drag_lock", input_cmd_drag_lock }, | 13 | { "drag_lock", input_cmd_drag_lock }, |
13 | { "dwt", input_cmd_dwt }, | 14 | { "dwt", input_cmd_dwt }, |
14 | { "events", input_cmd_events }, | 15 | { "events", input_cmd_events }, |
diff --git a/sway/commands/input/drag.c b/sway/commands/input/drag.c new file mode 100644 index 00000000..e325df29 --- /dev/null +++ b/sway/commands/input/drag.c | |||
@@ -0,0 +1,26 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/config.h" | ||
4 | #include "sway/commands.h" | ||
5 | #include "sway/input/input-manager.h" | ||
6 | #include "util.h" | ||
7 | |||
8 | struct cmd_results *input_cmd_drag(int argc, char **argv) { | ||
9 | struct cmd_results *error = NULL; | ||
10 | if ((error = checkarg(argc, "drag", EXPECTED_AT_LEAST, 1))) { | ||
11 | return error; | ||
12 | } | ||
13 | struct input_config *ic = config->handler_context.input_config; | ||
14 | if (!ic) { | ||
15 | return cmd_results_new(CMD_FAILURE, | ||
16 | "drag", "No input device defined."); | ||
17 | } | ||
18 | |||
19 | if (parse_boolean(argv[0], true)) { | ||
20 | ic->drag = LIBINPUT_CONFIG_DRAG_ENABLED; | ||
21 | } else { | ||
22 | ic->drag = LIBINPUT_CONFIG_DRAG_DISABLED; | ||
23 | } | ||
24 | |||
25 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
26 | } | ||
diff --git a/sway/commands/layout.c b/sway/commands/layout.c index ef3ec1cb..c2ce2e78 100644 --- a/sway/commands/layout.c +++ b/sway/commands/layout.c | |||
@@ -138,15 +138,14 @@ struct cmd_results *cmd_layout(int argc, char **argv) { | |||
138 | } | 138 | } |
139 | container->layout = new_layout; | 139 | container->layout = new_layout; |
140 | container_update_representation(container); | 140 | container_update_representation(container); |
141 | arrange_container(container); | ||
142 | } else { | 141 | } else { |
143 | if (old_layout != L_TABBED && old_layout != L_STACKED) { | 142 | if (old_layout != L_TABBED && old_layout != L_STACKED) { |
144 | workspace->prev_split_layout = old_layout; | 143 | workspace->prev_split_layout = old_layout; |
145 | } | 144 | } |
146 | workspace->layout = new_layout; | 145 | workspace->layout = new_layout; |
147 | workspace_update_representation(workspace); | 146 | workspace_update_representation(workspace); |
148 | arrange_workspace(workspace); | ||
149 | } | 147 | } |
148 | arrange_workspace(workspace); | ||
150 | } | 149 | } |
151 | 150 | ||
152 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 151 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
diff --git a/sway/commands/output/background.c b/sway/commands/output/background.c index 9e370d43..30fb47c4 100644 --- a/sway/commands/output/background.c +++ b/sway/commands/output/background.c | |||
@@ -123,19 +123,13 @@ struct cmd_results *output_cmd_background(int argc, char **argv) { | |||
123 | } | 123 | } |
124 | free(src); | 124 | free(src); |
125 | } else { | 125 | } else { |
126 | // Escape spaces and quotes in the final path for swaybg | 126 | // Escape double quotes in the final path for swaybg |
127 | for (size_t i = 0; i < strlen(src); i++) { | 127 | for (size_t i = 0; i < strlen(src); i++) { |
128 | switch (src[i]) { | 128 | if (src[i] == '"') { |
129 | case ' ': | 129 | src = realloc(src, strlen(src) + 2); |
130 | case '\'': | 130 | memmove(src + i + 1, src + i, strlen(src + i) + 1); |
131 | case '\"': | 131 | *(src + i) = '\\'; |
132 | src = realloc(src, strlen(src) + 2); | 132 | i++; |
133 | memmove(src + i + 1, src + i, strlen(src + i) + 1); | ||
134 | *(src + i) = '\\'; | ||
135 | i++; | ||
136 | break; | ||
137 | default: | ||
138 | break; | ||
139 | } | 133 | } |
140 | } | 134 | } |
141 | 135 | ||
diff --git a/sway/commands/resize.c b/sway/commands/resize.c index 99e9dbda..1343b165 100644 --- a/sway/commands/resize.c +++ b/sway/commands/resize.c | |||
@@ -179,11 +179,11 @@ static void container_recursive_resize(struct sway_container *container, | |||
179 | } | 179 | } |
180 | } | 180 | } |
181 | 181 | ||
182 | static void resize_tiled(struct sway_container *parent, int amount, | 182 | static bool resize_tiled(struct sway_container *parent, int amount, |
183 | enum resize_axis axis) { | 183 | enum resize_axis axis) { |
184 | struct sway_container *focused = parent; | 184 | struct sway_container *focused = parent; |
185 | if (!parent) { | 185 | if (!parent) { |
186 | return; | 186 | return false; |
187 | } | 187 | } |
188 | 188 | ||
189 | enum sway_container_layout parallel_layout = | 189 | enum sway_container_layout parallel_layout = |
@@ -216,7 +216,7 @@ static void resize_tiled(struct sway_container *parent, int amount, | |||
216 | } | 216 | } |
217 | if (!parent) { | 217 | if (!parent) { |
218 | // Can't resize in this direction | 218 | // Can't resize in this direction |
219 | return; | 219 | return false; |
220 | } | 220 | } |
221 | 221 | ||
222 | // Implement up/down/left/right direction by zeroing one of the weights, | 222 | // Implement up/down/left/right direction by zeroing one of the weights, |
@@ -248,22 +248,22 @@ static void resize_tiled(struct sway_container *parent, int amount, | |||
248 | if (sibling_pos < parent_pos && minor_weight) { | 248 | if (sibling_pos < parent_pos && minor_weight) { |
249 | double pixels = -amount / minor_weight; | 249 | double pixels = -amount / minor_weight; |
250 | if (major_weight && (sibling_size + pixels / 2) < min_sane) { | 250 | if (major_weight && (sibling_size + pixels / 2) < min_sane) { |
251 | return; // Too small | 251 | return false; // Too small |
252 | } else if (!major_weight && sibling_size + pixels < min_sane) { | 252 | } else if (!major_weight && sibling_size + pixels < min_sane) { |
253 | return; // Too small | 253 | return false; // Too small |
254 | } | 254 | } |
255 | } else if (sibling_pos > parent_pos && major_weight) { | 255 | } else if (sibling_pos > parent_pos && major_weight) { |
256 | double pixels = -amount / major_weight; | 256 | double pixels = -amount / major_weight; |
257 | if (minor_weight && (sibling_size + pixels / 2) < min_sane) { | 257 | if (minor_weight && (sibling_size + pixels / 2) < min_sane) { |
258 | return; // Too small | 258 | return false; // Too small |
259 | } else if (!minor_weight && sibling_size + pixels < min_sane) { | 259 | } else if (!minor_weight && sibling_size + pixels < min_sane) { |
260 | return; // Too small | 260 | return false; // Too small |
261 | } | 261 | } |
262 | } | 262 | } |
263 | } else { | 263 | } else { |
264 | double pixels = amount; | 264 | double pixels = amount; |
265 | if (parent_size + pixels < min_sane) { | 265 | if (parent_size + pixels < min_sane) { |
266 | return; // Too small | 266 | return false; // Too small |
267 | } | 267 | } |
268 | } | 268 | } |
269 | } | 269 | } |
@@ -317,9 +317,10 @@ static void resize_tiled(struct sway_container *parent, int amount, | |||
317 | } else { | 317 | } else { |
318 | arrange_workspace(parent->workspace); | 318 | arrange_workspace(parent->workspace); |
319 | } | 319 | } |
320 | return true; | ||
320 | } | 321 | } |
321 | 322 | ||
322 | void container_resize_tiled(struct sway_container *parent, | 323 | bool container_resize_tiled(struct sway_container *parent, |
323 | enum wlr_edges edge, int amount) { | 324 | enum wlr_edges edge, int amount) { |
324 | enum resize_axis axis = RESIZE_AXIS_INVALID; | 325 | enum resize_axis axis = RESIZE_AXIS_INVALID; |
325 | switch (edge) { | 326 | switch (edge) { |
@@ -338,7 +339,7 @@ void container_resize_tiled(struct sway_container *parent, | |||
338 | case WLR_EDGE_NONE: | 339 | case WLR_EDGE_NONE: |
339 | break; | 340 | break; |
340 | } | 341 | } |
341 | resize_tiled(parent, amount, axis); | 342 | return resize_tiled(parent, amount, axis); |
342 | } | 343 | } |
343 | 344 | ||
344 | /** | 345 | /** |
@@ -395,6 +396,10 @@ static struct cmd_results *resize_adjust_floating(enum resize_axis axis, | |||
395 | case RESIZE_AXIS_INVALID: | 396 | case RESIZE_AXIS_INVALID: |
396 | return cmd_results_new(CMD_INVALID, "resize", "Invalid axis/direction"); | 397 | return cmd_results_new(CMD_INVALID, "resize", "Invalid axis/direction"); |
397 | } | 398 | } |
399 | if (grow_x == 0 && grow_y == 0) { | ||
400 | return cmd_results_new(CMD_INVALID, "resize", | ||
401 | "Cannot resize any further"); | ||
402 | } | ||
398 | con->x += grow_x; | 403 | con->x += grow_x; |
399 | con->y += grow_y; | 404 | con->y += grow_y; |
400 | con->width += grow_width; | 405 | con->width += grow_width; |
@@ -442,7 +447,10 @@ static struct cmd_results *resize_adjust_tiled(enum resize_axis axis, | |||
442 | } | 447 | } |
443 | } | 448 | } |
444 | 449 | ||
445 | resize_tiled(current, amount->amount, axis); | 450 | if (!resize_tiled(current, amount->amount, axis)) { |
451 | return cmd_results_new(CMD_INVALID, "resize", | ||
452 | "Cannot resize any further"); | ||
453 | } | ||
446 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 454 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
447 | } | 455 | } |
448 | 456 | ||
diff --git a/sway/commands/smart_borders.c b/sway/commands/smart_borders.c new file mode 100644 index 00000000..fcb4040e --- /dev/null +++ b/sway/commands/smart_borders.c | |||
@@ -0,0 +1,25 @@ | |||
1 | #include "sway/commands.h" | ||
2 | #include "sway/config.h" | ||
3 | #include "sway/tree/arrange.h" | ||
4 | #include "sway/tree/view.h" | ||
5 | #include "util.h" | ||
6 | |||
7 | struct cmd_results *cmd_smart_borders(int argc, char **argv) { | ||
8 | struct cmd_results *error = NULL; | ||
9 | if ((error = checkarg(argc, "smart_borders", EXPECTED_EQUAL_TO, 1))) { | ||
10 | return error; | ||
11 | } | ||
12 | |||
13 | enum edge_border_types saved = config->hide_edge_borders; | ||
14 | if (strcmp(argv[0], "no_gaps") == 0) { | ||
15 | config->hide_edge_borders = E_SMART_NO_GAPS; | ||
16 | } else { | ||
17 | config->hide_edge_borders = parse_boolean(argv[0], true) ? | ||
18 | E_SMART : config->saved_edge_borders; | ||
19 | } | ||
20 | config->saved_edge_borders = saved; | ||
21 | |||
22 | arrange_root(); | ||
23 | |||
24 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
25 | } | ||
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c index f026a39d..63f29641 100644 --- a/sway/commands/workspace.c +++ b/sway/commands/workspace.c | |||
@@ -10,6 +10,28 @@ | |||
10 | #include "log.h" | 10 | #include "log.h" |
11 | #include "stringop.h" | 11 | #include "stringop.h" |
12 | 12 | ||
13 | static struct workspace_config *workspace_config_find_or_create(char *ws_name) { | ||
14 | struct workspace_config *wsc = workspace_find_config(ws_name); | ||
15 | if (wsc) { | ||
16 | return wsc; | ||
17 | } | ||
18 | wsc = calloc(1, sizeof(struct workspace_config)); | ||
19 | if (!wsc) { | ||
20 | return NULL; | ||
21 | } | ||
22 | wsc->workspace = strdup(ws_name); | ||
23 | wsc->gaps_inner = -1; | ||
24 | wsc->gaps_outer = -1; | ||
25 | list_add(config->workspace_configs, wsc); | ||
26 | return wsc; | ||
27 | } | ||
28 | |||
29 | void free_workspace_config(struct workspace_config *wsc) { | ||
30 | free(wsc->workspace); | ||
31 | free(wsc->output); | ||
32 | free(wsc); | ||
33 | } | ||
34 | |||
13 | struct cmd_results *cmd_workspace(int argc, char **argv) { | 35 | struct cmd_results *cmd_workspace(int argc, char **argv) { |
14 | struct cmd_results *error = NULL; | 36 | struct cmd_results *error = NULL; |
15 | if ((error = checkarg(argc, "workspace", EXPECTED_AT_LEAST, 1))) { | 37 | if ((error = checkarg(argc, "workspace", EXPECTED_AT_LEAST, 1))) { |
@@ -17,6 +39,7 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { | |||
17 | } | 39 | } |
18 | 40 | ||
19 | int output_location = -1; | 41 | int output_location = -1; |
42 | int gaps_location = -1; | ||
20 | 43 | ||
21 | for (int i = 0; i < argc; ++i) { | 44 | for (int i = 0; i < argc; ++i) { |
22 | if (strcasecmp(argv[i], "output") == 0) { | 45 | if (strcasecmp(argv[i], "output") == 0) { |
@@ -24,25 +47,54 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { | |||
24 | break; | 47 | break; |
25 | } | 48 | } |
26 | } | 49 | } |
50 | for (int i = 0; i < argc; ++i) { | ||
51 | if (strcasecmp(argv[i], "gaps") == 0) { | ||
52 | gaps_location = i; | ||
53 | break; | ||
54 | } | ||
55 | } | ||
27 | if (output_location >= 0) { | 56 | if (output_location >= 0) { |
28 | if ((error = checkarg(argc, "workspace", EXPECTED_EQUAL_TO, output_location + 2))) { | 57 | if ((error = checkarg(argc, "workspace", EXPECTED_EQUAL_TO, output_location + 2))) { |
29 | return error; | 58 | return error; |
30 | } | 59 | } |
31 | struct workspace_output *wso = calloc(1, sizeof(struct workspace_output)); | 60 | char *ws_name = join_args(argv, argc - 2); |
32 | if (!wso) { | 61 | struct workspace_config *wsc = workspace_config_find_or_create(ws_name); |
62 | free(ws_name); | ||
63 | if (!wsc) { | ||
33 | return cmd_results_new(CMD_FAILURE, "workspace output", | 64 | return cmd_results_new(CMD_FAILURE, "workspace output", |
34 | "Unable to allocate workspace output"); | 65 | "Unable to allocate workspace output"); |
35 | } | 66 | } |
36 | wso->workspace = join_args(argv, argc - 2); | 67 | free(wsc->output); |
37 | wso->output = strdup(argv[output_location + 1]); | 68 | wsc->output = strdup(argv[output_location + 1]); |
38 | int i = -1; | 69 | } else if (gaps_location >= 0) { |
39 | if ((i = list_seq_find(config->workspace_outputs, workspace_output_cmp_workspace, wso)) != -1) { | 70 | if ((error = checkarg(argc, "workspace", EXPECTED_EQUAL_TO, gaps_location + 3))) { |
40 | struct workspace_output *old = config->workspace_outputs->items[i]; | 71 | return error; |
41 | free(old); // workspaces can only be assigned to a single output | 72 | } |
42 | list_del(config->workspace_outputs, i); | 73 | char *ws_name = join_args(argv, argc - 3); |
74 | struct workspace_config *wsc = workspace_config_find_or_create(ws_name); | ||
75 | free(ws_name); | ||
76 | if (!wsc) { | ||
77 | return cmd_results_new(CMD_FAILURE, "workspace gaps", | ||
78 | "Unable to allocate workspace output"); | ||
79 | } | ||
80 | int *prop = NULL; | ||
81 | if (strcasecmp(argv[gaps_location + 1], "inner") == 0) { | ||
82 | prop = &wsc->gaps_inner; | ||
83 | } else if (strcasecmp(argv[gaps_location + 1], "outer") == 0) { | ||
84 | prop = &wsc->gaps_outer; | ||
85 | } else { | ||
86 | return cmd_results_new(CMD_FAILURE, "workspace gaps", | ||
87 | "Expected 'workspace <ws> gaps inner|outer <px>'"); | ||
88 | } | ||
89 | char *end; | ||
90 | int val = strtol(argv[gaps_location + 2], &end, 10); | ||
91 | |||
92 | if (strlen(end)) { | ||
93 | free(end); | ||
94 | return cmd_results_new(CMD_FAILURE, "workspace gaps", | ||
95 | "Expected 'workspace <ws> gaps inner|outer <px>'"); | ||
43 | } | 96 | } |
44 | wlr_log(WLR_DEBUG, "Assigning workspace %s to output %s", wso->workspace, wso->output); | 97 | *prop = val >= 0 ? val : 0; |
45 | list_add(config->workspace_outputs, wso); | ||
46 | } else { | 98 | } else { |
47 | if (config->reading || !config->active) { | 99 | if (config->reading || !config->active) { |
48 | return cmd_results_new(CMD_DEFER, "workspace", NULL); | 100 | return cmd_results_new(CMD_DEFER, "workspace", NULL); |