Skip to content

Commit 65c28ed

Browse files
committed
Wayland: Add support for xdg-foreign-unstable-v2
The v1 version is deprecated and bound to be removed in the future from all compositors. This patch adds a v1/v2 designator to everything related to the protocol and prefers the v2 protocol if both are available. Additionally, renames the event handler to follow the Wayland interface name, for consistency with the rest of the codebase.
1 parent aa8d9b8 commit 65c28ed

File tree

4 files changed

+287
-23
lines changed

4 files changed

+287
-23
lines changed

platform/linuxbsd/wayland/SCsub

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,25 @@ env.WAYLAND_API_CODE(
163163
)
164164

165165
env.WAYLAND_API_HEADER(
166-
target="protocol/xdg_foreign.gen.h",
166+
target="protocol/xdg_foreign_v1.gen.h",
167167
source="#thirdparty/wayland-protocols/unstable/xdg-foreign/xdg-foreign-unstable-v1.xml",
168168
)
169169

170170
env.WAYLAND_API_CODE(
171-
target="protocol/xdg_foreign.gen.c",
171+
target="protocol/xdg_foreign_v1.gen.c",
172172
source="#thirdparty/wayland-protocols/unstable/xdg-foreign/xdg-foreign-unstable-v1.xml",
173173
)
174174

175+
env.WAYLAND_API_HEADER(
176+
target="protocol/xdg_foreign_v2.gen.h",
177+
source="#thirdparty/wayland-protocols/unstable/xdg-foreign/xdg-foreign-unstable-v2.xml",
178+
)
179+
180+
env.WAYLAND_API_CODE(
181+
target="protocol/xdg_foreign_v2.gen.c",
182+
source="#thirdparty/wayland-protocols/unstable/xdg-foreign/xdg-foreign-unstable-v2.xml",
183+
)
184+
175185
env.WAYLAND_API_HEADER(
176186
target="protocol/xdg_system_bell.gen.h",
177187
source="#thirdparty/wayland-protocols/staging/xdg-system-bell/xdg-system-bell-v1.xml",
@@ -188,7 +198,8 @@ source_files = [
188198
"protocol/fractional_scale.gen.c",
189199
"protocol/xdg_shell.gen.c",
190200
"protocol/xdg_system_bell.gen.c",
191-
"protocol/xdg_foreign.gen.c",
201+
"protocol/xdg_foreign_v1.gen.c",
202+
"protocol/xdg_foreign_v2.gen.c",
192203
"protocol/xdg_decoration.gen.c",
193204
"protocol/xdg_activation.gen.c",
194205
"protocol/relative_pointer.gen.c",

platform/linuxbsd/wayland/wayland_thread.cpp

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,16 @@ void WaylandThread::_wl_registry_on_global(void *data, struct wl_registry *wl_re
378378
return;
379379
}
380380

381+
// NOTE: Deprecated.
381382
if (strcmp(interface, zxdg_exporter_v1_interface.name) == 0) {
382-
registry->xdg_exporter = (struct zxdg_exporter_v1 *)wl_registry_bind(wl_registry, name, &zxdg_exporter_v1_interface, 1);
383-
registry->xdg_exporter_name = name;
383+
registry->xdg_exporter_v1 = (struct zxdg_exporter_v1 *)wl_registry_bind(wl_registry, name, &zxdg_exporter_v1_interface, 1);
384+
registry->xdg_exporter_v1_name = name;
385+
return;
386+
}
387+
388+
if (strcmp(interface, zxdg_exporter_v2_interface.name) == 0) {
389+
registry->xdg_exporter_v2 = (struct zxdg_exporter_v2 *)wl_registry_bind(wl_registry, name, &zxdg_exporter_v2_interface, 1);
390+
registry->xdg_exporter_v2_name = name;
384391
return;
385392
}
386393

@@ -600,13 +607,25 @@ void WaylandThread::_wl_registry_on_global_remove(void *data, struct wl_registry
600607
return;
601608
}
602609

603-
if (name == registry->xdg_exporter_name) {
604-
if (registry->xdg_exporter) {
605-
zxdg_exporter_v1_destroy(registry->xdg_exporter);
606-
registry->xdg_exporter = nullptr;
610+
// NOTE: Deprecated.
611+
if (name == registry->xdg_exporter_v1_name) {
612+
if (registry->xdg_exporter_v1) {
613+
zxdg_exporter_v1_destroy(registry->xdg_exporter_v1);
614+
registry->xdg_exporter_v1 = nullptr;
615+
}
616+
617+
registry->xdg_exporter_v1_name = 0;
618+
619+
return;
620+
}
621+
622+
if (name == registry->xdg_exporter_v2_name) {
623+
if (registry->xdg_exporter_v2) {
624+
zxdg_exporter_v2_destroy(registry->xdg_exporter_v2);
625+
registry->xdg_exporter_v2 = nullptr;
607626
}
608627

609-
registry->xdg_exporter_name = 0;
628+
registry->xdg_exporter_v2_name = 0;
610629

611630
return;
612631
}
@@ -1187,7 +1206,15 @@ void WaylandThread::_xdg_toplevel_on_wm_capabilities(void *data, struct xdg_topl
11871206
}
11881207
}
11891208

1190-
void WaylandThread::_xdg_exported_on_exported(void *data, zxdg_exported_v1 *exported, const char *handle) {
1209+
// NOTE: Deprecated.
1210+
void WaylandThread::_xdg_exported_v1_on_handle(void *data, zxdg_exported_v1 *exported, const char *handle) {
1211+
WindowState *ws = (WindowState *)data;
1212+
ERR_FAIL_NULL(ws);
1213+
1214+
ws->exported_handle = vformat("wayland:%s", String::utf8(handle));
1215+
}
1216+
1217+
void WaylandThread::_xdg_exported_v2_on_handle(void *data, zxdg_exported_v2 *exported, const char *handle) {
11911218
WindowState *ws = (WindowState *)data;
11921219
ERR_FAIL_NULL(ws);
11931220

@@ -3285,9 +3312,12 @@ void WaylandThread::window_create(DisplayServer::WindowID p_window_id, int p_wid
32853312
ws.frame_callback = wl_surface_frame(ws.wl_surface);
32863313
wl_callback_add_listener(ws.frame_callback, &frame_wl_callback_listener, &ws);
32873314

3288-
if (registry.xdg_exporter) {
3289-
ws.xdg_exported = zxdg_exporter_v1_export(registry.xdg_exporter, ws.wl_surface);
3290-
zxdg_exported_v1_add_listener(ws.xdg_exported, &xdg_exported_listener, &ws);
3315+
if (registry.xdg_exporter_v2) {
3316+
ws.xdg_exported_v2 = zxdg_exporter_v2_export_toplevel(registry.xdg_exporter_v2, ws.wl_surface);
3317+
zxdg_exported_v2_add_listener(ws.xdg_exported_v2, &xdg_exported_v2_listener, &ws);
3318+
} else if (registry.xdg_exporter_v1) {
3319+
ws.xdg_exported_v1 = zxdg_exporter_v1_export(registry.xdg_exporter_v1, ws.wl_surface);
3320+
zxdg_exported_v1_add_listener(ws.xdg_exported_v1, &xdg_exported_v1_listener, &ws);
32913321
}
32923322

32933323
wl_surface_commit(ws.wl_surface);
@@ -4411,10 +4441,14 @@ void WaylandThread::destroy() {
44114441
xdg_wm_base_destroy(registry.xdg_wm_base);
44124442
}
44134443

4414-
if (registry.xdg_exporter) {
4415-
zxdg_exporter_v1_destroy(registry.xdg_exporter);
4444+
// NOTE: Deprecated.
4445+
if (registry.xdg_exporter_v1) {
4446+
zxdg_exporter_v1_destroy(registry.xdg_exporter_v1);
44164447
}
44174448

4449+
if (registry.xdg_exporter_v2) {
4450+
zxdg_exporter_v2_destroy(registry.xdg_exporter_v2);
4451+
}
44184452
if (registry.wl_shm) {
44194453
wl_shm_destroy(registry.wl_shm);
44204454
}

platform/linuxbsd/wayland/wayland_thread.h

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,13 @@
6767
#include "wayland/protocol/wayland.gen.h"
6868
#include "wayland/protocol/xdg_activation.gen.h"
6969
#include "wayland/protocol/xdg_decoration.gen.h"
70-
#include "wayland/protocol/xdg_foreign.gen.h"
70+
#include "wayland/protocol/xdg_foreign_v2.gen.h"
7171
#include "wayland/protocol/xdg_shell.gen.h"
7272
#include "wayland/protocol/xdg_system_bell.gen.h"
7373

74+
// NOTE: Deprecated.
75+
#include "wayland/protocol/xdg_foreign_v1.gen.h"
76+
7477
#ifdef LIBDECOR_ENABLED
7578
#ifdef SOWRAP_ENABLED
7679
#include "dynwrappers/libdecor-so_wrap.h"
@@ -149,8 +152,12 @@ class WaylandThread {
149152
struct xdg_wm_base *xdg_wm_base = nullptr;
150153
uint32_t xdg_wm_base_name = 0;
151154

152-
struct zxdg_exporter_v1 *xdg_exporter = nullptr;
153-
uint32_t xdg_exporter_name = 0;
155+
// NOTE: Deprecated.
156+
struct zxdg_exporter_v1 *xdg_exporter_v1 = nullptr;
157+
uint32_t xdg_exporter_v1_name = 0;
158+
159+
uint32_t xdg_exporter_v2_name = 0;
160+
struct zxdg_exporter_v2 *xdg_exporter_v2 = nullptr;
154161

155162
// wayland-protocols globals.
156163

@@ -224,7 +231,11 @@ class WaylandThread {
224231

225232
struct wp_viewport *wp_viewport = nullptr;
226233
struct wp_fractional_scale_v1 *wp_fractional_scale = nullptr;
227-
struct zxdg_exported_v1 *xdg_exported = nullptr;
234+
235+
// NOTE: Deprecated.
236+
struct zxdg_exported_v1 *xdg_exported_v1 = nullptr;
237+
238+
struct zxdg_exported_v2 *xdg_exported_v2 = nullptr;
228239

229240
String exported_handle;
230241

@@ -652,7 +663,10 @@ class WaylandThread {
652663

653664
static void _xdg_toplevel_decoration_on_configure(void *data, struct zxdg_toplevel_decoration_v1 *xdg_toplevel_decoration, uint32_t mode);
654665

655-
static void _xdg_exported_on_exported(void *data, zxdg_exported_v1 *exported, const char *handle);
666+
// NOTE: Deprecated.
667+
static void _xdg_exported_v1_on_handle(void *data, zxdg_exported_v1 *exported, const char *handle);
668+
669+
static void _xdg_exported_v2_on_handle(void *data, zxdg_exported_v2 *exported, const char *handle);
656670

657671
static void _xdg_activation_token_on_done(void *data, struct xdg_activation_token_v1 *xdg_activation_token, const char *token);
658672

@@ -820,8 +834,13 @@ class WaylandThread {
820834
.done = _wp_text_input_on_done,
821835
};
822836

823-
static constexpr struct zxdg_exported_v1_listener xdg_exported_listener = {
824-
.handle = _xdg_exported_on_exported
837+
// NOTE: Deprecated.
838+
static constexpr struct zxdg_exported_v1_listener xdg_exported_v1_listener = {
839+
.handle = _xdg_exported_v1_on_handle,
840+
};
841+
842+
static constexpr struct zxdg_exported_v2_listener xdg_exported_v2_listener = {
843+
.handle = _xdg_exported_v2_on_handle,
825844
};
826845

827846
static constexpr struct zxdg_toplevel_decoration_v1_listener xdg_toplevel_decoration_listener = {

0 commit comments

Comments
 (0)