Skip to content

Commit c39cf47

Browse files
authored
[Wayland] Add support for xdg-toplevel-tag-v1 protocol (#18317)
1 parent dc4d01a commit c39cf47

9 files changed

Lines changed: 136 additions & 11 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ gfx/common/wayland/single-pixel-buffer-v1.h
243243
gfx/common/wayland/single-pixel-buffer-v1.c
244244
gfx/common/wayland/xdg-toplevel-icon-v1.h
245245
gfx/common/wayland/xdg-toplevel-icon-v1.c
246+
gfx/common/wayland/xdg-toplevel-tag-v1.h
247+
gfx/common/wayland/xdg-toplevel-tag-v1.c
246248
gfx/common/wayland/webos-foreign.c
247249
gfx/common/wayland/webos-foreign.h
248250
gfx/common/wayland/webos-input-manager.c

Makefile.common

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,6 +1304,7 @@ ifeq ($(HAVE_WAYLAND), 1)
13041304
gfx/common/wayland/fractional-scale-v1.o \
13051305
gfx/common/wayland/viewporter.o \
13061306
gfx/common/wayland/xdg-toplevel-icon-v1.o \
1307+
gfx/common/wayland/xdg-toplevel-tag-v1.o \
13071308
gfx/common/wayland/xdg-shell.o \
13081309
gfx/common/wayland/idle-inhibit-unstable-v1.o \
13091310
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 <xaver.hugl@kde.org>
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
@@ -82,6 +82,7 @@ generate_source 'unstable/tablet' 'tablet-unstable-v2'
8282
generate_source 'staging/content-type' 'content-type-v1'
8383
generate_source 'staging/single-pixel-buffer' 'single-pixel-buffer-v1'
8484
generate_source 'staging/xdg-toplevel-icon' 'xdg-toplevel-icon-v1'
85+
generate_source 'staging/xdg-toplevel-tag' 'xdg-toplevel-tag-v1'
8586

8687
if [ -n "${CROSS_COMPILE:-}" ] && echo "${CROSS_COMPILE:-}" | grep -q "webos"; then
8788
if [ -z "${STAGING_DIR:-}" ]; then

gfx/common/wayland_common.c

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535

3636
#define SPLASH_SHM_NAME "retroarch-wayland-vk-splash"
3737

38-
#define WINDOW_TITLE "RetroArch"
38+
#define DEFAULT_WINDOW_TITLE "RetroArch"
39+
#define MAIN_WINDOW_TAG "main window"
3940

4041
#ifdef HAVE_LIBDECOR_H
4142
#include <libdecor.h>
@@ -319,10 +320,10 @@ void gfx_ctx_wl_destroy_resources_common(gfx_ctx_wayland_data_t *wl)
319320
if (wl->wl_touch)
320321
wl_touch_destroy(wl->wl_touch);
321322

322-
if (wl->cursor.theme)
323-
wl_cursor_theme_destroy(wl->cursor.theme);
324323
if (wl->cursor.surface)
325324
wl_surface_destroy(wl->cursor.surface);
325+
if (wl->cursor.theme)
326+
wl_cursor_theme_destroy(wl->cursor.theme);
326327

327328
if (wl->viewport)
328329
wp_viewport_destroy(wl->viewport);
@@ -332,19 +333,21 @@ void gfx_ctx_wl_destroy_resources_common(gfx_ctx_wayland_data_t *wl)
332333
zwp_idle_inhibitor_v1_destroy(wl->idle_inhibitor);
333334
if (wl->deco)
334335
zxdg_toplevel_decoration_v1_destroy(wl->deco);
335-
if (wl->xdg_toplevel)
336-
xdg_toplevel_destroy(wl->xdg_toplevel);
337-
if (wl->xdg_toplevel_icon_manager)
338-
xdg_toplevel_icon_manager_v1_destroy(wl->xdg_toplevel_icon_manager);
339336
if (wl->xdg_toplevel_icon)
340337
xdg_toplevel_icon_v1_destroy(wl->xdg_toplevel_icon);
338+
if (wl->xdg_toplevel)
339+
xdg_toplevel_destroy(wl->xdg_toplevel);
341340
if (wl->xdg_surface)
342341
xdg_surface_destroy(wl->xdg_surface);
343342
if (wl->surface)
344343
wl_surface_destroy(wl->surface);
345344

346345
if (wl->deco_manager)
347346
zxdg_decoration_manager_v1_destroy(wl->deco_manager);
347+
if (wl->xdg_toplevel_icon_manager)
348+
xdg_toplevel_icon_manager_v1_destroy(wl->xdg_toplevel_icon_manager);
349+
if (wl->xdg_toplevel_tag_manager)
350+
xdg_toplevel_tag_manager_v1_destroy(wl->xdg_toplevel_tag_manager);
348351
if (wl->idle_inhibit_manager)
349352
zwp_idle_inhibit_manager_v1_destroy(wl->idle_inhibit_manager);
350353
else
@@ -427,6 +430,7 @@ void gfx_ctx_wl_destroy_resources_common(gfx_ctx_wayland_data_t *wl)
427430
wl->xdg_toplevel = NULL;
428431
wl->xdg_toplevel_icon = NULL;
429432
wl->xdg_toplevel_icon_manager = NULL;
433+
wl->xdg_toplevel_tag_manager = NULL;
430434
wl->deco = NULL;
431435
wl->idle_inhibitor = NULL;
432436
wl->wl_touch = NULL;
@@ -849,6 +853,11 @@ bool gfx_ctx_wl_init_common(
849853
RARCH_LOG("[Wayland] Compositor doesn't support the %s protocol.\n", xdg_toplevel_icon_manager_v1_interface.name);
850854
}
851855

856+
if (!wl->xdg_toplevel_tag_manager)
857+
{
858+
RARCH_LOG("[Wayland] Compositor doesn't support the %s protocol.\n", xdg_toplevel_tag_manager_v1_interface.name);
859+
}
860+
852861
wl->surface = wl_compositor_create_surface(wl->compositor);
853862
if (wl->viewporter)
854863
wl->viewport = wp_viewporter_get_viewport(wl->viewporter, wl->surface);
@@ -880,14 +889,23 @@ bool gfx_ctx_wl_init_common(
880889
return false;
881890
}
882891

892+
struct xdg_toplevel *xdg_toplevel = wl->libdecor_frame_get_xdg_toplevel(wl->libdecor_frame);
893+
883894
if (wl->xdg_toplevel_icon_manager)
884895
{
885-
struct xdg_toplevel *xdg_toplevel = wl->libdecor_frame_get_xdg_toplevel(wl->libdecor_frame);
886896
wl_create_toplevel_icon(wl, xdg_toplevel);
887897
}
888898

899+
if (wl->xdg_toplevel_tag_manager)
900+
{
901+
xdg_toplevel_tag_manager_v1_set_toplevel_tag(
902+
wl->xdg_toplevel_tag_manager, xdg_toplevel, MAIN_WINDOW_TAG);
903+
xdg_toplevel_tag_manager_v1_set_toplevel_description(
904+
wl->xdg_toplevel_tag_manager, xdg_toplevel, DEFAULT_WINDOW_TITLE " " MAIN_WINDOW_TAG);
905+
}
906+
889907
wl->libdecor_frame_set_app_id(wl->libdecor_frame, WAYLAND_APP_ID);
890-
wl->libdecor_frame_set_title(wl->libdecor_frame, WINDOW_TITLE);
908+
wl->libdecor_frame_set_title(wl->libdecor_frame, DEFAULT_WINDOW_TITLE);
891909
wl->libdecor_frame_map(wl->libdecor_frame);
892910

893911
/* Waiting for libdecor to be configured before starting to draw */
@@ -913,7 +931,7 @@ bool gfx_ctx_wl_init_common(
913931
xdg_toplevel_add_listener(wl->xdg_toplevel, &toplevel_listener->xdg_toplevel_listener, wl);
914932

915933
xdg_toplevel_set_app_id(wl->xdg_toplevel, WAYLAND_APP_ID);
916-
xdg_toplevel_set_title(wl->xdg_toplevel, WINDOW_TITLE);
934+
xdg_toplevel_set_title(wl->xdg_toplevel, DEFAULT_WINDOW_TITLE);
917935

918936
if (wl->deco_manager)
919937
wl->deco = zxdg_decoration_manager_v1_get_toplevel_decoration(
@@ -922,6 +940,14 @@ bool gfx_ctx_wl_init_common(
922940
if (wl->xdg_toplevel_icon_manager)
923941
wl_create_toplevel_icon(wl, wl->xdg_toplevel);
924942

943+
if (wl->xdg_toplevel_tag_manager)
944+
{
945+
xdg_toplevel_tag_manager_v1_set_toplevel_tag(
946+
wl->xdg_toplevel_tag_manager, wl->xdg_toplevel, MAIN_WINDOW_TAG);
947+
xdg_toplevel_tag_manager_v1_set_toplevel_description(
948+
wl->xdg_toplevel_tag_manager, wl->xdg_toplevel, DEFAULT_WINDOW_TITLE " " MAIN_WINDOW_TAG);
949+
}
950+
925951
/* Waiting for xdg_toplevel to be configured before starting to draw */
926952
wl_surface_commit(wl->surface);
927953
wl->configured = true;

input/common/wayland_common.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,10 @@ static void wl_registry_handle_global(void *data, struct wl_registry *reg,
833833
wl->xdg_toplevel_icon_manager = (struct xdg_toplevel_icon_manager_v1*)
834834
wl_registry_bind(
835835
reg, id, &xdg_toplevel_icon_manager_v1_interface, MIN(version, 1));
836+
else if (string_is_equal(interface, xdg_toplevel_tag_manager_v1_interface.name) && found++)
837+
wl->xdg_toplevel_tag_manager = (struct xdg_toplevel_tag_manager_v1*)
838+
wl_registry_bind(
839+
reg, id, &xdg_toplevel_tag_manager_v1_interface, MIN(version, 1));
836840

837841
if (found > 1)
838842
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
@@ -50,6 +50,7 @@
5050
#include "../../gfx/common/wayland/xdg-decoration-unstable-v1.h"
5151
#include "../../gfx/common/wayland/xdg-shell.h"
5252
#include "../../gfx/common/wayland/xdg-toplevel-icon-v1.h"
53+
#include "../../gfx/common/wayland/xdg-toplevel-tag-v1.h"
5354

5455
#ifdef WEBOS
5556
#include "wayland_common_webos.h"
@@ -173,6 +174,7 @@ typedef struct gfx_ctx_wayland_data
173174
struct xdg_toplevel *xdg_toplevel;
174175
struct xdg_toplevel_icon_v1 *xdg_toplevel_icon;
175176
struct xdg_toplevel_icon_manager_v1 *xdg_toplevel_icon_manager;
177+
struct xdg_toplevel_tag_manager_v1 *xdg_toplevel_tag_manager;
176178
struct wl_keyboard *wl_keyboard;
177179
struct wl_pointer *wl_pointer;
178180
struct zwp_relative_pointer_v1 *wl_relative_pointer;

qb/config.libs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ check_header '' XSHM X11/Xlib.h X11/extensions/XShm.h
670670
check_val '' XKBCOMMON -lxkbcommon '' xkbcommon 0.3.2 '' false
671671
check_val '' WAYLAND '-lwayland-egl -lwayland-client' '' wayland-egl 10.1.0 '' false
672672
check_val '' WAYLAND_CURSOR -lwayland-cursor '' wayland-cursor 1.12 '' false
673-
check_pkgconf WAYLAND_PROTOS wayland-protocols 1.37
673+
check_pkgconf WAYLAND_PROTOS wayland-protocols 1.43
674674
check_pkgconf WAYLAND_SCANNER wayland-scanner '1.15 1.12'
675675

676676
if [ "$HAVE_WAYLAND_SCANNER" = yes ] &&

0 commit comments

Comments
 (0)