aboutsummaryrefslogtreecommitdiff
path: root/sway/commands
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-07-13 04:07:11 -0700
committerGitHub <noreply@github.com>2018-07-13 04:07:11 -0700
commitbcdf04d79c28866d971dc968a2497f7d95ec1aae (patch)
tree874386abb337c953b60ee2efe0a799d9dfb010ee /sway/commands
parent683a307151764f7cad38ff12c4175e8e0cf94226 (diff)
parentf8bc928b2d3f5166e8d51422c07bc16ca35b0b83 (diff)
Merge pull request #2252 from rkubosz/scroll-button-option
feature: scroll button option for input devices
Diffstat (limited to 'sway/commands')
-rw-r--r--sway/commands/input.c1
-rw-r--r--sway/commands/input/scroll_button.c44
2 files changed, 45 insertions, 0 deletions
diff --git a/sway/commands/input.c b/sway/commands/input.c
index 574e1f8c..e7906b0e 100644
--- a/sway/commands/input.c
+++ b/sway/commands/input.c
@@ -20,6 +20,7 @@ static struct cmd_handler input_handlers[] = {
{ "pointer_accel", input_cmd_pointer_accel },
{ "repeat_delay", input_cmd_repeat_delay },
{ "repeat_rate", input_cmd_repeat_rate },
+ { "scroll_button", input_cmd_scroll_button },
{ "scroll_method", input_cmd_scroll_method },
{ "tap", input_cmd_tap },
{ "xkb_layout", input_cmd_xkb_layout },
diff --git a/sway/commands/input/scroll_button.c b/sway/commands/input/scroll_button.c
new file mode 100644
index 00000000..350fcca2
--- /dev/null
+++ b/sway/commands/input/scroll_button.c
@@ -0,0 +1,44 @@
+#include <string.h>
+#include <strings.h>
+#include <errno.h>
+#include "sway/config.h"
+#include "sway/commands.h"
+#include "sway/input/input-manager.h"
+
+struct cmd_results *input_cmd_scroll_button(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "scroll_button", EXPECTED_AT_LEAST, 1))) {
+ return error;
+ }
+ struct input_config *current_input_config =
+ config->handler_context.input_config;
+ if (!current_input_config) {
+ return cmd_results_new(CMD_FAILURE, "scroll_button",
+ "No input device defined.");
+ }
+ struct input_config *new_config =
+ new_input_config(current_input_config->identifier);
+
+ errno = 0;
+ char *endptr;
+ int scroll_button = strtol(*argv, &endptr, 10);
+ if (endptr == *argv && scroll_button == 0) {
+ free_input_config(new_config);
+ return cmd_results_new(CMD_INVALID, "scroll_button",
+ "Scroll button identifier must be an integer.");
+ }
+ if (errno == ERANGE) {
+ free_input_config(new_config);
+ return cmd_results_new(CMD_INVALID, "scroll_button",
+ "Scroll button identifier out of range.");
+ }
+ if (scroll_button < 0) {
+ free_input_config(new_config);
+ return cmd_results_new(CMD_INVALID, "scroll_button",
+ "Scroll button identifier cannot be negative.");
+ }
+ new_config->scroll_button = scroll_button;
+
+ apply_input_config(new_config);
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}