Skip to content

Commit 188e5ce

Browse files
committed
wayland: Add experimental zone positioning support
1 parent 41039b4 commit 188e5ce

File tree

8 files changed

+1093
-21
lines changed

8 files changed

+1093
-21
lines changed

docs/README-wayland.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@ encounter limitations or behavior that is different from other windowing systems
66

77
## Common issues:
88

9+
### ```SDL_SetWindowPosition()``` doesn't work on non-popup windows
10+
11+
- Wayland requires the `ext-zones-v1` extension to position windows programmatically. Otherwise, toplevel windows may
12+
not be positioned programmatically.\
13+
\
14+
Enabling this protocol requires setting the `SDL_VIDEO_WAYLAND_ENABLE_ZONES` hint to `1`. After initializing the video
15+
subsystem, compositor support for the required protocol may be queried via the
16+
`SDL_PROP_GLOBAL_VIDEO_WAYLAND_HAS_ZONES_BOOLEAN` global video property.\
17+
\
18+
This protocol allows for positioning windows within the boundaries of desktop zones, the coordinates of which may not
19+
correspond 1:1 to output display coordinates. This is primarily intended for clients with multi-window interfaces that
20+
need to position windows relative to one another, development environments/workflows, and embedded scenarios where
21+
positioning is desired and the underlying environment and its capabilities are known. Single window clients should
22+
_not_ enable this by default, as it can override compositor window positioning, and tiling window managers in
23+
particular may demonstrate undesirable behavior with it.
24+
925
### Legacy, DPI-unaware applications are blurry
1026

1127
- Wayland handles high-DPI displays by scaling the desktop, which causes applications that are not designed to be
@@ -34,10 +50,6 @@ encounter limitations or behavior that is different from other windowing systems
3450
system settings, and falling back to a selection algorithm if this fails. If it is incorrect, it can be manually
3551
overridden by setting the ```SDL_VIDEO_DISPLAY_PRIORITY``` hint.
3652

37-
### ```SDL_SetWindowPosition()``` doesn't work on non-popup windows
38-
39-
- Wayland does not allow toplevel windows to position themselves programmatically.
40-
4153
### Retrieving the global mouse cursor position when the cursor is outside a window doesn't work
4254

4355
- Wayland only provides applications with the cursor position within the borders of the application windows. Querying

include/SDL3/SDL_hints.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3784,6 +3784,34 @@ extern "C" {
37843784
*/
37853785
#define SDL_HINT_VIDEO_WAYLAND_ALLOW_LIBDECOR "SDL_VIDEO_WAYLAND_ALLOW_LIBDECOR"
37863786

3787+
/**
3788+
* A variable controlling whether to allow positioning of windows via the
3789+
* `ext-zones-v1` protocol.
3790+
*
3791+
* This hint requires that the compositor supports the `ext-zones-v1` protocol.
3792+
* Support for this protocol can be checked via the global
3793+
* `SDL_PROP_GLOBAL_VIDEO_WAYLAND_HAS_ZONES_BOOLEAN` property after initializing
3794+
* the video subsystem with this hint set.
3795+
*
3796+
* If the compositor lacks support for the required protocol, this hint does
3797+
* nothing.
3798+
*
3799+
* Zones are arbitrary regions that allow for limited window placement within a
3800+
* logical space, and should not be presumed to correlate 1:1 to display output
3801+
* coordinates, so care must be taken when enabling this. See
3802+
* docs/README-wayland.md and wayland-protocols/ext-zones-v1.xml for more details.
3803+
*
3804+
* The variable can be set to the following values:
3805+
*
3806+
* - "0": positioning with ext-zones is disabled. (default)
3807+
* - "1": positioning with ext-zones is enabled.
3808+
*
3809+
* This hint should be set before SDL is initialized.
3810+
*
3811+
* \since This hint is available since SDL 3.1.6.
3812+
*/
3813+
#define SDL_HINT_VIDEO_WAYLAND_ENABLE_ZONES "SDL_VIDEO_WAYLAND_ENABLE_ZONES"
3814+
37873815
/**
37883816
* A variable controlling whether video mode emulation is enabled under
37893817
* Wayland.

include/SDL3/SDL_video.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,26 @@ typedef Uint32 SDL_WindowID;
100100
*/
101101
#define SDL_PROP_GLOBAL_VIDEO_WAYLAND_WL_DISPLAY_POINTER "SDL.video.wayland.wl_display"
102102

103+
/**
104+
* A boolean set to true if the windowing system supports the optional
105+
* ext-zones protocol for positioning windows in Wayland. Requires that the
106+
* `SDL_VIDEO_WAYLAND_ENABLE_ZONES` hint be set to enable. See
107+
* docs/README-wayland.md for more information.
108+
*
109+
* Can be queried after video subsystem initialization.
110+
*/
111+
#define SDL_PROP_GLOBAL_VIDEO_WAYLAND_HAS_ZONES_BOOLEAN "SDL.video.wayland.has_zones"
112+
113+
/**
114+
* A semicolon-separated list containing the mappings of outputs to zone handles, with
115+
* list items in the form <display name>=<zone handle>.
116+
*
117+
* Can be set before the video subsystem is initialized to import a list of existing
118+
* zone handles for outputs, or read after initialization to retrieve the current list of
119+
* zone handles for outputs.
120+
*/
121+
#define SDL_PROP_GLOBAL_VIDEO_WAYLAND_ZONE_MAPPING_STRING "SDL.video.wayland.zone_mapping"
122+
103123
/**
104124
* System theme.
105125
*
@@ -1337,6 +1357,9 @@ extern SDL_DECLSPEC SDL_Window * SDLCALL SDL_CreatePopupWindow(SDL_Window *paren
13371357
* - `SDL_PROP_WINDOW_CREATE_WAYLAND_WL_SURFACE_POINTER` - the wl_surface
13381358
* associated with the window, if you want to wrap an existing window. See
13391359
* [README-wayland](README-wayland) for more information.
1360+
* - `SDL_PROP_WINDOW_CREATE_WAYLAND_ZONE_LAYER_NUMBER` - the layer for the
1361+
* window when the ext-zones protocol is in use. See
1362+
* [README-wayland](README-wayland) for more information.
13401363
*
13411364
* These are additional supported properties on Windows:
13421365
*
@@ -1434,6 +1457,7 @@ extern SDL_DECLSPEC SDL_Window * SDLCALL SDL_CreateWindowWithProperties(SDL_Prop
14341457
#define SDL_PROP_WINDOW_CREATE_WAYLAND_SURFACE_ROLE_CUSTOM_BOOLEAN "SDL.window.create.wayland.surface_role_custom"
14351458
#define SDL_PROP_WINDOW_CREATE_WAYLAND_CREATE_EGL_WINDOW_BOOLEAN "SDL.window.create.wayland.create_egl_window"
14361459
#define SDL_PROP_WINDOW_CREATE_WAYLAND_WL_SURFACE_POINTER "SDL.window.create.wayland.wl_surface"
1460+
#define SDL_PROP_WINDOW_CREATE_WAYLAND_ZONE_LAYER_NUMBER "SDL.window.create.wayland.zone_layer"
14371461
#define SDL_PROP_WINDOW_CREATE_WIN32_HWND_POINTER "SDL.window.create.win32.hwnd"
14381462
#define SDL_PROP_WINDOW_CREATE_WIN32_PIXEL_FORMAT_HWND_POINTER "SDL.window.create.win32.pixel_format_hwnd"
14391463
#define SDL_PROP_WINDOW_CREATE_X11_WINDOW_NUMBER "SDL.window.create.x11.window"

0 commit comments

Comments
 (0)