wayland: Add a forced screen space scaling mode

Add a mode that forces Wayland windows to output with scaling that forces 1:1 pixel mapping.

This is intended to allow legacy applications to be displayed without desktop scaling being applied, and may have issues with some display configurations, as this forces the window to behave in a way that Wayland desktops were not designed to accommodate (rounding errors can result from certain combinations of window/scale values, the window may be unusably small, jump in size at times, or appear to be larger than the desktop space, and cursor precision may be reduced).

Windows flagged as DPI-aware are not affected by this.

The automated video test suite passes with the hint turned on.
This commit is contained in:
Frank Praznik
2024-01-19 10:30:07 -05:00
parent 9f7eb6c4c1
commit 5b8ca05f1a
7 changed files with 279 additions and 73 deletions

View File

@@ -2000,6 +2000,32 @@ extern "C" {
*/
#define SDL_HINT_VIDEO_WAYLAND_MODE_SCALING "SDL_VIDEO_WAYLAND_MODE_SCALING"
/**
* A variable forcing non-DPI-aware Wayland windows to output at 1:1 scaling.
*
* When this hint is set, Wayland windows that are not flagged as being DPI-aware will be
* output with scaling designed to force 1:1 pixel mapping.
*
* This is intended to allow legacy applications to be displayed without desktop scaling
* being applied, and has issues with certain display configurations, as this forces the
* window to behave in a way that Wayland desktops were not designed to accommodate:
*
* - Rounding errors can result with odd window sizes and/or desktop scales.
* - The window may be unusably small.
* - The window may jump in size at times.
* - The window may appear to be larger than the desktop size to the application.
* - Possible loss of cursor precision.
*
* New applications should be designed with proper DPI awareness handling instead of enabling this.
*
* This variable can be set to the following values:
* "0" - Windows will be scaled normally.
* "1" - Windows will be forced to scale to achieve 1:1 output.
*
* By default, scaling to the display is disabled.
*/
#define SDL_HINT_VIDEO_WAYLAND_SCALE_TO_DISPLAY "SDL_VIDEO_WAYLAND_SCALE_TO_DISPLAY"
/**
* Enable or disable mouse pointer warp emulation, needed by some older games.
*

View File

@@ -883,6 +883,18 @@ extern DECLSPEC SDL_Window *SDLCALL SDL_CreatePopupWindow(SDL_Window *parent, in
*
* These are additional supported properties on Wayland:
*
* - `SDL_PROP_WINDOW_CREATE_WAYLAND_SCALE_TO_DISPLAY` - true if the window
* should use forced scaling designed to produce 1:1 pixel mapping if not
* flagged as being DPI-aware. This is intended to allow legacy applications
* to be displayed without desktop scaling being applied, and has issues with
* certain display configurations, as this forces the window to behave in a
* way that Wayland desktops were not designed to accommodate. Potential
* issues include, but are not limited to: rounding errors can result when
* odd window sizes/scales are used, the window may be unusably small, the
* window may jump in visible size at times, the window may appear to be
* larger than the desktop space, and possible loss of cursor precision can
* occur. New applications should be designed with proper DPI awareness and
* handling instead of enabling this.
* - `SDL_PROP_WINDOW_CREATE_WAYLAND_SURFACE_ROLE_CUSTOM_BOOLEAN` - true if
* the application wants to use the Wayland surface for a custom role and
* does not want it attached to an XDG toplevel window. See
@@ -947,6 +959,7 @@ extern DECLSPEC SDL_Window *SDLCALL SDL_CreateWindowWithProperties(SDL_Propertie
#define SDL_PROP_WINDOW_CREATE_Y_NUMBER "y"
#define SDL_PROP_WINDOW_CREATE_COCOA_WINDOW_POINTER "cocoa.window"
#define SDL_PROP_WINDOW_CREATE_COCOA_VIEW_POINTER "cocoa.view"
#define SDL_PROP_WINDOW_CREATE_WAYLAND_SCALE_TO_DISPLAY "wayland.scale_to_display"
#define SDL_PROP_WINDOW_CREATE_WAYLAND_SURFACE_ROLE_CUSTOM_BOOLEAN "wayland.surface_role_custom"
#define SDL_PROP_WINDOW_CREATE_WAYLAND_CREATE_EGL_WINDOW_BOOLEAN "wayland.create_egl_window"
#define SDL_PROP_WINDOW_CREATE_WAYLAND_WL_SURFACE_POINTER "wayland.wl_surface"