From a78a5684ea8a19e54d797ab6cddd2f81f88360a5 Mon Sep 17 00:00:00 2001 From: frsfnrrg Date: Sun, 27 May 2018 12:37:18 -0400 Subject: Implement bindsym/bindcode --locked Adds the --locked flag to bindsym and bindcode commands. When a keyboard's associated seat has an exclusive client (i.e, a screenlocker), then bindings are only executed if they have the locked flag. When there is no such client, this restriction is lifted. --- sway/commands/bind.c | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) (limited to 'sway/commands') diff --git a/sway/commands/bind.c b/sway/commands/bind.c index cbabb07b..c6b3368a 100644 --- a/sway/commands/bind.c +++ b/sway/commands/bind.c @@ -83,20 +83,26 @@ struct cmd_results *cmd_bindsym(int argc, char **argv) { binding->keys = create_list(); binding->modifiers = 0; binding->release = false; + binding->locked = false; binding->bindcode = false; - // Handle --release - if (strcmp("--release", argv[0]) == 0) { - if (argc >= 3) { + // Handle --release and --locked + while (argc > 0) { + if (strcmp("--release", argv[0]) == 0) { binding->release = true; - argv++; - argc--; + } else if (strcmp("--locked", argv[0]) == 0) { + binding->locked = true; } else { - free_sway_binding(binding); - return cmd_results_new(CMD_FAILURE, "bindsym", - "Invalid bindsym command " - "(expected more than 2 arguments, got %d)", argc); + break; } + argv++; + argc--; + } + if (argc < 2) { + free_sway_binding(binding); + return cmd_results_new(CMD_FAILURE, "bindsym", + "Invalid bindsym command " + "(expected at least 2 non-option arguments, got %d)", argc); } binding->command = join_args(argv + 1, argc - 1); @@ -176,20 +182,26 @@ struct cmd_results *cmd_bindcode(int argc, char **argv) { binding->keys = create_list(); binding->modifiers = 0; binding->release = false; + binding->locked = false; binding->bindcode = true; - // Handle --release - if (strcmp("--release", argv[0]) == 0) { - if (argc >= 3) { + // Handle --release and --locked + while (argc > 0) { + if (strcmp("--release", argv[0]) == 0) { binding->release = true; - argv++; - argc--; + } else if (strcmp("--locked", argv[0]) == 0) { + binding->locked = true; } else { - free_sway_binding(binding); - return cmd_results_new(CMD_FAILURE, "bindcode", - "Invalid bindcode command " - "(expected more than 2 arguments, got %d)", argc); + break; } + argv++; + argc--; + } + if (argc < 2) { + free_sway_binding(binding); + return cmd_results_new(CMD_FAILURE, "bindcode", + "Invalid bindcode command " + "(expected at least 2 non-option arguments, got %d)", argc); } binding->command = join_args(argv + 1, argc - 1); -- cgit v1.2.3