- Refactor on platform implementation. See comment in interface/platform.h for more info
This commit is contained in:
@@ -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() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user