From 4e6bd53abf900020bbc38ceddb7b7505be4fb96d Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Thu, 10 Jan 2019 12:45:52 -0500 Subject: input_cmd_scroll_button: utilize mouse btn helpers This modifies `input_cmd_scroll_button` to utilize the mouse button helper `get_mouse_button` when parsing the button. x11 axis buttons are not supported with this command and `CMD_INVALID` will be returned, but all other x11 buttons, button event names, and button event codes should be working --- sway/commands/input/scroll_button.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'sway/commands/input/scroll_button.c') diff --git a/sway/commands/input/scroll_button.c b/sway/commands/input/scroll_button.c index 1958f23c..d82a1fe1 100644 --- a/sway/commands/input/scroll_button.c +++ b/sway/commands/input/scroll_button.c @@ -1,9 +1,7 @@ -#include -#include -#include +#include #include "sway/config.h" #include "sway/commands.h" -#include "sway/input/input-manager.h" +#include "sway/input/cursor.h" struct cmd_results *input_cmd_scroll_button(int argc, char **argv) { struct cmd_results *error = NULL; @@ -16,22 +14,26 @@ struct cmd_results *input_cmd_scroll_button(int argc, char **argv) { "No input device defined."); } - errno = 0; - char *endptr; - int scroll_button = strtol(*argv, &endptr, 10); - if (endptr == *argv && scroll_button == 0) { - return cmd_results_new(CMD_INVALID, "scroll_button", - "Scroll button identifier must be an integer."); + if (strcmp(*argv, "disable") == 0) { + ic->scroll_button = 0; + return cmd_results_new(CMD_SUCCESS, NULL, NULL); } - if (errno == ERANGE) { + + char *message = NULL; + uint32_t button = get_mouse_button(*argv, &message); + if (message) { + error = cmd_results_new(CMD_INVALID, "scroll_button", message); + free(message); + return error; + } else if (button == SWAY_SCROLL_UP || button == SWAY_SCROLL_DOWN + || button == SWAY_SCROLL_LEFT || button == SWAY_SCROLL_RIGHT) { return cmd_results_new(CMD_INVALID, "scroll_button", - "Scroll button identifier out of range."); - } - if (scroll_button < 0) { + "X11 axis buttons are not supported for scroll_button"); + } else if (!button) { return cmd_results_new(CMD_INVALID, "scroll_button", - "Scroll button identifier cannot be negative."); + "Unknown button %s", *argv); } - ic->scroll_button = scroll_button; + ic->scroll_button = button; return cmd_results_new(CMD_SUCCESS, NULL, NULL); } -- cgit v1.2.3-54-g00ecf