Skip to content

Commit 3877573

Browse files
committed
Merge pull request #99965 from Riteo/unstable-galore
Wayland: Add support for xdg-foreign-unstable-v2
2 parents 3dacc5f + 65c28ed commit 3877573

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
@@ -377,9 +377,16 @@ void WaylandThread::_wl_registry_on_global(void *data, struct wl_registry *wl_re
377377
return;
378378
}
379379

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

@@ -599,13 +606,25 @@ void WaylandThread::_wl_registry_on_global_remove(void *data, struct wl_registry
599606
return;
600607
}
601608

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

608-
registry->xdg_exporter_name = 0;
627+
registry->xdg_exporter_v2_name = 0;
609628

610629
return;
611630
}
@@ -1186,7 +1205,15 @@ void WaylandThread::_xdg_toplevel_on_wm_capabilities(void *data, struct xdg_topl
11861205
}
11871206
}
11881207

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

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

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

32923322
wl_surface_commit(ws.wl_surface);
@@ -4410,10 +4440,14 @@ void WaylandThread::destroy() {
44104440
xdg_wm_base_destroy(registry.xdg_wm_base);
44114441
}
44124442

4413-
if (registry.xdg_exporter) {
4414-
zxdg_exporter_v1_destroy(registry.xdg_exporter);
4443+
// NOTE: Deprecated.
4444+
if (registry.xdg_exporter_v1) {
4445+
zxdg_exporter_v1_destroy(registry.xdg_exporter_v1);
44154446
}
44164447

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

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)