- Refactor on platform implementation. See comment in interface/platform.h for more info
This commit is contained in:
@@ -16,89 +16,24 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// =====================================================================================================================
|
||||
|
||||
#include <fennec/fproc/filesystem/file.h>
|
||||
#include <fennec/platform/linux/platform.h>
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
#ifdef FENNEC_LIB_WAYLAND
|
||||
#include <fennec/platform/linux/wayland/lib/dyn.h>
|
||||
#include <fennec/platform/linux/wayland/displaydev.h>
|
||||
#endif
|
||||
#include <fennec/lang/startup.h>
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
linux_platform::linux_platform()
|
||||
: platform()
|
||||
, _display_driver(display_none) {
|
||||
#if FENNEC_BUILD_SERVER
|
||||
_runtime_server_checks();
|
||||
#else
|
||||
_runtime_client_checks();
|
||||
#endif
|
||||
STATIC_CONSTRUCTOR(_init_linux) {
|
||||
static linux_platform* platform = new linux_platform();
|
||||
file::cout().write(platform, sizeof(platform), 1);
|
||||
}
|
||||
|
||||
linux_platform::~linux_platform() {
|
||||
if (_display) {
|
||||
delete _display;
|
||||
_display = nullptr;
|
||||
}
|
||||
void linux_platform::initialize() {
|
||||
platform::initialize();
|
||||
}
|
||||
|
||||
shared_object* linux_platform::load_object(const cstring& file) {
|
||||
void* handle = dlopen(file, RTLD_NOW | RTLD_LOCAL);
|
||||
const char* load_error = dlerror();
|
||||
assert(handle != nullptr, load_error);
|
||||
return static_cast<shared_object*>(handle);
|
||||
}
|
||||
|
||||
void linux_platform::unload_object(shared_object* obj) {
|
||||
if (obj) {
|
||||
dlclose(obj);
|
||||
}
|
||||
}
|
||||
|
||||
platform::function_pointer linux_platform::find_symbol(shared_object* hndl, const cstring& name) {
|
||||
string _name = name;
|
||||
void* symbol = dlsym(hndl, _name);
|
||||
if (symbol == nullptr) {
|
||||
_name = '_' + _name;
|
||||
symbol = dlsym(hndl, _name);
|
||||
}
|
||||
return (function_pointer)symbol;
|
||||
}
|
||||
|
||||
platform::global linux_platform::find_global(shared_object* hndl, const cstring& name) {
|
||||
string _name = name;
|
||||
void* symbol = dlsym(hndl, _name);
|
||||
if (symbol == nullptr) {
|
||||
_name = '_' + _name;
|
||||
symbol = dlsym(hndl, _name);
|
||||
}
|
||||
return symbol;
|
||||
}
|
||||
|
||||
displaydev* linux_platform::get_display() {
|
||||
return _display;
|
||||
}
|
||||
|
||||
void linux_platform::_runtime_client_checks() {
|
||||
#ifdef FENNEC_LIB_WAYLAND
|
||||
if (libwayland::load_symbols(this)) {
|
||||
_display_driver = display_wayland;
|
||||
_display = new wayland_display(this);
|
||||
libwayland::unload_symbols(this); // Doesn't actually unload symbols, just resets ref counter to only consider
|
||||
// the created display
|
||||
}
|
||||
#endif
|
||||
assertf(_display != nullptr, "failed to find suitable display driver");
|
||||
}
|
||||
|
||||
void linux_platform::_find_display_driver() {
|
||||
|
||||
}
|
||||
|
||||
void linux_platform::_runtime_server_checks() {
|
||||
void linux_platform::shutdown() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -16,47 +16,71 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// =====================================================================================================================
|
||||
|
||||
#include <fennec/platform/linux/wayland/displaydev.h>
|
||||
#include <fennec/platform/linux/wayland/window.h>
|
||||
|
||||
#include <fennec/platform/linux/wayland/lib/dyn.h>
|
||||
#include <fennec/platform/linux/wayland/display.h>
|
||||
#include <fennec/platform/linux/wayland/lib/loader.h>
|
||||
#include <fennec/platform/linux/wayland/lib/wayland-client.h>
|
||||
|
||||
#include <fennec/lang/startup.h>
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
wayland_display::wayland_display(linux_platform* platform)
|
||||
: wayland_display(platform, nullptr) {
|
||||
static display* _create_wayland_display(platform* platform) {
|
||||
wayland_display* display = new wayland_display(platform);
|
||||
if (not display->connected()) {
|
||||
delete display, display = nullptr;
|
||||
}
|
||||
return display;
|
||||
}
|
||||
|
||||
wayland_display::wayland_display(linux_platform* platform, const cstring& drv)
|
||||
: displaydev(platform)
|
||||
STATIC_CONSTRUCTOR(_wayland_init) {
|
||||
platform::add_driver(_create_wayland_display, 1);
|
||||
}
|
||||
|
||||
wayland_display::wayland_display(platform* platform)
|
||||
: display(platform)
|
||||
, _handle(nullptr)
|
||||
, _registry(nullptr)
|
||||
, _compositor(nullptr) {
|
||||
, _compositor(nullptr)
|
||||
, _shell(nullptr)
|
||||
, _seat(nullptr)
|
||||
, _shm(nullptr)
|
||||
, _fifo(false) {
|
||||
|
||||
static constexpr wl_registry_listener listener = {
|
||||
listen_global, listen_global_remove
|
||||
};
|
||||
|
||||
// Load libwayland.so
|
||||
libwayland::load_symbols(get_platform<linux_platform>());
|
||||
libwayland::load_symbols(_platform);
|
||||
|
||||
// Get handles
|
||||
_handle = wl_display_connect(drv);
|
||||
_handle = wl_display_connect(nullptr);
|
||||
|
||||
if (not _handle) {
|
||||
cleanup();
|
||||
return;
|
||||
}
|
||||
|
||||
_registry = wl_display_get_registry(_handle);
|
||||
|
||||
if (not _registry) {
|
||||
cleanup();
|
||||
return;
|
||||
}
|
||||
|
||||
wl_registry_add_listener(_registry, &listener, this);
|
||||
wl_display_roundtrip(_handle);
|
||||
|
||||
if (not _fifo) {
|
||||
assert(_fifo, "Compositor does not support fifo-v1 protocol, falling back to other display protocols.");
|
||||
cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
wayland_display::~wayland_display() {
|
||||
wl_registry_destroy(_registry);
|
||||
wl_display_flush(_handle);
|
||||
wl_display_disconnect(_handle);
|
||||
libwayland::unload_symbols(get_platform<linux_platform>());
|
||||
_handle = nullptr;
|
||||
_platform = nullptr;
|
||||
for (const auto it : _windows) {
|
||||
delete it;
|
||||
if (_handle) {
|
||||
cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,11 +89,29 @@ bool wayland_display::connected() const {
|
||||
}
|
||||
|
||||
window* wayland_display::create_window() {
|
||||
_windows.push_back(new wayland_window(this, nullptr));
|
||||
return (window*)(_windows.back());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void wayland_display::listen_global(void* data, wl_registry* registry, uint32_t name, const char* itfc, uint32_t version) {
|
||||
void wayland_display::cleanup() {
|
||||
|
||||
// Cleanup members
|
||||
if (_shell) wl_shell_destroy(_shell);
|
||||
if (_compositor) wl_compositor_destroy(_compositor);
|
||||
if (_registry) wl_registry_destroy(_registry);
|
||||
if (_handle) {
|
||||
wl_display_flush(_handle);
|
||||
wl_display_disconnect(_handle);
|
||||
}
|
||||
|
||||
_shell = nullptr;
|
||||
_compositor = nullptr;
|
||||
_registry = nullptr;
|
||||
_handle = nullptr;
|
||||
|
||||
libwayland::unload_symbols(_platform);
|
||||
}
|
||||
|
||||
void wayland_display::listen_global(void* data, wl_registry* registry, uint32_t name, const char* itfc, uint32_t version) {
|
||||
static constexpr wl_seat_listener seat_listener = {
|
||||
listen_seat, nullptr
|
||||
};
|
||||
@@ -84,14 +126,16 @@ void wayland_display::listen_global(void* data, wl_registry* registry, uint32_t
|
||||
} else if (interface == "wl_seat") {
|
||||
device->_seat = static_cast<wl_seat*>(wl_registry_bind(registry, name, wl_seat_interface, version));
|
||||
wl_seat_add_listener(device->_seat, &seat_listener, device);
|
||||
} else if (interface == "wp_fifo_manager_v1") {
|
||||
device->_fifo = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void wayland_display::listen_global_remove(void*, wl_registry*, uint32_t) {
|
||||
void wayland_display::listen_global_remove(void*, wl_registry*, uint32_t) {
|
||||
}
|
||||
|
||||
void wayland_display::listen_seat(void*, wl_seat*, uint32_t) {
|
||||
void wayland_display::listen_seat(void*, wl_seat*, uint32_t) {
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,13 @@
|
||||
// =====================================================================================================================
|
||||
|
||||
#include <fennec/platform/linux/wayland/lib/wayland-client.h>
|
||||
#include <fennec/platform/linux/wayland/lib/dyn.h>
|
||||
#include <fennec/platform/linux/wayland/lib/loader.h>
|
||||
|
||||
#define FENNEC_LIB(name) bool FENNEC_HAS_LIB_##name;
|
||||
#define FENNEC_SYMBOL(ret, fn, ...) using sym_##fn = ret(*)(__VA_ARGS__); \
|
||||
sym_##fn fn;
|
||||
#define FENNEC_GLOBAL(type, name) type* name;
|
||||
#include <fennec/platform/linux/wayland/lib/sym.h>
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
@@ -25,7 +31,12 @@ namespace fennec
|
||||
namespace libwayland
|
||||
{
|
||||
|
||||
using shared_lib = platform::shared_lib;
|
||||
using shared_object = platform::shared_object;
|
||||
|
||||
struct shared_lib {
|
||||
shared_object* obj;
|
||||
const cstring name;
|
||||
};
|
||||
|
||||
static int _load_count = 0;
|
||||
|
||||
@@ -33,37 +44,37 @@ static int _load_count = 0;
|
||||
#define FENNEC_LIB(lib) static shared_lib _FENNEC_LIB_##lib = { nullptr, FENNEC_LIB_##lib };
|
||||
#include <fennec/platform/linux/wayland/lib/sym.h>
|
||||
|
||||
bool load_symbols(linux_platform* platform) {
|
||||
bool load_symbols(platform* platform) {
|
||||
if (_load_count++ != 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
shared_lib* current_lib = nullptr;
|
||||
#define FENNEC_LIB(lib) _FENNEC_LIB_##lib._lib = platform->load_object(_FENNEC_LIB_##lib._name); \
|
||||
FENNEC_HAS_LIB_##lib = _FENNEC_LIB_##lib._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, ...) fn = (sym_##fn)(platform->find_symbol(current_lib->_lib, #fn)); \
|
||||
#define FENNEC_SYMBOL(ret, fn, ...) fn = (sym_##fn)(platform->find_symbol(current_lib->obj, #fn)); \
|
||||
assertf(fn != nullptr, "Failed to find symbol: " #fn);
|
||||
#define FENNEC_GLOBAL(type, name) name = (type*)(platform->find_symbol(current_lib->_lib, #name)); \
|
||||
#define FENNEC_GLOBAL(type, name) name = (type*)(platform->find_symbol(current_lib->obj, #name)); \
|
||||
assertf(name != nullptr, "Failed to find global: " #name);
|
||||
|
||||
|
||||
#include <fennec/platform/linux/wayland/lib/sym.h>
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void unload_symbols(linux_platform* platform) {
|
||||
void unload_symbols(platform* platform) {
|
||||
if (--_load_count != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
#define FENNEC_LIB(lib) platform->unload_object(_FENNEC_LIB_##lib._lib); \
|
||||
_FENNEC_LIB_##lib._lib = nullptr;
|
||||
#define FENNEC_LIB(lib) platform->unload_object(_FENNEC_LIB_##lib.obj); \
|
||||
_FENNEC_LIB_##lib.obj = nullptr;
|
||||
#define FENNEC_SYMBOL(ret, fn, ...) fn = nullptr;
|
||||
#define FENNEC_GLOBAL(type, name) name = nullptr;
|
||||
#include <fennec/platform/linux/wayland/lib/sym.h>
|
||||
@@ -1,86 +0,0 @@
|
||||
// =====================================================================================================================
|
||||
// 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 <fennec/platform/linux/wayland/displaydev.h>
|
||||
#include <fennec/platform/linux/wayland/window.h>
|
||||
|
||||
#include <EGL/egl.h>
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
bool wayland_window::running() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void wayland_window::configure(const config& config) {
|
||||
assertf(running() == false, "Attempted to Configure Running Window.");
|
||||
|
||||
_config = config;
|
||||
}
|
||||
|
||||
bool wayland_window::initialize(bool modal) {
|
||||
assertf(_config, "Attempted to Initialize a Window Without Configuration");
|
||||
if (not _config) {
|
||||
return true;
|
||||
}
|
||||
|
||||
_config->flags &= ~flags_modal & ~flags_child;
|
||||
if (_parent != nullptr) {
|
||||
_config->flags |= flags_child;
|
||||
if (modal) {
|
||||
_config->flags |= flags_modal;
|
||||
}
|
||||
}
|
||||
|
||||
_surface = wl_compositor_create_surface(get_display<wayland_display>()->get_compositor());
|
||||
_shell = wl_shell_get_shell_surface(get_display<wayland_display>()->get_shell(), _surface);
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool wayland_window::shutdown() {
|
||||
wl_shell_surface_destroy(_shell);
|
||||
wl_surface_destroy(_surface);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool wayland_window::set_title(const cstring&) { return true; }
|
||||
bool wayland_window::set_title(const string&) { return true; }
|
||||
bool wayland_window::set_width(size_t) { return true; }
|
||||
bool wayland_window::set_height(size_t) { return true; }
|
||||
bool wayland_window::set_size(size_t, size_t) { return true; }
|
||||
bool wayland_window::set_fullscreen_mode(fullscreen_mode) { return true; }
|
||||
bool wayland_window::set_resizable(bool) { return true; }
|
||||
bool wayland_window::grab_keyboard(bool) { return true; }
|
||||
bool wayland_window::grab_mouse(bool) { return true; }
|
||||
bool wayland_window::block_screensaver(bool) { return true; }
|
||||
|
||||
wayland_window::wayland_window(wayland_display* display, wayland_window* parent)
|
||||
: window(display, parent)
|
||||
, _surface(nullptr)
|
||||
, _shell(nullptr)
|
||||
, _callback(nullptr) {
|
||||
}
|
||||
|
||||
wayland_window::~wayland_window() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
87
source/platform/linux/xkb/lib/loader.cpp
Normal file
87
source/platform/linux/xkb/lib/loader.cpp
Normal 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/>.
|
||||
// =====================================================================================================================
|
||||
|
||||
#define FENNEC_LIB(name) bool FENNEC_HAS_LIB_##name;
|
||||
#define FENNEC_SYMBOL(ret, fn, ...) using sym_##fn = ret(*)(__VA_ARGS__); \
|
||||
sym_##fn fn;
|
||||
#define FENNEC_GLOBAL(type, name) type* name;
|
||||
#include <fennec/platform/linux/xkb/lib/sym.h>
|
||||
|
||||
#include <fennec/platform/linux/xkb/lib/xkbcommon.h>
|
||||
#include <fennec/platform/linux/xkb/lib/loader.h>
|
||||
#include <fennec/platform/interface/platform.h>
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
namespace libxkbcommon
|
||||
{
|
||||
|
||||
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/xkb/lib/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, ...) fn = (sym_##fn)(platform->find_symbol(current_lib->obj, #fn)); \
|
||||
assertf(fn != nullptr, "Failed to find symbol: " #fn);
|
||||
#define FENNEC_GLOBAL(type, name) name = (type*)(platform->find_symbol(current_lib->obj, #name)); \
|
||||
assertf(name != nullptr, "Failed to find global: " #name);
|
||||
#include <fennec/platform/linux/xkb/lib/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, ...) fn = nullptr;
|
||||
#define FENNEC_GLOBAL(type, name) name = nullptr;
|
||||
#include <fennec/platform/linux/xkb/lib/sym.h>
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user