瀏覽代碼

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.
Frank Praznik 5 月之前
父節點
當前提交
fdd8b5d630
共有 1 個文件被更改,包括 9 次插入2 次删除
  1. 9 2
      src/video/wayland/SDL_waylandmouse.c

+ 9 - 2
src/video/wayland/SDL_waylandmouse.c

@@ -958,16 +958,23 @@ static bool Wayland_SetRelativeMouseMode(bool enabled)
  */
  */
 static SDL_MouseButtonFlags SDLCALL Wayland_GetGlobalMouseState(float *x, float *y)
 static SDL_MouseButtonFlags SDLCALL Wayland_GetGlobalMouseState(float *x, float *y)
 {
 {
-    SDL_Mouse *mouse = SDL_GetMouse();
+    const SDL_Mouse *mouse = SDL_GetMouse();
     SDL_MouseButtonFlags result = 0;
     SDL_MouseButtonFlags result = 0;
 
 
     // If there is no window with mouse focus, we have no idea what the actual position or button state is.
     // If there is no window with mouse focus, we have no idea what the actual position or button state is.
     if (mouse->focus) {
     if (mouse->focus) {
+        SDL_VideoData *video_data = SDL_GetVideoDevice()->internal;
+        SDL_WaylandSeat *seat;
         int off_x, off_y;
         int off_x, off_y;
         SDL_RelativeToGlobalForWindow(mouse->focus, mouse->focus->x, mouse->focus->y, &off_x, &off_y);
         SDL_RelativeToGlobalForWindow(mouse->focus, mouse->focus->x, mouse->focus->y, &off_x, &off_y);
-        result = SDL_GetMouseState(x, y);
+        SDL_GetMouseState(x, y);
         *x = mouse->x + off_x;
         *x = mouse->x + off_x;
         *y = mouse->y + off_y;
         *y = mouse->y + off_y;
+
+        // Query the buttons from the seats directly, as this may be called from within a hit test handler.
+        wl_list_for_each (seat, &video_data->seat_list, link) {
+            result |= seat->pointer.buttons_pressed;
+        }
     } else {
     } else {
         *x = 0.f;
         *x = 0.f;
         *y = 0.f;
         *y = 0.f;