aboutsummaryrefslogtreecommitdiff
path: root/sway/commands/input.c
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-04-12 20:19:54 -0400
committerDrew DeVault <sir@cmpwn.com>2018-04-12 20:19:54 -0400
commitcd1b32453a9296c18b28bff71607aeb22987b5cd (patch)
treec653c6d525b471914c01a9d7ae543f521b6138ed /sway/commands/input.c
parent8e06985cc1b479724446fba752e0fecfb998e87b (diff)
parent5785170421dc38437acde8bb61068cd16fda716c (diff)
downloadsway-cd1b32453a9296c18b28bff71607aeb22987b5cd.tar.xz
Merge branch 'wlroots'
Diffstat (limited to 'sway/commands/input.c')
-rw-r--r--sway/commands/input.c100
1 files changed, 64 insertions, 36 deletions
diff --git a/sway/commands/input.c b/sway/commands/input.c
index ad53d272..fa9cf05a 100644
--- a/sway/commands/input.c
+++ b/sway/commands/input.c
@@ -1,7 +1,7 @@
#include <string.h>
#include <strings.h>
#include "sway/commands.h"
-#include "sway/input.h"
+#include "sway/input/input-manager.h"
#include "log.h"
struct cmd_results *cmd_input(int argc, char **argv) {
@@ -11,45 +11,73 @@ struct cmd_results *cmd_input(int argc, char **argv) {
}
if (config->reading && strcmp("{", argv[1]) == 0) {
- current_input_config = new_input_config(argv[0]);
- sway_log(L_DEBUG, "entering input block: %s", current_input_config->identifier);
+ free_input_config(config->handler_context.input_config);
+ config->handler_context.input_config = new_input_config(argv[0]);
+ if (!config->handler_context.input_config) {
+ return cmd_results_new(CMD_FAILURE, NULL, "Couldn't allocate config");
+ }
+ wlr_log(L_DEBUG, "entering input block: %s", argv[0]);
return cmd_results_new(CMD_BLOCK_INPUT, NULL, NULL);
}
- if (argc > 2) {
- int argc_new = argc-2;
- char **argv_new = argv+2;
-
- struct cmd_results *res;
- current_input_config = new_input_config(argv[0]);
- if (strcasecmp("accel_profile", argv[1]) == 0) {
- res = input_cmd_accel_profile(argc_new, argv_new);
- } else if (strcasecmp("click_method", argv[1]) == 0) {
- res = input_cmd_click_method(argc_new, argv_new);
- } else if (strcasecmp("drag_lock", argv[1]) == 0) {
- res = input_cmd_drag_lock(argc_new, argv_new);
- } else if (strcasecmp("dwt", argv[1]) == 0) {
- res = input_cmd_dwt(argc_new, argv_new);
- } else if (strcasecmp("events", argv[1]) == 0) {
- res = input_cmd_events(argc_new, argv_new);
- } else if (strcasecmp("left_handed", argv[1]) == 0) {
- res = input_cmd_left_handed(argc_new, argv_new);
- } else if (strcasecmp("middle_emulation", argv[1]) == 0) {
- res = input_cmd_middle_emulation(argc_new, argv_new);
- } else if (strcasecmp("natural_scroll", argv[1]) == 0) {
- res = input_cmd_natural_scroll(argc_new, argv_new);
- } else if (strcasecmp("pointer_accel", argv[1]) == 0) {
- res = input_cmd_pointer_accel(argc_new, argv_new);
- } else if (strcasecmp("scroll_method", argv[1]) == 0) {
- res = input_cmd_scroll_method(argc_new, argv_new);
- } else if (strcasecmp("tap", argv[1]) == 0) {
- res = input_cmd_tap(argc_new, argv_new);
- } else {
- res = cmd_results_new(CMD_INVALID, "input <device>", "Unknown command %s", argv[1]);
+ if ((error = checkarg(argc, "input", EXPECTED_AT_LEAST, 3))) {
+ return error;
+ }
+
+ bool has_context = (config->handler_context.input_config != NULL);
+ if (!has_context) {
+ // caller did not give a context so create one just for this command
+ config->handler_context.input_config = new_input_config(argv[0]);
+ if (!config->handler_context.input_config) {
+ return cmd_results_new(CMD_FAILURE, NULL, "Couldn't allocate config");
}
- current_input_config = NULL;
- return res;
}
- return cmd_results_new(CMD_BLOCK_INPUT, NULL, NULL);
+ int argc_new = argc-2;
+ char **argv_new = argv+2;
+
+ struct cmd_results *res;
+ if (strcasecmp("accel_profile", argv[1]) == 0) {
+ res = input_cmd_accel_profile(argc_new, argv_new);
+ } else if (strcasecmp("click_method", argv[1]) == 0) {
+ res = input_cmd_click_method(argc_new, argv_new);
+ } else if (strcasecmp("drag_lock", argv[1]) == 0) {
+ res = input_cmd_drag_lock(argc_new, argv_new);
+ } else if (strcasecmp("dwt", argv[1]) == 0) {
+ res = input_cmd_dwt(argc_new, argv_new);
+ } else if (strcasecmp("events", argv[1]) == 0) {
+ res = input_cmd_events(argc_new, argv_new);
+ } else if (strcasecmp("left_handed", argv[1]) == 0) {
+ res = input_cmd_left_handed(argc_new, argv_new);
+ } else if (strcasecmp("middle_emulation", argv[1]) == 0) {
+ res = input_cmd_middle_emulation(argc_new, argv_new);
+ } else if (strcasecmp("natural_scroll", argv[1]) == 0) {
+ res = input_cmd_natural_scroll(argc_new, argv_new);
+ } else if (strcasecmp("pointer_accel", argv[1]) == 0) {
+ res = input_cmd_pointer_accel(argc_new, argv_new);
+ } else if (strcasecmp("scroll_method", argv[1]) == 0) {
+ res = input_cmd_scroll_method(argc_new, argv_new);
+ } else if (strcasecmp("tap", argv[1]) == 0) {
+ res = input_cmd_tap(argc_new, argv_new);
+ } else if (strcasecmp("xkb_layout", argv[1]) == 0) {
+ res = input_cmd_xkb_layout(argc_new, argv_new);
+ } else if (strcasecmp("xkb_model", argv[1]) == 0) {
+ res = input_cmd_xkb_model(argc_new, argv_new);
+ } else if (strcasecmp("xkb_options", argv[1]) == 0) {
+ res = input_cmd_xkb_options(argc_new, argv_new);
+ } else if (strcasecmp("xkb_rules", argv[1]) == 0) {
+ res = input_cmd_xkb_rules(argc_new, argv_new);
+ } else if (strcasecmp("xkb_variant", argv[1]) == 0) {
+ res = input_cmd_xkb_variant(argc_new, argv_new);
+ } else {
+ res = cmd_results_new(CMD_INVALID, "input <device>", "Unknown command %s", argv[1]);
+ }
+
+ if (!has_context) {
+ // clean up the context we created earlier
+ free_input_config(config->handler_context.input_config);
+ config->handler_context.input_config = NULL;
+ }
+
+ return res;
}