Skip to content

Commit 8781f02

Browse files
committed
[Wayland] Add support for xdg-toplevel-tag-v1 protocol
1 parent c117a73 commit 8781f02

8 files changed

Lines changed: 121 additions & 6 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ gfx/common/wayland/single-pixel-buffer-v1.h
242242
gfx/common/wayland/single-pixel-buffer-v1.c
243243
gfx/common/wayland/xdg-toplevel-icon-v1.h
244244
gfx/common/wayland/xdg-toplevel-icon-v1.c
245+
gfx/common/wayland/xdg-toplevel-tag-v1.h
246+
gfx/common/wayland/xdg-toplevel-tag-v1.c
245247

246248
# libretro-common samples
247249
libretro-common/samples/streams/rzip/rzip

Makefile.common

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,7 @@ ifeq ($(HAVE_WAYLAND), 1)
12721272
gfx/common/wayland/fractional-scale-v1.o \
12731273
gfx/common/wayland/viewporter.o \
12741274
gfx/common/wayland/xdg-toplevel-icon-v1.o \
1275+
gfx/common/wayland/xdg-toplevel-tag-v1.o \
12751276
gfx/common/wayland/xdg-shell.o \
12761277
gfx/common/wayland/idle-inhibit-unstable-v1.o \
12771278
gfx/common/wayland/xdg-decoration-unstable-v1.o \
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Toplevel tag protocol
2+
3+
Maintainers:
4+
Xaver Hugl <[email protected]>
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>

gfx/common/wayland/generate_wayland_protos.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,4 @@ generate_source 'unstable/tablet' 'tablet-unstable-v2'
7474
generate_source 'staging/content-type' 'content-type-v1'
7575
generate_source 'staging/single-pixel-buffer' 'single-pixel-buffer-v1'
7676
generate_source 'staging/xdg-toplevel-icon' 'xdg-toplevel-icon-v1'
77+
generate_source 'staging/xdg-toplevel-tag' 'xdg-toplevel-tag-v1'

gfx/common/wayland_common.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,10 @@ void gfx_ctx_wl_destroy_resources_common(gfx_ctx_wayland_data_t *wl)
280280
if (wl->wl_touch)
281281
wl_touch_destroy(wl->wl_touch);
282282

283-
if (wl->cursor.theme)
284-
wl_cursor_theme_destroy(wl->cursor.theme);
285283
if (wl->cursor.surface)
286284
wl_surface_destroy(wl->cursor.surface);
285+
if (wl->cursor.theme)
286+
wl_cursor_theme_destroy(wl->cursor.theme);
287287

288288
if (wl->viewport)
289289
wp_viewport_destroy(wl->viewport);
@@ -293,19 +293,21 @@ void gfx_ctx_wl_destroy_resources_common(gfx_ctx_wayland_data_t *wl)
293293
zwp_idle_inhibitor_v1_destroy(wl->idle_inhibitor);
294294
if (wl->deco)
295295
zxdg_toplevel_decoration_v1_destroy(wl->deco);
296-
if (wl->xdg_toplevel)
297-
xdg_toplevel_destroy(wl->xdg_toplevel);
298-
if (wl->xdg_toplevel_icon_manager)
299-
xdg_toplevel_icon_manager_v1_destroy(wl->xdg_toplevel_icon_manager);
300296
if (wl->xdg_toplevel_icon)
301297
xdg_toplevel_icon_v1_destroy(wl->xdg_toplevel_icon);
298+
if (wl->xdg_toplevel)
299+
xdg_toplevel_destroy(wl->xdg_toplevel);
302300
if (wl->xdg_surface)
303301
xdg_surface_destroy(wl->xdg_surface);
304302
if (wl->surface)
305303
wl_surface_destroy(wl->surface);
306304

307305
if (wl->deco_manager)
308306
zxdg_decoration_manager_v1_destroy(wl->deco_manager);
307+
if (wl->xdg_toplevel_icon_manager)
308+
xdg_toplevel_icon_manager_v1_destroy(wl->xdg_toplevel_icon_manager);
309+
if (wl->xdg_toplevel_tag_manager)
310+
xdg_toplevel_tag_manager_v1_destroy(wl->xdg_toplevel_tag_manager);
309311
if (wl->idle_inhibit_manager)
310312
zwp_idle_inhibit_manager_v1_destroy(wl->idle_inhibit_manager);
311313
else
@@ -388,6 +390,7 @@ void gfx_ctx_wl_destroy_resources_common(gfx_ctx_wayland_data_t *wl)
388390
wl->xdg_toplevel = NULL;
389391
wl->xdg_toplevel_icon = NULL;
390392
wl->xdg_toplevel_icon_manager = NULL;
393+
wl->xdg_toplevel_tag_manager = NULL;
391394
wl->deco = NULL;
392395
wl->idle_inhibitor = NULL;
393396
wl->wl_touch = NULL;
@@ -831,6 +834,11 @@ bool gfx_ctx_wl_init_common(
831834
RARCH_LOG("[Wayland] Compositor doesn't support the %s protocol.\n", xdg_toplevel_icon_manager_v1_interface.name);
832835
}
833836

837+
if (!wl->xdg_toplevel_tag_manager)
838+
{
839+
RARCH_LOG("[Wayland] Compositor doesn't support the %s protocol.\n", xdg_toplevel_tag_manager_v1_interface.name);
840+
}
841+
834842
wl->surface = wl_compositor_create_surface(wl->compositor);
835843
if (wl->viewporter)
836844
wl->viewport = wp_viewporter_get_viewport(wl->viewporter, wl->surface);
@@ -904,6 +912,14 @@ bool gfx_ctx_wl_init_common(
904912
if (wl->xdg_toplevel_icon_manager)
905913
wl_create_toplevel_icon(wl, wl->xdg_toplevel);
906914

915+
if (wl->xdg_toplevel_tag_manager)
916+
{
917+
xdg_toplevel_tag_manager_v1_set_toplevel_tag(
918+
wl->xdg_toplevel_tag_manager, wl->xdg_toplevel, WAYLAND_APP_ID);
919+
xdg_toplevel_tag_manager_v1_set_toplevel_description(
920+
wl->xdg_toplevel_tag_manager, wl->xdg_toplevel, WINDOW_TITLE);
921+
}
922+
907923
/* Waiting for xdg_toplevel to be configured before starting to draw */
908924
wl_surface_commit(wl->surface);
909925
wl->configured = true;

input/common/wayland_common.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,10 @@ static void wl_registry_handle_global(void *data, struct wl_registry *reg,
809809
wl->xdg_toplevel_icon_manager = (struct xdg_toplevel_icon_manager_v1*)
810810
wl_registry_bind(
811811
reg, id, &xdg_toplevel_icon_manager_v1_interface, MIN(version, 1));
812+
else if (string_is_equal(interface, xdg_toplevel_tag_manager_v1_interface.name) && found++)
813+
wl->xdg_toplevel_tag_manager = (struct xdg_toplevel_tag_manager_v1*)
814+
wl_registry_bind(
815+
reg, id, &xdg_toplevel_tag_manager_v1_interface, MIN(version, 1));
812816

813817
if (found > 1)
814818
RARCH_LOG("[Wayland] Registered interface %s at version %u.\n",

input/common/wayland_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "../../gfx/common/wayland/xdg-decoration-unstable-v1.h"
4646
#include "../../gfx/common/wayland/xdg-shell.h"
4747
#include "../../gfx/common/wayland/xdg-toplevel-icon-v1.h"
48+
#include "../../gfx/common/wayland/xdg-toplevel-tag-v1.h"
4849

4950
#define FRACTIONAL_SCALE_V1_DEN 120
5051
#define FRACTIONAL_SCALE_MULT(v, scale_num) \
@@ -162,6 +163,7 @@ typedef struct gfx_ctx_wayland_data
162163
struct xdg_toplevel *xdg_toplevel;
163164
struct xdg_toplevel_icon_v1 *xdg_toplevel_icon;
164165
struct xdg_toplevel_icon_manager_v1 *xdg_toplevel_icon_manager;
166+
struct xdg_toplevel_tag_manager_v1 *xdg_toplevel_tag_manager;
165167
struct wl_keyboard *wl_keyboard;
166168
struct wl_pointer *wl_pointer;
167169
struct zwp_relative_pointer_v1 *wl_relative_pointer;

0 commit comments

Comments
 (0)