(Wayland) Add scroll wheel support (#13398)

This commit is contained in:
Colin Kinloch 2021-12-24 02:42:33 +00:00 committed by GitHub
parent 1afbe4a326
commit c48d533950
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 1 deletions

View File

@ -240,7 +240,26 @@ static void pointer_handle_axis(void *data,
struct wl_pointer *wl_pointer,
uint32_t time,
uint32_t axis,
wl_fixed_t value) { }
wl_fixed_t value) {
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
double dvalue = wl_fixed_to_double(value);
switch (axis) {
case WL_POINTER_AXIS_VERTICAL_SCROLL:
if (dvalue < 0) {
wl->input.mouse.wu = true;
} else if (dvalue > 0) {
wl->input.mouse.wd = true;
}
break;
case WL_POINTER_AXIS_HORIZONTAL_SCROLL:
if (dvalue < 0) {
wl->input.mouse.wl = true;
} else if (dvalue > 0) {
wl->input.mouse.wr = true;
}
break;
}
}
static void touch_handle_down(void *data,
struct wl_touch *wl_touch,

View File

@ -102,6 +102,7 @@ typedef struct input_ctx_wayland_data
bool last_valid;
bool focus;
bool left, right, middle;
bool wu, wd, wl, wr;
} mouse;
bool keyboard_focus;

View File

@ -263,6 +263,14 @@ static int16_t input_wl_state(
if (port > 0) return 0; /* TODO: support mouse on additional ports */
switch (id)
{
case RETRO_DEVICE_ID_MOUSE_WHEELUP:
bool wheel_up = wl->mouse.wu;
wl->mouse.wu = false;
return wheel_up;
case RETRO_DEVICE_ID_MOUSE_WHEELDOWN:
bool wheel_down = wl->mouse.wd;
wl->mouse.wd = false;
return wheel_down;
case RETRO_DEVICE_ID_MOUSE_X:
return screen ? wl->mouse.x : wl->mouse.delta_x;
case RETRO_DEVICE_ID_MOUSE_Y: