video: Wayland: Clamp fullscreen window dimensions to desktop A scaled fullscreen window may exceed the bounds of the desktop. Clamp the window size to the desktop dimensions in fullscreen mode.
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
diff --git a/src/video/wayland/SDL_waylandwindow.c b/src/video/wayland/SDL_waylandwindow.c
index 2841e49..7c6eb64 100644
--- a/src/video/wayland/SDL_waylandwindow.c
+++ b/src/video/wayland/SDL_waylandwindow.c
@@ -173,6 +173,19 @@ NeedWindowedViewport(SDL_Window *window)
DesktopIsFractionalScaled(window) && (window->flags & SDL_WINDOW_ALLOW_HIGHDPI);
}
+/* Never set a fullscreen window size larger than the desktop. */
+SDL_FORCE_INLINE int
+GetWindowWidth(SDL_Window *window)
+{
+ return NeedFullscreenViewport(window) ? ((SDL_WaylandOutputData *)SDL_GetDisplayForWindow(window)->driverdata)->width : window->w;
+}
+
+SDL_FORCE_INLINE int
+GetWindowHeight(SDL_Window *window)
+{
+ return NeedFullscreenViewport(window) ? ((SDL_WaylandOutputData *)SDL_GetDisplayForWindow(window)->driverdata)->height : window->h;
+}
+
static void
GetWindowBufferSize(SDL_Window *window, int *width, int *height)
{
@@ -718,7 +731,7 @@ decoration_frame_configure(struct libdecor_frame *frame,
wind->shell_surface.libdecor.initial_configure_seen = SDL_TRUE;
/* ... then commit the changes on the libdecor side. */
- state = libdecor_state_new(width, height);
+ state = libdecor_state_new(GetWindowWidth(window), GetWindowHeight(window));
libdecor_frame_commit(frame, state, configuration);
libdecor_state_free(state);
@@ -1709,7 +1722,8 @@ Wayland_HandleResize(SDL_Window *window, int width, int height, float scale)
* but at least lets us not be terminated by the compositor.
* Can be removed once SDL's resize logic becomes compliant. */
if (viddata->shell.xdg && data->shell_surface.xdg.surface) {
- xdg_surface_set_window_geometry(data->shell_surface.xdg.surface, 0, 0, window->w, window->h);
+ xdg_surface_set_window_geometry(data->shell_surface.xdg.surface, 0, 0,
+ GetWindowWidth(window), GetWindowHeight(window));
}
/* Update the viewport */
@@ -1759,7 +1773,7 @@ void Wayland_SetWindowSize(_THIS, SDL_Window * window)
#ifdef HAVE_LIBDECOR_H
if (data->shell.libdecor && wind->shell_surface.libdecor.frame) {
- state = libdecor_state_new(window->w, window->h);
+ state = libdecor_state_new(GetWindowWidth(window), GetWindowHeight(window));
libdecor_frame_commit(wind->shell_surface.libdecor.frame, state, NULL);
libdecor_state_free(state);
}
@@ -1776,7 +1790,8 @@ void Wayland_SetWindowSize(_THIS, SDL_Window * window)
/* Update the geometry which may have been set by a hack in Wayland_HandleResize */
if (data->shell.xdg && wind->shell_surface.xdg.surface) {
- xdg_surface_set_window_geometry(wind->shell_surface.xdg.surface, 0, 0, window->w, window->h);
+ xdg_surface_set_window_geometry(wind->shell_surface.xdg.surface, 0, 0,
+ GetWindowWidth(window), GetWindowHeight(window));
}
}