Skip to content

Commit fdd8b5d

Browse files
committed
wayland: Query the mouse global button states from the seats
Mouse button events that trigger a hit test are not passed to the client, but the client may still query the global mouse button state from within the hit test handler, so the reported buttons need to be accurate. Query the buttons directly from the seat instead of the higher global mouse state to match the behavior of other platforms.
1 parent e3df61b commit fdd8b5d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/video/wayland/SDL_waylandmouse.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -958,16 +958,23 @@ static bool Wayland_SetRelativeMouseMode(bool enabled)
958958
*/
959959
static SDL_MouseButtonFlags SDLCALL Wayland_GetGlobalMouseState(float *x, float *y)
960960
{
961-
SDL_Mouse *mouse = SDL_GetMouse();
961+
const SDL_Mouse *mouse = SDL_GetMouse();
962962
SDL_MouseButtonFlags result = 0;
963963

964964
// If there is no window with mouse focus, we have no idea what the actual position or button state is.
965965
if (mouse->focus) {
966+
SDL_VideoData *video_data = SDL_GetVideoDevice()->internal;
967+
SDL_WaylandSeat *seat;
966968
int off_x, off_y;
967969
SDL_RelativeToGlobalForWindow(mouse->focus, mouse->focus->x, mouse->focus->y, &off_x, &off_y);
968-
result = SDL_GetMouseState(x, y);
970+
SDL_GetMouseState(x, y);
969971
*x = mouse->x + off_x;
970972
*y = mouse->y + off_y;
973+
974+
// Query the buttons from the seats directly, as this may be called from within a hit test handler.
975+
wl_list_for_each (seat, &video_data->seat_list, link) {
976+
result |= seat->pointer.buttons_pressed;
977+
}
971978
} else {
972979
*x = 0.f;
973980
*y = 0.f;

0 commit comments

Comments
 (0)