wayland: Support axis relative direction
This allows clients to be aware of "natural scrolling" settings in the compostior and adjust accordingly to optionally keep the same wheel and trackpad behaviour accross platforms. Testing using the "testmouse" example, behaviour in the demo is now the same regardless of the compositor setting for scrolling.
This commit is contained in:
committed by
Ethan Lee
parent
ac72cdcf79
commit
0c551e7069
@@ -64,7 +64,9 @@
|
||||
#include "../../events/SDL_keysym_to_scancode_c.h"
|
||||
|
||||
/* Clamp the wl_seat version on older versions of libwayland. */
|
||||
#if SDL_WAYLAND_CHECK_VERSION(1, 21, 0)
|
||||
#if SDL_WAYLAND_CHECK_VERSION(1, 22, 0)
|
||||
#define SDL_WL_SEAT_VERSION 9
|
||||
#elif SDL_WAYLAND_CHECK_VERSION(1, 21, 0)
|
||||
#define SDL_WL_SEAT_VERSION 8
|
||||
#else
|
||||
#define SDL_WL_SEAT_VERSION 5
|
||||
@@ -844,11 +846,31 @@ static void pointer_handle_axis(void *data, struct wl_pointer *pointer,
|
||||
}
|
||||
}
|
||||
|
||||
static void pointer_handle_frame(void *data, struct wl_pointer *pointer)
|
||||
static void
|
||||
pointer_handle_axis_relative_direction(void *data, struct wl_pointer *pointer,
|
||||
uint32_t axis, uint32_t axis_relative_direction)
|
||||
{
|
||||
struct SDL_WaylandInput *input = data;
|
||||
if (axis != WL_POINTER_AXIS_VERTICAL_SCROLL) {
|
||||
return;
|
||||
}
|
||||
switch (axis_relative_direction) {
|
||||
case WL_POINTER_AXIS_RELATIVE_DIRECTION_IDENTICAL:
|
||||
input->pointer_curr_axis_info.direction = SDL_MOUSEWHEEL_NORMAL;
|
||||
break;
|
||||
case WL_POINTER_AXIS_RELATIVE_DIRECTION_INVERTED:
|
||||
input->pointer_curr_axis_info.direction = SDL_MOUSEWHEEL_FLIPPED;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
pointer_handle_frame(void *data, struct wl_pointer *pointer)
|
||||
{
|
||||
struct SDL_WaylandInput *input = data;
|
||||
SDL_WindowData *window = input->pointer_focus;
|
||||
float x, y;
|
||||
SDL_MouseWheelDirection direction = input->pointer_curr_axis_info.direction;
|
||||
|
||||
switch (input->pointer_curr_axis_info.x_axis_type) {
|
||||
case AXIS_EVENT_CONTINUOUS:
|
||||
@@ -885,7 +907,7 @@ static void pointer_handle_frame(void *data, struct wl_pointer *pointer)
|
||||
|
||||
if (x != 0.0f || y != 0.0f) {
|
||||
SDL_SendMouseWheel(input->pointer_curr_axis_info.timestamp_ns,
|
||||
window->sdlwindow, 0, x, y, SDL_MOUSEWHEEL_NORMAL);
|
||||
window->sdlwindow, 0, x, y, direction);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -927,7 +949,8 @@ static const struct wl_pointer_listener pointer_listener = {
|
||||
pointer_handle_axis_source, /* Version 5 */
|
||||
pointer_handle_axis_stop, /* Version 5 */
|
||||
pointer_handle_axis_discrete, /* Version 5 */
|
||||
pointer_handle_axis_value120 /* Version 8 */
|
||||
pointer_handle_axis_value120, /* Version 8 */
|
||||
pointer_handle_axis_relative_direction /* Version 9 */
|
||||
};
|
||||
|
||||
static void touch_handler_down(void *data, struct wl_touch *touch, uint32_t serial,
|
||||
|
||||
@@ -21,9 +21,12 @@
|
||||
|
||||
#include "SDL_internal.h"
|
||||
|
||||
|
||||
#ifndef SDL_waylandevents_h_
|
||||
#define SDL_waylandevents_h_
|
||||
|
||||
#include "../../events/SDL_mouse_c.h"
|
||||
|
||||
#include "SDL_waylandvideo.h"
|
||||
#include "SDL_waylandwindow.h"
|
||||
#include "SDL_waylanddatamanager.h"
|
||||
@@ -151,6 +154,7 @@ struct SDL_WaylandInput
|
||||
|
||||
/* Event timestamp in nanoseconds */
|
||||
Uint64 timestamp_ns;
|
||||
SDL_MouseWheelDirection direction;
|
||||
} pointer_curr_axis_info;
|
||||
|
||||
SDL_WaylandKeyboardRepeat keyboard_repeat;
|
||||
|
||||
Reference in New Issue
Block a user