aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2019-01-13 20:40:42 -0500
committerLibravatar GitHub <noreply@github.com>2019-01-13 20:40:42 -0500
commit9f9ef761753e11235c85c232e7521506cfea512d (patch)
tree1f391e6a4a1d7d6d8eef0dc894d4c165ba7fbdbd
parentMerge pull request #3342 from RedSoxFan/scroll-buttons-improved (diff)
parentseat_cmd_cursor: utilize mouse button helpers (diff)
downloadsway-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
-rw-r--r--include/sway/input/cursor.h3
-rw-r--r--sway/commands/seat/cursor.c41
-rw-r--r--sway/input/cursor.c11
-rw-r--r--sway/sway-input.5.scd13
-rw-r--r--sway/sway.5.scd9
5 files changed, 54 insertions, 23 deletions
diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h
index 9f699dcd..77aa0ea1 100644
--- a/include/sway/input/cursor.h
+++ b/include/sway/input/cursor.h
@@ -80,6 +80,9 @@ void dispatch_cursor_button(struct sway_cursor *cursor,
80 struct wlr_input_device *device, uint32_t time_msec, uint32_t button, 80 struct wlr_input_device *device, uint32_t time_msec, uint32_t button,
81 enum wlr_button_state state); 81 enum wlr_button_state state);
82 82
83void dispatch_cursor_axis(struct sway_cursor *cursor,
84 struct wlr_event_pointer_axis *event);
85
83void cursor_set_image(struct sway_cursor *cursor, const char *image, 86void cursor_set_image(struct sway_cursor *cursor, const char *image,
84 struct wl_client *client); 87 struct wl_client *client);
85 88
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
12static const char *expected_syntax = "Expected 'cursor <move> <x> <y>' or " 13static 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
16static struct cmd_results *handle_command(struct sway_cursor *cursor, 17static 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);
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index c65548c3..08222494 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -716,11 +716,13 @@ static uint32_t wl_axis_to_button(struct wlr_event_pointer_axis *event) {
716 } 716 }
717} 717}
718 718
719static void dispatch_cursor_axis(struct sway_cursor *cursor, 719void dispatch_cursor_axis(struct sway_cursor *cursor,
720 struct wlr_event_pointer_axis *event) { 720 struct wlr_event_pointer_axis *event) {
721 struct sway_seat *seat = cursor->seat; 721 struct sway_seat *seat = cursor->seat;
722 struct sway_input_device *input_device = event->device->data; 722 struct sway_input_device *input_device =
723 struct input_config *ic = input_device_get_config(input_device); 723 event->device ? event->device->data : NULL;
724 struct input_config *ic =
725 input_device ? input_device_get_config(input_device) : NULL;
724 726
725 // Determine what's under the cursor 727 // Determine what's under the cursor
726 struct wlr_surface *surface = NULL; 728 struct wlr_surface *surface = NULL;
@@ -743,7 +745,8 @@ static void dispatch_cursor_axis(struct sway_cursor *cursor,
743 // Gather information needed for mouse bindings 745 // Gather information needed for mouse bindings
744 struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->wlr_seat); 746 struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->wlr_seat);
745 uint32_t modifiers = keyboard ? wlr_keyboard_get_modifiers(keyboard) : 0; 747 uint32_t modifiers = keyboard ? wlr_keyboard_get_modifiers(keyboard) : 0;
746 struct wlr_input_device *device = input_device->wlr_device; 748 struct wlr_input_device *device =
749 input_device ? input_device->wlr_device : NULL;
747 char *dev_id = device ? input_device_get_identifier(device) : strdup("*"); 750 char *dev_id = device ? input_device_get_identifier(device) : strdup("*");
748 uint32_t button = wl_axis_to_button(event); 751 uint32_t button = wl_axis_to_button(event);
749 752
diff --git a/sway/sway-input.5.scd b/sway/sway-input.5.scd
index 7d1a7169..c2673f2a 100644
--- a/sway/sway-input.5.scd
+++ b/sway/sway-input.5.scd
@@ -145,6 +145,19 @@ in their own "seat").
145 Attach an input device to this seat by its input identifier. A special 145 Attach an input device to this seat by its input identifier. A special
146 value of "\*" will attach all devices to the seat. 146 value of "\*" will attach all devices to the seat.
147 147
148*seat* <seat> cursor move|set <x> <y>
149 Move specified seat's cursor relative to current position or wrap to
150 absolute coordinates (with respect to the global coordinate space).
151 Specifying either value as 0 will not update that coordinate.
152
153*seat* <seat> cursor press|release button[1-9]|<event-name-or-code>
154 Simulate pressing (or releasing) the specified mouse button on the
155 specified seat. The button can either be provided as a button event name or
156 event code, which can be obtained from `libinput debug-events`, or as an x11
157 mouse button (button[1-9]). If using button[4-7], which map to axes, an axis
158 event will be simulated, however _press_ and _release_ will be ignored and
159 both will occur.
160
148*seat* <name> fallback true|false 161*seat* <name> fallback true|false
149 Set this seat as the fallback seat. A fallback seat will attach any device 162 Set this seat as the fallback seat. A fallback seat will attach any device
150 not explicitly attached to another seat (similar to a "default" seat). 163 not explicitly attached to another seat (similar to a "default" seat).
diff --git a/sway/sway.5.scd b/sway/sway.5.scd
index 3398ad58..a9f60c1b 100644
--- a/sway/sway.5.scd
+++ b/sway/sway.5.scd
@@ -491,15 +491,6 @@ The default colors are:
491*seat* <seat> <seat-subcommands...> 491*seat* <seat> <seat-subcommands...>
492 For details on seat subcommands, see *sway-input*(5). 492 For details on seat subcommands, see *sway-input*(5).
493 493
494*seat* <seat> cursor move|set <x> <y>
495 Move specified seat's cursor relative to current position or wrap to
496 absolute coordinates (with respect to the global coordinate space).
497 Specifying either value as 0 will not update that coordinate.
498
499*seat* <seat> cursor press|release left|right|1|2|3...
500 Simulate pressing (or releasing) the specified mouse button on the
501 specified seat.
502
503*kill* 494*kill*
504 Kills (closes) the currently focused container and all of its children. 495 Kills (closes) the currently focused container and all of its children.
505 496