aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/input
diff options
context:
space:
mode:
authorLibravatar ProgAndy <code@progandy.de>2018-07-22 22:22:16 +0200
committerLibravatar ProgAndy <code@progandy.de>2018-07-25 17:24:45 +0200
commitc7a3a03115aa672b8abd1155e7e93e6328512326 (patch)
treeea159dfc896a2aa106afe0a26589f58bd060981b /sway/commands/input
parentImplement setting NumLock and CapsLock status (diff)
downloadsway-c7a3a03115aa672b8abd1155e7e93e6328512326.tar.gz
sway-c7a3a03115aa672b8abd1155e7e93e6328512326.tar.zst
sway-c7a3a03115aa672b8abd1155e7e93e6328512326.zip
Add xkb_numlock/xkb_capslock commands (#2311)
Diffstat (limited to 'sway/commands/input')
-rw-r--r--sway/commands/input/xkb_capslock.c33
-rw-r--r--sway/commands/input/xkb_numlock.c33
2 files changed, 66 insertions, 0 deletions
diff --git a/sway/commands/input/xkb_capslock.c b/sway/commands/input/xkb_capslock.c
new file mode 100644
index 00000000..5442c463
--- /dev/null
+++ b/sway/commands/input/xkb_capslock.c
@@ -0,0 +1,33 @@
1#include <string.h>
2#include <strings.h>
3#include "sway/config.h"
4#include "sway/commands.h"
5#include "sway/input/input-manager.h"
6
7struct cmd_results *input_cmd_xkb_capslock(int argc, char **argv) {
8 struct cmd_results *error = NULL;
9 if ((error = checkarg(argc, "xkb_capslock", EXPECTED_AT_LEAST, 1))) {
10 return error;
11 }
12 struct input_config *current_input_config =
13 config->handler_context.input_config;
14 if (!current_input_config) {
15 return cmd_results_new(CMD_FAILURE, "xkb_capslock",
16 "No input device defined.");
17 }
18 struct input_config *new_config =
19 new_input_config(current_input_config->identifier);
20
21 if (strcasecmp(argv[0], "enabled") == 0) {
22 new_config->xkb_capslock = 1;
23 } else if (strcasecmp(argv[0], "disabled") == 0) {
24 new_config->xkb_capslock = 0;
25 } else {
26 free_input_config(new_config);
27 return cmd_results_new(CMD_INVALID, "xkb_capslock",
28 "Expected 'xkb_capslock <enabled|disabled>'");
29 }
30
31 apply_input_config(new_config);
32 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
33}
diff --git a/sway/commands/input/xkb_numlock.c b/sway/commands/input/xkb_numlock.c
new file mode 100644
index 00000000..39675366
--- /dev/null
+++ b/sway/commands/input/xkb_numlock.c
@@ -0,0 +1,33 @@
1#include <string.h>
2#include <strings.h>
3#include "sway/config.h"
4#include "sway/commands.h"
5#include "sway/input/input-manager.h"
6
7struct cmd_results *input_cmd_xkb_numlock(int argc, char **argv) {
8 struct cmd_results *error = NULL;
9 if ((error = checkarg(argc, "xkb_numlock", EXPECTED_AT_LEAST, 1))) {
10 return error;
11 }
12 struct input_config *current_input_config =
13 config->handler_context.input_config;
14 if (!current_input_config) {
15 return cmd_results_new(CMD_FAILURE, "xkb_numlock",
16 "No input device defined.");
17 }
18 struct input_config *new_config =
19 new_input_config(current_input_config->identifier);
20
21 if (strcasecmp(argv[0], "enabled") == 0) {
22 new_config->xkb_numlock = 1;
23 } else if (strcasecmp(argv[0], "disabled") == 0) {
24 new_config->xkb_numlock = 0;
25 } else {
26 free_input_config(new_config);
27 return cmd_results_new(CMD_INVALID, "xkb_numlock",
28 "Expected 'xkb_numlock <enabled|disabled>'");
29 }
30
31 apply_input_config(new_config);
32 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
33}