From c7a3a03115aa672b8abd1155e7e93e6328512326 Mon Sep 17 00:00:00 2001
From: ProgAndy <code@progandy.de>
Date: Sun, 22 Jul 2018 22:22:16 +0200
Subject: Add xkb_numlock/xkb_capslock commands (#2311)

---
 sway/commands/input.c | 2 ++
 1 file changed, 2 insertions(+)

(limited to 'sway/commands/input.c')

diff --git a/sway/commands/input.c b/sway/commands/input.c
index 5b203ea0..7f927073 100644
--- a/sway/commands/input.c
+++ b/sway/commands/input.c
@@ -24,8 +24,10 @@ static struct cmd_handler input_handlers[] = {
 	{ "scroll_method", input_cmd_scroll_method },
 	{ "tap", input_cmd_tap },
 	{ "tap_button_map", input_cmd_tap_button_map },
+	{ "xkb_capslock", input_cmd_xkb_capslock },
 	{ "xkb_layout", input_cmd_xkb_layout },
 	{ "xkb_model", input_cmd_xkb_model },
+	{ "xkb_numlock", input_cmd_xkb_numlock },
 	{ "xkb_options", input_cmd_xkb_options },
 	{ "xkb_rules", input_cmd_xkb_rules },
 	{ "xkb_variant", input_cmd_xkb_variant },
-- 
cgit v1.2.3


From 0ba52458abb8fb0414319d2084e6d0d0214ae304 Mon Sep 17 00:00:00 2001
From: ProgAndy <code@progandy.de>
Date: Wed, 25 Jul 2018 17:08:47 +0200
Subject: Restrict CapsLock and NumLock commands to the configuration file

---
 sway/commands/input.c | 23 ++++++++++++++++++++---
 sway/sway-input.5.scd |  8 ++++----
 2 files changed, 24 insertions(+), 7 deletions(-)

(limited to 'sway/commands/input.c')

diff --git a/sway/commands/input.c b/sway/commands/input.c
index 7f927073..84888fbb 100644
--- a/sway/commands/input.c
+++ b/sway/commands/input.c
@@ -24,15 +24,19 @@ static struct cmd_handler input_handlers[] = {
 	{ "scroll_method", input_cmd_scroll_method },
 	{ "tap", input_cmd_tap },
 	{ "tap_button_map", input_cmd_tap_button_map },
-	{ "xkb_capslock", input_cmd_xkb_capslock },
 	{ "xkb_layout", input_cmd_xkb_layout },
 	{ "xkb_model", input_cmd_xkb_model },
-	{ "xkb_numlock", input_cmd_xkb_numlock },
 	{ "xkb_options", input_cmd_xkb_options },
 	{ "xkb_rules", input_cmd_xkb_rules },
 	{ "xkb_variant", input_cmd_xkb_variant },
 };
 
+// must be in order for the bsearch
+static struct cmd_handler input_config_handlers[] = {
+	{ "xkb_capslock", input_cmd_xkb_capslock },
+	{ "xkb_numlock", input_cmd_xkb_numlock },
+};
+
 struct cmd_results *cmd_input(int argc, char **argv) {
 	struct cmd_results *error = NULL;
 	if ((error = checkarg(argc, "input", EXPECTED_AT_LEAST, 2))) {
@@ -46,8 +50,21 @@ struct cmd_results *cmd_input(int argc, char **argv) {
 		return cmd_results_new(CMD_FAILURE, NULL, "Couldn't allocate config");
 	}
 
-	struct cmd_results *res = config_subcommand(argv + 1, argc - 1,
+	struct cmd_results *res;
+
+	if (find_handler(argv[1], input_config_handlers,
+			sizeof(input_config_handlers))) {
+		if (config->reading) {
+			res = config_subcommand(argv + 1, argc - 1,
+				input_config_handlers, sizeof(input_config_handlers));
+		} else {
+			res = cmd_results_new(CMD_FAILURE, "input",
+				"Can only be used in config file.");
+		}
+	} else {
+		res = config_subcommand(argv + 1, argc - 1,
 			input_handlers, sizeof(input_handlers));
+	}
 
 	free_input_config(config->handler_context.input_config);
 	config->handler_context.input_config = NULL;
diff --git a/sway/sway-input.5.scd b/sway/sway-input.5.scd
index 372ca697..fa311971 100644
--- a/sway/sway-input.5.scd
+++ b/sway/sway-input.5.scd
@@ -33,13 +33,13 @@ For more information on these xkb configuration options, see
 *input* <identifier> xkb\_variant <variant>
 	Sets the variant of the keyboard like _dvorak_ or _colemak_.
 
+The following commands may only be used in the configuration file.
+
 *input* <identifier> xkb\_capslock enabled|disabled
-	Enables or disables CapsLock on sway startup, the default is disabled.
-	Only meaningful if sway controls the keyboard.
+	Initially enables or disables CapsLock, the default is disabled.
 
 *input* <identifier> xkb\_numlock enabled|disabled
-	Enables or disables NumLock on sway startup, the default is enabled.
-	Only meaningful if sway controls the keyboard.
+	Initially enables or disables NumLock, the default is enabled.
 
 ## MAPPING CONFIGURATION
 
-- 
cgit v1.2.3