wayland: Pin the fake window position at (0, 0). I kind of thought it'd be nice to have it in the center, but this is an issue for applications that still assume global mouse and window positions are accessible. For example, this fixes cursor offset issues in UE5.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
diff --git a/src/video/wayland/SDL_waylandwindow.c b/src/video/wayland/SDL_waylandwindow.c
index 476083b..89b93b7 100644
--- a/src/video/wayland/SDL_waylandwindow.c
+++ b/src/video/wayland/SDL_waylandwindow.c
@@ -815,12 +815,28 @@ Wayland_move_window(SDL_Window *window,
int i, numdisplays = SDL_GetNumVideoDisplays();
for (i = 0; i < numdisplays; i += 1) {
if (SDL_GetDisplay(i)->driverdata == driverdata) {
- /* Equivalent of SDL_WINDOWPOS_CENTERED_DISPLAY(i) */
+ /* We want to send a very very specific combination here:
+ *
+ * 1. A coordinate that tells the application what display we're on
+ * 2. Exactly (0, 0)
+ *
+ * Part 1 is useful information but is also really important for
+ * ensuring we end up on the right display for fullscreen, while
+ * part 2 is important because numerous applications use a specific
+ * combination of GetWindowPosition and GetGlobalMouseState, and of
+ * course neither are supported by Wayland. Since global mouse will
+ * fall back to just GetMouseState, we need the window position to
+ * be zero so the cursor math works without it going off in some
+ * random direction. See UE5 Editor for a notable example of this!
+ *
+ * This may be an issue some day if we're ever able to implement
+ * SDL_GetDisplayUsableBounds!
+ *
+ * -flibit
+ */
SDL_Rect bounds;
SDL_GetDisplayBounds(i, &bounds);
- SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED,
- bounds.x + (bounds.w - window->w) / 2,
- bounds.y + (bounds.h - window->h) / 2);
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, bounds.x, bounds.y);
break;
}
}