- Setup dynamic linking to libdecor

This commit is contained in:
2025-12-15 15:23:30 -05:00
parent 1acf00138a
commit b64ce44d4e
9 changed files with 386 additions and 13 deletions

View File

@@ -0,0 +1,87 @@
// =====================================================================================================================
// fennec, a free and open source game engine
// Copyright © 2025 Medusa Slockbower
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================
#include <libdecor.h>
#include <fennec/platform/linux/wayland/libdecor/loader.h>
#define FENNEC_LIB(name) bool FENNEC_HAS_LIB_##name;
#define FENNEC_SYMBOL(ret, fn, ...) using LIBDECOR_sym_##fn = ret(*)(__VA_ARGS__); \
LIBDECOR_sym_##fn LIBDECOR_##fn;
#define FENNEC_GLOBAL(type, name) type* LIBDECOR_##name;
#include <fennec/platform/linux/wayland/libdecor/sym.h>
namespace fennec
{
namespace libdecor
{
using shared_object = platform::shared_object;
struct shared_lib {
shared_object* obj;
const cstring name;
};
static int _load_count = 0;
// Create private variables
#define FENNEC_LIB(lib) static shared_lib _FENNEC_LIB_##lib = { nullptr, FENNEC_LIB_##lib };
#include <fennec/platform/linux/wayland/libdecor/sym.h>
bool load_symbols(platform* platform) {
if (_load_count++ != 0) {
return true;
}
shared_lib* current_lib = nullptr;
#define FENNEC_LIB(lib) _FENNEC_LIB_##lib.obj = platform->load_object(_FENNEC_LIB_##lib.name); \
FENNEC_HAS_LIB_##lib = _FENNEC_LIB_##lib.obj != nullptr; \
if(not FENNEC_HAS_LIB_##lib) { \
unload_symbols(platform); \
return false; \
} \
current_lib = &_FENNEC_LIB_##lib;
#define FENNEC_SYMBOL(ret, fn, ...) LIBDECOR_##fn = (LIBDECOR_sym_##fn)(platform->find_symbol(current_lib->obj, #fn)); \
assertf(LIBDECOR_##fn != nullptr, "Failed to find symbol: " #fn);
#define FENNEC_GLOBAL(type, name) LIBDECOR_##name = (type*)(platform->find_symbol(current_lib->obj, #name)); \
assertf(LIBDECOR_##name != nullptr, "Failed to find global: " #name);
#include <fennec/platform/linux/wayland/libdecor/sym.h>
return true;
}
void unload_symbols(platform* platform) {
if (--_load_count != 0) {
return;
}
#define FENNEC_LIB(lib) platform->unload_object(_FENNEC_LIB_##lib.obj); \
_FENNEC_LIB_##lib.obj = nullptr;
#define FENNEC_SYMBOL(ret, fn, ...) LIBDECOR_##fn = nullptr;
#define FENNEC_GLOBAL(type, name) LIBDECOR_##name = nullptr;
#include <fennec/platform/linux/wayland/libdecor/sym.h>
}
}
}

View File

@@ -17,24 +17,33 @@
// =====================================================================================================================
#include <fennec/core/logger.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/loader.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/loader.h>
#endif
namespace fennec
{
wayland_server::wayland_server(fennec::platform* p)
: display_server_base(p)
, display(nullptr), registry(nullptr), compositor(nullptr), seat(nullptr), fifo(false) {
, display(nullptr), registry(nullptr), compositor(nullptr), seat(nullptr), fifo(false), libdecor(false) {
// load shared lib
if (libwayland::load_symbols(platform)) {
return;
}
assertf(libwayland::load_symbols(platform), "Failed to load libwayland.");
#if FENNEC_HAS_LIBDECOR
libdecor = libdecor::load_symbols(platform);
#endif
}
wayland_server::~wayland_server() {

View File

@@ -59,6 +59,12 @@ void wayland_window::show() {
return;
}
if (is_running()) {
// reshow window
return;
}
wayland_window* root = this;
while (root != nullptr and root->is_popup()) {
root = static_cast<wayland_window*>(root->get_parent());
@@ -78,6 +84,10 @@ void wayland_window::show() {
xdgtoplevel = xdg_surface_get_toplevel(xdgsurface);
xdg_toplevel_add_listener(xdgtoplevel, &xdg_toplevel_listener, this);
if (has_decorations()) {
}
frame_callback = wl_surface_frame(surface);
wl_callback_add_listener(frame_callback, &frame_callback_listener, this);