mirror of
https://github.com/swaywm/sway.git
synced 2024-11-29 03:11:27 +00:00
Merge pull request #3343 from RedSoxFan/seat-cursor-buttons-improved
Improve mouse button parsing: seat cursor buttons
This commit is contained in:
commit
9f9ef76175
|
@ -80,6 +80,9 @@ void dispatch_cursor_button(struct sway_cursor *cursor,
|
||||||
struct wlr_input_device *device, uint32_t time_msec, uint32_t button,
|
struct wlr_input_device *device, uint32_t time_msec, uint32_t button,
|
||||||
enum wlr_button_state state);
|
enum wlr_button_state state);
|
||||||
|
|
||||||
|
void dispatch_cursor_axis(struct sway_cursor *cursor,
|
||||||
|
struct wlr_event_pointer_axis *event);
|
||||||
|
|
||||||
void cursor_set_image(struct sway_cursor *cursor, const char *image,
|
void cursor_set_image(struct sway_cursor *cursor, const char *image,
|
||||||
struct wl_client *client);
|
struct wl_client *client);
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include <wlr/types/wlr_cursor.h>
|
#include <wlr/types/wlr_cursor.h>
|
||||||
|
#include <wlr/types/wlr_pointer.h>
|
||||||
#include "sway/commands.h"
|
#include "sway/commands.h"
|
||||||
#include "sway/input/cursor.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 <move> <x> <y>' or "
|
static const char *expected_syntax = "Expected 'cursor <move> <x> <y>' or "
|
||||||
"'cursor <set> <x> <y>' or "
|
"'cursor <set> <x> <y>' or "
|
||||||
"'curor <press|release> <left|right|1|2|3...>'";
|
"'curor <press|release> <button[1-9]|event-name-or-code>'";
|
||||||
|
|
||||||
static struct cmd_results *handle_command(struct sway_cursor *cursor,
|
static struct cmd_results *handle_command(struct sway_cursor *cursor,
|
||||||
int argc, char **argv) {
|
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);
|
return cmd_results_new(CMD_INVALID, "cursor", expected_syntax);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcasecmp(button_str, "left") == 0) {
|
char *message = NULL;
|
||||||
button = BTN_LEFT;
|
button = get_mouse_button(button_str, &message);
|
||||||
} else if (strcasecmp(button_str, "right") == 0) {
|
if (message) {
|
||||||
button = BTN_RIGHT;
|
struct cmd_results *error =
|
||||||
} else {
|
cmd_results_new(CMD_INVALID, "cursor", message);
|
||||||
button = strtol(button_str, NULL, 10);
|
free(message);
|
||||||
if (button == 0) {
|
return error;
|
||||||
return cmd_results_new(CMD_INVALID, "cursor", expected_syntax);
|
} 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);
|
dispatch_cursor_button(cursor, NULL, 0, button, state);
|
||||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||||
|
|
|
@ -716,11 +716,13 @@ static uint32_t wl_axis_to_button(struct wlr_event_pointer_axis *event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dispatch_cursor_axis(struct sway_cursor *cursor,
|
void dispatch_cursor_axis(struct sway_cursor *cursor,
|
||||||
struct wlr_event_pointer_axis *event) {
|
struct wlr_event_pointer_axis *event) {
|
||||||
struct sway_seat *seat = cursor->seat;
|
struct sway_seat *seat = cursor->seat;
|
||||||
struct sway_input_device *input_device = event->device->data;
|
struct sway_input_device *input_device =
|
||||||
struct input_config *ic = input_device_get_config(input_device);
|
event->device ? event->device->data : NULL;
|
||||||
|
struct input_config *ic =
|
||||||
|
input_device ? input_device_get_config(input_device) : NULL;
|
||||||
|
|
||||||
// Determine what's under the cursor
|
// Determine what's under the cursor
|
||||||
struct wlr_surface *surface = NULL;
|
struct wlr_surface *surface = NULL;
|
||||||
|
@ -743,7 +745,8 @@ static void dispatch_cursor_axis(struct sway_cursor *cursor,
|
||||||
// Gather information needed for mouse bindings
|
// Gather information needed for mouse bindings
|
||||||
struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->wlr_seat);
|
struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->wlr_seat);
|
||||||
uint32_t modifiers = keyboard ? wlr_keyboard_get_modifiers(keyboard) : 0;
|
uint32_t modifiers = keyboard ? wlr_keyboard_get_modifiers(keyboard) : 0;
|
||||||
struct wlr_input_device *device = input_device->wlr_device;
|
struct wlr_input_device *device =
|
||||||
|
input_device ? input_device->wlr_device : NULL;
|
||||||
char *dev_id = device ? input_device_get_identifier(device) : strdup("*");
|
char *dev_id = device ? input_device_get_identifier(device) : strdup("*");
|
||||||
uint32_t button = wl_axis_to_button(event);
|
uint32_t button = wl_axis_to_button(event);
|
||||||
|
|
||||||
|
|
|
@ -145,6 +145,19 @@ in their own "seat").
|
||||||
Attach an input device to this seat by its input identifier. A special
|
Attach an input device to this seat by its input identifier. A special
|
||||||
value of "\*" will attach all devices to the seat.
|
value of "\*" will attach all devices to the seat.
|
||||||
|
|
||||||
|
*seat* <seat> cursor move|set <x> <y>
|
||||||
|
Move specified seat's cursor relative to current position or wrap to
|
||||||
|
absolute coordinates (with respect to the global coordinate space).
|
||||||
|
Specifying either value as 0 will not update that coordinate.
|
||||||
|
|
||||||
|
*seat* <seat> cursor press|release button[1-9]|<event-name-or-code>
|
||||||
|
Simulate pressing (or releasing) the specified mouse button on the
|
||||||
|
specified seat. The button can either be provided as a button event name or
|
||||||
|
event code, which can be obtained from `libinput debug-events`, or as an x11
|
||||||
|
mouse button (button[1-9]). If using button[4-7], which map to axes, an axis
|
||||||
|
event will be simulated, however _press_ and _release_ will be ignored and
|
||||||
|
both will occur.
|
||||||
|
|
||||||
*seat* <name> fallback true|false
|
*seat* <name> fallback true|false
|
||||||
Set this seat as the fallback seat. A fallback seat will attach any device
|
Set this seat as the fallback seat. A fallback seat will attach any device
|
||||||
not explicitly attached to another seat (similar to a "default" seat).
|
not explicitly attached to another seat (similar to a "default" seat).
|
||||||
|
|
|
@ -491,15 +491,6 @@ The default colors are:
|
||||||
*seat* <seat> <seat-subcommands...>
|
*seat* <seat> <seat-subcommands...>
|
||||||
For details on seat subcommands, see *sway-input*(5).
|
For details on seat subcommands, see *sway-input*(5).
|
||||||
|
|
||||||
*seat* <seat> cursor move|set <x> <y>
|
|
||||||
Move specified seat's cursor relative to current position or wrap to
|
|
||||||
absolute coordinates (with respect to the global coordinate space).
|
|
||||||
Specifying either value as 0 will not update that coordinate.
|
|
||||||
|
|
||||||
*seat* <seat> cursor press|release left|right|1|2|3...
|
|
||||||
Simulate pressing (or releasing) the specified mouse button on the
|
|
||||||
specified seat.
|
|
||||||
|
|
||||||
*kill*
|
*kill*
|
||||||
Kills (closes) the currently focused container and all of its children.
|
Kills (closes) the currently focused container and all of its children.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue