Skip to content

Commit

Permalink
Merge pull request godotengine#99965 from Riteo/unstable-galore
Browse files Browse the repository at this point in the history
Wayland: Add support for xdg-foreign-unstable-v2
  • Loading branch information
Repiteo committed Dec 11, 2024
2 parents 3dacc5f + 65c28ed commit 3877573
Show file tree
Hide file tree
Showing 4 changed files with 287 additions and 23 deletions.
17 changes: 14 additions & 3 deletions platform/linuxbsd/wayland/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,25 @@ env.WAYLAND_API_CODE(
)

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

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

env.WAYLAND_API_HEADER(
target="protocol/xdg_foreign_v2.gen.h",
source="#thirdparty/wayland-protocols/unstable/xdg-foreign/xdg-foreign-unstable-v2.xml",
)

env.WAYLAND_API_CODE(
target="protocol/xdg_foreign_v2.gen.c",
source="#thirdparty/wayland-protocols/unstable/xdg-foreign/xdg-foreign-unstable-v2.xml",
)

env.WAYLAND_API_HEADER(
target="protocol/xdg_system_bell.gen.h",
source="#thirdparty/wayland-protocols/staging/xdg-system-bell/xdg-system-bell-v1.xml",
Expand All @@ -188,7 +198,8 @@ source_files = [
"protocol/fractional_scale.gen.c",
"protocol/xdg_shell.gen.c",
"protocol/xdg_system_bell.gen.c",
"protocol/xdg_foreign.gen.c",
"protocol/xdg_foreign_v1.gen.c",
"protocol/xdg_foreign_v2.gen.c",
"protocol/xdg_decoration.gen.c",
"protocol/xdg_activation.gen.c",
"protocol/relative_pointer.gen.c",
Expand Down
60 changes: 47 additions & 13 deletions platform/linuxbsd/wayland/wayland_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,16 @@ void WaylandThread::_wl_registry_on_global(void *data, struct wl_registry *wl_re
return;
}

// NOTE: Deprecated.
if (strcmp(interface, zxdg_exporter_v1_interface.name) == 0) {
registry->xdg_exporter = (struct zxdg_exporter_v1 *)wl_registry_bind(wl_registry, name, &zxdg_exporter_v1_interface, 1);
registry->xdg_exporter_name = name;
registry->xdg_exporter_v1 = (struct zxdg_exporter_v1 *)wl_registry_bind(wl_registry, name, &zxdg_exporter_v1_interface, 1);
registry->xdg_exporter_v1_name = name;
return;
}

if (strcmp(interface, zxdg_exporter_v2_interface.name) == 0) {
registry->xdg_exporter_v2 = (struct zxdg_exporter_v2 *)wl_registry_bind(wl_registry, name, &zxdg_exporter_v2_interface, 1);
registry->xdg_exporter_v2_name = name;
return;
}

Expand Down Expand Up @@ -599,13 +606,25 @@ void WaylandThread::_wl_registry_on_global_remove(void *data, struct wl_registry
return;
}

if (name == registry->xdg_exporter_name) {
if (registry->xdg_exporter) {
zxdg_exporter_v1_destroy(registry->xdg_exporter);
registry->xdg_exporter = nullptr;
// NOTE: Deprecated.
if (name == registry->xdg_exporter_v1_name) {
if (registry->xdg_exporter_v1) {
zxdg_exporter_v1_destroy(registry->xdg_exporter_v1);
registry->xdg_exporter_v1 = nullptr;
}

registry->xdg_exporter_v1_name = 0;

return;
}

if (name == registry->xdg_exporter_v2_name) {
if (registry->xdg_exporter_v2) {
zxdg_exporter_v2_destroy(registry->xdg_exporter_v2);
registry->xdg_exporter_v2 = nullptr;
}

registry->xdg_exporter_name = 0;
registry->xdg_exporter_v2_name = 0;

return;
}
Expand Down Expand Up @@ -1186,7 +1205,15 @@ void WaylandThread::_xdg_toplevel_on_wm_capabilities(void *data, struct xdg_topl
}
}

void WaylandThread::_xdg_exported_on_exported(void *data, zxdg_exported_v1 *exported, const char *handle) {
// NOTE: Deprecated.
void WaylandThread::_xdg_exported_v1_on_handle(void *data, zxdg_exported_v1 *exported, const char *handle) {
WindowState *ws = (WindowState *)data;
ERR_FAIL_NULL(ws);

ws->exported_handle = vformat("wayland:%s", String::utf8(handle));
}

void WaylandThread::_xdg_exported_v2_on_handle(void *data, zxdg_exported_v2 *exported, const char *handle) {
WindowState *ws = (WindowState *)data;
ERR_FAIL_NULL(ws);

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

if (registry.xdg_exporter) {
ws.xdg_exported = zxdg_exporter_v1_export(registry.xdg_exporter, ws.wl_surface);
zxdg_exported_v1_add_listener(ws.xdg_exported, &xdg_exported_listener, &ws);
if (registry.xdg_exporter_v2) {
ws.xdg_exported_v2 = zxdg_exporter_v2_export_toplevel(registry.xdg_exporter_v2, ws.wl_surface);
zxdg_exported_v2_add_listener(ws.xdg_exported_v2, &xdg_exported_v2_listener, &ws);
} else if (registry.xdg_exporter_v1) {
ws.xdg_exported_v1 = zxdg_exporter_v1_export(registry.xdg_exporter_v1, ws.wl_surface);
zxdg_exported_v1_add_listener(ws.xdg_exported_v1, &xdg_exported_v1_listener, &ws);
}

wl_surface_commit(ws.wl_surface);
Expand Down Expand Up @@ -4410,10 +4440,14 @@ void WaylandThread::destroy() {
xdg_wm_base_destroy(registry.xdg_wm_base);
}

if (registry.xdg_exporter) {
zxdg_exporter_v1_destroy(registry.xdg_exporter);
// NOTE: Deprecated.
if (registry.xdg_exporter_v1) {
zxdg_exporter_v1_destroy(registry.xdg_exporter_v1);
}

if (registry.xdg_exporter_v2) {
zxdg_exporter_v2_destroy(registry.xdg_exporter_v2);
}
if (registry.wl_shm) {
wl_shm_destroy(registry.wl_shm);
}
Expand Down
33 changes: 26 additions & 7 deletions platform/linuxbsd/wayland/wayland_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,13 @@
#include "wayland/protocol/wayland.gen.h"
#include "wayland/protocol/xdg_activation.gen.h"
#include "wayland/protocol/xdg_decoration.gen.h"
#include "wayland/protocol/xdg_foreign.gen.h"
#include "wayland/protocol/xdg_foreign_v2.gen.h"
#include "wayland/protocol/xdg_shell.gen.h"
#include "wayland/protocol/xdg_system_bell.gen.h"

// NOTE: Deprecated.
#include "wayland/protocol/xdg_foreign_v1.gen.h"

#ifdef LIBDECOR_ENABLED
#ifdef SOWRAP_ENABLED
#include "dynwrappers/libdecor-so_wrap.h"
Expand Down Expand Up @@ -149,8 +152,12 @@ class WaylandThread {
struct xdg_wm_base *xdg_wm_base = nullptr;
uint32_t xdg_wm_base_name = 0;

struct zxdg_exporter_v1 *xdg_exporter = nullptr;
uint32_t xdg_exporter_name = 0;
// NOTE: Deprecated.
struct zxdg_exporter_v1 *xdg_exporter_v1 = nullptr;
uint32_t xdg_exporter_v1_name = 0;

uint32_t xdg_exporter_v2_name = 0;
struct zxdg_exporter_v2 *xdg_exporter_v2 = nullptr;

// wayland-protocols globals.

Expand Down Expand Up @@ -224,7 +231,11 @@ class WaylandThread {

struct wp_viewport *wp_viewport = nullptr;
struct wp_fractional_scale_v1 *wp_fractional_scale = nullptr;
struct zxdg_exported_v1 *xdg_exported = nullptr;

// NOTE: Deprecated.
struct zxdg_exported_v1 *xdg_exported_v1 = nullptr;

struct zxdg_exported_v2 *xdg_exported_v2 = nullptr;

String exported_handle;

Expand Down Expand Up @@ -652,7 +663,10 @@ class WaylandThread {

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

static void _xdg_exported_on_exported(void *data, zxdg_exported_v1 *exported, const char *handle);
// NOTE: Deprecated.
static void _xdg_exported_v1_on_handle(void *data, zxdg_exported_v1 *exported, const char *handle);

static void _xdg_exported_v2_on_handle(void *data, zxdg_exported_v2 *exported, const char *handle);

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

Expand Down Expand Up @@ -820,8 +834,13 @@ class WaylandThread {
.done = _wp_text_input_on_done,
};

static constexpr struct zxdg_exported_v1_listener xdg_exported_listener = {
.handle = _xdg_exported_on_exported
// NOTE: Deprecated.
static constexpr struct zxdg_exported_v1_listener xdg_exported_v1_listener = {
.handle = _xdg_exported_v1_on_handle,
};

static constexpr struct zxdg_exported_v2_listener xdg_exported_v2_listener = {
.handle = _xdg_exported_v2_on_handle,
};

static constexpr struct zxdg_toplevel_decoration_v1_listener xdg_toplevel_decoration_listener = {
Expand Down
Loading

0 comments on commit 3877573

Please sign in to comment.