- Windows now use libdecor when present.

This commit is contained in:
2025-12-15 16:29:00 -05:00
parent b64ce44d4e
commit 97f5bbfe00
6 changed files with 225 additions and 102 deletions

View File

@@ -23,8 +23,8 @@
#include <fennec/platform/linux/wayland/server.h>
#include <fennec/platform/linux/wayland/window.h>
#include <fennec/platform/linux/wayland/lib/loader.h>
#include <fennec/platform/linux/wayland/lib/wayland.h>
#include <fennec/platform/linux/wayland/lib/loader.h>
#include <fennec/platform/linux/wayland/lib/headers/xdg-shell-client-protocols.h>
#if FENNEC_HAS_LIBDECOR
@@ -36,13 +36,13 @@ namespace fennec
wayland_server::wayland_server(fennec::platform* p)
: display_server_base(p)
, display(nullptr), registry(nullptr), compositor(nullptr), seat(nullptr), fifo(false), libdecor(false) {
, display(nullptr), registry(nullptr), compositor(nullptr), seat(nullptr), fifo(false), has_libdecor(false) {
// load shared lib
assertf(libwayland::load_symbols(platform), "Failed to load libwayland.");
#if FENNEC_HAS_LIBDECOR
libdecor = libdecor::load_symbols(platform);
has_libdecor = libdecor::load_symbols(platform);
#endif
}
@@ -58,7 +58,7 @@ wayland_server::~wayland_server() {
void wayland_server::connect() {
static constexpr wl_registry_listener listener = {
listen_global, listen_global_remove
_wl_registry_listen_global, _wl_registry_on_global_remove
};
if (display != nullptr) {
@@ -90,6 +90,27 @@ void wayland_server::connect() {
return;
}
#if FENNEC_HAS_LIBDECOR
static libdecor_interface libdecor_listener = {
.error = _libdecor_on_error,
.reserved0 = nullptr,
.reserved1 = nullptr,
.reserved2 = nullptr,
.reserved3 = nullptr,
.reserved4 = nullptr,
.reserved5 = nullptr,
.reserved6 = nullptr,
.reserved7 = nullptr,
.reserved8 = nullptr,
.reserved9 = nullptr,
};
if (has_libdecor) {
libdecor = libdecor_new(display, &libdecor_listener);
}
#endif
auto contexts = ctx_registry::get_type_list();
while (not contexts.empty()) {
const auto& ctx = contexts.front();
@@ -154,13 +175,13 @@ window* wayland_server::create_window(const window::config& conf) {
return windows[id];
}
void wayland_server::listen_global(void* data, wl_registry* reg, uint32_t id, const char* name, uint32_t version) {
void wayland_server::_wl_registry_listen_global(void* data, wl_registry* reg, uint32_t id, const char* name, uint32_t version) {
static constexpr wl_seat_listener seat_listener = {
listen_seat_capabilities, listen_seat_name
_wl_seat_listen_capabilities, _wl_seat_listen_name
};
static constexpr xdg_wm_base_listener xdg_listener = {
listen_xdg_ping
_xdg_listen_ping
};
wayland_server* server = static_cast<wayland_server*>(data);
@@ -189,20 +210,28 @@ void wayland_server::listen_global(void* data, wl_registry* reg, uint32_t id, co
}
}
void wayland_server::listen_global_remove(void*, wl_registry*, uint32_t) {
void wayland_server::_wl_registry_on_global_remove(void*, wl_registry*, uint32_t) {
}
void wayland_server::listen_seat_capabilities(void*, wl_seat*, uint32_t) {
void wayland_server::_wl_seat_listen_capabilities(void*, wl_seat*, uint32_t) {
}
void wayland_server::listen_seat_name(void*, wl_seat*, const char*) {}
void wayland_server::_wl_seat_listen_name(void*, wl_seat*, const char*) {}
void wayland_server::listen_xdg_ping(void*, xdg_wm_base* xdg, uint32_t serial) {
void wayland_server::_xdg_listen_ping(void*, xdg_wm_base* xdg, uint32_t serial) {
xdg_wm_base_pong(xdg, serial);
}
#if FENNEC_HAS_LIBDECOR
void wayland_server::_libdecor_on_error(struct libdecor*, libdecor_error error, const char* message) {
fennec::logger::log(
fennec::format("libdecor error ({}): {}", static_cast<int>(error), fennec::cstring(message, strlen(message)))
);
}
#endif
}

View File

@@ -18,11 +18,16 @@
#include <fennec/platform/interface/display_server.h>
#include <fennec/renderers/interface/gfxcontext.h>
#include <fennec/platform/linux/wayland/server.h>
#include <fennec/platform/linux/wayland/window.h>
#include <fennec/platform/linux/wayland/lib/wayland.h>
#include <fennec/platform/linux/wayland/lib/headers/xdg-shell-client-protocols.h>
#include <fennec/renderers/interface/gfxcontext.h>
#if FENNEC_HAS_LIBDECOR
#include <fennec/platform/linux/wayland/libdecor/libdecor.h>
#endif
using namespace fennec;
@@ -39,20 +44,25 @@ wayland_window::~wayland_window() {
void wayland_window::show() {
static constexpr wl_surface_listener surface_listener = {
listen_enter, listen_leave, listen_preferred_buffer_scale, listen_preferred_buffer_transform
.enter = _wl_surface_listen_enter,
.leave = _wl_surface_listen_leave,
.preferred_buffer_scale = _wl_surface_listen_preferred_buffer_scale,
.preferred_buffer_transform = _wl_surface_listen_preferred_buffer_transform
};
static constexpr xdg_surface_listener xdg_surface_listener = {
listen_xdg_surface_configure
.configure = _xdg_surface_listen_configure
};
static constexpr xdg_toplevel_listener xdg_toplevel_listener = {
listen_xdg_toplevel_configure, listen_xdg_toplevel_close, listen_xdg_toplevel_configure_bounds,
listen_xdg_toplevel_capabilities
.configure = _xdg_toplevel_listen_configure,
.close = _xdg_toplevel_listen_close,
.configure_bounds = _xdg_toplevel_listen_configure_bounds,
.wm_capabilities = _xdg_toplevel_listen_wm_capabilities
};
static constexpr wl_callback_listener frame_callback_listener = {
listen_frame_callback
.done = _wl_frame_listen_done
};
if (is_visible()) {
@@ -77,15 +87,42 @@ void wayland_window::show() {
surface = wl_compositor_create_surface(wl_server->compositor);
wl_surface_add_listener(surface, &surface_listener, this);
#if FENNEC_HAS_LIBDECOR
static libdecor_frame_interface libdecor_frame_listener = {
.configure = _libdecor_frame_listen_configure,
.close = _libdecor_frame_listen_close,
.commit = _libdecor_frame_listen_commit,
.dismiss_popup = _libdecor_frame_listen_dismiss_popup,
xdgsurface = xdg_wm_base_get_xdg_surface(wl_server->xdg, surface);
xdg_surface_add_listener(xdgsurface, &xdg_surface_listener, this);
.reserved0 = nullptr,
.reserved1 = nullptr,
.reserved2 = nullptr,
.reserved3 = nullptr,
.reserved4 = nullptr,
.reserved5 = nullptr,
.reserved6 = nullptr,
.reserved7 = nullptr,
.reserved8 = nullptr,
.reserved9 = nullptr,
};
xdgtoplevel = xdg_surface_get_toplevel(xdgsurface);
xdg_toplevel_add_listener(xdgtoplevel, &xdg_toplevel_listener, this);
if (wl_server->has_libdecor) {
libdecorframe = libdecor_decorate(wl_server->libdecor, surface, &libdecor_frame_listener, this);
libdecor_frame_map(libdecorframe);
xdgsurface = libdecor_frame_get_xdg_surface(libdecorframe);
xdgtoplevel = libdecor_frame_get_xdg_toplevel(libdecorframe);
} else
#endif
{
xdgsurface = xdg_wm_base_get_xdg_surface(wl_server->xdg, surface);
xdg_surface_add_listener(xdgsurface, &xdg_surface_listener, this);
xdgtoplevel = xdg_surface_get_toplevel(xdgsurface);
xdg_toplevel_add_listener(xdgtoplevel, &xdg_toplevel_listener, this);
if (has_decorations()) {
}
@@ -109,16 +146,24 @@ void wayland_window::hide() {
wayland_server* wl_server = static_cast<wayland_server*>(server);
if (xdgtoplevel) {
xdg_toplevel_destroy(xdgtoplevel);
xdgtoplevel = nullptr;
}
if (frame_callback) {
wl_callback_destroy(frame_callback);
frame_callback = nullptr;
}
#if FENNEC_HAS_LIBDECOR
if (libdecorframe) {
libdecor_frame_unref(libdecorframe);
xdgtoplevel = nullptr;
xdgsurface = nullptr;
}
#endif
if (xdgtoplevel) {
xdg_toplevel_destroy(xdgtoplevel);
xdgtoplevel = nullptr;
}
if (xdgsurface) {
xdg_surface_destroy(xdgsurface);
xdgsurface = nullptr;
@@ -143,24 +188,50 @@ bool wayland_window::set_flag(uint8_t, bool) {
return false;
}
void wayland_window::listen_enter(void*, wl_surface*, wl_output*) {}
void wayland_window::listen_leave(void*, wl_surface*, wl_output*) {}
void wayland_window::listen_preferred_buffer_scale(void*, wl_surface*, int32_t) {}
void wayland_window::listen_preferred_buffer_transform(void*, wl_surface*, uint32_t) {}
// Surface Listeners
void wayland_window::listen_frame_callback(void*, wl_callback*, uint32_t) {}
void wayland_window::_wl_surface_listen_enter(void*, wl_surface*, wl_output*) {}
void wayland_window::_wl_surface_listen_leave(void*, wl_surface*, wl_output*) {}
void wayland_window::_wl_surface_listen_preferred_buffer_scale(void*, wl_surface*, int32_t) {}
void wayland_window::_wl_surface_listen_preferred_buffer_transform(void*, wl_surface*, uint32_t) {}
void wayland_window::listen_xdg_surface_configure(void*, xdg_surface* xdg, uint32_t serial) {
// Frame Listeners
void wayland_window::_wl_frame_listen_done(void*, wl_callback*, uint32_t) {}
// XDG Listeners
void wayland_window::_xdg_surface_listen_configure(void*, xdg_surface* xdg, uint32_t serial) {
xdg_surface_ack_configure(xdg, serial);
}
void wayland_window::listen_xdg_toplevel_configure(void*, xdg_toplevel*, int32_t, int32_t, wl_array*) {}
void wayland_window::listen_xdg_toplevel_configure_bounds(void*, xdg_toplevel*, int32_t, int32_t) {}
void wayland_window::_xdg_toplevel_listen_configure(void*, xdg_toplevel*, int32_t, int32_t, wl_array*) {}
void wayland_window::_xdg_toplevel_listen_configure_bounds(void*, xdg_toplevel*, int32_t, int32_t) {}
void wayland_window::listen_xdg_toplevel_close(void* data, xdg_toplevel*) {
void wayland_window::_xdg_toplevel_listen_close(void* data, xdg_toplevel*) {
wayland_window* window = static_cast<wayland_window*>(data);
window->hide();
}
void wayland_window::listen_xdg_toplevel_capabilities(void*, xdg_toplevel*, wl_array*) {}
void wayland_window::_xdg_toplevel_listen_wm_capabilities(void*, xdg_toplevel*, wl_array*) {}
// Libdecor Listeners
#if FENNEC_HAS_LIBDECOR
void wayland_window::_libdecor_frame_listen_configure(libdecor_frame*, libdecor_configuration*, void*) {}
void wayland_window::_libdecor_frame_listen_close(libdecor_frame*, void* data) {
wayland_window* window = static_cast<wayland_window*>(data);
window->hide();
}
void wayland_window::_libdecor_frame_listen_commit(libdecor_frame*, void*) {}
void wayland_window::_libdecor_frame_listen_dismiss_popup(libdecor_frame*, const char*, void*) {}
#endif