From 9fe5c1512fb762f18c567fa4bc78b20c0c440617 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 27 Dec 2025 14:50:43 -0800
Subject: [PATCH] Added support for extended buttons on Wayland
Fixes https://github.com/libsdl-org/SDL/issues/14681
---
src/video/wayland/SDL_waylandevents.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c
index be3d1930a2863..1755813297caf 100644
--- a/src/video/wayland/SDL_waylandevents.c
+++ b/src/video/wayland/SDL_waylandevents.c
@@ -871,7 +871,12 @@ static void pointer_handle_leave(void *data, struct wl_pointer *pointer,
SDL_WaylandSeat *seat = (SDL_WaylandSeat *)data;
seat->pointer.focus = NULL;
- seat->pointer.buttons_pressed = 0;
+ for (int i = 0; seat->pointer.buttons_pressed; ++i) {
+ if (seat->pointer.buttons_pressed & SDL_BUTTON_MASK(i)) {
+ SDL_SendMouseButton(0, window->sdlwindow, seat->pointer.sdl_id, i, false);
+ seat->pointer.buttons_pressed &= ~SDL_BUTTON_MASK(i);
+ }
+ }
SDL_SendMouseButton(0, window->sdlwindow, seat->pointer.sdl_id, SDL_BUTTON_LEFT, false);
SDL_SendMouseButton(0, window->sdlwindow, seat->pointer.sdl_id, SDL_BUTTON_RIGHT, false);
SDL_SendMouseButton(0, window->sdlwindow, seat->pointer.sdl_id, SDL_BUTTON_MIDDLE, false);
@@ -992,14 +997,9 @@ static void pointer_handle_button_common(SDL_WaylandSeat *seat, uint32_t serial,
case BTN_RIGHT:
sdl_button = SDL_BUTTON_RIGHT;
break;
- case BTN_SIDE:
- sdl_button = SDL_BUTTON_X1;
- break;
- case BTN_EXTRA:
- sdl_button = SDL_BUTTON_X2;
- break;
default:
- return;
+ sdl_button = SDL_BUTTON_X1 + (button - BTN_SIDE);
+ break;
}
if (window) {