// =====================================================================================================================
// 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 .
// =====================================================================================================================
#include
#include
#include
#include
namespace fennec
{
wayland_display::wayland_display(linux_platform* platform)
: wayland_display(platform, nullptr) {
}
wayland_display::wayland_display(linux_platform* platform, const cstring& drv)
: displaydev(platform)
, _handle(nullptr)
, _registry(nullptr)
, _compositor(nullptr) {
static constexpr wl_registry_listener listener = {
listen_global, listen_global_remove
};
// Load libwayland.so
libwayland::load_symbols(get_platform());
// Get handles
_handle = wl_display_connect(drv);
_registry = wl_display_get_registry(_handle);
wl_registry_add_listener(_registry, &listener, this);
}
wayland_display::~wayland_display() {
wl_registry_destroy(_registry);
wl_display_flush(_handle);
wl_display_disconnect(_handle);
libwayland::unload_symbols(get_platform());
_handle = nullptr;
_platform = nullptr;
for (const auto it : _windows) {
delete it;
}
}
bool wayland_display::connected() const {
return _handle != nullptr;
}
window* wayland_display::create_window() {
_windows.push_back(new wayland_window(this, nullptr));
return (window*)(_windows.back());
}
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
};
wayland_display* device = static_cast(data);
const cstring interface = cstring(itfc, strlen(itfc) + 1);
if (interface == "wl_compositor") {
device->_compositor = static_cast(wl_registry_bind(registry, name, wl_compositor_interface, version));
} else if (interface == "wl_shell") {
device->_shell = static_cast(wl_registry_bind(registry, name, wl_shell_interface, version));
} else if (interface == "wl_seat") {
device->_seat = static_cast(wl_registry_bind(registry, name, wl_seat_interface, version));
wl_seat_add_listener(device->_seat, &seat_listener, device);
}
}
void wayland_display::listen_global_remove(void*, wl_registry*, uint32_t) {
}
void wayland_display::listen_seat(void*, wl_seat*, uint32_t) {
}
}