aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands.c')
-rw-r--r--sway/commands.c47
1 files changed, 28 insertions, 19 deletions
diff --git a/sway/commands.c b/sway/commands.c
index 5b20857a..fdae1961 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -98,12 +98,18 @@ static struct cmd_handler handlers[] = {
98 { "client.unfocused", cmd_client_unfocused }, 98 { "client.unfocused", cmd_client_unfocused },
99 { "client.urgent", cmd_client_urgent }, 99 { "client.urgent", cmd_client_urgent },
100 { "default_border", cmd_default_border }, 100 { "default_border", cmd_default_border },
101 { "default_floating_border", cmd_default_floating_border },
101 { "exec", cmd_exec }, 102 { "exec", cmd_exec },
102 { "exec_always", cmd_exec_always }, 103 { "exec_always", cmd_exec_always },
104 { "floating_maximum_size", cmd_floating_maximum_size },
105 { "floating_minimum_size", cmd_floating_minimum_size },
106 { "floating_modifier", cmd_floating_modifier },
107 { "focus", cmd_focus },
103 { "focus_follows_mouse", cmd_focus_follows_mouse }, 108 { "focus_follows_mouse", cmd_focus_follows_mouse },
104 { "focus_wrapping", cmd_focus_wrapping }, 109 { "focus_wrapping", cmd_focus_wrapping },
105 { "font", cmd_font }, 110 { "font", cmd_font },
106 { "for_window", cmd_for_window }, 111 { "for_window", cmd_for_window },
112 { "force_display_urgency_hint", cmd_force_display_urgency_hint },
107 { "force_focus_wrapping", cmd_force_focus_wrapping }, 113 { "force_focus_wrapping", cmd_force_focus_wrapping },
108 { "fullscreen", cmd_fullscreen }, 114 { "fullscreen", cmd_fullscreen },
109 { "gaps", cmd_gaps }, 115 { "gaps", cmd_gaps },
@@ -112,6 +118,7 @@ static struct cmd_handler handlers[] = {
112 { "input", cmd_input }, 118 { "input", cmd_input },
113 { "mode", cmd_mode }, 119 { "mode", cmd_mode },
114 { "mouse_warping", cmd_mouse_warping }, 120 { "mouse_warping", cmd_mouse_warping },
121 { "no_focus", cmd_no_focus },
115 { "output", cmd_output }, 122 { "output", cmd_output },
116 { "seat", cmd_seat }, 123 { "seat", cmd_seat },
117 { "set", cmd_set }, 124 { "set", cmd_set },
@@ -133,7 +140,6 @@ static struct cmd_handler command_handlers[] = {
133 { "border", cmd_border }, 140 { "border", cmd_border },
134 { "exit", cmd_exit }, 141 { "exit", cmd_exit },
135 { "floating", cmd_floating }, 142 { "floating", cmd_floating },
136 { "focus", cmd_focus },
137 { "fullscreen", cmd_fullscreen }, 143 { "fullscreen", cmd_fullscreen },
138 { "kill", cmd_kill }, 144 { "kill", cmd_kill },
139 { "layout", cmd_layout }, 145 { "layout", cmd_layout },
@@ -143,6 +149,7 @@ static struct cmd_handler command_handlers[] = {
143 { "reload", cmd_reload }, 149 { "reload", cmd_reload },
144 { "rename", cmd_rename }, 150 { "rename", cmd_rename },
145 { "resize", cmd_resize }, 151 { "resize", cmd_resize },
152 { "scratchpad", cmd_scratchpad },
146 { "split", cmd_split }, 153 { "split", cmd_split },
147 { "splith", cmd_splith }, 154 { "splith", cmd_splith },
148 { "splitt", cmd_splitt }, 155 { "splitt", cmd_splitt },
@@ -151,6 +158,7 @@ static struct cmd_handler command_handlers[] = {
151 { "swap", cmd_swap }, 158 { "swap", cmd_swap },
152 { "title_format", cmd_title_format }, 159 { "title_format", cmd_title_format },
153 { "unmark", cmd_unmark }, 160 { "unmark", cmd_unmark },
161 { "urgent", cmd_urgent },
154}; 162};
155 163
156static int handler_compare(const void *_a, const void *_b) { 164static int handler_compare(const void *_a, const void *_b) {
@@ -163,7 +171,7 @@ struct cmd_handler *find_handler(char *line, struct cmd_handler *cmd_handlers,
163 int handlers_size) { 171 int handlers_size) {
164 struct cmd_handler d = { .command=line }; 172 struct cmd_handler d = { .command=line };
165 struct cmd_handler *res = NULL; 173 struct cmd_handler *res = NULL;
166 wlr_log(L_DEBUG, "find_handler(%s)", line); 174 wlr_log(WLR_DEBUG, "find_handler(%s)", line);
167 175
168 bool config_loading = config->reading || !config->active; 176 bool config_loading = config->reading || !config->active;
169 177
@@ -248,10 +256,10 @@ struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) {
248 cmd = argsep(&cmdlist, ","); 256 cmd = argsep(&cmdlist, ",");
249 cmd += strspn(cmd, whitespace); 257 cmd += strspn(cmd, whitespace);
250 if (strcmp(cmd, "") == 0) { 258 if (strcmp(cmd, "") == 0) {
251 wlr_log(L_INFO, "Ignoring empty command."); 259 wlr_log(WLR_INFO, "Ignoring empty command.");
252 continue; 260 continue;
253 } 261 }
254 wlr_log(L_INFO, "Handling command '%s'", cmd); 262 wlr_log(WLR_INFO, "Handling command '%s'", cmd);
255 //TODO better handling of argv 263 //TODO better handling of argv
256 int argc; 264 int argc;
257 char **argv = split_args(cmd, &argc); 265 char **argv = split_args(cmd, &argc);
@@ -319,7 +327,7 @@ struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) {
319 } while(head); 327 } while(head);
320cleanup: 328cleanup:
321 free(exec); 329 free(exec);
322 free(views); 330 list_free(views);
323 if (!results) { 331 if (!results) {
324 results = cmd_results_new(CMD_SUCCESS, NULL, NULL); 332 results = cmd_results_new(CMD_SUCCESS, NULL, NULL);
325 } 333 }
@@ -344,7 +352,7 @@ struct cmd_results *config_command(char *exec) {
344 352
345 // Start block 353 // Start block
346 if (argc > 1 && strcmp(argv[argc - 1], "{") == 0) { 354 if (argc > 1 && strcmp(argv[argc - 1], "{") == 0) {
347 char *block = join_args(argv, argc - 1); 355 char *block = join_args(argv, argc - 1);
348 results = cmd_results_new(CMD_BLOCK, block, NULL); 356 results = cmd_results_new(CMD_BLOCK, block, NULL);
349 free(block); 357 free(block);
350 goto cleanup; 358 goto cleanup;
@@ -355,7 +363,7 @@ struct cmd_results *config_command(char *exec) {
355 results = cmd_results_new(CMD_BLOCK_END, NULL, NULL); 363 results = cmd_results_new(CMD_BLOCK_END, NULL, NULL);
356 goto cleanup; 364 goto cleanup;
357 } 365 }
358 wlr_log(L_INFO, "handling config command '%s'", exec); 366 wlr_log(WLR_INFO, "handling config command '%s'", exec);
359 struct cmd_handler *handler = find_handler(argv[0], NULL, 0); 367 struct cmd_handler *handler = find_handler(argv[0], NULL, 0);
360 if (!handler) { 368 if (!handler) {
361 char *input = argv[0] ? argv[0] : "(empty)"; 369 char *input = argv[0] ? argv[0] : "(empty)";
@@ -388,7 +396,7 @@ cleanup:
388struct cmd_results *config_subcommand(char **argv, int argc, 396struct cmd_results *config_subcommand(char **argv, int argc,
389 struct cmd_handler *handlers, size_t handlers_size) { 397 struct cmd_handler *handlers, size_t handlers_size) {
390 char *command = join_args(argv, argc); 398 char *command = join_args(argv, argc);
391 wlr_log(L_DEBUG, "Subcommand: %s", command); 399 wlr_log(WLR_DEBUG, "Subcommand: %s", command);
392 free(command); 400 free(command);
393 401
394 struct cmd_handler *handler = find_handler(argv[0], handlers, 402 struct cmd_handler *handler = find_handler(argv[0], handlers,
@@ -428,8 +436,7 @@ struct cmd_results *config_commands_command(char *exec) {
428 436
429 struct cmd_handler *handler = find_handler(cmd, NULL, 0); 437 struct cmd_handler *handler = find_handler(cmd, NULL, 0);
430 if (!handler && strcmp(cmd, "*") != 0) { 438 if (!handler && strcmp(cmd, "*") != 0) {
431 char *input = cmd ? cmd : "(empty)"; 439 results = cmd_results_new(CMD_INVALID, cmd, "Unknown/invalid command");
432 results = cmd_results_new(CMD_INVALID, input, "Unknown/invalid command");
433 goto cleanup; 440 goto cleanup;
434 } 441 }
435 442
@@ -471,14 +478,16 @@ struct cmd_results *config_commands_command(char *exec) {
471 } 478 }
472 if (!policy) { 479 if (!policy) {
473 policy = alloc_command_policy(cmd); 480 policy = alloc_command_policy(cmd);
474 sway_assert(policy, "Unable to allocate security policy"); 481 if (!sway_assert(policy, "Unable to allocate security policy")) {
475 if (policy) { 482 results = cmd_results_new(CMD_INVALID, cmd,
476 list_add(config->command_policies, policy); 483 "Unable to allocate memory");
484 goto cleanup;
477 } 485 }
486 list_add(config->command_policies, policy);
478 } 487 }
479 policy->context = context; 488 policy->context = context;
480 489
481 wlr_log(L_INFO, "Set command policy for %s to %d", 490 wlr_log(WLR_INFO, "Set command policy for %s to %d",
482 policy->command, policy->context); 491 policy->command, policy->context);
483 492
484 results = cmd_results_new(CMD_SUCCESS, NULL, NULL); 493 results = cmd_results_new(CMD_SUCCESS, NULL, NULL);
@@ -492,7 +501,7 @@ struct cmd_results *cmd_results_new(enum cmd_status status,
492 const char *input, const char *format, ...) { 501 const char *input, const char *format, ...) {
493 struct cmd_results *results = malloc(sizeof(struct cmd_results)); 502 struct cmd_results *results = malloc(sizeof(struct cmd_results));
494 if (!results) { 503 if (!results) {
495 wlr_log(L_ERROR, "Unable to allocate command results"); 504 wlr_log(WLR_ERROR, "Unable to allocate command results");
496 return NULL; 505 return NULL;
497 } 506 }
498 results->status = status; 507 results->status = status;
@@ -526,7 +535,7 @@ void free_cmd_results(struct cmd_results *results) {
526 free(results); 535 free(results);
527} 536}
528 537
529const char *cmd_results_to_json(struct cmd_results *results) { 538char *cmd_results_to_json(struct cmd_results *results) {
530 json_object *result_array = json_object_new_array(); 539 json_object *result_array = json_object_new_array();
531 json_object *root = json_object_new_object(); 540 json_object *root = json_object_new_object();
532 json_object_object_add(root, "success", 541 json_object_object_add(root, "success",
@@ -541,9 +550,9 @@ const char *cmd_results_to_json(struct cmd_results *results) {
541 } 550 }
542 json_object_array_add(result_array, root); 551 json_object_array_add(result_array, root);
543 const char *json = json_object_to_json_string(result_array); 552 const char *json = json_object_to_json_string(result_array);
544 free(result_array); 553 char *res = strdup(json);
545 free(root); 554 json_object_put(result_array);
546 return json; 555 return res;
547} 556}
548 557
549/** 558/**