diff options
author | Drew DeVault <sir@cmpwn.com> | 2019-01-13 20:40:42 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-13 20:40:42 -0500 |
commit | 9f9ef761753e11235c85c232e7521506cfea512d (patch) | |
tree | 1f391e6a4a1d7d6d8eef0dc894d4c165ba7fbdbd /sway/commands | |
parent | Merge pull request #3342 from RedSoxFan/scroll-buttons-improved (diff) | |
parent | seat_cmd_cursor: utilize mouse button helpers (diff) | |
download | sway-9f9ef761753e11235c85c232e7521506cfea512d.tar.gz sway-9f9ef761753e11235c85c232e7521506cfea512d.tar.zst sway-9f9ef761753e11235c85c232e7521506cfea512d.zip |
Merge pull request #3343 from RedSoxFan/seat-cursor-buttons-improved
Improve mouse button parsing: seat cursor buttons
Diffstat (limited to 'sway/commands')
-rw-r--r-- | sway/commands/seat/cursor.c | 41 |
1 files changed, 31 insertions, 10 deletions
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 @@ | |||
3 | 3 | ||
4 | #include <strings.h> | 4 | #include <strings.h> |
5 | #include <wlr/types/wlr_cursor.h> | 5 | #include <wlr/types/wlr_cursor.h> |
6 | #include <wlr/types/wlr_pointer.h> | ||
6 | #include "sway/commands.h" | 7 | #include "sway/commands.h" |
7 | #include "sway/input/cursor.h" | 8 | #include "sway/input/cursor.h" |
8 | 9 | ||
@@ -11,7 +12,7 @@ static struct cmd_results *press_or_release(struct sway_cursor *cursor, | |||
11 | 12 | ||
12 | static const char *expected_syntax = "Expected 'cursor <move> <x> <y>' or " | 13 | static const char *expected_syntax = "Expected 'cursor <move> <x> <y>' or " |
13 | "'cursor <set> <x> <y>' or " | 14 | "'cursor <set> <x> <y>' or " |
14 | "'curor <press|release> <left|right|1|2|3...>'"; | 15 | "'curor <press|release> <button[1-9]|event-name-or-code>'"; |
15 | 16 | ||
16 | static struct cmd_results *handle_command(struct sway_cursor *cursor, | 17 | static struct cmd_results *handle_command(struct sway_cursor *cursor, |
17 | int argc, char **argv) { | 18 | int argc, char **argv) { |
@@ -91,15 +92,35 @@ static struct cmd_results *press_or_release(struct sway_cursor *cursor, | |||
91 | return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); | 92 | return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); |
92 | } | 93 | } |
93 | 94 | ||
94 | if (strcasecmp(button_str, "left") == 0) { | 95 | char *message = NULL; |
95 | button = BTN_LEFT; | 96 | button = get_mouse_button(button_str, &message); |
96 | } else if (strcasecmp(button_str, "right") == 0) { | 97 | if (message) { |
97 | button = BTN_RIGHT; | 98 | struct cmd_results *error = |
98 | } else { | 99 | cmd_results_new(CMD_INVALID, "cursor", message); |
99 | button = strtol(button_str, NULL, 10); | 100 | free(message); |
100 | if (button == 0) { | 101 | return error; |
101 | return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); | 102 | } else if (button == SWAY_SCROLL_UP || button == SWAY_SCROLL_DOWN |
102 | } | 103 | || button == SWAY_SCROLL_LEFT || button == SWAY_SCROLL_RIGHT) { |
104 | // Dispatch axis event | ||
105 | enum wlr_axis_orientation orientation = | ||
106 | (button == SWAY_SCROLL_UP || button == SWAY_SCROLL_DOWN) | ||
107 | ? WLR_AXIS_ORIENTATION_VERTICAL | ||
108 | : WLR_AXIS_ORIENTATION_HORIZONTAL; | ||
109 | double delta = (button == SWAY_SCROLL_UP || button == SWAY_SCROLL_LEFT) | ||
110 | ? -1 : 1; | ||
111 | struct wlr_event_pointer_axis event = { | ||
112 | .device = NULL, | ||
113 | .time_msec = 0, | ||
114 | .source = WLR_AXIS_SOURCE_WHEEL, | ||
115 | .orientation = orientation, | ||
116 | .delta = delta * 15, | ||
117 | .delta_discrete = delta | ||
118 | }; | ||
119 | dispatch_cursor_axis(cursor, &event); | ||
120 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
121 | } else if (!button) { | ||
122 | return cmd_results_new(CMD_INVALID, "curor", | ||
123 | "Unknown button %s", button_str); | ||
103 | } | 124 | } |
104 | dispatch_cursor_button(cursor, NULL, 0, button, state); | 125 | dispatch_cursor_button(cursor, NULL, 0, button, state); |
105 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 126 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |