- Setup wayland display and window. Window surface is created and appears in hotbar. Window is not visible.
This commit is contained in:
29
source/core/log.cpp
Normal file
29
source/core/log.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
// =====================================================================================================================
|
||||
// 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/>.
|
||||
// =====================================================================================================================
|
||||
|
||||
///
|
||||
/// \file log.h
|
||||
/// \brief
|
||||
///
|
||||
///
|
||||
/// \details
|
||||
/// \author Medusa Slockbower
|
||||
///
|
||||
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
|
||||
///
|
||||
///
|
||||
47
source/core/logger.cpp
Normal file
47
source/core/logger.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
// =====================================================================================================================
|
||||
// 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/>.
|
||||
// =====================================================================================================================
|
||||
|
||||
///
|
||||
/// \file logger.h
|
||||
/// \brief
|
||||
///
|
||||
///
|
||||
/// \details
|
||||
/// \author Medusa Slockbower
|
||||
///
|
||||
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
|
||||
///
|
||||
///
|
||||
|
||||
#include <fennec/core/logger.h>
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
logger::logger()
|
||||
: _logfile("./logs/current.log", fmode_write)
|
||||
, _cout(&file::cout()) {
|
||||
if (_logfile.get_error() != nullptr) {
|
||||
_logfile.clear_error();
|
||||
}
|
||||
}
|
||||
|
||||
logger::~logger() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,7 +19,6 @@
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <bits/posix2_lim.h>
|
||||
|
||||
#include <fennec/filesystem/file.h>
|
||||
#include <fennec/filesystem/path.h>
|
||||
@@ -32,6 +31,7 @@
|
||||
#else
|
||||
|
||||
#include <sys/file.h>
|
||||
#include <bits/posix2_lim.h>
|
||||
|
||||
#endif
|
||||
|
||||
@@ -120,7 +120,9 @@ file::file()
|
||||
}
|
||||
|
||||
file::~file() {
|
||||
close();
|
||||
if (is_open()) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
file::file(file&& file) noexcept
|
||||
@@ -1030,6 +1032,23 @@ wstring file::getwline() {
|
||||
return wstring(L"");
|
||||
}
|
||||
|
||||
void file::print(const cstring& str) {
|
||||
write(str.data(), str.length());
|
||||
}
|
||||
|
||||
void file::print(const string& str) {
|
||||
write(str.data(), str.length());
|
||||
}
|
||||
|
||||
void file::println(const cstring& str) {
|
||||
write(str.data(), str.length());
|
||||
putc('\n');
|
||||
}
|
||||
|
||||
void file::println(const string& str) {
|
||||
write(str.data(), str.length());
|
||||
}
|
||||
|
||||
bool file::putc(char c) {
|
||||
assert(_error == nullptr, "Attempted an Operation on a File in an Errored State");
|
||||
assert(not(_mode & fmode_wide), "Attempted Wide Operation on Byte File");
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// =====================================================================================================================
|
||||
|
||||
#include <fennec/core/logger.h>
|
||||
#include <fennec/platform/interface/display_server.h>
|
||||
#include <fennec/platform/interface/platform.h>
|
||||
|
||||
namespace fennec
|
||||
@@ -27,9 +29,24 @@ platform::platform() {
|
||||
}
|
||||
|
||||
void platform::initialize() {
|
||||
logger::log(fennec::format("Initializing platform {}", get_type().name()));
|
||||
|
||||
display_server::entrylist_t display_servers = display_server::get_type_list();
|
||||
while (not display_servers.empty()) {
|
||||
display_server::entry it = display_servers.front();
|
||||
display_servers.pop();
|
||||
|
||||
unique_ptr<display_server> server = unique_ptr(it.ctor(this));
|
||||
server->connect();
|
||||
if (server->connected()) {
|
||||
display = move(server);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void platform::shutdown() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
41
source/platform/interface/window.cpp
Normal file
41
source/platform/interface/window.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
// =====================================================================================================================
|
||||
// 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/>.
|
||||
// =====================================================================================================================
|
||||
|
||||
///
|
||||
/// \file window.h
|
||||
/// \brief
|
||||
///
|
||||
///
|
||||
/// \details
|
||||
/// \author Medusa Slockbower
|
||||
///
|
||||
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
|
||||
///
|
||||
///
|
||||
|
||||
#include <fennec/platform/interface/window.h>
|
||||
#include <fennec/platform/interface/display_server.h>
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
window* window::get_parent() const {
|
||||
return server->get_window(cfg.parent);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,9 +29,11 @@ FENNEC_PRIVATE_STATIC_CONSTRUCTOR(_init_linux) {
|
||||
}
|
||||
|
||||
void linux_platform::initialize() {
|
||||
platform::initialize();
|
||||
}
|
||||
|
||||
void linux_platform::shutdown() {
|
||||
platform::shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
185
source/platform/linux/wayland/server.cpp
Normal file
185
source/platform/linux/wayland/server.cpp
Normal file
@@ -0,0 +1,185 @@
|
||||
// =====================================================================================================================
|
||||
// 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/>.
|
||||
// =====================================================================================================================
|
||||
|
||||
///
|
||||
/// \file wayland_server.h
|
||||
/// \brief
|
||||
///
|
||||
///
|
||||
/// \details
|
||||
/// \author Medusa Slockbower
|
||||
///
|
||||
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
|
||||
///
|
||||
///
|
||||
|
||||
#include <fennec/core/logger.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>
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
wayland_server::wayland_server(fennec::platform* p)
|
||||
: display_server(p)
|
||||
, display(nullptr), registry(nullptr), compositor(nullptr), seat(nullptr), fifo(false) {
|
||||
|
||||
// load shared lib
|
||||
if (libwayland::load_symbols(platform)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
wayland_server::~wayland_server() {
|
||||
|
||||
// ensure we did disconnect
|
||||
wayland_server::disconnect();
|
||||
|
||||
// unload shared lib
|
||||
libwayland::unload_symbols(platform);
|
||||
}
|
||||
|
||||
void wayland_server::connect() {
|
||||
|
||||
static constexpr wl_registry_listener listener = {
|
||||
listen_global, listen_global_remove
|
||||
};
|
||||
|
||||
if (display != nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
// connect to wayland
|
||||
display = wl_display_connect(nullptr);
|
||||
if (display == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
// get the registry
|
||||
registry = wl_display_get_registry(display);
|
||||
if (registry == nullptr) {
|
||||
assert(registry, "Failed to acquire registry from Wayland");
|
||||
disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
// Aquire interfaces
|
||||
wl_registry_add_listener(registry, &listener, this);
|
||||
wl_display_roundtrip(display);
|
||||
|
||||
// Check for fifo v1, wayland's builtin fifo only allows one frame to be in flight at a time
|
||||
if (not fifo) {
|
||||
assert(fifo, "Compositor does not support fifo-v1 protocol, falling back to other display protocols.");
|
||||
disconnect();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void wayland_server::disconnect() {
|
||||
|
||||
// early escape
|
||||
if (display == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
// check compositor
|
||||
if (compositor) {
|
||||
wl_compositor_destroy(compositor);
|
||||
}
|
||||
|
||||
// check registry
|
||||
if (registry) {
|
||||
wl_registry_destroy(registry);
|
||||
}
|
||||
|
||||
// disconnect from wayland
|
||||
wl_display_flush(display);
|
||||
wl_display_disconnect(display);
|
||||
|
||||
// clear vars
|
||||
display = nullptr;
|
||||
registry = nullptr;
|
||||
compositor = nullptr;
|
||||
seat = nullptr;
|
||||
fifo = false;
|
||||
}
|
||||
|
||||
bool wayland_server::connected() const {
|
||||
return display != nullptr;
|
||||
}
|
||||
|
||||
window* wayland_server::create_window(const window::config& conf) {
|
||||
size_t id = windows.insert(new wayland_window(this, windows.next_id(), conf));
|
||||
return windows[id];
|
||||
}
|
||||
|
||||
void wayland_server::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
|
||||
};
|
||||
|
||||
static constexpr xdg_wm_base_listener xdg_listener = {
|
||||
listen_xdg_ping
|
||||
};
|
||||
|
||||
wayland_server* server = static_cast<wayland_server*>(data);
|
||||
const cstring interface = cstring(name, strlen(name) + 1);
|
||||
|
||||
if (interface == "wl_compositor") {
|
||||
server->compositor = static_cast<wl_compositor*>(wl_registry_bind(reg, id, &wl_compositor_interface, version));
|
||||
return;
|
||||
}
|
||||
|
||||
if (interface == "xdg_wm_base") {
|
||||
server->xdg = static_cast<xdg_wm_base*>(wl_registry_bind(reg, id, &xdg_wm_base_interface, version));
|
||||
xdg_wm_base_add_listener(server->xdg, &xdg_listener, server);
|
||||
return;
|
||||
}
|
||||
|
||||
if (interface == "wl_seat") {
|
||||
server->seat = static_cast<wl_seat*>(wl_registry_bind(reg, id, &wl_seat_interface, version));
|
||||
wl_seat_add_listener(server->seat, &seat_listener, server);
|
||||
return;
|
||||
}
|
||||
|
||||
if (interface == "wp_fifo_manager_v1") {
|
||||
server->fifo = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void wayland_server::listen_global_remove(void*, wl_registry*, uint32_t) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void wayland_server::listen_seat_capabilities(void*, wl_seat*, uint32_t) {
|
||||
|
||||
}
|
||||
|
||||
void wayland_server::listen_seat_name(void*, wl_seat*, const char*) {}
|
||||
|
||||
|
||||
void wayland_server::listen_xdg_ping(void*, xdg_wm_base* xdg, uint32_t serial) {
|
||||
xdg_wm_base_pong(xdg, serial);
|
||||
}
|
||||
|
||||
}
|
||||
160
source/platform/linux/wayland/window.cpp
Normal file
160
source/platform/linux/wayland/window.cpp
Normal file
@@ -0,0 +1,160 @@
|
||||
// =====================================================================================================================
|
||||
// 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/>.
|
||||
// =====================================================================================================================
|
||||
|
||||
///
|
||||
/// \file window.h
|
||||
/// \brief
|
||||
///
|
||||
///
|
||||
/// \details
|
||||
/// \author Medusa Slockbower
|
||||
///
|
||||
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
|
||||
///
|
||||
///
|
||||
|
||||
#include <fennec/platform/interface/display_server.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>
|
||||
|
||||
using namespace fennec;
|
||||
|
||||
wayland_window::wayland_window(display_server* server, uint32_t id, const config& cfg)
|
||||
: window(server, id, cfg)
|
||||
, surface(nullptr)
|
||||
, xdgsurface(nullptr) {
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
static constexpr xdg_surface_listener xdg_surface_listener = {
|
||||
listen_xdg_surface_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
|
||||
};
|
||||
|
||||
static constexpr wl_callback_listener frame_callback_listener = {
|
||||
listen_frame_callback
|
||||
};
|
||||
|
||||
if (is_visible()) {
|
||||
return;
|
||||
}
|
||||
|
||||
wayland_window* root = this;
|
||||
while (root != nullptr and root->is_popup()) {
|
||||
root = static_cast<wayland_window*>(root->get_parent());
|
||||
}
|
||||
|
||||
assertf(root != nullptr, "Failed to find appropriate top-level window.");
|
||||
|
||||
wayland_server* wl_server = static_cast<wayland_server*>(server);
|
||||
|
||||
surface = wl_compositor_create_surface(wl_server->compositor);
|
||||
wl_surface_add_listener(surface, &surface_listener, this);
|
||||
|
||||
|
||||
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);
|
||||
|
||||
|
||||
frame_callback = wl_surface_frame(surface);
|
||||
wl_callback_add_listener(frame_callback, &frame_callback_listener, this);
|
||||
|
||||
|
||||
wl_surface_commit(surface);
|
||||
wl_display_roundtrip(wl_server->display);
|
||||
|
||||
cfg.flags.set(flag_visible);
|
||||
cfg.flags.set(flag_running);
|
||||
}
|
||||
|
||||
void wayland_window::hide() {
|
||||
if (not is_visible()) {
|
||||
return;
|
||||
}
|
||||
|
||||
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 (xdgsurface) {
|
||||
xdg_surface_destroy(xdgsurface);
|
||||
xdgsurface = nullptr;
|
||||
}
|
||||
|
||||
if (surface) {
|
||||
wl_surface_destroy(surface);
|
||||
surface = nullptr;
|
||||
}
|
||||
|
||||
wl_display_roundtrip(wl_server->display);
|
||||
|
||||
cfg.flags.clear(flag_visible);
|
||||
cfg.flags.clear(flag_running);
|
||||
}
|
||||
|
||||
void wayland_window::dispatch() {
|
||||
wayland_server* wl_server = static_cast<wayland_server*>(server);
|
||||
wl_display_dispatch(wl_server->display);
|
||||
}
|
||||
|
||||
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) {}
|
||||
|
||||
void wayland_window::listen_frame_callback(void*, wl_callback*, uint32_t) {}
|
||||
|
||||
void wayland_window::listen_xdg_surface_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::listen_xdg_toplevel_close(void*, xdg_toplevel*) {}
|
||||
void wayland_window::listen_xdg_toplevel_capabilities(void*, xdg_toplevel*, wl_array*) {}
|
||||
Reference in New Issue
Block a user