diff options
Diffstat (limited to 'sway/commands.c')
-rw-r--r-- | sway/commands.c | 53 |
1 files changed, 14 insertions, 39 deletions
diff --git a/sway/commands.c b/sway/commands.c index b09a04c7..8d003dfa 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -1,4 +1,3 @@ | |||
1 | #define _POSIX_C_SOURCE 200809 | ||
2 | #include <ctype.h> | 1 | #include <ctype.h> |
3 | #include <stdarg.h> | 2 | #include <stdarg.h> |
4 | #include <stdlib.h> | 3 | #include <stdlib.h> |
@@ -46,11 +45,13 @@ static const struct cmd_handler handlers[] = { | |||
46 | { "assign", cmd_assign }, | 45 | { "assign", cmd_assign }, |
47 | { "bar", cmd_bar }, | 46 | { "bar", cmd_bar }, |
48 | { "bindcode", cmd_bindcode }, | 47 | { "bindcode", cmd_bindcode }, |
48 | { "bindgesture", cmd_bindgesture }, | ||
49 | { "bindswitch", cmd_bindswitch }, | 49 | { "bindswitch", cmd_bindswitch }, |
50 | { "bindsym", cmd_bindsym }, | 50 | { "bindsym", cmd_bindsym }, |
51 | { "client.background", cmd_client_noop }, | 51 | { "client.background", cmd_client_noop }, |
52 | { "client.focused", cmd_client_focused }, | 52 | { "client.focused", cmd_client_focused }, |
53 | { "client.focused_inactive", cmd_client_focused_inactive }, | 53 | { "client.focused_inactive", cmd_client_focused_inactive }, |
54 | { "client.focused_tab_title", cmd_client_focused_tab_title }, | ||
54 | { "client.placeholder", cmd_client_noop }, | 55 | { "client.placeholder", cmd_client_noop }, |
55 | { "client.unfocused", cmd_client_unfocused }, | 56 | { "client.unfocused", cmd_client_unfocused }, |
56 | { "client.urgent", cmd_client_urgent }, | 57 | { "client.urgent", cmd_client_urgent }, |
@@ -91,6 +92,7 @@ static const struct cmd_handler handlers[] = { | |||
91 | { "titlebar_border_thickness", cmd_titlebar_border_thickness }, | 92 | { "titlebar_border_thickness", cmd_titlebar_border_thickness }, |
92 | { "titlebar_padding", cmd_titlebar_padding }, | 93 | { "titlebar_padding", cmd_titlebar_padding }, |
93 | { "unbindcode", cmd_unbindcode }, | 94 | { "unbindcode", cmd_unbindcode }, |
95 | { "unbindgesture", cmd_unbindgesture }, | ||
94 | { "unbindswitch", cmd_unbindswitch }, | 96 | { "unbindswitch", cmd_unbindswitch }, |
95 | { "unbindsym", cmd_unbindsym }, | 97 | { "unbindsym", cmd_unbindsym }, |
96 | { "workspace", cmd_workspace }, | 98 | { "workspace", cmd_workspace }, |
@@ -101,6 +103,7 @@ static const struct cmd_handler handlers[] = { | |||
101 | static const struct cmd_handler config_handlers[] = { | 103 | static const struct cmd_handler config_handlers[] = { |
102 | { "default_orientation", cmd_default_orientation }, | 104 | { "default_orientation", cmd_default_orientation }, |
103 | { "include", cmd_include }, | 105 | { "include", cmd_include }, |
106 | { "primary_selection", cmd_primary_selection }, | ||
104 | { "swaybg_command", cmd_swaybg_command }, | 107 | { "swaybg_command", cmd_swaybg_command }, |
105 | { "swaynag_command", cmd_swaynag_command }, | 108 | { "swaynag_command", cmd_swaynag_command }, |
106 | { "workspace_layout", cmd_workspace_layout }, | 109 | { "workspace_layout", cmd_workspace_layout }, |
@@ -144,7 +147,7 @@ static int handler_compare(const void *_a, const void *_b) { | |||
144 | return strcasecmp(a->command, b->command); | 147 | return strcasecmp(a->command, b->command); |
145 | } | 148 | } |
146 | 149 | ||
147 | const struct cmd_handler *find_handler(char *line, | 150 | const struct cmd_handler *find_handler(const char *line, |
148 | const struct cmd_handler *handlers, size_t handlers_size) { | 151 | const struct cmd_handler *handlers, size_t handlers_size) { |
149 | if (!handlers || !handlers_size) { | 152 | if (!handlers || !handlers_size) { |
150 | return NULL; | 153 | return NULL; |
@@ -377,10 +380,13 @@ struct cmd_results *config_command(char *exec, char **new_block) { | |||
377 | sway_log(SWAY_INFO, "Config command: %s", exec); | 380 | sway_log(SWAY_INFO, "Config command: %s", exec); |
378 | const struct cmd_handler *handler = find_core_handler(argv[0]); | 381 | const struct cmd_handler *handler = find_core_handler(argv[0]); |
379 | if (!handler || !handler->handle) { | 382 | if (!handler || !handler->handle) { |
380 | const char *error = handler | 383 | if (handler) { |
381 | ? "Command '%s' is shimmed, but unimplemented" | 384 | results = cmd_results_new(CMD_INVALID, |
382 | : "Unknown/invalid command '%s'"; | 385 | "Command '%s' is shimmed, but unimplemented", argv[0]); |
383 | results = cmd_results_new(CMD_INVALID, error, argv[0]); | 386 | } else { |
387 | results = cmd_results_new(CMD_INVALID, | ||
388 | "Unknown/invalid command '%s'", argv[0]); | ||
389 | } | ||
384 | goto cleanup; | 390 | goto cleanup; |
385 | } | 391 | } |
386 | 392 | ||
@@ -406,6 +412,7 @@ struct cmd_results *config_command(char *exec, char **new_block) { | |||
406 | && handler->handle != cmd_bindsym | 412 | && handler->handle != cmd_bindsym |
407 | && handler->handle != cmd_bindcode | 413 | && handler->handle != cmd_bindcode |
408 | && handler->handle != cmd_bindswitch | 414 | && handler->handle != cmd_bindswitch |
415 | && handler->handle != cmd_bindgesture | ||
409 | && handler->handle != cmd_set | 416 | && handler->handle != cmd_set |
410 | && handler->handle != cmd_for_window | 417 | && handler->handle != cmd_for_window |
411 | && (*argv[i] == '\"' || *argv[i] == '\'')) { | 418 | && (*argv[i] == '\"' || *argv[i] == '\'')) { |
@@ -465,34 +472,6 @@ struct cmd_results *config_commands_command(char *exec) { | |||
465 | goto cleanup; | 472 | goto cleanup; |
466 | } | 473 | } |
467 | 474 | ||
468 | enum command_context context = 0; | ||
469 | |||
470 | struct { | ||
471 | char *name; | ||
472 | enum command_context context; | ||
473 | } context_names[] = { | ||
474 | { "config", CONTEXT_CONFIG }, | ||
475 | { "binding", CONTEXT_BINDING }, | ||
476 | { "ipc", CONTEXT_IPC }, | ||
477 | { "criteria", CONTEXT_CRITERIA }, | ||
478 | { "all", CONTEXT_ALL }, | ||
479 | }; | ||
480 | |||
481 | for (int i = 1; i < argc; ++i) { | ||
482 | size_t j; | ||
483 | for (j = 0; j < sizeof(context_names) / sizeof(context_names[0]); ++j) { | ||
484 | if (strcmp(context_names[j].name, argv[i]) == 0) { | ||
485 | break; | ||
486 | } | ||
487 | } | ||
488 | if (j == sizeof(context_names) / sizeof(context_names[0])) { | ||
489 | results = cmd_results_new(CMD_INVALID, | ||
490 | "Invalid command context %s", argv[i]); | ||
491 | goto cleanup; | ||
492 | } | ||
493 | context |= context_names[j].context; | ||
494 | } | ||
495 | |||
496 | results = cmd_results_new(CMD_SUCCESS, NULL); | 475 | results = cmd_results_new(CMD_SUCCESS, NULL); |
497 | 476 | ||
498 | cleanup: | 477 | cleanup: |
@@ -509,14 +488,10 @@ struct cmd_results *cmd_results_new(enum cmd_status status, | |||
509 | } | 488 | } |
510 | results->status = status; | 489 | results->status = status; |
511 | if (format) { | 490 | if (format) { |
512 | char *error = malloc(256); | ||
513 | va_list args; | 491 | va_list args; |
514 | va_start(args, format); | 492 | va_start(args, format); |
515 | if (error) { | 493 | results->error = vformat_str(format, args); |
516 | vsnprintf(error, 256, format, args); | ||
517 | } | ||
518 | va_end(args); | 494 | va_end(args); |
519 | results->error = error; | ||
520 | } else { | 495 | } else { |
521 | results->error = NULL; | 496 | results->error = NULL; |
522 | } | 497 | } |