diff options
author | 2016-09-01 21:39:08 -0500 | |
---|---|---|
committer | 2016-09-01 21:39:08 -0500 | |
commit | b374c35758777f98e5ddbe4b0dc43bd7c80f36d7 (patch) | |
tree | 04bb4cfc3da7d2e0de7fbc38db42f65c66d2df4c /sway/commands.c | |
parent | Merge pull request #874 from yohanesu75/ipc-client-fix (diff) | |
download | sway-b374c35758777f98e5ddbe4b0dc43bd7c80f36d7.tar.gz sway-b374c35758777f98e5ddbe4b0dc43bd7c80f36d7.tar.zst sway-b374c35758777f98e5ddbe4b0dc43bd7c80f36d7.zip |
refactor commands.c
Diffstat (limited to 'sway/commands.c')
-rw-r--r-- | sway/commands.c | 3222 |
1 files changed, 5 insertions, 3217 deletions
diff --git a/sway/commands.c b/sway/commands.c index 5a5bcd22..7b0780ec 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -35,120 +35,15 @@ | |||
35 | #include "input.h" | 35 | #include "input.h" |
36 | #include "border.h" | 36 | #include "border.h" |
37 | 37 | ||
38 | typedef struct cmd_results *sway_cmd(int argc, char **argv); | ||
39 | |||
40 | struct cmd_handler { | 38 | struct cmd_handler { |
41 | char *command; | 39 | char *command; |
42 | sway_cmd *handle; | 40 | sway_cmd *handle; |
43 | }; | 41 | }; |
44 | 42 | ||
45 | static sway_cmd cmd_assign; | ||
46 | static sway_cmd cmd_bar; | ||
47 | static sway_cmd cmd_bindcode; | ||
48 | static sway_cmd cmd_bindsym; | ||
49 | static sway_cmd cmd_border; | ||
50 | static sway_cmd cmd_client_focused; | ||
51 | static sway_cmd cmd_client_focused_inactive; | ||
52 | static sway_cmd cmd_client_unfocused; | ||
53 | static sway_cmd cmd_client_urgent; | ||
54 | static sway_cmd cmd_client_placeholder; | ||
55 | static sway_cmd cmd_client_background; | ||
56 | static sway_cmd cmd_debuglog; | ||
57 | static sway_cmd cmd_exec; | ||
58 | static sway_cmd cmd_exec_always; | ||
59 | static sway_cmd cmd_exit; | ||
60 | static sway_cmd cmd_floating; | ||
61 | static sway_cmd cmd_floating_maximum_size; | ||
62 | static sway_cmd cmd_floating_minimum_size; | ||
63 | static sway_cmd cmd_floating_mod; | ||
64 | static sway_cmd cmd_floating_scroll; | ||
65 | static sway_cmd cmd_focus; | ||
66 | static sway_cmd cmd_focus_follows_mouse; | ||
67 | static sway_cmd cmd_font; | ||
68 | static sway_cmd cmd_for_window; | ||
69 | static sway_cmd cmd_fullscreen; | ||
70 | static sway_cmd cmd_gaps; | ||
71 | static sway_cmd cmd_hide_edge_borders; | ||
72 | static sway_cmd cmd_include; | ||
73 | static sway_cmd cmd_input; | ||
74 | static sway_cmd cmd_kill; | ||
75 | static sway_cmd cmd_layout; | ||
76 | static sway_cmd cmd_log_colors; | ||
77 | static sway_cmd cmd_mode; | ||
78 | static sway_cmd cmd_mouse_warping; | ||
79 | static sway_cmd cmd_move; | ||
80 | static sway_cmd cmd_new_float; | ||
81 | static sway_cmd cmd_new_window; | ||
82 | static sway_cmd cmd_orientation; | ||
83 | static sway_cmd cmd_output; | ||
84 | static sway_cmd cmd_reload; | ||
85 | static sway_cmd cmd_resize; | ||
86 | static sway_cmd cmd_resize_set; | ||
87 | static sway_cmd cmd_scratchpad; | ||
88 | static sway_cmd cmd_set; | ||
89 | static sway_cmd cmd_smart_gaps; | ||
90 | static sway_cmd cmd_split; | ||
91 | static sway_cmd cmd_splith; | ||
92 | static sway_cmd cmd_splitt; | ||
93 | static sway_cmd cmd_splitv; | ||
94 | static sway_cmd cmd_sticky; | ||
95 | static sway_cmd cmd_workspace; | ||
96 | static sway_cmd cmd_ws_auto_back_and_forth; | ||
97 | static sway_cmd cmd_workspace_layout; | ||
98 | |||
99 | static sway_cmd bar_cmd_binding_mode_indicator; | ||
100 | static sway_cmd bar_cmd_bindsym; | ||
101 | static sway_cmd bar_cmd_colors; | ||
102 | static sway_cmd bar_cmd_font; | ||
103 | static sway_cmd bar_cmd_mode; | ||
104 | static sway_cmd bar_cmd_modifier; | ||
105 | static sway_cmd bar_cmd_output; | ||
106 | static sway_cmd bar_cmd_height; | ||
107 | static sway_cmd bar_cmd_hidden_state; | ||
108 | static sway_cmd bar_cmd_id; | ||
109 | static sway_cmd bar_cmd_position; | ||
110 | static sway_cmd bar_cmd_separator_symbol; | ||
111 | static sway_cmd bar_cmd_status_command; | ||
112 | static sway_cmd bar_cmd_pango_markup; | ||
113 | static sway_cmd bar_cmd_strip_workspace_numbers; | ||
114 | static sway_cmd bar_cmd_swaybar_command; | ||
115 | static sway_cmd bar_cmd_tray_output; | ||
116 | static sway_cmd bar_cmd_tray_padding; | ||
117 | static sway_cmd bar_cmd_wrap_scroll; | ||
118 | static sway_cmd bar_cmd_workspace_buttons; | ||
119 | |||
120 | static sway_cmd bar_colors_cmd_active_workspace; | ||
121 | static sway_cmd bar_colors_cmd_background; | ||
122 | static sway_cmd bar_colors_cmd_background; | ||
123 | static sway_cmd bar_colors_cmd_binding_mode; | ||
124 | static sway_cmd bar_colors_cmd_focused_workspace; | ||
125 | static sway_cmd bar_colors_cmd_inactive_workspace; | ||
126 | static sway_cmd bar_colors_cmd_separator; | ||
127 | static sway_cmd bar_colors_cmd_statusline; | ||
128 | static sway_cmd bar_colors_cmd_urgent_workspace; | ||
129 | |||
130 | static struct cmd_results *add_color(const char*, char*, const char*); | ||
131 | |||
132 | swayc_t *sp_view; | ||
133 | int sp_index = 0; | 43 | int sp_index = 0; |
134 | 44 | ||
135 | static char *bg_options[] = { | ||
136 | "stretch", | ||
137 | "center", | ||
138 | "fill", | ||
139 | "fit", | ||
140 | "tile" | ||
141 | }; | ||
142 | |||
143 | enum expected_args { | ||
144 | EXPECTED_MORE_THAN, | ||
145 | EXPECTED_AT_LEAST, | ||
146 | EXPECTED_LESS_THAN, | ||
147 | EXPECTED_EQUAL_TO | ||
148 | }; | ||
149 | |||
150 | // Returns error object, or NULL if check succeeds. | 45 | // Returns error object, or NULL if check succeeds. |
151 | static struct cmd_results *checkarg(int argc, const char *name, enum expected_args type, int val) { | 46 | struct cmd_results *checkarg(int argc, const char *name, enum expected_args type, int val) { |
152 | struct cmd_results *error = NULL; | 47 | struct cmd_results *error = NULL; |
153 | switch (type) { | 48 | switch (type) { |
154 | case EXPECTED_MORE_THAN: | 49 | case EXPECTED_MORE_THAN: |
@@ -186,751 +81,7 @@ static struct cmd_results *checkarg(int argc, const char *name, enum expected_ar | |||
186 | return error; | 81 | return error; |
187 | } | 82 | } |
188 | 83 | ||
189 | static struct cmd_results *cmd_assign(int argc, char **argv) { | 84 | void hide_view_in_scratchpad(swayc_t *sp_view) { |
190 | struct cmd_results *error = NULL; | ||
191 | if ((error = checkarg(argc, "assign", EXPECTED_AT_LEAST, 2))) { | ||
192 | return error; | ||
193 | } | ||
194 | |||
195 | char *criteria = *argv++; | ||
196 | |||
197 | if (strncmp(*argv, "→", strlen("→")) == 0) { | ||
198 | if (argc < 3) { | ||
199 | return cmd_results_new(CMD_INVALID, "assign", "Missing workspace"); | ||
200 | } | ||
201 | argv++; | ||
202 | } | ||
203 | |||
204 | char *movecmd = "move container to workspace "; | ||
205 | int arglen = strlen(movecmd) + strlen(*argv) + 1; | ||
206 | char *cmdlist = calloc(1, arglen); | ||
207 | |||
208 | snprintf(cmdlist, arglen, "%s%s", movecmd, *argv); | ||
209 | |||
210 | struct criteria *crit = malloc(sizeof(struct criteria)); | ||
211 | crit->crit_raw = strdup(criteria); | ||
212 | crit->cmdlist = cmdlist; | ||
213 | crit->tokens = create_list(); | ||
214 | char *err_str = extract_crit_tokens(crit->tokens, crit->crit_raw); | ||
215 | |||
216 | if (err_str) { | ||
217 | error = cmd_results_new(CMD_INVALID, "assign", err_str); | ||
218 | free(err_str); | ||
219 | free_criteria(crit); | ||
220 | } else if (crit->tokens->length == 0) { | ||
221 | error = cmd_results_new(CMD_INVALID, "assign", "Found no name/value pairs in criteria"); | ||
222 | free_criteria(crit); | ||
223 | } else if (list_seq_find(config->criteria, criteria_cmp, crit) != -1) { | ||
224 | sway_log(L_DEBUG, "assign: Duplicate, skipping."); | ||
225 | free_criteria(crit); | ||
226 | } else { | ||
227 | sway_log(L_DEBUG, "assign: '%s' -> '%s' added", crit->crit_raw, crit->cmdlist); | ||
228 | list_add(config->criteria, crit); | ||
229 | } | ||
230 | return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
231 | } | ||
232 | |||
233 | int binding_order = 0; | ||
234 | |||
235 | static struct cmd_results *cmd_bindsym(int argc, char **argv) { | ||
236 | struct cmd_results *error = NULL; | ||
237 | if ((error = checkarg(argc, "bindsym", EXPECTED_MORE_THAN, 1))) { | ||
238 | return error; | ||
239 | } | ||
240 | |||
241 | struct sway_binding *binding = malloc(sizeof(struct sway_binding)); | ||
242 | binding->keys = create_list(); | ||
243 | binding->modifiers = 0; | ||
244 | binding->release = false; | ||
245 | binding->bindcode = false; | ||
246 | |||
247 | // Handle --release | ||
248 | if (strcmp("--release", argv[0]) == 0) { | ||
249 | if (argc >= 3) { | ||
250 | binding->release = true; | ||
251 | argv++; | ||
252 | argc--; | ||
253 | } else { | ||
254 | free_sway_binding(binding); | ||
255 | return cmd_results_new(CMD_FAILURE, "bindsym", | ||
256 | "Invalid bindsym command " | ||
257 | "(expected more than 2 arguments, got %d)", argc); | ||
258 | } | ||
259 | } | ||
260 | |||
261 | binding->command = join_args(argv + 1, argc - 1); | ||
262 | |||
263 | list_t *split = split_string(argv[0], "+"); | ||
264 | for (int i = 0; i < split->length; ++i) { | ||
265 | // Check for a modifier key | ||
266 | uint32_t mod; | ||
267 | if ((mod = get_modifier_mask_by_name(split->items[i])) > 0) { | ||
268 | binding->modifiers |= mod; | ||
269 | continue; | ||
270 | } | ||
271 | // Check for xkb key | ||
272 | xkb_keysym_t sym = xkb_keysym_from_name(split->items[i], XKB_KEYSYM_CASE_INSENSITIVE); | ||
273 | if (!sym) { | ||
274 | error = cmd_results_new(CMD_INVALID, "bindsym", "Unknown key '%s'", (char *)split->items[i]); | ||
275 | free_sway_binding(binding); | ||
276 | list_free(split); | ||
277 | return error; | ||
278 | } | ||
279 | xkb_keysym_t *key = malloc(sizeof(xkb_keysym_t)); | ||
280 | *key = sym; | ||
281 | list_add(binding->keys, key); | ||
282 | } | ||
283 | free_flat_list(split); | ||
284 | |||
285 | struct sway_mode *mode = config->current_mode; | ||
286 | int i = list_seq_find(mode->bindings, sway_binding_cmp_keys, binding); | ||
287 | if (i > -1) { | ||
288 | sway_log(L_DEBUG, "bindsym - '%s' already exists, overwriting", argv[0]); | ||
289 | struct sway_binding *dup = mode->bindings->items[i]; | ||
290 | free_sway_binding(dup); | ||
291 | list_del(mode->bindings, i); | ||
292 | } | ||
293 | binding->order = binding_order++; | ||
294 | list_add(mode->bindings, binding); | ||
295 | list_qsort(mode->bindings, sway_binding_cmp_qsort); | ||
296 | |||
297 | sway_log(L_DEBUG, "bindsym - Bound %s to command %s", argv[0], binding->command); | ||
298 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
299 | } | ||
300 | |||
301 | static struct cmd_results *cmd_bindcode(int argc, char **argv) { | ||
302 | struct cmd_results *error = NULL; | ||
303 | if ((error = checkarg(argc, "bindcode", EXPECTED_MORE_THAN, 1))) { | ||
304 | return error; | ||
305 | } | ||
306 | |||
307 | struct sway_binding *binding = malloc(sizeof(struct sway_binding)); | ||
308 | binding->keys = create_list(); | ||
309 | binding->modifiers = 0; | ||
310 | binding->release = false; | ||
311 | binding->bindcode = true; | ||
312 | |||
313 | // Handle --release | ||
314 | if (strcmp("--release", argv[0]) == 0) { | ||
315 | if (argc >= 3) { | ||
316 | binding->release = true; | ||
317 | argv++; | ||
318 | argc--; | ||
319 | } else { | ||
320 | free_sway_binding(binding); | ||
321 | return cmd_results_new(CMD_FAILURE, "bindcode", | ||
322 | "Invalid bindcode command " | ||
323 | "(expected more than 2 arguments, got %d)", argc); | ||
324 | } | ||
325 | } | ||
326 | |||
327 | binding->command = join_args(argv + 1, argc - 1); | ||
328 | |||
329 | list_t *split = split_string(argv[0], "+"); | ||
330 | for (int i = 0; i < split->length; ++i) { | ||
331 | // Check for a modifier key | ||
332 | uint32_t mod; | ||
333 | if ((mod = get_modifier_mask_by_name(split->items[i])) > 0) { | ||
334 | binding->modifiers |= mod; | ||
335 | continue; | ||
336 | } | ||
337 | // parse keycode | ||
338 | xkb_keycode_t keycode = (int)strtol(split->items[i], NULL, 10); | ||
339 | if (!xkb_keycode_is_legal_ext(keycode)) { | ||
340 | error = cmd_results_new(CMD_INVALID, "bindcode", "Invalid keycode '%s'", (char *)split->items[i]); | ||
341 | free_sway_binding(binding); | ||
342 | list_free(split); | ||
343 | return error; | ||
344 | } | ||
345 | xkb_keycode_t *key = malloc(sizeof(xkb_keycode_t)); | ||
346 | *key = keycode - 8; | ||
347 | list_add(binding->keys, key); | ||
348 | } | ||
349 | free_flat_list(split); | ||
350 | |||
351 | struct sway_mode *mode = config->current_mode; | ||
352 | int i = list_seq_find(mode->bindings, sway_binding_cmp_keys, binding); | ||
353 | if (i > -1) { | ||
354 | struct sway_binding *dup = mode->bindings->items[i]; | ||
355 | if (dup->bindcode) { | ||
356 | sway_log(L_DEBUG, "bindcode - '%s' already exists, overwriting", argv[0]); | ||
357 | } else { | ||
358 | sway_log(L_DEBUG, "bindcode - '%s' already exists as bindsym, overwriting", argv[0]); | ||
359 | } | ||
360 | free_sway_binding(dup); | ||
361 | list_del(mode->bindings, i); | ||
362 | } | ||
363 | binding->order = binding_order++; | ||
364 | list_add(mode->bindings, binding); | ||
365 | list_qsort(mode->bindings, sway_binding_cmp_qsort); | ||
366 | |||
367 | sway_log(L_DEBUG, "bindcode - Bound %s to command %s", argv[0], binding->command); | ||
368 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
369 | } | ||
370 | |||
371 | static struct cmd_results *cmd_border(int argc, char **argv) { | ||
372 | struct cmd_results *error = NULL; | ||
373 | if (!config->active) { | ||
374 | return cmd_results_new(CMD_FAILURE, "border", "Can only be used when sway is running."); | ||
375 | } | ||
376 | if ((error = checkarg(argc, "border", EXPECTED_AT_LEAST, 1))) { | ||
377 | return error; | ||
378 | } | ||
379 | |||
380 | if (argc > 2) { | ||
381 | return cmd_results_new(CMD_INVALID, "border", | ||
382 | "Expected 'border <normal|pixel|none|toggle> [<n>]"); | ||
383 | } | ||
384 | |||
385 | swayc_t *view = get_focused_view(&root_container); | ||
386 | enum swayc_border_types border = view->border_type; | ||
387 | int thickness = view->border_thickness; | ||
388 | |||
389 | if (strcasecmp(argv[0], "none") == 0) { | ||
390 | border = B_NONE; | ||
391 | } else if (strcasecmp(argv[0], "normal") == 0) { | ||
392 | border = B_NORMAL; | ||
393 | } else if (strcasecmp(argv[0], "pixel") == 0) { | ||
394 | border = B_PIXEL; | ||
395 | } else if (strcasecmp(argv[0], "toggle") == 0) { | ||
396 | switch (border) { | ||
397 | case B_NONE: | ||
398 | border = B_PIXEL; | ||
399 | break; | ||
400 | case B_NORMAL: | ||
401 | border = B_NONE; | ||
402 | break; | ||
403 | case B_PIXEL: | ||
404 | border = B_NORMAL; | ||
405 | break; | ||
406 | } | ||
407 | } else { | ||
408 | return cmd_results_new(CMD_INVALID, "border", | ||
409 | "Expected 'border <normal|pixel|none|toggle>"); | ||
410 | } | ||
411 | |||
412 | if (argc == 2 && (border == B_NORMAL || border == B_PIXEL)) { | ||
413 | thickness = (int)strtol(argv[1], NULL, 10); | ||
414 | if (errno == ERANGE || thickness < 0) { | ||
415 | errno = 0; | ||
416 | return cmd_results_new(CMD_INVALID, "border", "Number is out out of range."); | ||
417 | } | ||
418 | } | ||
419 | |||
420 | if (view) { | ||
421 | view->border_type = border; | ||
422 | view->border_thickness = thickness; | ||
423 | update_geometry(view); | ||
424 | } | ||
425 | |||
426 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
427 | } | ||
428 | |||
429 | static struct cmd_results *parse_border_color(struct border_colors *border_colors, const char *cmd_name, int argc, char **argv) { | ||
430 | struct cmd_results *error = NULL; | ||
431 | if (argc != 5) { | ||
432 | return cmd_results_new(CMD_INVALID, cmd_name, "Requires exactly five color values"); | ||
433 | } | ||
434 | |||
435 | uint32_t colors[5]; | ||
436 | int i; | ||
437 | for (i = 0; i < 5; i++) { | ||
438 | char buffer[10]; | ||
439 | error = add_color(cmd_name, buffer, argv[i]); | ||
440 | if (error) { | ||
441 | return error; | ||
442 | } | ||
443 | colors[i] = strtoul(buffer+1, NULL, 16); | ||
444 | } | ||
445 | |||
446 | border_colors->border = colors[0]; | ||
447 | border_colors->background = colors[1]; | ||
448 | border_colors->text = colors[2]; | ||
449 | border_colors->indicator = colors[3]; | ||
450 | border_colors->child_border = colors[4]; | ||
451 | |||
452 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
453 | } | ||
454 | |||
455 | static struct cmd_results *cmd_client_focused(int argc, char **argv) { | ||
456 | return parse_border_color(&config->border_colors.focused, "client.focused", argc, argv); | ||
457 | } | ||
458 | |||
459 | static struct cmd_results *cmd_client_focused_inactive(int argc, char **argv) { | ||
460 | return parse_border_color(&config->border_colors.focused_inactive, "client.focused_inactive", argc, argv); | ||
461 | } | ||
462 | |||
463 | static struct cmd_results *cmd_client_unfocused(int argc, char **argv) { | ||
464 | return parse_border_color(&config->border_colors.unfocused, "client.unfocused", argc, argv); | ||
465 | } | ||
466 | |||
467 | static struct cmd_results *cmd_client_urgent(int argc, char **argv) { | ||
468 | return parse_border_color(&config->border_colors.urgent, "client.urgent", argc, argv); | ||
469 | } | ||
470 | |||
471 | static struct cmd_results *cmd_client_placeholder(int argc, char **argv) { | ||
472 | return parse_border_color(&config->border_colors.placeholder, "client.placeholder", argc, argv); | ||
473 | } | ||
474 | |||
475 | static struct cmd_results *cmd_client_background(int argc, char **argv) { | ||
476 | char buffer[10]; | ||
477 | struct cmd_results *error = NULL; | ||
478 | uint32_t background; | ||
479 | |||
480 | if (argc != 1) { | ||
481 | return cmd_results_new(CMD_INVALID, "client.background", "Requires exactly one color value"); | ||
482 | } | ||
483 | |||
484 | error = add_color("client.background", buffer, argv[0]); | ||
485 | if (error) { | ||
486 | return error; | ||
487 | } | ||
488 | |||
489 | background = strtoul(buffer+1, NULL, 16); | ||
490 | config->border_colors.background = background; | ||
491 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
492 | } | ||
493 | |||
494 | static struct cmd_results *cmd_exec_always(int argc, char **argv) { | ||
495 | struct cmd_results *error = NULL; | ||
496 | if (!config->active) return cmd_results_new(CMD_DEFER, NULL, NULL); | ||
497 | if ((error = checkarg(argc, "exec_always", EXPECTED_MORE_THAN, 0))) { | ||
498 | return error; | ||
499 | } | ||
500 | |||
501 | char *tmp = NULL; | ||
502 | if (strcmp((char*)*argv, "--no-startup-id") == 0) { | ||
503 | sway_log(L_INFO, "exec switch '--no-startup-id' not supported, ignored."); | ||
504 | if ((error = checkarg(argc - 1, "exec_always", EXPECTED_MORE_THAN, 0))) { | ||
505 | return error; | ||
506 | } | ||
507 | |||
508 | tmp = join_args(argv + 1, argc - 1); | ||
509 | } else { | ||
510 | tmp = join_args(argv, argc); | ||
511 | } | ||
512 | |||
513 | // Put argument into cmd array | ||
514 | char cmd[4096]; | ||
515 | strncpy(cmd, tmp, sizeof(cmd)); | ||
516 | cmd[sizeof(cmd) - 1] = 0; | ||
517 | free(tmp); | ||
518 | sway_log(L_DEBUG, "Executing %s", cmd); | ||
519 | |||
520 | int fd[2]; | ||
521 | if (pipe(fd) != 0) { | ||
522 | sway_log(L_ERROR, "Unable to create pipe for fork"); | ||
523 | } | ||
524 | |||
525 | pid_t pid; | ||
526 | pid_t *child = malloc(sizeof(pid_t)); // malloc'd so that Linux can avoid copying the process space | ||
527 | // Fork process | ||
528 | if ((pid = fork()) == 0) { | ||
529 | // Fork child process again | ||
530 | setsid(); | ||
531 | if ((*child = fork()) == 0) { | ||
532 | execl("/bin/sh", "/bin/sh", "-c", cmd, (void *)NULL); | ||
533 | /* Not reached */ | ||
534 | } | ||
535 | close(fd[0]); | ||
536 | ssize_t s = 0; | ||
537 | while ((size_t)s < sizeof(pid_t)) { | ||
538 | s += write(fd[1], ((uint8_t *)child) + s, sizeof(pid_t) - s); | ||
539 | } | ||
540 | close(fd[1]); | ||
541 | _exit(0); // Close child process | ||
542 | } else if (pid < 0) { | ||
543 | free(child); | ||
544 | return cmd_results_new(CMD_FAILURE, "exec_always", "Command failed (sway could not fork)."); | ||
545 | } | ||
546 | close(fd[1]); // close write | ||
547 | ssize_t s = 0; | ||
548 | while ((size_t)s < sizeof(pid_t)) { | ||
549 | s += read(fd[0], ((uint8_t *)child) + s, sizeof(pid_t) - s); | ||
550 | } | ||
551 | close(fd[0]); | ||
552 | // cleanup child process | ||
553 | wait(0); | ||
554 | swayc_t *ws = swayc_active_workspace(); | ||
555 | if (*child > 0 && ws) { | ||
556 | sway_log(L_DEBUG, "Child process created with pid %d for workspace %s", *child, ws->name); | ||
557 | struct pid_workspace *pw = malloc(sizeof(struct pid_workspace)); | ||
558 | pw->pid = child; | ||
559 | pw->workspace = strdup(ws->name); | ||
560 | pid_workspace_add(pw); | ||
561 | // TODO: keep track of this pid and open the corresponding view on the current workspace | ||
562 | // blocked pending feature in wlc | ||
563 | } else { | ||
564 | free(child); | ||
565 | } | ||
566 | |||
567 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
568 | } | ||
569 | |||
570 | static struct cmd_results *cmd_debuglog(int argc, char **argv) { | ||
571 | struct cmd_results *error = NULL; | ||
572 | if ((error = checkarg(argc, "debuglog", EXPECTED_EQUAL_TO, 1))) { | ||
573 | return error; | ||
574 | } else if (strcasecmp(argv[0], "toggle") == 0) { | ||
575 | if (config->reading) { | ||
576 | return cmd_results_new(CMD_FAILURE, "debuglog toggle", "Can't be used in config file."); | ||
577 | } | ||
578 | if (toggle_debug_logging()) { | ||
579 | sway_log(L_DEBUG, "Debuglog turned on."); | ||
580 | } | ||
581 | } else if (strcasecmp(argv[0], "on") == 0) { | ||
582 | set_log_level(L_DEBUG); | ||
583 | sway_log(L_DEBUG, "Debuglog turned on."); | ||
584 | } else if (strcasecmp(argv[0], "off") == 0) { | ||
585 | reset_log_level(); | ||
586 | } else { | ||
587 | return cmd_results_new(CMD_FAILURE, "debuglog", "Expected 'debuglog on|off|toggle'"); | ||
588 | } | ||
589 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
590 | } | ||
591 | |||
592 | static struct cmd_results *cmd_exec(int argc, char **argv) { | ||
593 | if (!config->active) return cmd_results_new(CMD_DEFER, "exec", NULL); | ||
594 | if (config->reloading) { | ||
595 | char *args = join_args(argv, argc); | ||
596 | sway_log(L_DEBUG, "Ignoring 'exec %s' due to reload", args); | ||
597 | free(args); | ||
598 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
599 | } | ||
600 | return cmd_exec_always(argc, argv); | ||
601 | } | ||
602 | |||
603 | static struct cmd_results *cmd_exit(int argc, char **argv) { | ||
604 | struct cmd_results *error = NULL; | ||
605 | if (config->reading) return cmd_results_new(CMD_FAILURE, "exit", "Can't be used in config file."); | ||
606 | if ((error = checkarg(argc, "exit", EXPECTED_EQUAL_TO, 0))) { | ||
607 | return error; | ||
608 | } | ||
609 | // Close all views | ||
610 | close_views(&root_container); | ||
611 | sway_terminate(EXIT_SUCCESS); | ||
612 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
613 | } | ||
614 | |||
615 | static struct cmd_results *cmd_floating(int argc, char **argv) { | ||
616 | struct cmd_results *error = NULL; | ||
617 | if (config->reading) return cmd_results_new(CMD_FAILURE, "floating", "Can't be used in config file."); | ||
618 | if ((error = checkarg(argc, "floating", EXPECTED_EQUAL_TO, 1))) { | ||
619 | return error; | ||
620 | } | ||
621 | swayc_t *view = get_focused_container(&root_container); | ||
622 | bool wants_floating; | ||
623 | if (strcasecmp(argv[0], "enable") == 0) { | ||
624 | wants_floating = true; | ||
625 | } else if (strcasecmp(argv[0], "disable") == 0) { | ||
626 | wants_floating = false; | ||
627 | } else if (strcasecmp(argv[0], "toggle") == 0) { | ||
628 | wants_floating = !view->is_floating; | ||
629 | } else { | ||
630 | return cmd_results_new(CMD_FAILURE, "floating", | ||
631 | "Expected 'floating <enable|disable|toggle>"); | ||
632 | } | ||
633 | |||
634 | // Prevent running floating commands on things like workspaces | ||
635 | if (view->type != C_VIEW) { | ||
636 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
637 | } | ||
638 | |||
639 | // Change from nonfloating to floating | ||
640 | if (!view->is_floating && wants_floating) { | ||
641 | // Remove view from its current location | ||
642 | destroy_container(remove_child(view)); | ||
643 | |||
644 | // and move it into workspace floating | ||
645 | add_floating(swayc_active_workspace(), view); | ||
646 | view->x = (swayc_active_workspace()->width - view->width)/2; | ||
647 | view->y = (swayc_active_workspace()->height - view->height)/2; | ||
648 | if (view->desired_width != -1) { | ||
649 | view->width = view->desired_width; | ||
650 | } | ||
651 | if (view->desired_height != -1) { | ||
652 | view->height = view->desired_height; | ||
653 | } | ||
654 | arrange_windows(swayc_active_workspace(), -1, -1); | ||
655 | |||
656 | } else if (view->is_floating && !wants_floating) { | ||
657 | // Delete the view from the floating list and unset its is_floating flag | ||
658 | remove_child(view); | ||
659 | view->is_floating = false; | ||
660 | // Get the properly focused container, and add in the view there | ||
661 | swayc_t *focused = container_under_pointer(); | ||
662 | // If focused is null, it's because the currently focused container is a workspace | ||
663 | if (focused == NULL || focused->is_floating) { | ||
664 | focused = swayc_active_workspace(); | ||
665 | } | ||
666 | set_focused_container(focused); | ||
667 | |||
668 | sway_log(L_DEBUG, "Non-floating focused container is %p", focused); | ||
669 | |||
670 | // Case of focused workspace, just create as child of it | ||
671 | if (focused->type == C_WORKSPACE) { | ||
672 | add_child(focused, view); | ||
673 | } | ||
674 | // Regular case, create as sibling of current container | ||
675 | else { | ||
676 | add_sibling(focused, view); | ||
677 | } | ||
678 | // Refocus on the view once its been put back into the layout | ||
679 | view->width = view->height = 0; | ||
680 | arrange_windows(swayc_active_workspace(), -1, -1); | ||
681 | remove_view_from_scratchpad(view); | ||
682 | ipc_event_window(view, "floating"); | ||
683 | } | ||
684 | set_focused_container(view); | ||
685 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
686 | } | ||
687 | |||
688 | static struct cmd_results *cmd_floating_maximum_size(int argc, char **argv) { | ||
689 | struct cmd_results *error = NULL; | ||
690 | int32_t width; | ||
691 | int32_t height; | ||
692 | char *ptr; | ||
693 | |||
694 | if ((error = checkarg(argc, "floating_maximum_size", EXPECTED_EQUAL_TO, 3))) { | ||
695 | return error; | ||
696 | } | ||
697 | width = strtol(argv[0], &ptr, 10); | ||
698 | height = strtol(argv[2], &ptr, 10); | ||
699 | |||
700 | if (width < -1) { | ||
701 | sway_log(L_DEBUG, "floating_maximum_size invalid width value: '%s'", argv[0]); | ||
702 | |||
703 | } else { | ||
704 | config->floating_maximum_width = width; | ||
705 | |||
706 | } | ||
707 | |||
708 | if (height < -1) { | ||
709 | sway_log(L_DEBUG, "floating_maximum_size invalid height value: '%s'", argv[2]); | ||
710 | } | ||
711 | else { | ||
712 | config->floating_maximum_height = height; | ||
713 | |||
714 | } | ||
715 | |||
716 | sway_log(L_DEBUG, "New floating_maximum_size: '%d' x '%d'", config->floating_maximum_width, | ||
717 | config->floating_maximum_height); | ||
718 | |||
719 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
720 | } | ||
721 | |||
722 | static struct cmd_results *cmd_floating_minimum_size(int argc, char **argv) { | ||
723 | struct cmd_results *error = NULL; | ||
724 | int32_t width; | ||
725 | int32_t height; | ||
726 | char *ptr; | ||
727 | |||
728 | if ((error = checkarg(argc, "floating_minimum_size", EXPECTED_EQUAL_TO, 3))) { | ||
729 | return error; | ||
730 | } | ||
731 | width = strtol(argv[0], &ptr, 10); | ||
732 | height = strtol(argv[2], &ptr, 10); | ||
733 | |||
734 | if (width <= 0) { | ||
735 | sway_log(L_DEBUG, "floating_minimum_size invalid width value: '%s'", argv[0]); | ||
736 | |||
737 | } else { | ||
738 | config->floating_minimum_width = width; | ||
739 | |||
740 | } | ||
741 | |||
742 | if (height <= 0) { | ||
743 | sway_log(L_DEBUG, "floating_minimum_size invalid height value: '%s'", argv[2]); | ||
744 | } | ||
745 | else { | ||
746 | config->floating_minimum_height = height; | ||
747 | |||
748 | } | ||
749 | |||
750 | sway_log(L_DEBUG, "New floating_minimum_size: '%d' x '%d'", config->floating_minimum_width, | ||
751 | config->floating_minimum_height); | ||
752 | |||
753 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
754 | } | ||
755 | |||
756 | static struct cmd_results *cmd_floating_mod(int argc, char **argv) { | ||
757 | struct cmd_results *error = NULL; | ||
758 | if ((error = checkarg(argc, "floating_modifier", EXPECTED_AT_LEAST, 1))) { | ||
759 | return error; | ||
760 | } | ||
761 | int i; | ||
762 | list_t *split = split_string(argv[0], "+"); | ||
763 | config->floating_mod = 0; | ||
764 | |||
765 | // set modifier keys | ||
766 | for (i = 0; i < split->length; ++i) { | ||
767 | config->floating_mod |= get_modifier_mask_by_name(split->items[i]); | ||
768 | } | ||
769 | free_flat_list(split); | ||
770 | if (!config->floating_mod) { | ||
771 | error = cmd_results_new(CMD_INVALID, "floating_modifier", "Unknown keys %s", argv[0]); | ||
772 | return error; | ||
773 | } | ||
774 | |||
775 | if (argc >= 2) { | ||
776 | if (strcasecmp("inverse", argv[1]) == 0) { | ||
777 | config->dragging_key = M_RIGHT_CLICK; | ||
778 | config->resizing_key = M_LEFT_CLICK; | ||
779 | } else if (strcasecmp("normal", argv[1]) == 0) { | ||
780 | config->dragging_key = M_LEFT_CLICK; | ||
781 | config->resizing_key = M_RIGHT_CLICK; | ||
782 | } else { | ||
783 | error = cmd_results_new(CMD_INVALID, "floating_modifier", "Invalid definition %s", argv[1]); | ||
784 | return error; | ||
785 | } | ||
786 | } | ||
787 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
788 | } | ||
789 | |||
790 | static struct cmd_results *cmd_floating_scroll(int argc, char **argv) { | ||
791 | struct cmd_results *error = NULL; | ||
792 | if ((error = checkarg(argc, "floating_scroll", EXPECTED_AT_LEAST, 1))) { | ||
793 | return error; | ||
794 | } | ||
795 | if (!strcasecmp("up", argv[0])) { | ||
796 | free(config->floating_scroll_up_cmd); | ||
797 | if (argc < 2) { | ||
798 | config->floating_scroll_up_cmd = strdup(""); | ||
799 | } else { | ||
800 | config->floating_scroll_up_cmd = join_args(argv + 1, argc - 1); | ||
801 | } | ||
802 | } else if (!strcasecmp("down", argv[0])) { | ||
803 | free(config->floating_scroll_down_cmd); | ||
804 | if (argc < 2) { | ||
805 | config->floating_scroll_down_cmd = strdup(""); | ||
806 | } else { | ||
807 | config->floating_scroll_down_cmd = join_args(argv + 1, argc - 1); | ||
808 | } | ||
809 | } else if (!strcasecmp("left", argv[0])) { | ||
810 | free(config->floating_scroll_left_cmd); | ||
811 | if (argc < 2) { | ||
812 | config->floating_scroll_left_cmd = strdup(""); | ||
813 | } else { | ||
814 | config->floating_scroll_left_cmd = join_args(argv + 1, argc - 1); | ||
815 | } | ||
816 | } else if (!strcasecmp("right", argv[0])) { | ||
817 | free(config->floating_scroll_right_cmd); | ||
818 | if (argc < 2) { | ||
819 | config->floating_scroll_right_cmd = strdup(""); | ||
820 | } else { | ||
821 | config->floating_scroll_right_cmd = join_args(argv + 1, argc - 1); | ||
822 | } | ||
823 | } else { | ||
824 | error = cmd_results_new(CMD_INVALID, "floating_scroll", "Unknown command: '%s'", argv[0]); | ||
825 | return error; | ||
826 | } | ||
827 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
828 | } | ||
829 | |||
830 | static struct cmd_results *cmd_focus(int argc, char **argv) { | ||
831 | if (config->reading) return cmd_results_new(CMD_FAILURE, "focus", "Can't be used in config file."); | ||
832 | struct cmd_results *error = NULL; | ||
833 | if (argc > 0 && strcasecmp(argv[0], "output") == 0) { | ||
834 | swayc_t *output = NULL; | ||
835 | struct wlc_point abs_pos; | ||
836 | get_absolute_center_position(get_focused_container(&root_container), &abs_pos); | ||
837 | if ((error = checkarg(argc, "focus", EXPECTED_EQUAL_TO, 2))) { | ||
838 | return error; | ||
839 | } else if (!(output = output_by_name(argv[1], &abs_pos))) { | ||
840 | return cmd_results_new(CMD_FAILURE, "focus output", | ||
841 | "Can't find output with name/at direction '%s' @ (%i,%i)", argv[1], abs_pos.x, abs_pos.y); | ||
842 | } else if (!workspace_switch(swayc_active_workspace_for(output))) { | ||
843 | return cmd_results_new(CMD_FAILURE, "focus output", | ||
844 | "Switching to workspace on output '%s' was blocked", argv[1]); | ||
845 | } else if (config->mouse_warping) { | ||
846 | swayc_t *focused = get_focused_view(output); | ||
847 | if (focused && focused->type == C_VIEW) { | ||
848 | center_pointer_on(focused); | ||
849 | } | ||
850 | } | ||
851 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
852 | } else if ((error = checkarg(argc, "focus", EXPECTED_EQUAL_TO, 1))) { | ||
853 | return error; | ||
854 | } | ||
855 | static int floating_toggled_index = 0; | ||
856 | static int tiled_toggled_index = 0; | ||
857 | if (strcasecmp(argv[0], "left") == 0) { | ||
858 | move_focus(MOVE_LEFT); | ||
859 | } else if (strcasecmp(argv[0], "right") == 0) { | ||
860 | move_focus(MOVE_RIGHT); | ||
861 | } else if (strcasecmp(argv[0], "up") == 0) { | ||
862 | move_focus(MOVE_UP); | ||
863 | } else if (strcasecmp(argv[0], "down") == 0) { | ||
864 | move_focus(MOVE_DOWN); | ||
865 | } else if (strcasecmp(argv[0], "parent") == 0) { | ||
866 | move_focus(MOVE_PARENT); | ||
867 | } else if (strcasecmp(argv[0], "child") == 0) { | ||
868 | move_focus(MOVE_CHILD); | ||
869 | } else if (strcasecmp(argv[0], "mode_toggle") == 0) { | ||
870 | int i; | ||
871 | swayc_t *workspace = swayc_active_workspace(); | ||
872 | swayc_t *focused = get_focused_view(workspace); | ||
873 | if (focused->is_floating) { | ||
874 | if (workspace->children->length > 0) { | ||
875 | for (i = 0;i < workspace->floating->length; i++) { | ||
876 | if (workspace->floating->items[i] == focused) { | ||
877 | floating_toggled_index = i; | ||
878 | break; | ||
879 | } | ||
880 | } | ||
881 | if (workspace->children->length > tiled_toggled_index) { | ||
882 | set_focused_container(get_focused_view(workspace->children->items[tiled_toggled_index])); | ||
883 | } else { | ||
884 | set_focused_container(get_focused_view(workspace->children->items[0])); | ||
885 | tiled_toggled_index = 0; | ||
886 | } | ||
887 | } | ||
888 | } else { | ||
889 | if (workspace->floating->length > 0) { | ||
890 | for (i = 0;i < workspace->children->length; i++) { | ||
891 | if (workspace->children->items[i] == focused) { | ||
892 | tiled_toggled_index = i; | ||
893 | break; | ||
894 | } | ||
895 | } | ||
896 | if (workspace->floating->length > floating_toggled_index) { | ||
897 | swayc_t *floating = workspace->floating->items[floating_toggled_index]; | ||
898 | set_focused_container(get_focused_view(floating)); | ||
899 | } else { | ||
900 | swayc_t *floating = workspace->floating->items[workspace->floating->length - 1]; | ||
901 | set_focused_container(get_focused_view(floating)); | ||
902 | tiled_toggled_index = workspace->floating->length - 1; | ||
903 | } | ||
904 | } | ||
905 | } | ||
906 | } else { | ||
907 | return cmd_results_new(CMD_INVALID, "focus", | ||
908 | "Expected 'focus <direction|parent|child|mode_toggle>' or 'focus output <direction|name>'"); | ||
909 | } | ||
910 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
911 | } | ||
912 | |||
913 | static struct cmd_results *cmd_focus_follows_mouse(int argc, char **argv) { | ||
914 | struct cmd_results *error = NULL; | ||
915 | if ((error = checkarg(argc, "focus_follows_mouse", EXPECTED_EQUAL_TO, 1))) { | ||
916 | return error; | ||
917 | } | ||
918 | |||
919 | config->focus_follows_mouse = !strcasecmp(argv[0], "yes"); | ||
920 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
921 | } | ||
922 | |||
923 | static struct cmd_results *cmd_seamless_mouse(int argc, char **argv) { | ||
924 | struct cmd_results *error = NULL; | ||
925 | if ((error = checkarg(argc, "seamless_mouse", EXPECTED_EQUAL_TO, 1))) { | ||
926 | return error; | ||
927 | } | ||
928 | |||
929 | config->seamless_mouse = (strcasecmp(argv[0], "on") == 0 || strcasecmp(argv[0], "yes") == 0); | ||
930 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
931 | } | ||
932 | |||
933 | static void hide_view_in_scratchpad(swayc_t *sp_view) { | ||
934 | if (sp_view == NULL) { | 85 | if (sp_view == NULL) { |
935 | return; | 86 | return; |
936 | } | 87 | } |
@@ -947,313 +98,7 @@ static void hide_view_in_scratchpad(swayc_t *sp_view) { | |||
947 | set_focused_container(container_under_pointer()); | 98 | set_focused_container(container_under_pointer()); |
948 | } | 99 | } |
949 | 100 | ||
950 | static struct cmd_results *cmd_mode(int argc, char **argv) { | 101 | void input_cmd_apply(struct input_config *input) { |
951 | struct cmd_results *error = NULL; | ||
952 | if ((error = checkarg(argc, "mode", EXPECTED_AT_LEAST, 1))) { | ||
953 | return error; | ||
954 | } | ||
955 | |||
956 | const char *mode_name = argv[0]; | ||
957 | bool mode_make = (argc == 2 && strcmp(argv[1], "{") == 0); | ||
958 | if (mode_make) { | ||
959 | if (!config->reading) | ||
960 | return cmd_results_new(CMD_FAILURE, "mode", "Can only be used in config file."); | ||
961 | } | ||
962 | struct sway_mode *mode = NULL; | ||
963 | // Find mode | ||
964 | int i, len = config->modes->length; | ||
965 | for (i = 0; i < len; ++i) { | ||
966 | struct sway_mode *find = config->modes->items[i]; | ||
967 | if (strcasecmp(find->name, mode_name) == 0) { | ||
968 | mode = find; | ||
969 | break; | ||
970 | } | ||
971 | } | ||
972 | // Create mode if it doesn't exist | ||
973 | if (!mode && mode_make) { | ||
974 | mode = malloc(sizeof*mode); | ||
975 | mode->name = strdup(mode_name); | ||
976 | mode->bindings = create_list(); | ||
977 | list_add(config->modes, mode); | ||
978 | } | ||
979 | if (!mode) { | ||
980 | error = cmd_results_new(CMD_INVALID, "mode", "Unknown mode `%s'", mode_name); | ||
981 | return error; | ||
982 | } | ||
983 | if ((config->reading && mode_make) || (!config->reading && !mode_make)) { | ||
984 | sway_log(L_DEBUG, "Switching to mode `%s'",mode->name); | ||
985 | } | ||
986 | // Set current mode | ||
987 | config->current_mode = mode; | ||
988 | if (!mode_make) { | ||
989 | // trigger IPC mode event | ||
990 | ipc_event_mode(config->current_mode->name); | ||
991 | } | ||
992 | return cmd_results_new(mode_make ? CMD_BLOCK_MODE : CMD_SUCCESS, NULL, NULL); | ||
993 | } | ||
994 | |||
995 | static struct cmd_results *cmd_mouse_warping(int argc, char **argv) { | ||
996 | struct cmd_results *error = NULL; | ||
997 | if ((error = checkarg(argc, "mouse_warping", EXPECTED_EQUAL_TO, 1))) { | ||
998 | return error; | ||
999 | } else if (strcasecmp(argv[0], "output") == 0) { | ||
1000 | config->mouse_warping = true; | ||
1001 | } else if (strcasecmp(argv[0], "none") == 0) { | ||
1002 | config->mouse_warping = false; | ||
1003 | } else { | ||
1004 | return cmd_results_new(CMD_FAILURE, "mouse_warping", "Expected 'mouse_warping output|none'"); | ||
1005 | } | ||
1006 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1007 | } | ||
1008 | |||
1009 | static struct cmd_results *cmd_move(int argc, char **argv) { | ||
1010 | struct cmd_results *error = NULL; | ||
1011 | if (config->reading) return cmd_results_new(CMD_FAILURE, "move", "Can't be used in config file."); | ||
1012 | if ((error = checkarg(argc, "move", EXPECTED_AT_LEAST, 1))) { | ||
1013 | return error; | ||
1014 | } | ||
1015 | const char* expected_syntax = "Expected 'move <left|right|up|down>' or " | ||
1016 | "'move <container|window> to workspace <name>' or " | ||
1017 | "'move <container|window|workspace> to output <name|direction>' or " | ||
1018 | "'move position mouse'"; | ||
1019 | swayc_t *view = get_focused_container(&root_container); | ||
1020 | |||
1021 | if (strcasecmp(argv[0], "left") == 0) { | ||
1022 | move_container(view, MOVE_LEFT); | ||
1023 | } else if (strcasecmp(argv[0], "right") == 0) { | ||
1024 | move_container(view, MOVE_RIGHT); | ||
1025 | } else if (strcasecmp(argv[0], "up") == 0) { | ||
1026 | move_container(view, MOVE_UP); | ||
1027 | } else if (strcasecmp(argv[0], "down") == 0) { | ||
1028 | move_container(view, MOVE_DOWN); | ||
1029 | } else if (strcasecmp(argv[0], "container") == 0 || strcasecmp(argv[0], "window") == 0) { | ||
1030 | // "move container ... | ||
1031 | if ((error = checkarg(argc, "move container/window", EXPECTED_AT_LEAST, 4))) { | ||
1032 | return error; | ||
1033 | } else if ( strcasecmp(argv[1], "to") == 0 && strcasecmp(argv[2], "workspace") == 0) { | ||
1034 | // move container to workspace x | ||
1035 | if (view->type == C_WORKSPACE) { | ||
1036 | view = new_container(view, view->layout); | ||
1037 | } if (view->type != C_CONTAINER && view->type != C_VIEW) { | ||
1038 | return cmd_results_new(CMD_FAILURE, "move", "Can only move containers and views."); | ||
1039 | } | ||
1040 | |||
1041 | const char *ws_name = argv[3]; | ||
1042 | swayc_t *ws; | ||
1043 | if (argc == 5 && strcasecmp(ws_name, "number") == 0) { | ||
1044 | // move "container to workspace number x" | ||
1045 | ws_name = argv[4]; | ||
1046 | ws = workspace_by_number(ws_name); | ||
1047 | } else { | ||
1048 | ws = workspace_by_name(ws_name); | ||
1049 | } | ||
1050 | |||
1051 | if (ws == NULL) { | ||
1052 | ws = workspace_create(ws_name); | ||
1053 | } | ||
1054 | move_container_to(view, get_focused_container(ws)); | ||
1055 | } else if (strcasecmp(argv[1], "to") == 0 && strcasecmp(argv[2], "output") == 0) { | ||
1056 | // move container to output x | ||
1057 | swayc_t *output = NULL; | ||
1058 | struct wlc_point abs_pos; | ||
1059 | get_absolute_center_position(view, &abs_pos); | ||
1060 | if (view->type == C_WORKSPACE) { | ||
1061 | view = new_container(view, view->layout); | ||
1062 | } else if (view->type != C_CONTAINER && view->type != C_VIEW) { | ||
1063 | return cmd_results_new(CMD_FAILURE, "move", "Can only move containers and views."); | ||
1064 | } else if (!(output = output_by_name(argv[3], &abs_pos))) { | ||
1065 | return cmd_results_new(CMD_FAILURE, "move", | ||
1066 | "Can't find output with name/direction '%s' @ (%i,%i)", argv[3], abs_pos.x, abs_pos.y); | ||
1067 | } | ||
1068 | |||
1069 | swayc_t *container = get_focused_container(output); | ||
1070 | if (container->is_floating) { | ||
1071 | move_container_to(view, container->parent); | ||
1072 | } else { | ||
1073 | move_container_to(view, container); | ||
1074 | } | ||
1075 | } else { | ||
1076 | return cmd_results_new(CMD_INVALID, "move", expected_syntax); | ||
1077 | } | ||
1078 | } else if (strcasecmp(argv[0], "workspace") == 0) { | ||
1079 | // move workspace (to output x) | ||
1080 | swayc_t *output = NULL; | ||
1081 | struct wlc_point abs_pos; | ||
1082 | get_absolute_center_position(view, &abs_pos); | ||
1083 | if ((error = checkarg(argc, "move workspace", EXPECTED_EQUAL_TO, 4))) { | ||
1084 | return error; | ||
1085 | } else if (strcasecmp(argv[1], "to") != 0 || strcasecmp(argv[2], "output") != 0) { | ||
1086 | return cmd_results_new(CMD_INVALID, "move", expected_syntax); | ||
1087 | } else if (!(output = output_by_name(argv[3], &abs_pos))) { | ||
1088 | return cmd_results_new(CMD_FAILURE, "move workspace", | ||
1089 | "Can't find output with name/direction '%s' @ (%i,%i)", argv[3], abs_pos.x, abs_pos.y); | ||
1090 | } | ||
1091 | if (view->type == C_WORKSPACE) { | ||
1092 | // This probably means we're moving an empty workspace, but | ||
1093 | // that's fine. | ||
1094 | move_workspace_to(view, output); | ||
1095 | } else { | ||
1096 | swayc_t *workspace = swayc_parent_by_type(view, C_WORKSPACE); | ||
1097 | move_workspace_to(workspace, output); | ||
1098 | } | ||
1099 | } else if (strcasecmp(argv[0], "scratchpad") == 0) { | ||
1100 | // move scratchpad ... | ||
1101 | if (view->type != C_CONTAINER && view->type != C_VIEW) { | ||
1102 | return cmd_results_new(CMD_FAILURE, "move scratchpad", "Can only move containers and views."); | ||
1103 | } | ||
1104 | swayc_t *view = get_focused_container(&root_container); | ||
1105 | int i; | ||
1106 | for (i = 0; i < scratchpad->length; i++) { | ||
1107 | if (scratchpad->items[i] == view) { | ||
1108 | hide_view_in_scratchpad(view); | ||
1109 | sp_view = NULL; | ||
1110 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1111 | } | ||
1112 | } | ||
1113 | list_add(scratchpad, view); | ||
1114 | if (!view->is_floating) { | ||
1115 | destroy_container(remove_child(view)); | ||
1116 | } else { | ||
1117 | remove_child(view); | ||
1118 | } | ||
1119 | wlc_view_set_mask(view->handle, 0); | ||
1120 | arrange_windows(swayc_active_workspace(), -1, -1); | ||
1121 | swayc_t *focused = container_under_pointer(); | ||
1122 | if (focused == NULL) { | ||
1123 | focused = swayc_active_workspace(); | ||
1124 | } | ||
1125 | set_focused_container(focused); | ||
1126 | } else if (strcasecmp(argv[0], "position") == 0) { | ||
1127 | if ((error = checkarg(argc, "move workspace", EXPECTED_EQUAL_TO, 2))) { | ||
1128 | return error; | ||
1129 | } | ||
1130 | if (strcasecmp(argv[1], "mouse")) { | ||
1131 | return cmd_results_new(CMD_INVALID, "move", expected_syntax); | ||
1132 | } | ||
1133 | |||
1134 | if (view->is_floating) { | ||
1135 | swayc_t *output = swayc_parent_by_type(view, C_OUTPUT); | ||
1136 | struct wlc_geometry g; | ||
1137 | wlc_view_get_visible_geometry(view->handle, &g); | ||
1138 | const struct wlc_size *size = wlc_output_get_resolution(output->handle); | ||
1139 | |||
1140 | struct wlc_point origin; | ||
1141 | wlc_pointer_get_position(&origin); | ||
1142 | |||
1143 | int32_t x = origin.x - g.size.w / 2; | ||
1144 | int32_t y = origin.y - g.size.h / 2; | ||
1145 | |||
1146 | uint32_t w = size->w - g.size.w; | ||
1147 | uint32_t h = size->h - g.size.h; | ||
1148 | |||
1149 | view->x = g.origin.x = MIN((int32_t)w, MAX(x, 0)); | ||
1150 | view->y = g.origin.y = MIN((int32_t)h, MAX(y, 0)); | ||
1151 | |||
1152 | wlc_view_set_geometry(view->handle, 0, &g); | ||
1153 | } | ||
1154 | } else { | ||
1155 | return cmd_results_new(CMD_INVALID, "move", expected_syntax); | ||
1156 | } | ||
1157 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1158 | } | ||
1159 | |||
1160 | static struct cmd_results *cmd_new_float(int argc, char **argv) { | ||
1161 | struct cmd_results *error = NULL; | ||
1162 | if ((error = checkarg(argc, "new_float", EXPECTED_AT_LEAST, 1))) { | ||
1163 | return error; | ||
1164 | } | ||
1165 | |||
1166 | if (argc > 2) { | ||
1167 | return cmd_results_new(CMD_INVALID, "new_float", | ||
1168 | "Expected 'new_float <normal|none|pixel> [<n>]"); | ||
1169 | } | ||
1170 | |||
1171 | enum swayc_border_types border = config->floating_border; | ||
1172 | int thickness = config->floating_border_thickness; | ||
1173 | |||
1174 | if (strcasecmp(argv[0], "none") == 0) { | ||
1175 | border = B_NONE; | ||
1176 | } else if (strcasecmp(argv[0], "normal") == 0) { | ||
1177 | border = B_NORMAL; | ||
1178 | } else if (strcasecmp(argv[0], "pixel") == 0) { | ||
1179 | border = B_PIXEL; | ||
1180 | } else { | ||
1181 | return cmd_results_new(CMD_INVALID, "new_float", | ||
1182 | "Expected 'border <normal|none|pixel>"); | ||
1183 | } | ||
1184 | |||
1185 | if (argc == 2 && (border == B_NORMAL || border == B_PIXEL)) { | ||
1186 | thickness = (int)strtol(argv[1], NULL, 10); | ||
1187 | if (errno == ERANGE || thickness < 0) { | ||
1188 | errno = 0; | ||
1189 | return cmd_results_new(CMD_INVALID, "new_float", "Number is out out of range."); | ||
1190 | } | ||
1191 | } | ||
1192 | |||
1193 | config->floating_border = border; | ||
1194 | config->floating_border_thickness = thickness; | ||
1195 | |||
1196 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1197 | } | ||
1198 | |||
1199 | static struct cmd_results *cmd_new_window(int argc, char **argv) { | ||
1200 | struct cmd_results *error = NULL; | ||
1201 | if ((error = checkarg(argc, "new_window", EXPECTED_AT_LEAST, 1))) { | ||
1202 | return error; | ||
1203 | } | ||
1204 | |||
1205 | if (argc > 2) { | ||
1206 | return cmd_results_new(CMD_INVALID, "new_window", | ||
1207 | "Expected 'new_window <normal|none|pixel> [<n>]"); | ||
1208 | } | ||
1209 | |||
1210 | enum swayc_border_types border = config->border; | ||
1211 | int thickness = config->border_thickness; | ||
1212 | |||
1213 | if (strcasecmp(argv[0], "none") == 0) { | ||
1214 | border = B_NONE; | ||
1215 | } else if (strcasecmp(argv[0], "normal") == 0) { | ||
1216 | border = B_NORMAL; | ||
1217 | } else if (strcasecmp(argv[0], "pixel") == 0) { | ||
1218 | border = B_PIXEL; | ||
1219 | } else { | ||
1220 | return cmd_results_new(CMD_INVALID, "new_window", | ||
1221 | "Expected 'border <normal|none|pixel>"); | ||
1222 | } | ||
1223 | |||
1224 | if (argc == 2 && (border == B_NORMAL || border == B_PIXEL)) { | ||
1225 | thickness = (int)strtol(argv[1], NULL, 10); | ||
1226 | if (errno == ERANGE || thickness < 0) { | ||
1227 | errno = 0; | ||
1228 | return cmd_results_new(CMD_INVALID, "new_window", "Number is out out of range."); | ||
1229 | } | ||
1230 | } | ||
1231 | |||
1232 | config->border = border; | ||
1233 | config->border_thickness = thickness; | ||
1234 | |||
1235 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1236 | } | ||
1237 | |||
1238 | static struct cmd_results *cmd_orientation(int argc, char **argv) { | ||
1239 | struct cmd_results *error = NULL; | ||
1240 | if (!config->reading) return cmd_results_new(CMD_FAILURE, "orientation", "Can only be used in config file."); | ||
1241 | if ((error = checkarg(argc, "orientation", EXPECTED_EQUAL_TO, 1))) { | ||
1242 | return error; | ||
1243 | } | ||
1244 | if (strcasecmp(argv[0], "horizontal") == 0) { | ||
1245 | config->default_orientation = L_HORIZ; | ||
1246 | } else if (strcasecmp(argv[0], "vertical") == 0) { | ||
1247 | config->default_orientation = L_VERT; | ||
1248 | } else if (strcasecmp(argv[0], "auto") == 0) { | ||
1249 | // Do nothing | ||
1250 | } else { | ||
1251 | return cmd_results_new(CMD_INVALID, "orientation", "Expected 'orientation <horizontal|vertical|auto>'"); | ||
1252 | } | ||
1253 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1254 | } | ||
1255 | |||
1256 | static void input_cmd_apply(struct input_config *input) { | ||
1257 | int i; | 102 | int i; |
1258 | i = list_seq_find(config->input_configs, input_identifier_cmp, input->identifier); | 103 | i = list_seq_find(config->input_configs, input_identifier_cmp, input->identifier); |
1259 | if (i >= 0) { | 104 | if (i >= 0) { |
@@ -1286,935 +131,6 @@ static void input_cmd_apply(struct input_config *input) { | |||
1286 | } | 131 | } |
1287 | } | 132 | } |
1288 | 133 | ||
1289 | static struct cmd_results *input_cmd_accel_profile(int argc, char **argv) { | ||
1290 | struct cmd_results *error = NULL; | ||
1291 | if ((error = checkarg(argc, "accel_profile", EXPECTED_AT_LEAST, 1))) { | ||
1292 | return error; | ||
1293 | } | ||
1294 | if (!current_input_config) { | ||
1295 | return cmd_results_new(CMD_FAILURE, "accel_profile", "No input device defined."); | ||
1296 | } | ||
1297 | struct input_config *new_config = new_input_config(current_input_config->identifier); | ||
1298 | |||
1299 | if (strcasecmp(argv[0], "adaptive") == 0) { | ||
1300 | new_config->accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE; | ||
1301 | } else if (strcasecmp(argv[0], "flat") == 0) { | ||
1302 | new_config->accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT; | ||
1303 | } else { | ||
1304 | return cmd_results_new(CMD_INVALID, "accel_profile", | ||
1305 | "Expected 'accel_profile <adaptive|flat>'"); | ||
1306 | } | ||
1307 | |||
1308 | input_cmd_apply(new_config); | ||
1309 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1310 | } | ||
1311 | |||
1312 | static struct cmd_results *input_cmd_click_method(int argc, char **argv) { | ||
1313 | sway_log(L_DEBUG, "click_method for device: %d %s", current_input_config==NULL, current_input_config->identifier); | ||
1314 | struct cmd_results *error = NULL; | ||
1315 | if ((error = checkarg(argc, "click_method", EXPECTED_AT_LEAST, 1))) { | ||
1316 | return error; | ||
1317 | } | ||
1318 | if (!current_input_config) { | ||
1319 | return cmd_results_new(CMD_FAILURE, "click_method", "No input device defined."); | ||
1320 | } | ||
1321 | struct input_config *new_config = new_input_config(current_input_config->identifier); | ||
1322 | |||
1323 | if (strcasecmp(argv[0], "none") == 0) { | ||
1324 | new_config->click_method = LIBINPUT_CONFIG_CLICK_METHOD_NONE; | ||
1325 | } else if (strcasecmp(argv[0], "button_areas") == 0) { | ||
1326 | new_config->click_method = LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS; | ||
1327 | } else if (strcasecmp(argv[0], "clickfinger") == 0) { | ||
1328 | new_config->click_method = LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER; | ||
1329 | } else { | ||
1330 | return cmd_results_new(CMD_INVALID, "click_method", "Expected 'click_method <none|button_areas|clickfinger'"); | ||
1331 | } | ||
1332 | |||
1333 | input_cmd_apply(new_config); | ||
1334 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1335 | } | ||
1336 | |||
1337 | static struct cmd_results *input_cmd_drag_lock(int argc, char **argv) { | ||
1338 | struct cmd_results *error = NULL; | ||
1339 | if ((error = checkarg(argc, "drag_lock", EXPECTED_AT_LEAST, 1))) { | ||
1340 | return error; | ||
1341 | } | ||
1342 | if (!current_input_config) { | ||
1343 | return cmd_results_new(CMD_FAILURE, "drag_lock", "No input device defined."); | ||
1344 | } | ||
1345 | struct input_config *new_config = new_input_config(current_input_config->identifier); | ||
1346 | |||
1347 | if (strcasecmp(argv[0], "enabled") == 0) { | ||
1348 | new_config->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_ENABLED; | ||
1349 | } else if (strcasecmp(argv[0], "disabled") == 0) { | ||
1350 | new_config->drag_lock = LIBINPUT_CONFIG_DRAG_LOCK_DISABLED; | ||
1351 | } else { | ||
1352 | return cmd_results_new(CMD_INVALID, "drag_lock", "Expected 'drag_lock <enabled|disabled>'"); | ||
1353 | } | ||
1354 | |||
1355 | input_cmd_apply(new_config); | ||
1356 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1357 | } | ||
1358 | |||
1359 | static struct cmd_results *input_cmd_dwt(int argc, char **argv) { | ||
1360 | struct cmd_results *error = NULL; | ||
1361 | if ((error = checkarg(argc, "dwt", EXPECTED_AT_LEAST, 1))) { | ||
1362 | return error; | ||
1363 | } | ||
1364 | if (!current_input_config) { | ||
1365 | return cmd_results_new(CMD_FAILURE, "dwt", "No input device defined."); | ||
1366 | } | ||
1367 | struct input_config *new_config = new_input_config(current_input_config->identifier); | ||
1368 | |||
1369 | if (strcasecmp(argv[0], "enabled") == 0) { | ||
1370 | new_config->dwt = LIBINPUT_CONFIG_DWT_ENABLED; | ||
1371 | } else if (strcasecmp(argv[0], "disabled") == 0) { | ||
1372 | new_config->dwt = LIBINPUT_CONFIG_DWT_DISABLED; | ||
1373 | } else { | ||
1374 | return cmd_results_new(CMD_INVALID, "dwt", "Expected 'dwt <enabled|disabled>'"); | ||
1375 | } | ||
1376 | |||
1377 | input_cmd_apply(new_config); | ||
1378 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1379 | } | ||
1380 | |||
1381 | static struct cmd_results *input_cmd_events(int argc, char **argv) { | ||
1382 | sway_log(L_DEBUG, "events for device: %s", current_input_config->identifier); | ||
1383 | struct cmd_results *error = NULL; | ||
1384 | if ((error = checkarg(argc, "events", EXPECTED_AT_LEAST, 1))) { | ||
1385 | return error; | ||
1386 | } | ||
1387 | if (!current_input_config) { | ||
1388 | return cmd_results_new(CMD_FAILURE, "events", "No input device defined."); | ||
1389 | } | ||
1390 | struct input_config *new_config = new_input_config(current_input_config->identifier); | ||
1391 | |||
1392 | if (strcasecmp(argv[0], "enabled") == 0) { | ||
1393 | new_config->send_events = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED; | ||
1394 | } else if (strcasecmp(argv[0], "disabled") == 0) { | ||
1395 | new_config->send_events = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED; | ||
1396 | } else if (strcasecmp(argv[0], "disabled_on_external_mouse") == 0) { | ||
1397 | new_config->send_events = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE; | ||
1398 | } else { | ||
1399 | return cmd_results_new(CMD_INVALID, "events", "Expected 'events <enabled|disabled|disabled_on_external_mouse>'"); | ||
1400 | } | ||
1401 | |||
1402 | input_cmd_apply(new_config); | ||
1403 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1404 | } | ||
1405 | |||
1406 | static struct cmd_results *input_cmd_middle_emulation(int argc, char **argv) { | ||
1407 | struct cmd_results *error = NULL; | ||
1408 | if ((error = checkarg(argc, "middle_emulation", EXPECTED_AT_LEAST, 1))) { | ||
1409 | return error; | ||
1410 | } | ||
1411 | if (!current_input_config) { | ||
1412 | return cmd_results_new(CMD_FAILURE, "middle_emulation", "No input device defined."); | ||
1413 | } | ||
1414 | struct input_config *new_config = new_input_config(current_input_config->identifier); | ||
1415 | |||
1416 | if (strcasecmp(argv[0], "enabled") == 0) { | ||
1417 | new_config->middle_emulation = LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED; | ||
1418 | } else if (strcasecmp(argv[0], "disabled") == 0) { | ||
1419 | new_config->middle_emulation = LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED; | ||
1420 | } else { | ||
1421 | return cmd_results_new(CMD_INVALID, "middle_emulation", "Expected 'middle_emulation <enabled|disabled>'"); | ||
1422 | } | ||
1423 | |||
1424 | input_cmd_apply(new_config); | ||
1425 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1426 | } | ||
1427 | |||
1428 | static struct cmd_results *input_cmd_natural_scroll(int argc, char **argv) { | ||
1429 | struct cmd_results *error = NULL; | ||
1430 | if ((error = checkarg(argc, "natural_scroll", EXPECTED_AT_LEAST, 1))) { | ||
1431 | return error; | ||
1432 | } | ||
1433 | if (!current_input_config) { | ||
1434 | return cmd_results_new(CMD_FAILURE, "natural_scoll", "No input device defined."); | ||
1435 | } | ||
1436 | struct input_config *new_config = new_input_config(current_input_config->identifier); | ||
1437 | |||
1438 | if (strcasecmp(argv[0], "enabled") == 0) { | ||
1439 | new_config->natural_scroll = 1; | ||
1440 | } else if (strcasecmp(argv[0], "disabled") == 0) { | ||
1441 | new_config->natural_scroll = 0; | ||
1442 | } else { | ||
1443 | return cmd_results_new(CMD_INVALID, "natural_scroll", "Expected 'natural_scroll <enabled|disabled>'"); | ||
1444 | } | ||
1445 | |||
1446 | input_cmd_apply(new_config); | ||
1447 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1448 | } | ||
1449 | |||
1450 | static struct cmd_results *input_cmd_pointer_accel(int argc, char **argv) { | ||
1451 | struct cmd_results *error = NULL; | ||
1452 | if ((error = checkarg(argc, "pointer_accel", EXPECTED_AT_LEAST, 1))) { | ||
1453 | return error; | ||
1454 | } | ||
1455 | if (!current_input_config) { | ||
1456 | return cmd_results_new(CMD_FAILURE, "pointer_accel", "No input device defined."); | ||
1457 | } | ||
1458 | struct input_config *new_config = new_input_config(current_input_config->identifier); | ||
1459 | |||
1460 | float pointer_accel = atof(argv[0]); | ||
1461 | if (pointer_accel < -1 || pointer_accel > 1) { | ||
1462 | return cmd_results_new(CMD_INVALID, "pointer_accel", "Input out of range [-1, 1]"); | ||
1463 | } | ||
1464 | new_config->pointer_accel = pointer_accel; | ||
1465 | |||
1466 | input_cmd_apply(new_config); | ||
1467 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1468 | } | ||
1469 | |||
1470 | static struct cmd_results *input_cmd_scroll_method(int argc, char **argv) { | ||
1471 | struct cmd_results *error = NULL; | ||
1472 | if ((error = checkarg(argc, "scroll_method", EXPECTED_AT_LEAST, 1))) { | ||
1473 | return error; | ||
1474 | } | ||
1475 | if (!current_input_config) { | ||
1476 | return cmd_results_new(CMD_FAILURE, "scroll_method", "No input device defined."); | ||
1477 | } | ||
1478 | struct input_config *new_config = new_input_config(current_input_config->identifier); | ||
1479 | |||
1480 | if (strcasecmp(argv[0], "none") == 0) { | ||
1481 | new_config->scroll_method = LIBINPUT_CONFIG_SCROLL_NO_SCROLL; | ||
1482 | } else if (strcasecmp(argv[0], "two_finger") == 0) { | ||
1483 | new_config->scroll_method = LIBINPUT_CONFIG_SCROLL_2FG; | ||
1484 | } else if (strcasecmp(argv[0], "edge") == 0) { | ||
1485 | new_config->scroll_method = LIBINPUT_CONFIG_SCROLL_EDGE; | ||
1486 | } else if (strcasecmp(argv[0], "on_button_down") == 0) { | ||
1487 | new_config->scroll_method = LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN; | ||
1488 | } else { | ||
1489 | return cmd_results_new(CMD_INVALID, "scroll_method", "Expected 'scroll_method <none|two_finger|edge|on_button_down>'"); | ||
1490 | } | ||
1491 | |||
1492 | input_cmd_apply(new_config); | ||
1493 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1494 | } | ||
1495 | |||
1496 | static struct cmd_results *input_cmd_tap(int argc, char **argv) { | ||
1497 | sway_log(L_DEBUG, "tap for device: %s", current_input_config->identifier); | ||
1498 | struct cmd_results *error = NULL; | ||
1499 | if ((error = checkarg(argc, "tap", EXPECTED_AT_LEAST, 1))) { | ||
1500 | return error; | ||
1501 | } | ||
1502 | if (!current_input_config) { | ||
1503 | return cmd_results_new(CMD_FAILURE, "tap", "No input device defined."); | ||
1504 | } | ||
1505 | struct input_config *new_config = new_input_config(current_input_config->identifier); | ||
1506 | |||
1507 | if (strcasecmp(argv[0], "enabled") == 0) { | ||
1508 | new_config->tap = LIBINPUT_CONFIG_TAP_ENABLED; | ||
1509 | } else if (strcasecmp(argv[0], "disabled") == 0) { | ||
1510 | new_config->tap = LIBINPUT_CONFIG_TAP_DISABLED; | ||
1511 | } else { | ||
1512 | return cmd_results_new(CMD_INVALID, "tap", "Expected 'tap <enabled|disabled>'"); | ||
1513 | } | ||
1514 | |||
1515 | sway_log(L_DEBUG, "apply-tap for device: %s", current_input_config->identifier); | ||
1516 | input_cmd_apply(new_config); | ||
1517 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1518 | } | ||
1519 | |||
1520 | static struct cmd_results *cmd_include(int argc, char **argv) { | ||
1521 | struct cmd_results *error = NULL; | ||
1522 | if ((error = checkarg(argc, "include", EXPECTED_EQUAL_TO, 1))) { | ||
1523 | return error; | ||
1524 | } | ||
1525 | |||
1526 | if (!load_include_configs(argv[0], config)) { | ||
1527 | return cmd_results_new(CMD_INVALID, "include", "Failed to include sub configuration file: %s", argv[0]); | ||
1528 | } | ||
1529 | |||
1530 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1531 | } | ||
1532 | |||
1533 | static struct cmd_results *cmd_input(int argc, char **argv) { | ||
1534 | struct cmd_results *error = NULL; | ||
1535 | if ((error = checkarg(argc, "input", EXPECTED_AT_LEAST, 2))) { | ||
1536 | return error; | ||
1537 | } | ||
1538 | |||
1539 | if (config->reading && strcmp("{", argv[1]) == 0) { | ||
1540 | current_input_config = new_input_config(argv[0]); | ||
1541 | sway_log(L_DEBUG, "entering input block: %s", current_input_config->identifier); | ||
1542 | return cmd_results_new(CMD_BLOCK_INPUT, NULL, NULL); | ||
1543 | } | ||
1544 | |||
1545 | if (argc > 2) { | ||
1546 | int argc_new = argc-2; | ||
1547 | char **argv_new = argv+2; | ||
1548 | |||
1549 | struct cmd_results *res; | ||
1550 | current_input_config = new_input_config(argv[0]); | ||
1551 | if (strcasecmp("accel_profile", argv[1]) == 0) { | ||
1552 | res = input_cmd_accel_profile(argc_new, argv_new); | ||
1553 | } else if (strcasecmp("click_method", argv[1]) == 0) { | ||
1554 | res = input_cmd_click_method(argc_new, argv_new); | ||
1555 | } else if (strcasecmp("drag_lock", argv[1]) == 0) { | ||
1556 | res = input_cmd_drag_lock(argc_new, argv_new); | ||
1557 | } else if (strcasecmp("dwt", argv[1]) == 0) { | ||
1558 | res = input_cmd_dwt(argc_new, argv_new); | ||
1559 | } else if (strcasecmp("events", argv[1]) == 0) { | ||
1560 | res = input_cmd_events(argc_new, argv_new); | ||
1561 | } else if (strcasecmp("middle_emulation", argv[1]) == 0) { | ||
1562 | res = input_cmd_middle_emulation(argc_new, argv_new); | ||
1563 | } else if (strcasecmp("natural_scroll", argv[1]) == 0) { | ||
1564 | res = input_cmd_natural_scroll(argc_new, argv_new); | ||
1565 | } else if (strcasecmp("pointer_accel", argv[1]) == 0) { | ||
1566 | res = input_cmd_pointer_accel(argc_new, argv_new); | ||
1567 | } else if (strcasecmp("scroll_method", argv[1]) == 0) { | ||
1568 | res = input_cmd_scroll_method(argc_new, argv_new); | ||
1569 | } else if (strcasecmp("tap", argv[1]) == 0) { | ||
1570 | res = input_cmd_tap(argc_new, argv_new); | ||
1571 | } else { | ||
1572 | res = cmd_results_new(CMD_INVALID, "input <device>", "Unknown command %s", argv[1]); | ||
1573 | } | ||
1574 | current_input_config = NULL; | ||
1575 | return res; | ||
1576 | } | ||
1577 | |||
1578 | return cmd_results_new(CMD_BLOCK_INPUT, NULL, NULL); | ||
1579 | } | ||
1580 | |||
1581 | static struct cmd_results *cmd_output(int argc, char **argv) { | ||
1582 | struct cmd_results *error = NULL; | ||
1583 | if ((error = checkarg(argc, "output", EXPECTED_AT_LEAST, 1))) { | ||
1584 | return error; | ||
1585 | } | ||
1586 | const char *name = argv[0]; | ||
1587 | |||
1588 | struct output_config *output = calloc(1, sizeof(struct output_config)); | ||
1589 | output->x = output->y = output->width = output->height = -1; | ||
1590 | output->name = strdup(name); | ||
1591 | output->enabled = -1; | ||
1592 | output->scale = 1; | ||
1593 | |||
1594 | // TODO: atoi doesn't handle invalid numbers | ||
1595 | |||
1596 | int i; | ||
1597 | for (i = 1; i < argc; ++i) { | ||
1598 | const char *command = argv[i]; | ||
1599 | |||
1600 | if (strcasecmp(command, "disable") == 0) { | ||
1601 | output->enabled = 0; | ||
1602 | } else if (strcasecmp(command, "resolution") == 0 || strcasecmp(command, "res") == 0) { | ||
1603 | if (++i >= argc) { | ||
1604 | return cmd_results_new(CMD_INVALID, "output", "Missing resolution argument."); | ||
1605 | } | ||
1606 | char *res = argv[i]; | ||
1607 | char *x = strchr(res, 'x'); | ||
1608 | int width = -1, height = -1; | ||
1609 | if (x != NULL) { | ||
1610 | // Format is 1234x4321 | ||
1611 | *x = '\0'; | ||
1612 | width = atoi(res); | ||
1613 | height = atoi(x + 1); | ||
1614 | *x = 'x'; | ||
1615 | } else { | ||
1616 | // Format is 1234 4321 | ||
1617 | width = atoi(res); | ||
1618 | if (++i >= argc) { | ||
1619 | return cmd_results_new(CMD_INVALID, "output", "Missing resolution argument (height)."); | ||
1620 | } | ||
1621 | res = argv[i]; | ||
1622 | height = atoi(res); | ||
1623 | } | ||
1624 | output->width = width; | ||
1625 | output->height = height; | ||
1626 | } else if (strcasecmp(command, "position") == 0 || strcasecmp(command, "pos") == 0) { | ||
1627 | if (++i >= argc) { | ||
1628 | return cmd_results_new(CMD_INVALID, "output", "Missing position argument."); | ||
1629 | } | ||
1630 | char *res = argv[i]; | ||
1631 | char *c = strchr(res, ','); | ||
1632 | int x = -1, y = -1; | ||
1633 | if (c != NULL) { | ||
1634 | // Format is 1234,4321 | ||
1635 | *c = '\0'; | ||
1636 | x = atoi(res); | ||
1637 | y = atoi(c + 1); | ||
1638 | *c = ','; | ||
1639 | } else { | ||
1640 | // Format is 1234 4321 | ||
1641 | x = atoi(res); | ||
1642 | if (++i >= argc) { | ||
1643 | return cmd_results_new(CMD_INVALID, "output", "Missing position argument (y)."); | ||
1644 | } | ||
1645 | res = argv[i]; | ||
1646 | y = atoi(res); | ||
1647 | } | ||
1648 | output->x = x; | ||
1649 | output->y = y; | ||
1650 | } else if (strcasecmp(command, "scale") == 0) { | ||
1651 | if (++i >= argc) { | ||
1652 | return cmd_results_new(CMD_INVALID, "output", "Missing scale parameter."); | ||
1653 | } | ||
1654 | output->scale = atoi(argv[i]); | ||
1655 | } else if (strcasecmp(command, "background") == 0 || strcasecmp(command, "bg") == 0) { | ||
1656 | wordexp_t p; | ||
1657 | if (++i >= argc) { | ||
1658 | return cmd_results_new(CMD_INVALID, "output", "Missing background file or color specification."); | ||
1659 | } | ||
1660 | if (i + 1 >= argc) { | ||
1661 | return cmd_results_new(CMD_INVALID, "output", "Missing background scaling mode or `solid_color`."); | ||
1662 | } | ||
1663 | if (strcasecmp(argv[argc - 1], "solid_color") == 0) { | ||
1664 | output->background = strdup(argv[argc - 2]); | ||
1665 | output->background_option = strdup("solid_color"); | ||
1666 | } else { | ||
1667 | char *src = join_args(argv + i, argc - i - 1); | ||
1668 | char *mode = argv[argc - 1]; | ||
1669 | if (wordexp(src, &p, 0) != 0 || p.we_wordv[0] == NULL) { | ||
1670 | return cmd_results_new(CMD_INVALID, "output", "Invalid syntax (%s)", src); | ||
1671 | } | ||
1672 | free(src); | ||
1673 | src = p.we_wordv[0]; | ||
1674 | if (config->reading && *src != '/') { | ||
1675 | char *conf = strdup(config->current_config); | ||
1676 | char *conf_path = dirname(conf); | ||
1677 | src = malloc(strlen(conf_path) + strlen(src) + 2); | ||
1678 | sprintf(src, "%s/%s", conf_path, p.we_wordv[0]); | ||
1679 | free(conf); | ||
1680 | } | ||
1681 | if (access(src, F_OK) == -1) { | ||
1682 | return cmd_results_new(CMD_INVALID, "output", "Background file unreadable (%s)", src); | ||
1683 | } | ||
1684 | for (char *m = mode; *m; ++m) *m = tolower(*m); | ||
1685 | // Check mode | ||
1686 | bool valid = false; | ||
1687 | size_t j; | ||
1688 | for (j = 0; j < sizeof(bg_options) / sizeof(char *); ++j) { | ||
1689 | if (strcasecmp(mode, bg_options[j]) == 0) { | ||
1690 | valid = true; | ||
1691 | break; | ||
1692 | } | ||
1693 | } | ||
1694 | if (!valid) { | ||
1695 | return cmd_results_new(CMD_INVALID, "output", "Invalid background scaling mode."); | ||
1696 | } | ||
1697 | output->background = strdup(src); | ||
1698 | output->background_option = strdup(mode); | ||
1699 | if (src != p.we_wordv[0]) { | ||
1700 | free(src); | ||
1701 | } | ||
1702 | wordfree(&p); | ||
1703 | } | ||
1704 | } | ||
1705 | } | ||
1706 | |||
1707 | i = list_seq_find(config->output_configs, output_name_cmp, name); | ||
1708 | if (i >= 0) { | ||
1709 | // merge existing config | ||
1710 | struct output_config *oc = config->output_configs->items[i]; | ||
1711 | merge_output_config(oc, output); | ||
1712 | free_output_config(output); | ||
1713 | output = oc; | ||
1714 | } else { | ||
1715 | list_add(config->output_configs, output); | ||
1716 | } | ||
1717 | |||
1718 | sway_log(L_DEBUG, "Config stored for output %s (enabled:%d) (%d x %d @ %d, %d scale %d) (bg %s %s)", | ||
1719 | output->name, output->enabled, output->width, | ||
1720 | output->height, output->x, output->y, output->scale, | ||
1721 | output->background, output->background_option); | ||
1722 | |||
1723 | if (output->name) { | ||
1724 | // Try to find the output container and apply configuration now. If | ||
1725 | // this is during startup then there will be no container and config | ||
1726 | // will be applied during normal "new output" event from wlc. | ||
1727 | swayc_t *cont = NULL; | ||
1728 | for (int i = 0; i < root_container.children->length; ++i) { | ||
1729 | cont = root_container.children->items[i]; | ||
1730 | if (cont->name && ((strcmp(cont->name, output->name) == 0) || (strcmp(output->name, "*") == 0))) { | ||
1731 | apply_output_config(output, cont); | ||
1732 | |||
1733 | if (strcmp(output->name, "*") != 0) { | ||
1734 | // stop looking if the output config isn't applicable to all outputs | ||
1735 | break; | ||
1736 | } | ||
1737 | } | ||
1738 | } | ||
1739 | } | ||
1740 | |||
1741 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1742 | } | ||
1743 | |||
1744 | static struct cmd_results *cmd_gaps(int argc, char **argv) { | ||
1745 | struct cmd_results *error = NULL; | ||
1746 | if ((error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1))) { | ||
1747 | return error; | ||
1748 | } | ||
1749 | const char* expected_syntax = | ||
1750 | "Expected 'gaps edge_gaps <on|off|toggle>' or " | ||
1751 | "'gaps <inner|outer> <current|all|workspace> <set|plus|minus n>'"; | ||
1752 | const char *amount_str = argv[0]; | ||
1753 | // gaps amount | ||
1754 | if (argc >= 1 && isdigit(*amount_str)) { | ||
1755 | int amount = (int)strtol(amount_str, NULL, 10); | ||
1756 | if (errno == ERANGE) { | ||
1757 | errno = 0; | ||
1758 | return cmd_results_new(CMD_INVALID, "gaps", "Number is out out of range."); | ||
1759 | } | ||
1760 | config->gaps_inner = config->gaps_outer = amount; | ||
1761 | arrange_windows(&root_container, -1, -1); | ||
1762 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1763 | } | ||
1764 | // gaps inner|outer n | ||
1765 | else if (argc >= 2 && isdigit((amount_str = argv[1])[0])) { | ||
1766 | int amount = (int)strtol(amount_str, NULL, 10); | ||
1767 | if (errno == ERANGE) { | ||
1768 | errno = 0; | ||
1769 | return cmd_results_new(CMD_INVALID, "gaps", "Number is out out of range."); | ||
1770 | } | ||
1771 | const char *target_str = argv[0]; | ||
1772 | if (strcasecmp(target_str, "inner") == 0) { | ||
1773 | config->gaps_inner = amount; | ||
1774 | } else if (strcasecmp(target_str, "outer") == 0) { | ||
1775 | config->gaps_outer = amount; | ||
1776 | } | ||
1777 | arrange_windows(&root_container, -1, -1); | ||
1778 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1779 | } else if (argc == 2 && strcasecmp(argv[0], "edge_gaps") == 0) { | ||
1780 | // gaps edge_gaps <on|off|toggle> | ||
1781 | if (strcasecmp(argv[1], "toggle") == 0) { | ||
1782 | if (config->reading) { | ||
1783 | return cmd_results_new(CMD_FAILURE, "gaps edge_gaps toggle", | ||
1784 | "Can't be used in config file."); | ||
1785 | } | ||
1786 | config->edge_gaps = !config->edge_gaps; | ||
1787 | } else { | ||
1788 | config->edge_gaps = | ||
1789 | (strcasecmp(argv[1], "yes") == 0 || strcasecmp(argv[1], "on") == 0); | ||
1790 | } | ||
1791 | arrange_windows(&root_container, -1, -1); | ||
1792 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1793 | } | ||
1794 | // gaps inner|outer current|all set|plus|minus n | ||
1795 | if (argc < 4 || config->reading) { | ||
1796 | return cmd_results_new(CMD_INVALID, "gaps", expected_syntax); | ||
1797 | } | ||
1798 | // gaps inner|outer ... | ||
1799 | const char *inout_str = argv[0]; | ||
1800 | enum {INNER, OUTER} inout; | ||
1801 | if (strcasecmp(inout_str, "inner") == 0) { | ||
1802 | inout = INNER; | ||
1803 | } else if (strcasecmp(inout_str, "outer") == 0) { | ||
1804 | inout = OUTER; | ||
1805 | } else { | ||
1806 | return cmd_results_new(CMD_INVALID, "gaps", expected_syntax); | ||
1807 | } | ||
1808 | |||
1809 | // gaps ... current|all ... | ||
1810 | const char *target_str = argv[1]; | ||
1811 | enum {CURRENT, WORKSPACE, ALL} target; | ||
1812 | if (strcasecmp(target_str, "current") == 0) { | ||
1813 | target = CURRENT; | ||
1814 | } else if (strcasecmp(target_str, "all") == 0) { | ||
1815 | target = ALL; | ||
1816 | } else if (strcasecmp(target_str, "workspace") == 0) { | ||
1817 | if (inout == OUTER) { | ||
1818 | target = CURRENT; | ||
1819 | } else { | ||
1820 | // Set gap for views in workspace | ||
1821 | target = WORKSPACE; | ||
1822 | } | ||
1823 | } else { | ||
1824 | return cmd_results_new(CMD_INVALID, "gaps", expected_syntax); | ||
1825 | } | ||
1826 | |||
1827 | // gaps ... n | ||
1828 | amount_str = argv[3]; | ||
1829 | int amount = (int)strtol(amount_str, NULL, 10); | ||
1830 | if (errno == ERANGE) { | ||
1831 | errno = 0; | ||
1832 | return cmd_results_new(CMD_INVALID, "gaps", "Number is out out of range."); | ||
1833 | } | ||
1834 | |||
1835 | // gaps ... set|plus|minus ... | ||
1836 | const char *method_str = argv[2]; | ||
1837 | enum {SET, ADD} method; | ||
1838 | if (strcasecmp(method_str, "set") == 0) { | ||
1839 | method = SET; | ||
1840 | } else if (strcasecmp(method_str, "plus") == 0) { | ||
1841 | method = ADD; | ||
1842 | } else if (strcasecmp(method_str, "minus") == 0) { | ||
1843 | method = ADD; | ||
1844 | amount *= -1; | ||
1845 | } else { | ||
1846 | return cmd_results_new(CMD_INVALID, "gaps", expected_syntax); | ||
1847 | } | ||
1848 | |||
1849 | if (target == CURRENT) { | ||
1850 | swayc_t *cont; | ||
1851 | if (inout == OUTER) { | ||
1852 | if ((cont = swayc_active_workspace()) == NULL) { | ||
1853 | return cmd_results_new(CMD_FAILURE, "gaps", "There's no active workspace."); | ||
1854 | } | ||
1855 | } else { | ||
1856 | if ((cont = get_focused_view(&root_container))->type != C_VIEW) { | ||
1857 | return cmd_results_new(CMD_FAILURE, "gaps", "Currently focused item is not a view."); | ||
1858 | } | ||
1859 | } | ||
1860 | cont->gaps = swayc_gap(cont); | ||
1861 | if (method == SET) { | ||
1862 | cont->gaps = amount; | ||
1863 | } else if ((cont->gaps += amount) < 0) { | ||
1864 | cont->gaps = 0; | ||
1865 | } | ||
1866 | arrange_windows(cont->parent, -1, -1); | ||
1867 | } else if (inout == OUTER) { | ||
1868 | //resize all workspace. | ||
1869 | int i,j; | ||
1870 | for (i = 0; i < root_container.children->length; ++i) { | ||
1871 | swayc_t *op = root_container.children->items[i]; | ||
1872 | for (j = 0; j < op->children->length; ++j) { | ||
1873 | swayc_t *ws = op->children->items[j]; | ||
1874 | if (method == SET) { | ||
1875 | ws->gaps = amount; | ||
1876 | } else if ((ws->gaps += amount) < 0) { | ||
1877 | ws->gaps = 0; | ||
1878 | } | ||
1879 | } | ||
1880 | } | ||
1881 | arrange_windows(&root_container, -1, -1); | ||
1882 | } else { | ||
1883 | // Resize gaps for all views in workspace | ||
1884 | swayc_t *top; | ||
1885 | if (target == WORKSPACE) { | ||
1886 | if ((top = swayc_active_workspace()) == NULL) { | ||
1887 | return cmd_results_new(CMD_FAILURE, "gaps", "There's currently no active workspace."); | ||
1888 | } | ||
1889 | } else { | ||
1890 | top = &root_container; | ||
1891 | } | ||
1892 | int top_gap = top->gaps; | ||
1893 | container_map(top, method == SET ? set_gaps : add_gaps, &amount); | ||
1894 | top->gaps = top_gap; | ||
1895 | arrange_windows(top, -1, -1); | ||
1896 | } | ||
1897 | |||
1898 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1899 | } | ||
1900 | |||
1901 | static struct cmd_results *cmd_smart_gaps(int argc, char **argv) { | ||
1902 | struct cmd_results *error = NULL; | ||
1903 | if ((error = checkarg(argc, "smart_gaps", EXPECTED_EQUAL_TO, 1))) { | ||
1904 | return error; | ||
1905 | } | ||
1906 | |||
1907 | if (strcasecmp(argv[0], "on") == 0) { | ||
1908 | config->smart_gaps = true; | ||
1909 | } else if (strcasecmp(argv[0], "off") == 0) { | ||
1910 | config->smart_gaps = false; | ||
1911 | } else { | ||
1912 | return cmd_results_new(CMD_INVALID, "smart_gaps", "Expected 'smart_gaps <on|off>'"); | ||
1913 | } | ||
1914 | |||
1915 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1916 | } | ||
1917 | |||
1918 | static struct cmd_results *cmd_hide_edge_borders(int argc, char **argv) { | ||
1919 | struct cmd_results *error = NULL; | ||
1920 | if ((error = checkarg(argc, "hide_edge_borders", EXPECTED_EQUAL_TO, 1))) { | ||
1921 | return error; | ||
1922 | } | ||
1923 | |||
1924 | if (strcasecmp(argv[0], "none") == 0) { | ||
1925 | config->hide_edge_borders = E_NONE; | ||
1926 | } else if (strcasecmp(argv[0], "vertical") == 0) { | ||
1927 | config->hide_edge_borders = E_VERTICAL; | ||
1928 | } else if (strcasecmp(argv[0], "horizontal") == 0) { | ||
1929 | config->hide_edge_borders = E_HORIZONTAL; | ||
1930 | } else if (strcasecmp(argv[0], "both") == 0) { | ||
1931 | config->hide_edge_borders = E_BOTH; | ||
1932 | } else { | ||
1933 | return cmd_results_new(CMD_INVALID, "hide_edge_borders", | ||
1934 | "Expected 'hide_edge_borders <none|vertical|horizontal|both>'"); | ||
1935 | } | ||
1936 | |||
1937 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1938 | } | ||
1939 | |||
1940 | |||
1941 | static struct cmd_results *cmd_kill(int argc, char **argv) { | ||
1942 | if (config->reading) return cmd_results_new(CMD_FAILURE, "kill", "Can't be used in config file."); | ||
1943 | if (!config->active) return cmd_results_new(CMD_FAILURE, "kill", "Can only be used when sway is running."); | ||
1944 | |||
1945 | swayc_t *container = get_focused_container(&root_container); | ||
1946 | close_views(container); | ||
1947 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
1948 | } | ||
1949 | |||
1950 | static struct cmd_results *cmd_layout(int argc, char **argv) { | ||
1951 | struct cmd_results *error = NULL; | ||
1952 | if (config->reading) return cmd_results_new(CMD_FAILURE, "layout", "Can't be used in config file."); | ||
1953 | if (!config->active) return cmd_results_new(CMD_FAILURE, "layout", "Can only be used when sway is running."); | ||
1954 | if ((error = checkarg(argc, "layout", EXPECTED_MORE_THAN, 0))) { | ||
1955 | return error; | ||
1956 | } | ||
1957 | swayc_t *parent = get_focused_container(&root_container); | ||
1958 | if (parent->is_floating) { | ||
1959 | return cmd_results_new(CMD_FAILURE, "layout", "Unable to change layout of floating windows"); | ||
1960 | } | ||
1961 | |||
1962 | while (parent->type == C_VIEW) { | ||
1963 | parent = parent->parent; | ||
1964 | } | ||
1965 | |||
1966 | enum swayc_layouts old_layout = parent->layout; | ||
1967 | |||
1968 | if (strcasecmp(argv[0], "default") == 0) { | ||
1969 | parent->layout = parent->prev_layout; | ||
1970 | if (parent->layout == L_NONE) { | ||
1971 | swayc_t *output = swayc_parent_by_type(parent, C_OUTPUT); | ||
1972 | parent->layout = default_layout(output); | ||
1973 | } | ||
1974 | } else { | ||
1975 | if (parent->layout != L_TABBED && parent->layout != L_STACKED) { | ||
1976 | parent->prev_layout = parent->layout; | ||
1977 | } | ||
1978 | |||
1979 | if (strcasecmp(argv[0], "tabbed") == 0) { | ||
1980 | if (parent->type != C_CONTAINER && !swayc_is_empty_workspace(parent)){ | ||
1981 | parent = new_container(parent, L_TABBED); | ||
1982 | } | ||
1983 | |||
1984 | parent->layout = L_TABBED; | ||
1985 | } else if (strcasecmp(argv[0], "stacking") == 0) { | ||
1986 | if (parent->type != C_CONTAINER && !swayc_is_empty_workspace(parent)) { | ||
1987 | parent = new_container(parent, L_STACKED); | ||
1988 | } | ||
1989 | |||
1990 | parent->layout = L_STACKED; | ||
1991 | } else if (strcasecmp(argv[0], "splith") == 0) { | ||
1992 | parent->layout = L_HORIZ; | ||
1993 | } else if (strcasecmp(argv[0], "splitv") == 0) { | ||
1994 | parent->layout = L_VERT; | ||
1995 | } else if (strcasecmp(argv[0], "toggle") == 0 && argc == 2 && strcasecmp(argv[1], "split") == 0) { | ||
1996 | if (parent->layout == L_VERT) { | ||
1997 | parent->layout = L_HORIZ; | ||
1998 | } else { | ||
1999 | parent->layout = L_VERT; | ||
2000 | } | ||
2001 | } | ||
2002 | } | ||
2003 | |||
2004 | update_layout_geometry(parent, old_layout); | ||
2005 | update_geometry(parent); | ||
2006 | |||
2007 | arrange_windows(parent, parent->width, parent->height); | ||
2008 | |||
2009 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
2010 | } | ||
2011 | |||
2012 | static struct cmd_results *cmd_reload(int argc, char **argv) { | ||
2013 | struct cmd_results *error = NULL; | ||
2014 | if (config->reading) return cmd_results_new(CMD_FAILURE, "reload", "Can't be used in config file."); | ||
2015 | if ((error = checkarg(argc, "reload", EXPECTED_EQUAL_TO, 0))) { | ||
2016 | return error; | ||
2017 | } | ||
2018 | if (!load_main_config(config->current_config, true)) { | ||
2019 | return cmd_results_new(CMD_FAILURE, "reload", "Error(s) reloading config."); | ||
2020 | } | ||
2021 | |||
2022 | load_swaybars(); | ||
2023 | |||
2024 | arrange_windows(&root_container, -1, -1); | ||
2025 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
2026 | } | ||
2027 | |||
2028 | static struct cmd_results *cmd_resize(int argc, char **argv) { | ||
2029 | struct cmd_results *error = NULL; | ||
2030 | if (config->reading) return cmd_results_new(CMD_FAILURE, "resize", "Can't be used in config file."); | ||
2031 | if (!config->active) return cmd_results_new(CMD_FAILURE, "resize", "Can only be used when sway is running."); | ||
2032 | |||
2033 | if (strcasecmp(argv[0], "set") == 0) { | ||
2034 | return cmd_resize_set(argc - 1, &argv[1]); | ||
2035 | } | ||
2036 | |||
2037 | if ((error = checkarg(argc, "resize", EXPECTED_AT_LEAST, 2))) { | ||
2038 | return error; | ||
2039 | } | ||
2040 | |||
2041 | int dim_arg = argc - 1; | ||
2042 | |||
2043 | enum resize_dim_types dim_type = RESIZE_DIM_DEFAULT; | ||
2044 | if (strcasecmp(argv[dim_arg], "ppt") == 0) { | ||
2045 | dim_type = RESIZE_DIM_PPT; | ||
2046 | dim_arg--; | ||
2047 | } else if (strcasecmp(argv[dim_arg], "px") == 0) { | ||
2048 | dim_type = RESIZE_DIM_PX; | ||
2049 | dim_arg--; | ||
2050 | } | ||
2051 | |||
2052 | int amount = (int)strtol(argv[dim_arg], NULL, 10); | ||
2053 | if (errno == ERANGE || amount == 0) { | ||
2054 | errno = 0; | ||
2055 | amount = 10; // this is the default resize dimension used by i3 for both px and ppt | ||
2056 | sway_log(L_DEBUG, "Tried to get resize dimension out of '%s' but failed; setting dimension to default %d", | ||
2057 | argv[dim_arg], amount); | ||
2058 | } | ||
2059 | |||
2060 | bool use_width = false; | ||
2061 | if (strcasecmp(argv[1], "width") == 0) { | ||
2062 | use_width = true; | ||
2063 | } else if (strcasecmp(argv[1], "height") != 0) { | ||
2064 | return cmd_results_new(CMD_INVALID, "resize", | ||
2065 | "Expected 'resize <shrink|grow> <width|height> [<amount>] [px|ppt]'"); | ||
2066 | } | ||
2067 | |||
2068 | if (strcasecmp(argv[0], "shrink") == 0) { | ||
2069 | amount *= -1; | ||
2070 | } else if (strcasecmp(argv[0], "grow") != 0) { | ||
2071 | return cmd_results_new(CMD_INVALID, "resize", | ||
2072 | "Expected 'resize <shrink|grow> <width|height> [<amount>] [px|ppt]'"); | ||
2073 | } | ||
2074 | |||
2075 | resize(amount, use_width, dim_type); | ||
2076 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
2077 | } | ||
2078 | |||
2079 | static struct cmd_results *cmd_resize_set(int argc, char **argv) { | ||
2080 | struct cmd_results *error = NULL; | ||
2081 | if ((error = checkarg(argc, "resize set", EXPECTED_AT_LEAST, 2))) { | ||
2082 | return error; | ||
2083 | } | ||
2084 | |||
2085 | if (strcasecmp(argv[0], "width") == 0 || strcasecmp(argv[0], "height") == 0) { | ||
2086 | // handle `reset set width 100 px height 100 px` syntax, also allows | ||
2087 | // specifying only one dimension for a `resize set` | ||
2088 | int cmd_num = 0; | ||
2089 | int dim; | ||
2090 | |||
2091 | while ((cmd_num + 1) < argc) { | ||
2092 | dim = (int)strtol(argv[cmd_num + 1], NULL, 10); | ||
2093 | if (errno == ERANGE || dim == 0) { | ||
2094 | errno = 0; | ||
2095 | return cmd_results_new(CMD_INVALID, "resize set", | ||
2096 | "Expected 'resize set <width|height> <amount> [px] [<width|height> <amount> [px]]'"); | ||
2097 | } | ||
2098 | |||
2099 | if (strcasecmp(argv[cmd_num], "width") == 0) { | ||
2100 | set_size(dim, true); | ||
2101 | } else if (strcasecmp(argv[cmd_num], "height") == 0) { | ||
2102 | set_size(dim, false); | ||
2103 | } else { | ||
2104 | return cmd_results_new(CMD_INVALID, "resize set", | ||
2105 | "Expected 'resize set <width|height> <amount> [px] [<width|height> <amount> [px]]'"); | ||
2106 | } | ||
2107 | |||
2108 | cmd_num += 2; | ||
2109 | |||
2110 | if (cmd_num < argc && strcasecmp(argv[cmd_num], "px") == 0) { | ||
2111 | // if this was `resize set width 400 px height 300 px`, disregard the `px` arg | ||
2112 | cmd_num++; | ||
2113 | } | ||
2114 | } | ||
2115 | } else { | ||
2116 | // handle `reset set 100 px 100 px` syntax | ||
2117 | int width = (int)strtol(argv[0], NULL, 10); | ||
2118 | if (errno == ERANGE || width == 0) { | ||
2119 | errno = 0; | ||
2120 | return cmd_results_new(CMD_INVALID, "resize set", | ||
2121 | "Expected 'resize set <width> [px] <height> [px]'"); | ||
2122 | } | ||
2123 | |||
2124 | int height_arg = 1; | ||
2125 | if (strcasecmp(argv[1], "px") == 0) { | ||
2126 | height_arg = 2; | ||
2127 | } | ||
2128 | |||
2129 | int height = (int)strtol(argv[height_arg], NULL, 10); | ||
2130 | if (errno == ERANGE || height == 0) { | ||
2131 | errno = 0; | ||
2132 | return cmd_results_new(CMD_INVALID, "resize set", | ||
2133 | "Expected 'resize set <width> [px] <height> [px]'"); | ||
2134 | } | ||
2135 | |||
2136 | set_size(width, true); | ||
2137 | set_size(height, false); | ||
2138 | } | ||
2139 | |||
2140 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
2141 | } | ||
2142 | |||
2143 | static struct cmd_results *cmd_bar(int argc, char **argv) { | ||
2144 | struct cmd_results *error = NULL; | ||
2145 | if ((error = checkarg(argc, "bar", EXPECTED_AT_LEAST, 1))) { | ||
2146 | return error; | ||
2147 | } | ||
2148 | |||
2149 | if (config->reading && strcmp("{", argv[0]) != 0) { | ||
2150 | return cmd_results_new(CMD_INVALID, "bar", | ||
2151 | "Expected '{' at start of bar config definition."); | ||
2152 | } | ||
2153 | |||
2154 | if (!config->reading) { | ||
2155 | if (argc > 1) { | ||
2156 | if (strcasecmp("mode", argv[0]) == 0) { | ||
2157 | return bar_cmd_mode(argc-1, argv + 1); | ||
2158 | } | ||
2159 | |||
2160 | if (strcasecmp("hidden_state", argv[0]) == 0) { | ||
2161 | return bar_cmd_hidden_state(argc-1, argv + 1); | ||
2162 | } | ||
2163 | } | ||
2164 | |||
2165 | return cmd_results_new(CMD_FAILURE, "bar", "Can only be used in config file."); | ||
2166 | } | ||
2167 | |||
2168 | // Create new bar with default values | ||
2169 | struct bar_config *bar = default_bar_config(); | ||
2170 | |||
2171 | // set bar id | ||
2172 | int i; | ||
2173 | for (i = 0; i < config->bars->length; ++i) { | ||
2174 | if (bar == config->bars->items[i]) { | ||
2175 | const int len = 5 + numlen(i); // "bar-" + i + \0 | ||
2176 | bar->id = malloc(len * sizeof(char)); | ||
2177 | snprintf(bar->id, len, "bar-%d", i); | ||
2178 | break; | ||
2179 | } | ||
2180 | } | ||
2181 | |||
2182 | // Set current bar | ||
2183 | config->current_bar = bar; | ||
2184 | sway_log(L_DEBUG, "Configuring bar %s", bar->id); | ||
2185 | return cmd_results_new(CMD_BLOCK_BAR, NULL, NULL); | ||
2186 | } | ||
2187 | |||
2188 | static swayc_t *fetch_view_from_scratchpad() { | ||
2189 | if (sp_index >= scratchpad->length) { | ||
2190 | sp_index = 0; | ||
2191 | } | ||
2192 | swayc_t *view = scratchpad->items[sp_index++]; | ||
2193 | |||
2194 | if (wlc_view_get_output(view->handle) != swayc_active_output()->handle) { | ||
2195 | wlc_view_set_output(view->handle, swayc_active_output()->handle); | ||
2196 | } | ||
2197 | if (!view->is_floating) { | ||
2198 | view->width = swayc_active_workspace()->width/2; | ||
2199 | view->height = swayc_active_workspace()->height/2; | ||
2200 | view->x = (swayc_active_workspace()->width - view->width)/2; | ||
2201 | view->y = (swayc_active_workspace()->height - view->height)/2; | ||
2202 | } | ||
2203 | if (swayc_active_workspace()->width < view->x + 20 || view->x + view->width < 20) { | ||
2204 | view->x = (swayc_active_workspace()->width - view->width)/2; | ||
2205 | } | ||
2206 | if (swayc_active_workspace()->height < view->y + 20 || view->y + view->height < 20) { | ||
2207 | view->y = (swayc_active_workspace()->height - view->height)/2; | ||
2208 | } | ||
2209 | |||
2210 | add_floating(swayc_active_workspace(), view); | ||
2211 | wlc_view_set_mask(view->handle, VISIBLE); | ||
2212 | view->visible = true; | ||
2213 | arrange_windows(swayc_active_workspace(), -1, -1); | ||
2214 | set_focused_container(view); | ||
2215 | return view; | ||
2216 | } | ||
2217 | |||
2218 | void remove_view_from_scratchpad(swayc_t *view) { | 134 | void remove_view_from_scratchpad(swayc_t *view) { |
2219 | int i; | 135 | int i; |
2220 | for (i = 0; i < scratchpad->length; i++) { | 136 | for (i = 0; i < scratchpad->length; i++) { |
@@ -2230,423 +146,6 @@ void remove_view_from_scratchpad(swayc_t *view) { | |||
2230 | } | 146 | } |
2231 | } | 147 | } |
2232 | 148 | ||
2233 | static struct cmd_results *cmd_scratchpad(int argc, char **argv) { | ||
2234 | struct cmd_results *error = NULL; | ||
2235 | if (config->reading) return cmd_results_new(CMD_FAILURE, "scratchpad", "Can't be used in config file."); | ||
2236 | if (!config->active) return cmd_results_new(CMD_FAILURE, "scratchpad", "Can only be used when sway is running."); | ||
2237 | if ((error = checkarg(argc, "scratchpad", EXPECTED_EQUAL_TO, 1))) { | ||
2238 | return error; | ||
2239 | } | ||
2240 | |||
2241 | if (strcasecmp(argv[0], "show") == 0 && scratchpad->length > 0) { | ||
2242 | if (!sp_view) { | ||
2243 | sp_view = fetch_view_from_scratchpad(); | ||
2244 | } else { | ||
2245 | if (swayc_active_workspace() != sp_view->parent) { | ||
2246 | hide_view_in_scratchpad(sp_view); | ||
2247 | if (sp_index == 0) { | ||
2248 | sp_index = scratchpad->length; | ||
2249 | } | ||
2250 | sp_index--; | ||
2251 | sp_view = fetch_view_from_scratchpad(); | ||
2252 | } else { | ||
2253 | hide_view_in_scratchpad(sp_view); | ||
2254 | sp_view = NULL; | ||
2255 | } | ||
2256 | } | ||
2257 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
2258 | } | ||
2259 | return cmd_results_new(CMD_FAILURE, "scratchpad", "Expected 'scratchpad show' when scratchpad is not empty."); | ||
2260 | } | ||
2261 | |||
2262 | // sort in order of longest->shortest | ||
2263 | static int compare_set_qsort(const void *_l, const void *_r) { | ||
2264 | struct sway_variable const *l = *(void **)_l; | ||
2265 | struct sway_variable const *r = *(void **)_r; | ||
2266 | return strlen(r->name) - strlen(l->name); | ||
2267 | } | ||
2268 | |||
2269 | static struct cmd_results *cmd_set(int argc, char **argv) { | ||
2270 | char *tmp; | ||
2271 | int size; | ||
2272 | struct cmd_results *error = NULL; | ||
2273 | if (!config->reading) return cmd_results_new(CMD_FAILURE, "set", "Can only be used in config file."); | ||
2274 | if ((error = checkarg(argc, "set", EXPECTED_AT_LEAST, 2))) { | ||
2275 | return error; | ||
2276 | } | ||
2277 | |||
2278 | if (argv[0][0] != '$') { | ||
2279 | sway_log(L_INFO, "Warning: variable '%s' doesn't start with $", argv[0]); | ||
2280 | |||
2281 | size = asprintf(&tmp, "%s%s", "$", argv[0]); | ||
2282 | if (size == -1) { | ||
2283 | return cmd_results_new(CMD_FAILURE, "set", "Not possible to create variable $'%s'", argv[0]); | ||
2284 | } | ||
2285 | |||
2286 | argv[0] = strdup(tmp); | ||
2287 | free(tmp); | ||
2288 | } | ||
2289 | |||
2290 | struct sway_variable *var = NULL; | ||
2291 | // Find old variable if it exists | ||
2292 | int i; | ||
2293 | for (i = 0; i < config->symbols->length; ++i) { | ||
2294 | var = config->symbols->items[i]; | ||
2295 | if (strcmp(var->name, argv[0]) == 0) { | ||
2296 | break; | ||
2297 | } | ||
2298 | var = NULL; | ||
2299 | } | ||
2300 | if (var) { | ||
2301 | free(var->value); | ||
2302 | } else { | ||
2303 | var = malloc(sizeof(struct sway_variable)); | ||
2304 | var->name = strdup(argv[0]); | ||
2305 | list_add(config->symbols, var); | ||
2306 | list_qsort(config->symbols, compare_set_qsort); | ||
2307 | } | ||
2308 | var->value = join_args(argv + 1, argc - 1); | ||
2309 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
2310 | } | ||
2311 | |||
2312 | static struct cmd_results *_do_split(int argc, char **argv, int layout) { | ||
2313 | char *name = layout == L_VERT ? "splitv" : | ||
2314 | layout == L_HORIZ ? "splith" : "split"; | ||
2315 | struct cmd_results *error = NULL; | ||
2316 | if (config->reading) return cmd_results_new(CMD_FAILURE, name, "Can't be used in config file."); | ||
2317 | if (!config->active) return cmd_results_new(CMD_FAILURE, name, "Can only be used when sway is running."); | ||
2318 | if ((error = checkarg(argc, name, EXPECTED_EQUAL_TO, 0))) { | ||
2319 | return error; | ||
2320 | } | ||
2321 | swayc_t *focused = get_focused_container(&root_container); | ||
2322 | |||
2323 | // Case of floating window, don't split | ||
2324 | if (focused->is_floating) { | ||
2325 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
2326 | } | ||
2327 | /* Case that focus is on an workspace with 0/1 children.change its layout */ | ||
2328 | if (focused->type == C_WORKSPACE && focused->children->length <= 1) { | ||
2329 | sway_log(L_DEBUG, "changing workspace layout"); | ||
2330 | focused->layout = layout; | ||
2331 | } else if (focused->type != C_WORKSPACE && focused->parent->children->length == 1) { | ||
2332 | /* Case of no siblings. change parent layout */ | ||
2333 | sway_log(L_DEBUG, "changing container layout"); | ||
2334 | focused->parent->layout = layout; | ||
2335 | } else { | ||
2336 | /* regular case where new split container is build around focused container | ||
2337 | * or in case of workspace, container inherits its children */ | ||
2338 | sway_log(L_DEBUG, "Adding new container around current focused container"); | ||
2339 | sway_log(L_INFO, "FOCUSED SIZE: %.f %.f", focused->width, focused->height); | ||
2340 | swayc_t *parent = new_container(focused, layout); | ||
2341 | set_focused_container(focused); | ||
2342 | arrange_windows(parent, -1, -1); | ||
2343 | } | ||
2344 | |||
2345 | // update container every time | ||
2346 | // if it is tabbed/stacked then the title must change | ||
2347 | // if the indicator color is different then the border must change | ||
2348 | update_container_border(focused); | ||
2349 | swayc_t *output = swayc_parent_by_type(focused, C_OUTPUT); | ||
2350 | // schedule render to make changes take effect right away, | ||
2351 | // otherwise we would have to wait for the view to render, | ||
2352 | // which is unpredictable. | ||
2353 | wlc_output_schedule_render(output->handle); | ||
2354 | |||
2355 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
2356 | } | ||
2357 | |||
2358 | static struct cmd_results *cmd_split(int argc, char **argv) { | ||
2359 | struct cmd_results *error = NULL; | ||
2360 | if (config->reading) return cmd_results_new(CMD_FAILURE, "split", "Can't be used in config file."); | ||
2361 | if (!config->active) return cmd_results_new(CMD_FAILURE, "split", "Can only be used when sway is running."); | ||
2362 | if ((error = checkarg(argc, "split", EXPECTED_EQUAL_TO, 1))) { | ||
2363 | return error; | ||
2364 | } | ||
2365 | if (strcasecmp(argv[0], "v") == 0 || strcasecmp(argv[0], "vertical") == 0) { | ||
2366 | _do_split(argc - 1, argv + 1, L_VERT); | ||
2367 | } else if (strcasecmp(argv[0], "h") == 0 || strcasecmp(argv[0], "horizontal") == 0) { | ||
2368 | _do_split(argc - 1, argv + 1, L_HORIZ); | ||
2369 | } else if (strcasecmp(argv[0], "t") == 0 || strcasecmp(argv[0], "toggle") == 0) { | ||
2370 | swayc_t *focused = get_focused_container(&root_container); | ||
2371 | if (focused->parent->layout == L_VERT) { | ||
2372 | _do_split(argc - 1, argv + 1, L_HORIZ); | ||
2373 | } else { | ||
2374 | _do_split(argc - 1, argv + 1, L_VERT); | ||
2375 | } | ||
2376 | } else { | ||
2377 | error = cmd_results_new(CMD_FAILURE, "split", | ||
2378 | "Invalid split command (expected either horizontal or vertical)."); | ||
2379 | return error; | ||
2380 | } | ||
2381 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
2382 | } | ||
2383 | |||
2384 | static struct cmd_results *cmd_splitv(int argc, char **argv) { | ||
2385 | return _do_split(argc, argv, L_VERT); | ||
2386 | } | ||
2387 | |||
2388 | static struct cmd_results *cmd_splith(int argc, char **argv) { | ||
2389 | return _do_split(argc, argv, L_HORIZ); | ||
2390 | } | ||
2391 | |||
2392 | static struct cmd_results *cmd_splitt(int argc, char **argv) { | ||
2393 | swayc_t *focused = get_focused_container(&root_container); | ||
2394 | if (focused->parent->layout == L_VERT) { | ||
2395 | return _do_split(argc, argv, L_HORIZ); | ||
2396 | } else { | ||
2397 | return _do_split(argc, argv, L_VERT); | ||
2398 | } | ||
2399 | } | ||
2400 | |||
2401 | static struct cmd_results *cmd_sticky(int argc, char **argv) { | ||
2402 | struct cmd_results *error = NULL; | ||
2403 | if (config->reading) return cmd_results_new(CMD_FAILURE, "sticky", "Can't be used in config file."); | ||
2404 | if (!config->active) return cmd_results_new(CMD_FAILURE, "sticky", "Can only be used when sway is running."); | ||
2405 | if ((error = checkarg(argc, "sticky", EXPECTED_EQUAL_TO, 1))) { | ||
2406 | return error; | ||
2407 | } | ||
2408 | char *action = argv[0]; | ||
2409 | swayc_t *cont = get_focused_view(&root_container); | ||
2410 | if (strcmp(action, "toggle") == 0) { | ||
2411 | cont->sticky = !cont->sticky; | ||
2412 | } else if (strcmp(action, "enable") == 0) { | ||
2413 | cont->sticky = true; | ||
2414 | } else if (strcmp(action, "disable") == 0) { | ||
2415 | cont->sticky = false; | ||
2416 | } else { | ||
2417 | return cmd_results_new(CMD_FAILURE, "sticky", | ||
2418 | "Expected 'sticky enable|disable|toggle'"); | ||
2419 | } | ||
2420 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
2421 | } | ||
2422 | |||
2423 | static struct cmd_results *cmd_log_colors(int argc, char **argv) { | ||
2424 | struct cmd_results *error = NULL; | ||
2425 | if (!config->reading) return cmd_results_new(CMD_FAILURE, "log_colors", "Can only be used in config file."); | ||
2426 | if ((error = checkarg(argc, "log_colors", EXPECTED_EQUAL_TO, 1))) { | ||
2427 | return error; | ||
2428 | } | ||
2429 | if (strcasecmp(argv[0], "no") == 0) { | ||
2430 | sway_log_colors(0); | ||
2431 | } else if (strcasecmp(argv[0], "yes") == 0) { | ||
2432 | sway_log_colors(1); | ||
2433 | } else { | ||
2434 | error = cmd_results_new(CMD_FAILURE, "log_colors", | ||
2435 | "Invalid log_colors command (expected `yes` or `no`, got '%s')", argv[0]); | ||
2436 | return error; | ||
2437 | } | ||
2438 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
2439 | } | ||
2440 | |||
2441 | static struct cmd_results *cmd_font(int argc, char **argv) { | ||
2442 | struct cmd_results *error = NULL; | ||
2443 | if ((error = checkarg(argc, "font", EXPECTED_AT_LEAST, 1))) { | ||
2444 | return error; | ||
2445 | } | ||
2446 | |||
2447 | char *font = join_args(argv, argc); | ||
2448 | free(config->font); | ||
2449 | if (strlen(font) > 6 && strncmp("pango:", font, 6) == 0) { | ||
2450 | config->font = strdup(font + 6); | ||
2451 | free(font); | ||
2452 | } else { | ||
2453 | config->font = font; | ||
2454 | } | ||
2455 | |||
2456 | config->font_height = get_font_text_height(config->font); | ||
2457 | |||
2458 | sway_log(L_DEBUG, "Settings font %s", config->font); | ||
2459 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
2460 | } | ||
2461 | |||
2462 | |||
2463 | static struct cmd_results *cmd_for_window(int argc, char **argv) { | ||
2464 | struct cmd_results *error = NULL; | ||
2465 | if ((error = checkarg(argc, "for_window", EXPECTED_AT_LEAST, 2))) { | ||
2466 | return error; | ||
2467 | } | ||
2468 | // add command to a criteria/command pair that is run against views when they appear. | ||
2469 | char *criteria = argv[0], *cmdlist = join_args(argv + 1, argc - 1); | ||
2470 | |||
2471 | struct criteria *crit = malloc(sizeof(struct criteria)); | ||
2472 | crit->crit_raw = strdup(criteria); | ||
2473 | crit->cmdlist = cmdlist; | ||
2474 | crit->tokens = create_list(); | ||
2475 | char *err_str = extract_crit_tokens(crit->tokens, crit->crit_raw); | ||
2476 | |||
2477 | if (err_str) { | ||
2478 | error = cmd_results_new(CMD_INVALID, "for_window", err_str); | ||
2479 | free(err_str); | ||
2480 | free_criteria(crit); | ||
2481 | } else if (crit->tokens->length == 0) { | ||
2482 | error = cmd_results_new(CMD_INVALID, "for_window", "Found no name/value pairs in criteria"); | ||
2483 | free_criteria(crit); | ||
2484 | } else if (list_seq_find(config->criteria, criteria_cmp, crit) != -1) { | ||
2485 | sway_log(L_DEBUG, "for_window: Duplicate, skipping."); | ||
2486 | free_criteria(crit); | ||
2487 | } else { | ||
2488 | sway_log(L_DEBUG, "for_window: '%s' -> '%s' added", crit->crit_raw, crit->cmdlist); | ||
2489 | list_add(config->criteria, crit); | ||
2490 | } | ||
2491 | return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
2492 | } | ||
2493 | |||
2494 | static struct cmd_results *cmd_fullscreen(int argc, char **argv) { | ||
2495 | struct cmd_results *error = NULL; | ||
2496 | if (config->reading) return cmd_results_new(CMD_FAILURE, "fullscreen", "Can't be used in config file."); | ||
2497 | if (!config->active) return cmd_results_new(CMD_FAILURE, "fullscreen", "Can only be used when sway is running."); | ||
2498 | if ((error = checkarg(argc, "fullscreen", EXPECTED_AT_LEAST, 0))) { | ||
2499 | return error; | ||
2500 | } | ||
2501 | swayc_t *container = get_focused_view(&root_container); | ||
2502 | if(container->type != C_VIEW){ | ||
2503 | return cmd_results_new(CMD_INVALID, "fullscreen", "Only views can fullscreen"); | ||
2504 | } | ||
2505 | swayc_t *workspace = swayc_parent_by_type(container, C_WORKSPACE); | ||
2506 | bool current = swayc_is_fullscreen(container); | ||
2507 | wlc_view_set_state(container->handle, WLC_BIT_FULLSCREEN, !current); | ||
2508 | |||
2509 | if (container->is_floating) { | ||
2510 | if (current) { | ||
2511 | // set dimensions back to what they were before we fullscreened this | ||
2512 | container->x = container->cached_geometry.origin.x; | ||
2513 | container->y = container->cached_geometry.origin.y; | ||
2514 | container->width = container->cached_geometry.size.w; | ||
2515 | container->height = container->cached_geometry.size.h; | ||
2516 | } else { | ||
2517 | // cache dimensions so we can reset them after we "unfullscreen" this | ||
2518 | struct wlc_geometry geo = { | ||
2519 | .origin = { | ||
2520 | .x = container->x, | ||
2521 | .y = container->y | ||
2522 | }, | ||
2523 | .size = { | ||
2524 | .w = container->width, | ||
2525 | .h = container->height | ||
2526 | } | ||
2527 | }; | ||
2528 | container->cached_geometry = geo; | ||
2529 | } | ||
2530 | } | ||
2531 | |||
2532 | // Resize workspace if going from fullscreen -> notfullscreen | ||
2533 | // otherwise just resize container | ||
2534 | if (!current) { | ||
2535 | arrange_windows(workspace, -1, -1); | ||
2536 | workspace->fullscreen = container; | ||
2537 | } else { | ||
2538 | arrange_windows(container, -1, -1); | ||
2539 | workspace->fullscreen = NULL; | ||
2540 | } | ||
2541 | ipc_event_window(container, "fullscreen_mode"); | ||
2542 | |||
2543 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
2544 | } | ||
2545 | |||
2546 | static struct cmd_results *cmd_workspace(int argc, char **argv) { | ||
2547 | struct cmd_results *error = NULL; | ||
2548 | if ((error = checkarg(argc, "workspace", EXPECTED_AT_LEAST, 1))) { | ||
2549 | return error; | ||
2550 | } | ||
2551 | if (argc == 1 || (argc == 2 && strcasecmp(argv[0], "number") == 0) ) { | ||
2552 | if (config->reading || !config->active) { | ||
2553 | return cmd_results_new(CMD_DEFER, "workspace", NULL); | ||
2554 | } | ||
2555 | // Handle workspace next/prev | ||
2556 | swayc_t *ws = NULL; | ||
2557 | if (argc == 2) { | ||
2558 | if (!(ws = workspace_by_number(argv[1]))) { | ||
2559 | ws = workspace_create(argv[1]); | ||
2560 | } | ||
2561 | } else if (strcasecmp(argv[0], "next") == 0) { | ||
2562 | ws = workspace_next(); | ||
2563 | } else if (strcasecmp(argv[0], "prev") == 0) { | ||
2564 | ws = workspace_prev(); | ||
2565 | } else if (strcasecmp(argv[0], "next_on_output") == 0) { | ||
2566 | ws = workspace_output_next(); | ||
2567 | } else if (strcasecmp(argv[0], "prev_on_output") == 0) { | ||
2568 | ws = workspace_output_prev(); | ||
2569 | } else if (strcasecmp(argv[0], "back_and_forth") == 0) { | ||
2570 | // if auto_back_and_forth is enabled, workspace_switch will swap | ||
2571 | // the workspaces. If we created prev_workspace here, workspace_switch | ||
2572 | // would put us back on original workspace. | ||
2573 | if (config->auto_back_and_forth) { | ||
2574 | ws = swayc_active_workspace(); | ||
2575 | } else if (prev_workspace_name && !(ws = workspace_by_name(prev_workspace_name))) { | ||
2576 | ws = workspace_create(prev_workspace_name); | ||
2577 | } | ||
2578 | } else { | ||
2579 | if (!(ws = workspace_by_name(argv[0]))) { | ||
2580 | ws = workspace_create(argv[0]); | ||
2581 | } | ||
2582 | } | ||
2583 | swayc_t *old_output = swayc_active_output(); | ||
2584 | workspace_switch(ws); | ||
2585 | swayc_t *new_output = swayc_active_output(); | ||
2586 | |||
2587 | if (config->mouse_warping && old_output != new_output) { | ||
2588 | swayc_t *focused = get_focused_view(ws); | ||
2589 | if (focused && focused->type == C_VIEW) { | ||
2590 | center_pointer_on(focused); | ||
2591 | } | ||
2592 | } | ||
2593 | } else { | ||
2594 | if (strcasecmp(argv[1], "output") == 0) { | ||
2595 | if ((error = checkarg(argc, "workspace", EXPECTED_EQUAL_TO, 3))) { | ||
2596 | return error; | ||
2597 | } | ||
2598 | struct workspace_output *wso = calloc(1, sizeof(struct workspace_output)); | ||
2599 | wso->workspace = strdup(argv[0]); | ||
2600 | wso->output = strdup(argv[2]); | ||
2601 | int i = -1; | ||
2602 | if ((i = list_seq_find(config->workspace_outputs, workspace_output_cmp_workspace, wso)) != -1) { | ||
2603 | struct workspace_output *old = config->workspace_outputs->items[i]; | ||
2604 | free(old); // workspaces can only be assigned to a single output | ||
2605 | list_del(config->workspace_outputs, i); | ||
2606 | } | ||
2607 | sway_log(L_DEBUG, "Assigning workspace %s to output %s", argv[0], argv[2]); | ||
2608 | list_add(config->workspace_outputs, wso); | ||
2609 | if (!config->reading) { | ||
2610 | // TODO: Move workspace to output. (don't do so when reloading) | ||
2611 | } | ||
2612 | } | ||
2613 | } | ||
2614 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
2615 | } | ||
2616 | |||
2617 | static struct cmd_results *cmd_workspace_layout(int argc, char **argv) { | ||
2618 | struct cmd_results *error = NULL; | ||
2619 | if ((error = checkarg(argc, "workspace_layout", EXPECTED_EQUAL_TO, 1))) { | ||
2620 | return error; | ||
2621 | } | ||
2622 | |||
2623 | if (strcasecmp(argv[0], "default") == 0) { | ||
2624 | config->default_layout = L_NONE; | ||
2625 | } else if (strcasecmp(argv[0], "stacking") == 0) { | ||
2626 | config->default_layout = L_STACKED; | ||
2627 | } else if (strcasecmp(argv[0], "tabbed") == 0) { | ||
2628 | config->default_layout = L_TABBED; | ||
2629 | } else { | ||
2630 | return cmd_results_new(CMD_INVALID, "workspace_layout", "Expected 'workspace_layout <default|stacking|tabbed>'"); | ||
2631 | } | ||
2632 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
2633 | } | ||
2634 | |||
2635 | static struct cmd_results *cmd_ws_auto_back_and_forth(int argc, char **argv) { | ||
2636 | struct cmd_results *error = NULL; | ||
2637 | if ((error = checkarg(argc, "workspace_auto_back_and_forth", EXPECTED_EQUAL_TO, 1))) { | ||
2638 | return error; | ||
2639 | } | ||
2640 | if (strcasecmp(argv[0], "yes") == 0) { | ||
2641 | config->auto_back_and_forth = true; | ||
2642 | } else if (strcasecmp(argv[0], "no") == 0) { | ||
2643 | config->auto_back_and_forth = false; | ||
2644 | } else { | ||
2645 | return cmd_results_new(CMD_INVALID, "workspace_auto_back_and_forth", "Expected 'workspace_auto_back_and_forth <yes|no>'"); | ||
2646 | } | ||
2647 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
2648 | } | ||
2649 | |||
2650 | /* Keep alphabetized */ | 149 | /* Keep alphabetized */ |
2651 | static struct cmd_handler handlers[] = { | 150 | static struct cmd_handler handlers[] = { |
2652 | { "assign", cmd_assign }, | 151 | { "assign", cmd_assign }, |
@@ -2704,573 +203,6 @@ static struct cmd_handler handlers[] = { | |||
2704 | { "workspace_layout", cmd_workspace_layout }, | 203 | { "workspace_layout", cmd_workspace_layout }, |
2705 | }; | 204 | }; |
2706 | 205 | ||
2707 | static struct cmd_results *bar_cmd_binding_mode_indicator(int argc, char **argv) { | ||
2708 | struct cmd_results *error = NULL; | ||
2709 | if ((error = checkarg(argc, "binding_mode_indicator", EXPECTED_EQUAL_TO, 1))) { | ||
2710 | return error; | ||
2711 | } | ||
2712 | |||
2713 | if (!config->current_bar) { | ||
2714 | return cmd_results_new(CMD_FAILURE, "binding_mode_indicator", "No bar defined."); | ||
2715 | } | ||
2716 | |||
2717 | if (strcasecmp("yes", argv[0]) == 0) { | ||
2718 | config->current_bar->binding_mode_indicator = true; | ||
2719 | sway_log(L_DEBUG, "Enabling binding mode indicator on bar: %s", config->current_bar->id); | ||
2720 | } else if (strcasecmp("no", argv[0]) == 0) { | ||
2721 | config->current_bar->binding_mode_indicator = false; | ||
2722 | sway_log(L_DEBUG, "Disabling binding mode indicator on bar: %s", config->current_bar->id); | ||
2723 | } else { | ||
2724 | error = cmd_results_new(CMD_INVALID, "binding_mode_indicator", "Invalid value %s", argv[0]); | ||
2725 | return error; | ||
2726 | } | ||
2727 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
2728 | } | ||
2729 | |||
2730 | static struct cmd_results *bar_cmd_bindsym(int argc, char **argv) { | ||
2731 | struct cmd_results *error = NULL; | ||
2732 | if ((error = checkarg(argc, "bindsym", EXPECTED_MORE_THAN, 1))) { | ||
2733 | return error; | ||
2734 | } else if (!config->reading) { | ||
2735 | return cmd_results_new(CMD_FAILURE, "bindsym", "Can only be used in config file."); | ||
2736 | } | ||
2737 | |||
2738 | if (!config->current_bar) { | ||
2739 | return cmd_results_new(CMD_FAILURE, "bindsym", "No bar defined."); | ||
2740 | } | ||
2741 | |||
2742 | if (strlen(argv[1]) != 7) { | ||
2743 | return cmd_results_new(CMD_INVALID, "bindsym", "Invalid mouse binding %s", argv[1]); | ||
2744 | } | ||
2745 | uint32_t numbutton = (uint32_t)atoi(argv[1] + 6); | ||
2746 | if (numbutton < 1 || numbutton > 5 || strncmp(argv[1], "button", 6) != 0) { | ||
2747 | return cmd_results_new(CMD_INVALID, "bindsym", "Invalid mouse binding %s", argv[1]); | ||
2748 | } | ||
2749 | struct sway_mouse_binding *binding = malloc(sizeof(struct sway_mouse_binding)); | ||
2750 | binding->button = numbutton; | ||
2751 | binding->command = join_args(argv + 1, argc - 1); | ||
2752 | |||
2753 | struct bar_config *bar = config->current_bar; | ||
2754 | int i = list_seq_find(bar->bindings, sway_mouse_binding_cmp_buttons, binding); | ||
2755 | if (i > -1) { | ||
2756 | sway_log(L_DEBUG, "bindsym - '%s' for swaybar already exists, overwriting", argv[0]); | ||
2757 | struct sway_mouse_binding *dup = bar->bindings->items[i]; | ||
2758 | free_sway_mouse_binding(dup); | ||
2759 | list_del(bar->bindings, i); | ||
2760 | } | ||
2761 | list_add(bar->bindings, binding); | ||
2762 | list_qsort(bar->bindings, sway_mouse_binding_cmp_qsort); | ||
2763 | |||
2764 | sway_log(L_DEBUG, "bindsym - Bound %s to command %s when clicking swaybar", argv[0], binding->command); | ||
2765 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
2766 | } | ||
2767 | |||
2768 | static struct cmd_results *bar_cmd_colors(int argc, char **argv) { | ||
2769 | struct cmd_results *error = NULL; | ||
2770 | if ((error = checkarg(argc, "colors", EXPECTED_EQUAL_TO, 1))) { | ||
2771 | return error; | ||
2772 | } | ||
2773 | |||
2774 | if (strcmp("{", argv[0]) != 0) { | ||
2775 | return cmd_results_new(CMD_INVALID, "colors", | ||
2776 | "Expected '{' at the start of colors config definition."); | ||
2777 | } | ||
2778 | |||
2779 | return cmd_results_new(CMD_BLOCK_BAR_COLORS, NULL, NULL); | ||
2780 | } | ||
2781 | |||
2782 | static struct cmd_results *bar_cmd_font(int argc, char **argv) { | ||
2783 | struct cmd_results *error = NULL; | ||
2784 | if ((error = checkarg(argc, "font", EXPECTED_AT_LEAST, 1))) { | ||
2785 | return error; | ||
2786 | } | ||
2787 | |||
2788 | if (!config->current_bar) { | ||
2789 | return cmd_results_new(CMD_FAILURE, "font", "No bar defined."); | ||
2790 | } | ||
2791 | |||
2792 | char *font = join_args(argv, argc); | ||
2793 | free(config->current_bar->font); | ||
2794 | if (strlen(font) > 6 && strncmp("pango:", font, 6) == 0) { | ||
2795 | config->current_bar->font = font; | ||
2796 | } else { | ||
2797 | config->current_bar->font = font; | ||
2798 | } | ||
2799 | |||
2800 | sway_log(L_DEBUG, "Settings font '%s' for bar: %s", config->current_bar->font, config->current_bar->id); | ||
2801 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
2802 | } | ||
2803 | |||
2804 | static struct cmd_results *bar_cmd_height(int argc, char **argv) { | ||
2805 | struct cmd_results *error = NULL; | ||
2806 | if ((error = checkarg(argc, "height", EXPECTED_EQUAL_TO, 1))) { | ||
2807 | return error; | ||
2808 | } | ||
2809 | |||
2810 | int height = atoi(argv[0]); | ||
2811 | if (height < 0) { | ||
2812 | return cmd_results_new(CMD_INVALID, "height", | ||
2813 | "Invalid height value: %s", argv[0]); | ||
2814 | } | ||
2815 | |||
2816 | config->current_bar->height = height; | ||
2817 | sway_log(L_DEBUG, "Setting bar height to %d on bar: %s", height, config->current_bar->id); | ||
2818 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
2819 | } | ||
2820 | |||
2821 | static struct cmd_results *bar_set_hidden_state(struct bar_config *bar, const char *hidden_state) { | ||
2822 | char *old_state = bar->hidden_state; | ||
2823 | if (strcasecmp("toggle", hidden_state) == 0 && !config->reading) { | ||
2824 | if (strcasecmp("hide", bar->hidden_state) == 0) { | ||
2825 | bar->hidden_state = strdup("show"); | ||
2826 | } else if (strcasecmp("show", bar->hidden_state) == 0) { | ||
2827 | bar->hidden_state = strdup("hide"); | ||
2828 | } | ||
2829 | } else if (strcasecmp("hide", hidden_state) == 0) { | ||
2830 | bar->hidden_state = strdup("hide"); | ||
2831 | } else if (strcasecmp("show", hidden_state) == 0) { | ||
2832 | bar->hidden_state = strdup("show"); | ||
2833 | } else { | ||
2834 | return cmd_results_new(CMD_INVALID, "hidden_state", "Invalid value %s", hidden_state); | ||
2835 | } | ||
2836 | |||
2837 | if (strcmp(old_state, bar->hidden_state) != 0) { | ||
2838 | if (!config->reading) { | ||
2839 | ipc_event_barconfig_update(bar); | ||
2840 | } | ||
2841 | sway_log(L_DEBUG, "Setting hidden_state: '%s' for bar: %s", bar->hidden_state, bar->id); | ||
2842 | } | ||
2843 | |||
2844 | // free old mode | ||
2845 | free(old_state); | ||
2846 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
2847 | } | ||
2848 | |||
2849 | |||
2850 | static struct cmd_results *bar_cmd_hidden_state(int argc, char **argv) { | ||
2851 | struct cmd_results *error = NULL; | ||
2852 | if ((error = checkarg(argc, "hidden_state", EXPECTED_AT_LEAST, 1))) { | ||
2853 | return error; | ||
2854 | } | ||
2855 | if ((error = checkarg(argc, "hidden_state", EXPECTED_LESS_THAN, 3))) { | ||
2856 | return error; | ||
2857 | } | ||
2858 | |||
2859 | if (config->reading && argc > 1) { | ||
2860 | return cmd_results_new(CMD_INVALID, "hidden_state", "Unexpected value %s in config mode", argv[1]); | ||
2861 | } | ||
2862 | |||
2863 | const char *state = argv[0]; | ||
2864 | |||
2865 | if (config->reading) { | ||
2866 | return bar_set_hidden_state(config->current_bar, state); | ||
2867 | } | ||
2868 | |||
2869 | const char *id = NULL; | ||
2870 | if (argc == 2) { | ||
2871 | id = argv[1]; | ||
2872 | } | ||
2873 | |||
2874 | int i; | ||
2875 | struct bar_config *bar; | ||
2876 | for (i = 0; i < config->bars->length; ++i) { | ||
2877 | bar = config->bars->items[i]; | ||
2878 | if (id && strcmp(id, bar->id) == 0) { | ||
2879 | return bar_set_hidden_state(bar, state); | ||
2880 | } | ||
2881 | |||
2882 | error = bar_set_hidden_state(bar, state); | ||
2883 | if (error) { | ||
2884 | return error; | ||
2885 | } | ||
2886 | } | ||
2887 | |||
2888 | // active bar modifiers might have changed. | ||
2889 | update_active_bar_modifiers(); | ||
2890 | |||
2891 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
2892 | } | ||
2893 | |||
2894 | static struct cmd_results *bar_set_mode(struct bar_config *bar, const char *mode) { | ||
2895 | char *old_mode = bar->mode; | ||
2896 | if (strcasecmp("toggle", mode) == 0 && !config->reading) { | ||
2897 | if (strcasecmp("dock", bar->mode) == 0) { | ||
2898 | bar->mode = strdup("hide"); | ||
2899 | } else if (strcasecmp("hide", bar->mode) == 0) { | ||
2900 | bar->mode = strdup("dock"); | ||
2901 | } | ||
2902 | } else if (strcasecmp("dock", mode) == 0) { | ||
2903 | bar->mode = strdup("dock"); | ||
2904 | } else if (strcasecmp("hide", mode) == 0) { | ||
2905 | bar->mode = strdup("hide"); | ||
2906 | } else if (strcasecmp("invisible", mode) == 0) { | ||
2907 | bar->mode = strdup("invisible"); | ||
2908 | } else { | ||
2909 | return cmd_results_new(CMD_INVALID, "mode", "Invalid value %s", mode); | ||
2910 | } | ||
2911 | |||
2912 | if (strcmp(old_mode, bar->mode) != 0) { | ||
2913 | if (!config->reading) { | ||
2914 | ipc_event_barconfig_update(bar); | ||
2915 | |||
2916 | // active bar modifiers might have changed. | ||
2917 | update_active_bar_modifiers(); | ||
2918 | } | ||
2919 | sway_log(L_DEBUG, "Setting mode: '%s' for bar: %s", bar->mode, bar->id); | ||
2920 | } | ||
2921 | |||
2922 | // free old mode | ||
2923 | free(old_mode); | ||
2924 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
2925 | } | ||
2926 | |||
2927 | static struct cmd_results *bar_cmd_mode(int argc, char **argv) { | ||
2928 | struct cmd_results *error = NULL; | ||
2929 | if ((error = checkarg(argc, "mode", EXPECTED_AT_LEAST, 1))) { | ||
2930 | return error; | ||
2931 | } | ||
2932 | if ((error = checkarg(argc, "mode", EXPECTED_LESS_THAN, 3))) { | ||
2933 | return error; | ||
2934 | } | ||
2935 | |||
2936 | if (config->reading && argc > 1) { | ||
2937 | return cmd_results_new(CMD_INVALID, "mode", "Unexpected value %s in config mode", argv[1]); | ||
2938 | } | ||
2939 | |||
2940 | const char *mode = argv[0]; | ||
2941 | |||
2942 | if (config->reading) { | ||
2943 | return bar_set_mode(config->current_bar, mode); | ||
2944 | } | ||
2945 | |||
2946 | const char *id = NULL; | ||
2947 | if (argc == 2) { | ||
2948 | id = argv[1]; | ||
2949 | } | ||
2950 | |||
2951 | int i; | ||
2952 | struct bar_config *bar; | ||
2953 | for (i = 0; i < config->bars->length; ++i) { | ||
2954 | bar = config->bars->items[i]; | ||
2955 | if (id && strcmp(id, bar->id) == 0) { | ||
2956 | return bar_set_mode(bar, mode); | ||
2957 | } | ||
2958 | |||
2959 | error = bar_set_mode(bar, mode); | ||
2960 | if (error) { | ||
2961 | return error; | ||
2962 | } | ||
2963 | } | ||
2964 | |||
2965 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
2966 | } | ||
2967 | |||
2968 | static struct cmd_results *bar_cmd_id(int argc, char **argv) { | ||
2969 | struct cmd_results *error = NULL; | ||
2970 | if ((error = checkarg(argc, "id", EXPECTED_EQUAL_TO, 1))) { | ||
2971 | return error; | ||
2972 | } | ||
2973 | |||
2974 | const char *name = argv[0]; | ||
2975 | const char *oldname = config->current_bar->id; | ||
2976 | |||
2977 | // check if id is used by a previously defined bar | ||
2978 | int i; | ||
2979 | for (i = 0; i < config->bars->length; ++i) { | ||
2980 | struct bar_config *find = config->bars->items[i]; | ||
2981 | if (strcmp(name, find->id) == 0 && config->current_bar != find) { | ||
2982 | return cmd_results_new(CMD_FAILURE, "id", | ||
2983 | "Id '%s' already defined for another bar. Id unchanged (%s).", | ||
2984 | name, oldname); | ||
2985 | } | ||
2986 | } | ||
2987 | |||
2988 | sway_log(L_DEBUG, "Renaming bar: '%s' to '%s'", oldname, name); | ||
2989 | |||
2990 | // free old bar id | ||
2991 | free(config->current_bar->id); | ||
2992 | |||
2993 | config->current_bar->id = strdup(name); | ||
2994 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
2995 | } | ||
2996 | |||
2997 | static struct cmd_results *bar_cmd_modifier(int argc, char **argv) { | ||
2998 | struct cmd_results *error = NULL; | ||
2999 | if ((error = checkarg(argc, "modifier", EXPECTED_EQUAL_TO, 1))) { | ||
3000 | return error; | ||
3001 | } | ||
3002 | |||
3003 | if (!config->current_bar) { | ||
3004 | return cmd_results_new(CMD_FAILURE, "modifier", "No bar defined."); | ||
3005 | } | ||
3006 | |||
3007 | uint32_t mod = 0; | ||
3008 | |||
3009 | list_t *split = split_string(argv[0], "+"); | ||
3010 | for (int i = 0; i < split->length; ++i) { | ||
3011 | uint32_t tmp_mod; | ||
3012 | if ((tmp_mod = get_modifier_mask_by_name(split->items[i])) > 0) { | ||
3013 | mod |= tmp_mod; | ||
3014 | continue; | ||
3015 | } else { | ||
3016 | free_flat_list(split); | ||
3017 | return cmd_results_new(CMD_INVALID, "modifier", "Unknown modifier '%s'", split->items[i]); | ||
3018 | } | ||
3019 | } | ||
3020 | free_flat_list(split); | ||
3021 | |||
3022 | config->current_bar->modifier = mod; | ||
3023 | sway_log(L_DEBUG, "Show/Hide the bar when pressing '%s' in hide mode.", argv[0]); | ||
3024 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
3025 | } | ||
3026 | |||
3027 | static struct cmd_results *bar_cmd_output(int argc, char **argv) { | ||
3028 | struct cmd_results *error = NULL; | ||
3029 | if ((error = checkarg(argc, "output", EXPECTED_EQUAL_TO, 1))) { | ||
3030 | return error; | ||
3031 | } | ||
3032 | |||
3033 | if (!config->current_bar) { | ||
3034 | return cmd_results_new(CMD_FAILURE, "output", "No bar defined."); | ||
3035 | } | ||
3036 | |||
3037 | const char *output = argv[0]; | ||
3038 | list_t *outputs = config->current_bar->outputs; | ||
3039 | if (!outputs) { | ||
3040 | outputs = create_list(); | ||
3041 | config->current_bar->outputs = outputs; | ||
3042 | } | ||
3043 | |||
3044 | int i; | ||
3045 | int add_output = 1; | ||
3046 | if (strcmp("*", output) == 0) { | ||
3047 | // remove all previous defined outputs and replace with '*' | ||
3048 | for (i = 0; i < outputs->length; ++i) { | ||
3049 | free(outputs->items[i]); | ||
3050 | list_del(outputs, i); | ||
3051 | } | ||
3052 | } else { | ||
3053 | // only add output if not already defined with either the same | ||
3054 | // name or as '*' | ||
3055 | for (i = 0; i < outputs->length; ++i) { | ||
3056 | const char *find = outputs->items[i]; | ||
3057 | if (strcmp("*", find) == 0 || strcmp(output, find) == 0) { | ||
3058 | add_output = 0; | ||
3059 | break; | ||
3060 | } | ||
3061 | } | ||
3062 | } | ||
3063 | |||
3064 | if (add_output) { | ||
3065 | list_add(outputs, strdup(output)); | ||
3066 | sway_log(L_DEBUG, "Adding bar: '%s' to output '%s'", config->current_bar->id, output); | ||
3067 | } | ||
3068 | |||
3069 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
3070 | } | ||
3071 | |||
3072 | static struct cmd_results *bar_cmd_position(int argc, char **argv) { | ||
3073 | struct cmd_results *error = NULL; | ||
3074 | if ((error = checkarg(argc, "position", EXPECTED_EQUAL_TO, 1))) { | ||
3075 | return error; | ||
3076 | } | ||
3077 | |||
3078 | if (!config->current_bar) { | ||
3079 | return cmd_results_new(CMD_FAILURE, "position", "No bar defined."); | ||
3080 | } | ||
3081 | |||
3082 | if (strcasecmp("top", argv[0]) == 0) { | ||
3083 | config->current_bar->position = DESKTOP_SHELL_PANEL_POSITION_TOP; | ||
3084 | } else if (strcasecmp("bottom", argv[0]) == 0) { | ||
3085 | config->current_bar->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM; | ||
3086 | } else if (strcasecmp("left", argv[0]) == 0) { | ||
3087 | sway_log(L_INFO, "Warning: swaybar currently only supports top and bottom positioning. YMMV"); | ||
3088 | config->current_bar->position = DESKTOP_SHELL_PANEL_POSITION_LEFT; | ||
3089 | } else if (strcasecmp("right", argv[0]) == 0) { | ||
3090 | sway_log(L_INFO, "Warning: swaybar currently only supports top and bottom positioning. YMMV"); | ||
3091 | config->current_bar->position = DESKTOP_SHELL_PANEL_POSITION_RIGHT; | ||
3092 | } else { | ||
3093 | error = cmd_results_new(CMD_INVALID, "position", "Invalid value %s", argv[0]); | ||
3094 | return error; | ||
3095 | } | ||
3096 | |||
3097 | sway_log(L_DEBUG, "Setting bar position '%s' for bar: %s", argv[0], config->current_bar->id); | ||
3098 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
3099 | } | ||
3100 | |||
3101 | static struct cmd_results *bar_cmd_separator_symbol(int argc, char **argv) { | ||
3102 | struct cmd_results *error = NULL; | ||
3103 | if ((error = checkarg(argc, "separator_symbol", EXPECTED_EQUAL_TO, 1))) { | ||
3104 | return error; | ||
3105 | } | ||
3106 | |||
3107 | if (!config->current_bar) { | ||
3108 | return cmd_results_new(CMD_FAILURE, "separator_symbol", "No bar defined."); | ||
3109 | } | ||
3110 | |||
3111 | free(config->current_bar->separator_symbol); | ||
3112 | config->current_bar->separator_symbol = strdup(argv[0]); | ||
3113 | sway_log(L_DEBUG, "Settings separator_symbol '%s' for bar: %s", config->current_bar->separator_symbol, config->current_bar->id); | ||
3114 | |||
3115 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
3116 | } | ||
3117 | |||
3118 | static struct cmd_results *bar_cmd_status_command(int argc, char **argv) { | ||
3119 | struct cmd_results *error = NULL; | ||
3120 | if ((error = checkarg(argc, "status_command", EXPECTED_AT_LEAST, 1))) { | ||
3121 | return error; | ||
3122 | } | ||
3123 | |||
3124 | if (!config->current_bar) { | ||
3125 | return cmd_results_new(CMD_FAILURE, "status_command", "No bar defined."); | ||
3126 | } | ||
3127 | |||
3128 | free(config->current_bar->status_command); | ||
3129 | config->current_bar->status_command = join_args(argv, argc); | ||
3130 | sway_log(L_DEBUG, "Feeding bar with status command: %s", config->current_bar->status_command); | ||
3131 | |||
3132 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
3133 | } | ||
3134 | |||
3135 | static struct cmd_results *bar_cmd_pango_markup(int argc, char **argv) { | ||
3136 | struct cmd_results *error = NULL; | ||
3137 | if ((error = checkarg(argc, "pango_markup", EXPECTED_EQUAL_TO, 1))) { | ||
3138 | return error; | ||
3139 | } | ||
3140 | |||
3141 | if (!config->current_bar) { | ||
3142 | return cmd_results_new(CMD_FAILURE, "pango_markup", "No bar defined."); | ||
3143 | } | ||
3144 | |||
3145 | if (strcasecmp("enabled", argv[0]) == 0) { | ||
3146 | config->current_bar->pango_markup = true; | ||
3147 | sway_log(L_DEBUG, "Enabling pango markup for bar: %s", config->current_bar->id); | ||
3148 | } else if (strcasecmp("disabled", argv[0]) == 0) { | ||
3149 | config->current_bar->pango_markup = false; | ||
3150 | sway_log(L_DEBUG, "Disabling pango markup for bar: %s", config->current_bar->id); | ||
3151 | } else { | ||
3152 | error = cmd_results_new(CMD_INVALID, "pango_markup", "Invalid value %s", argv[0]); | ||
3153 | return error; | ||
3154 | } | ||
3155 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
3156 | } | ||
3157 | |||
3158 | static struct cmd_results *bar_cmd_strip_workspace_numbers(int argc, char **argv) { | ||
3159 | struct cmd_results *error = NULL; | ||
3160 | if ((error = checkarg(argc, "strip_workspace_numbers", EXPECTED_EQUAL_TO, 1))) { | ||
3161 | return error; | ||
3162 | } | ||
3163 | |||
3164 | if (!config->current_bar) { | ||
3165 | return cmd_results_new(CMD_FAILURE, "strip_workspace_numbers", "No bar defined."); | ||
3166 | } | ||
3167 | |||
3168 | if (strcasecmp("yes", argv[0]) == 0) { | ||
3169 | config->current_bar->strip_workspace_numbers = true; | ||
3170 | sway_log(L_DEBUG, "Stripping workspace numbers on bar: %s", config->current_bar->id); | ||
3171 | } else if (strcasecmp("no", argv[0]) == 0) { | ||
3172 | config->current_bar->strip_workspace_numbers = false; | ||
3173 | sway_log(L_DEBUG, "Enabling workspace numbers on bar: %s", config->current_bar->id); | ||
3174 | } else { | ||
3175 | error = cmd_results_new(CMD_INVALID, "strip_workspace_numbers", "Invalid value %s", argv[0]); | ||
3176 | return error; | ||
3177 | } | ||
3178 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
3179 | } | ||
3180 | |||
3181 | static struct cmd_results *bar_cmd_swaybar_command(int argc, char **argv) { | ||
3182 | struct cmd_results *error = NULL; | ||
3183 | if ((error = checkarg(argc, "swaybar_command", EXPECTED_AT_LEAST, 1))) { | ||
3184 | return error; | ||
3185 | } | ||
3186 | |||
3187 | if (!config->current_bar) { | ||
3188 | return cmd_results_new(CMD_FAILURE, "swaybar_command", "No bar defined."); | ||
3189 | } | ||
3190 | |||
3191 | free(config->current_bar->swaybar_command); | ||
3192 | config->current_bar->swaybar_command = join_args(argv, argc); | ||
3193 | sway_log(L_DEBUG, "Using custom swaybar command: %s", config->current_bar->swaybar_command); | ||
3194 | |||
3195 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
3196 | } | ||
3197 | |||
3198 | static struct cmd_results *bar_cmd_tray_output(int argc, char **argv) { | ||
3199 | sway_log(L_ERROR, "Warning: tray_output is not supported on wayland"); | ||
3200 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
3201 | } | ||
3202 | |||
3203 | static struct cmd_results *bar_cmd_tray_padding(int argc, char **argv) { | ||
3204 | struct cmd_results *error = NULL; | ||
3205 | if ((error = checkarg(argc, "tray_padding", EXPECTED_AT_LEAST, 1))) { | ||
3206 | return error; | ||
3207 | } | ||
3208 | |||
3209 | if (!config->current_bar) { | ||
3210 | return cmd_results_new(CMD_FAILURE, "tray_padding", "No bar defined."); | ||
3211 | } | ||
3212 | |||
3213 | int padding = atoi(argv[0]); | ||
3214 | if (padding < 0) { | ||
3215 | return cmd_results_new(CMD_INVALID, "tray_padding", | ||
3216 | "Invalid padding value %s, minimum is 0", argv[0]); | ||
3217 | } | ||
3218 | |||
3219 | if (argc > 1 && strcasecmp("px", argv[1]) != 0) { | ||
3220 | return cmd_results_new(CMD_INVALID, "tray_padding", | ||
3221 | "Unknown unit %s", argv[1]); | ||
3222 | } | ||
3223 | config->current_bar->tray_padding = padding; | ||
3224 | sway_log(L_DEBUG, "Enabling tray padding of %d px on bar: %s", padding, config->current_bar->id); | ||
3225 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
3226 | } | ||
3227 | |||
3228 | static struct cmd_results *bar_cmd_wrap_scroll(int argc, char **argv) { | ||
3229 | struct cmd_results *error = NULL; | ||
3230 | if ((error = checkarg(argc, "wrap_scroll", EXPECTED_EQUAL_TO, 1))) { | ||
3231 | return error; | ||
3232 | } | ||
3233 | |||
3234 | if (!config->current_bar) { | ||
3235 | return cmd_results_new(CMD_FAILURE, "wrap_scroll", "No bar defined."); | ||
3236 | } | ||
3237 | |||
3238 | if (strcasecmp("yes", argv[0]) == 0) { | ||
3239 | config->current_bar->wrap_scroll = true; | ||
3240 | sway_log(L_DEBUG, "Enabling wrap scroll on bar: %s", config->current_bar->id); | ||
3241 | } else if (strcasecmp("no", argv[0]) == 0) { | ||
3242 | config->current_bar->wrap_scroll = false; | ||
3243 | sway_log(L_DEBUG, "Disabling wrap scroll on bar: %s", config->current_bar->id); | ||
3244 | } else { | ||
3245 | error = cmd_results_new(CMD_INVALID, "wrap_scroll", "Invalid value %s", argv[0]); | ||
3246 | return error; | ||
3247 | } | ||
3248 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
3249 | } | ||
3250 | |||
3251 | static struct cmd_results *bar_cmd_workspace_buttons(int argc, char **argv) { | ||
3252 | struct cmd_results *error = NULL; | ||
3253 | if ((error = checkarg(argc, "workspace_buttons", EXPECTED_EQUAL_TO, 1))) { | ||
3254 | return error; | ||
3255 | } | ||
3256 | |||
3257 | if (!config->current_bar) { | ||
3258 | return cmd_results_new(CMD_FAILURE, "workspace_buttons", "No bar defined."); | ||
3259 | } | ||
3260 | |||
3261 | if (strcasecmp("yes", argv[0]) == 0) { | ||
3262 | config->current_bar->workspace_buttons = true; | ||
3263 | sway_log(L_DEBUG, "Enabling workspace buttons on bar: %s", config->current_bar->id); | ||
3264 | } else if (strcasecmp("no", argv[0]) == 0) { | ||
3265 | config->current_bar->workspace_buttons = false; | ||
3266 | sway_log(L_DEBUG, "Disabling workspace buttons on bar: %s", config->current_bar->id); | ||
3267 | } else { | ||
3268 | error = cmd_results_new(CMD_INVALID, "workspace_buttons", "Invalid value %s", argv[0]); | ||
3269 | return error; | ||
3270 | } | ||
3271 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
3272 | } | ||
3273 | |||
3274 | static struct cmd_handler bar_handlers[] = { | 206 | static struct cmd_handler bar_handlers[] = { |
3275 | { "binding_mode_indicator", bar_cmd_binding_mode_indicator }, | 207 | { "binding_mode_indicator", bar_cmd_binding_mode_indicator }, |
3276 | { "bindsym", bar_cmd_bindsym }, | 208 | { "bindsym", bar_cmd_bindsym }, |
@@ -3299,7 +231,7 @@ static struct cmd_handler bar_handlers[] = { | |||
3299 | * | 231 | * |
3300 | * return error object, or NULL if color is valid. | 232 | * return error object, or NULL if color is valid. |
3301 | */ | 233 | */ |
3302 | static struct cmd_results *add_color(const char *name, char *buffer, const char *color) { | 234 | struct cmd_results *add_color(const char *name, char *buffer, const char *color) { |
3303 | int len = strlen(color); | 235 | int len = strlen(color); |
3304 | if (len != 7 && len != 9 ) { | 236 | if (len != 7 && len != 9 ) { |
3305 | return cmd_results_new(CMD_INVALID, name, "Invalid color definition %s", color); | 237 | return cmd_results_new(CMD_INVALID, name, "Invalid color definition %s", color); |
@@ -3327,150 +259,6 @@ static struct cmd_results *add_color(const char *name, char *buffer, const char | |||
3327 | return NULL; | 259 | return NULL; |
3328 | } | 260 | } |
3329 | 261 | ||
3330 | static struct cmd_results *bar_colors_cmd_active_workspace(int argc, char **argv) { | ||
3331 | struct cmd_results *error = NULL; | ||
3332 | if ((error = checkarg(argc, "active_workspace", EXPECTED_EQUAL_TO, 3))) { | ||
3333 | return error; | ||
3334 | } | ||
3335 | |||
3336 | if ((error = add_color("active_workspace_border", config->current_bar->colors.active_workspace_border, argv[0]))) { | ||
3337 | return error; | ||
3338 | } | ||
3339 | |||
3340 | if ((error = add_color("active_workspace_bg", config->current_bar->colors.active_workspace_bg, argv[1]))) { | ||
3341 | return error; | ||
3342 | } | ||
3343 | |||
3344 | if ((error = add_color("active_workspace_text", config->current_bar->colors.active_workspace_text, argv[2]))) { | ||
3345 | return error; | ||
3346 | } | ||
3347 | |||
3348 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
3349 | } | ||
3350 | |||
3351 | static struct cmd_results *bar_colors_cmd_background(int argc, char **argv) { | ||
3352 | struct cmd_results *error = NULL; | ||
3353 | if ((error = checkarg(argc, "background", EXPECTED_EQUAL_TO, 1))) { | ||
3354 | return error; | ||
3355 | } | ||
3356 | |||
3357 | if ((error = add_color("background", config->current_bar->colors.background, argv[0]))) { | ||
3358 | return error; | ||
3359 | } | ||
3360 | |||
3361 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
3362 | } | ||
3363 | |||
3364 | static struct cmd_results *bar_colors_cmd_binding_mode(int argc, char **argv) { | ||
3365 | struct cmd_results *error = NULL; | ||
3366 | if ((error = checkarg(argc, "binding_mode", EXPECTED_EQUAL_TO, 3))) { | ||
3367 | return error; | ||
3368 | } | ||
3369 | |||
3370 | if ((error = add_color("binding_mode_border", config->current_bar->colors.binding_mode_border, argv[0]))) { | ||
3371 | return error; | ||
3372 | } | ||
3373 | |||
3374 | if ((error = add_color("binding_mode_bg", config->current_bar->colors.binding_mode_bg, argv[1]))) { | ||
3375 | return error; | ||
3376 | } | ||
3377 | |||
3378 | if ((error = add_color("binding_mode_text", config->current_bar->colors.binding_mode_text, argv[2]))) { | ||
3379 | return error; | ||
3380 | } | ||
3381 | |||
3382 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
3383 | } | ||
3384 | |||
3385 | static struct cmd_results *bar_colors_cmd_focused_workspace(int argc, char **argv) { | ||
3386 | struct cmd_results *error = NULL; | ||
3387 | if ((error = checkarg(argc, "focused_workspace", EXPECTED_EQUAL_TO, 3))) { | ||
3388 | return error; | ||
3389 | } | ||
3390 | |||
3391 | if ((error = add_color("focused_workspace_border", config->current_bar->colors.focused_workspace_border, argv[0]))) { | ||
3392 | return error; | ||
3393 | } | ||
3394 | |||
3395 | if ((error = add_color("focused_workspace_bg", config->current_bar->colors.focused_workspace_bg, argv[1]))) { | ||
3396 | return error; | ||
3397 | } | ||
3398 | |||
3399 | if ((error = add_color("focused_workspace_text", config->current_bar->colors.focused_workspace_text, argv[2]))) { | ||
3400 | return error; | ||
3401 | } | ||
3402 | |||
3403 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
3404 | } | ||
3405 | |||
3406 | static struct cmd_results *bar_colors_cmd_inactive_workspace(int argc, char **argv) { | ||
3407 | struct cmd_results *error = NULL; | ||
3408 | if ((error = checkarg(argc, "inactive_workspace", EXPECTED_EQUAL_TO, 3))) { | ||
3409 | return error; | ||
3410 | } | ||
3411 | |||
3412 | if ((error = add_color("inactive_workspace_border", config->current_bar->colors.inactive_workspace_border, argv[0]))) { | ||
3413 | return error; | ||
3414 | } | ||
3415 | |||
3416 | if ((error = add_color("inactive_workspace_bg", config->current_bar->colors.inactive_workspace_bg, argv[1]))) { | ||
3417 | return error; | ||
3418 | } | ||
3419 | |||
3420 | if ((error = add_color("inactive_workspace_text", config->current_bar->colors.inactive_workspace_text, argv[2]))) { | ||
3421 | return error; | ||
3422 | } | ||
3423 | |||
3424 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
3425 | } | ||
3426 | |||
3427 | static struct cmd_results *bar_colors_cmd_separator(int argc, char **argv) { | ||
3428 | struct cmd_results *error = NULL; | ||
3429 | if ((error = checkarg(argc, "separator", EXPECTED_EQUAL_TO, 1))) { | ||
3430 | return error; | ||
3431 | } | ||
3432 | |||
3433 | if ((error = add_color("separator", config->current_bar->colors.separator, argv[0]))) { | ||
3434 | return error; | ||
3435 | } | ||
3436 | |||
3437 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
3438 | } | ||
3439 | |||
3440 | static struct cmd_results *bar_colors_cmd_statusline(int argc, char **argv) { | ||
3441 | struct cmd_results *error = NULL; | ||
3442 | if ((error = checkarg(argc, "statusline", EXPECTED_EQUAL_TO, 1))) { | ||
3443 | return error; | ||
3444 | } | ||
3445 | |||
3446 | if ((error = add_color("statusline", config->current_bar->colors.statusline, argv[0]))) { | ||
3447 | return error; | ||
3448 | } | ||
3449 | |||
3450 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
3451 | } | ||
3452 | |||
3453 | static struct cmd_results *bar_colors_cmd_urgent_workspace(int argc, char **argv) { | ||
3454 | struct cmd_results *error = NULL; | ||
3455 | if ((error = checkarg(argc, "urgent_workspace", EXPECTED_EQUAL_TO, 3))) { | ||
3456 | return error; | ||
3457 | } | ||
3458 | |||
3459 | if ((error = add_color("urgent_workspace_border", config->current_bar->colors.urgent_workspace_border, argv[0]))) { | ||
3460 | return error; | ||
3461 | } | ||
3462 | |||
3463 | if ((error = add_color("urgent_workspace_bg", config->current_bar->colors.urgent_workspace_bg, argv[1]))) { | ||
3464 | return error; | ||
3465 | } | ||
3466 | |||
3467 | if ((error = add_color("urgent_workspace_text", config->current_bar->colors.urgent_workspace_text, argv[2]))) { | ||
3468 | return error; | ||
3469 | } | ||
3470 | |||
3471 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
3472 | } | ||
3473 | |||
3474 | static struct cmd_handler input_handlers[] = { | 262 | static struct cmd_handler input_handlers[] = { |
3475 | { "accel_profile", input_cmd_accel_profile }, | 263 | { "accel_profile", input_cmd_accel_profile }, |
3476 | { "click_method", input_cmd_click_method }, | 264 | { "click_method", input_cmd_click_method }, |
@@ -3514,7 +302,7 @@ static struct cmd_handler *find_handler(char *line, enum cmd_status block) { | |||
3514 | sizeof(bar_colors_handlers) / sizeof(struct cmd_handler), | 302 | sizeof(bar_colors_handlers) / sizeof(struct cmd_handler), |
3515 | sizeof(struct cmd_handler), handler_compare); | 303 | sizeof(struct cmd_handler), handler_compare); |
3516 | } else if (block == CMD_BLOCK_INPUT) { | 304 | } else if (block == CMD_BLOCK_INPUT) { |
3517 | sway_log(L_DEBUG, "lookng at input handlers"); | 305 | sway_log(L_DEBUG, "looking at input handlers"); |
3518 | res = bsearch(&d, input_handlers, | 306 | res = bsearch(&d, input_handlers, |
3519 | sizeof(input_handlers) / sizeof(struct cmd_handler), | 307 | sizeof(input_handlers) / sizeof(struct cmd_handler), |
3520 | sizeof(struct cmd_handler), handler_compare); | 308 | sizeof(struct cmd_handler), handler_compare); |