From aa1c838f9733f9b5e90e8267a10e455790cd2642 Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Thu, 10 Jan 2019 11:47:34 -0500 Subject: seat_cmd_cursor: utilize mouse button helpers This modifies `seat_cmd_cursor` to utilize `get_mouse_button` when parsing mouse buttons for the `press` and `release` operations. All x11 buttons, button event names, and button event codes are supported. For x11 axis buttons, `dispatch_cursor_axis` is used instead of `dispatch_cursor_button`. However the `press`/`release` state is ignored and the either axis event is processed. This also removes support for `left` and `right` in favor of `BTN_LEFT` and `BTN_RIGHT`. --- sway/commands/seat/cursor.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) (limited to 'sway/commands/seat') diff --git a/sway/commands/seat/cursor.c b/sway/commands/seat/cursor.c index 1fbc68a1..8d9e426a 100644 --- a/sway/commands/seat/cursor.c +++ b/sway/commands/seat/cursor.c @@ -3,6 +3,7 @@ #include #include +#include #include "sway/commands.h" #include "sway/input/cursor.h" @@ -11,7 +12,7 @@ static struct cmd_results *press_or_release(struct sway_cursor *cursor, static const char *expected_syntax = "Expected 'cursor ' or " "'cursor ' or " - "'curor '"; + "'curor '"; static struct cmd_results *handle_command(struct sway_cursor *cursor, int argc, char **argv) { @@ -91,15 +92,35 @@ static struct cmd_results *press_or_release(struct sway_cursor *cursor, return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); } - if (strcasecmp(button_str, "left") == 0) { - button = BTN_LEFT; - } else if (strcasecmp(button_str, "right") == 0) { - button = BTN_RIGHT; - } else { - button = strtol(button_str, NULL, 10); - if (button == 0) { - return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); - } + char *message = NULL; + button = get_mouse_button(button_str, &message); + if (message) { + struct cmd_results *error = + cmd_results_new(CMD_INVALID, "cursor", message); + free(message); + return error; + } else if (button == SWAY_SCROLL_UP || button == SWAY_SCROLL_DOWN + || button == SWAY_SCROLL_LEFT || button == SWAY_SCROLL_RIGHT) { + // Dispatch axis event + enum wlr_axis_orientation orientation = + (button == SWAY_SCROLL_UP || button == SWAY_SCROLL_DOWN) + ? WLR_AXIS_ORIENTATION_VERTICAL + : WLR_AXIS_ORIENTATION_HORIZONTAL; + double delta = (button == SWAY_SCROLL_UP || button == SWAY_SCROLL_LEFT) + ? -1 : 1; + struct wlr_event_pointer_axis event = { + .device = NULL, + .time_msec = 0, + .source = WLR_AXIS_SOURCE_WHEEL, + .orientation = orientation, + .delta = delta * 15, + .delta_discrete = delta + }; + dispatch_cursor_axis(cursor, &event); + return cmd_results_new(CMD_SUCCESS, NULL, NULL); + } else if (!button) { + return cmd_results_new(CMD_INVALID, "curor", + "Unknown button %s", button_str); } dispatch_cursor_button(cursor, NULL, 0, button, state); return cmd_results_new(CMD_SUCCESS, NULL, NULL); -- cgit v1.2.3