Skip to content

Commit a23e9d6

Browse files
committed
wayland: Add support for the toplevel tag protocol
Uses the same ID string as the session manager protocol.
1 parent 92a9116 commit a23e9d6

4 files changed

Lines changed: 110 additions & 6 deletions

File tree

src/video/wayland/SDL_waylandvideo.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
#include "pointer-gestures-unstable-v1-client-protocol.h"
7272
#include "single-pixel-buffer-v1-client-protocol.h"
7373
#include "xdg-session-management-v1-client-protocol.h"
74+
#include "xdg-toplevel-tag-v1-client-protocol.h"
7475

7576
#ifdef HAVE_LIBDECOR_H
7677
#include <libdecor.h>
@@ -1509,6 +1510,8 @@ static void handle_registry_global(void *data, struct wl_registry *registry, uin
15091510
d->single_pixel_buffer_manager = wl_registry_bind(d->registry, id, &wp_single_pixel_buffer_manager_v1_interface, 1);
15101511
} else if (SDL_strcmp(interface, xdg_session_manager_v1_interface.name) == 0) {
15111512
d->xdg_session_manager = wl_registry_bind(d->registry, id, &xdg_session_manager_v1_interface, 1);
1513+
} else if (SDL_strcmp(interface, xdg_toplevel_tag_manager_v1_interface.name) == 0) {
1514+
d->xdg_toplevel_tag_manager = wl_registry_bind(d->registry, id, &xdg_toplevel_tag_manager_v1_interface, 1);
15121515
}
15131516
#ifdef SDL_WL_FIXES_VERSION
15141517
else if (SDL_strcmp(interface, wl_fixes_interface.name) == 0) {
@@ -1933,6 +1936,11 @@ static void Wayland_VideoCleanup(SDL_VideoDevice *_this)
19331936
data->xdg_session_manager = NULL;
19341937
}
19351938

1939+
if (data->xdg_toplevel_tag_manager) {
1940+
xdg_toplevel_tag_manager_v1_destroy(data->xdg_toplevel_tag_manager);
1941+
data->xdg_toplevel_tag_manager = NULL;
1942+
}
1943+
19361944
if (data->subcompositor) {
19371945
wl_subcompositor_destroy(data->subcompositor);
19381946
data->subcompositor = NULL;

src/video/wayland/SDL_waylandvideo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ struct SDL_VideoData
8888
struct zwp_pointer_gestures_v1 *zwp_pointer_gestures;
8989
struct wp_single_pixel_buffer_manager_v1 *single_pixel_buffer_manager;
9090
struct xdg_session_manager_v1 *xdg_session_manager;
91+
struct xdg_toplevel_tag_manager_v1 *xdg_toplevel_tag_manager;
9192

9293
struct xdg_session_v1 *xdg_session;
9394
struct xkb_context *xkb_context;

src/video/wayland/SDL_waylandwindow.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "xdg-toplevel-icon-v1-client-protocol.h"
5151
#include "color-management-v1-client-protocol.h"
5252
#include "xdg-session-management-v1-client-protocol.h"
53+
#include "xdg-toplevel-tag-v1-client-protocol.h"
5354

5455
#ifdef HAVE_LIBDECOR_H
5556
#include <libdecor.h>
@@ -2053,17 +2054,26 @@ bool Wayland_SetWindowModal(SDL_VideoDevice *_this, SDL_Window *window, bool mod
20532054

20542055
static void Wayland_RegisterToplevelForSession(SDL_WindowData *data)
20552056
{
2056-
SDL_VideoDevice *viddev = SDL_GetVideoDevice();
2057-
SDL_VideoData *viddata = viddev->internal;
2057+
const char *id = SDL_GetStringProperty(data->sdlwindow->props, SDL_PROP_WINDOW_WAYLAND_WINDOW_ID_STRING, NULL);
2058+
if (id && *id != '\0') {
2059+
SDL_VideoDevice *viddev = SDL_GetVideoDevice();
2060+
SDL_VideoData *viddata = viddev->internal;
2061+
struct xdg_toplevel *toplevel = GetToplevelForWindow(data);
20582062

2059-
if (viddata->xdg_session_manager) {
2060-
const char *id = SDL_GetStringProperty(data->sdlwindow->props, SDL_PROP_WINDOW_WAYLAND_WINDOW_ID_STRING, NULL);
2061-
if (id && *id != '\0') {
2063+
if (!toplevel) {
2064+
return;
2065+
}
2066+
2067+
if (viddata->xdg_toplevel_tag_manager) {
2068+
xdg_toplevel_tag_manager_v1_set_toplevel_tag(viddata->xdg_toplevel_tag_manager, toplevel, id);
2069+
}
2070+
2071+
if (viddata->xdg_session_manager) {
20622072
Wayland_CreateSession(viddata);
20632073

20642074
if (viddata->xdg_session) {
20652075
CHECK_PARAM (true) {
2066-
// Windows must not have a duplicate ID string, or a protocol error will result.
2076+
// Windows added to a session must not have a duplicate ID string, or a protocol error will result.
20672077
for (SDL_Window *w = viddev->windows; w; w = w->next) {
20682078
SDL_WindowData *d = w->internal;
20692079
if (d->session_id && SDL_strcmp(d->session_id, id) == 0) {
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<protocol name="xdg_toplevel_tag_v1">
3+
<copyright>
4+
Copyright © 2024 Xaver Hugl
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a
7+
copy of this software and associated documentation files (the "Software"),
8+
to deal in the Software without restriction, including without limitation
9+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
10+
and/or sell copies of the Software, and to permit persons to whom the
11+
Software is furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice (including the next
14+
paragraph) shall be included in all copies or substantial portions of the
15+
Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23+
DEALINGS IN THE SOFTWARE.
24+
</copyright>
25+
26+
<interface name="xdg_toplevel_tag_manager_v1" version="1">
27+
<description summary="protocol for setting toplevel tags">
28+
In order to make some window properties like position, size,
29+
"always on top" or user defined rules for window behavior persistent, the
30+
compositor needs some way to identify windows even after the application
31+
has been restarted.
32+
This protocol allows clients to make this possible by setting a tag for
33+
toplevels.
34+
35+
Warning! The protocol described in this file is currently in the testing
36+
phase. Backward compatible changes may be added together with the
37+
corresponding interface version bump. Backward incompatible changes can
38+
only be done by creating a new major version of the extension.
39+
</description>
40+
41+
<request name="destroy" type="destructor">
42+
<description summary="destroy toplevel tag object">
43+
Destroy this toplevel tag manager object. This request has no other
44+
effects.
45+
</description>
46+
</request>
47+
48+
<request name="set_toplevel_tag">
49+
<description summary="set tag">
50+
Set a tag for a toplevel. The tag may be shown to the user in UI, so
51+
it's preferable for it to be human readable, but it must be suitable
52+
for configuration files and should not be translated.
53+
Suitable tags would for example be "main window", "settings",
54+
"e-mail composer" or similar.
55+
56+
The tag does not need to be unique across applications, and the client
57+
may set the same tag for multiple windows, for example if the user has
58+
opened the same UI twice. How the potentially resulting conflicts are
59+
handled is compositor policy.
60+
61+
The client should set the tag as part of the initial commit on the
62+
associated toplevel, but it may set it at any time afterwards as well,
63+
for example if the purpose of the toplevel changes.
64+
</description>
65+
<arg name="toplevel" type="object" interface="xdg_toplevel"/>
66+
<arg name="tag" type="string" summary="untranslated tag"/>
67+
</request>
68+
69+
<request name="set_toplevel_description">
70+
<description summary="set description">
71+
Set a description for a toplevel. This description may be shown to the
72+
user in UI or read by a screen reader for accessibility purposes, and
73+
should be translated.
74+
It is recommended to make the description the translation of the tag.
75+
76+
The client should set the description as part of the initial commit on
77+
the associated toplevel, but it may set it at any time afterwards as
78+
well, for example if the purpose of the toplevel changes.
79+
</description>
80+
<arg name="toplevel" type="object" interface="xdg_toplevel"/>
81+
<arg name="description" type="string" summary="translated description"/>
82+
</request>
83+
</interface>
84+
85+
</protocol>

0 commit comments

Comments
 (0)