Compare commits

..

3 Commits

Author SHA1 Message Date
520a0e1363 - Setup libdecor, which is used automatically when available.
TODO:
 - xdg decorations
 - threading
 - thread-safe window manager
2025-12-15 23:40:06 -05:00
97f5bbfe00 - Windows now use libdecor when present. 2025-12-15 16:29:00 -05:00
b64ce44d4e - Setup dynamic linking to libdecor 2025-12-15 15:23:45 -05:00
32 changed files with 1063 additions and 149 deletions

View File

@@ -286,6 +286,9 @@ add_library(fennec STATIC
# EXTRA SOURCES ======================================================================================================== # EXTRA SOURCES ========================================================================================================
${FENNEC_EXTRA_SOURCES} ${FENNEC_EXTRA_SOURCES}
include/fennec/math/ext/rect.h
include/fennec/platform/opengl/egl/error.h
include/fennec/platform/window_manager.h
) )

View File

@@ -34,7 +34,7 @@ endif()
find_package(GLEW REQUIRED) find_package(GLEW REQUIRED)
if(TARGET OpenGL::GL AND TARGET GLEW::GLEW) if(TARGET OpenGL::GL AND TARGET GLEW::GLEW)
message(STATUS "Found OpenGL: ${OPENGL_gl_LIBRARY}") message(STATUS "Found OpenGL: ${OPENGL_LIBRARIES}")
fennec_add_link_libraries(OpenGL::GL GLEW::GLEW) fennec_add_link_libraries(OpenGL::GL GLEW::GLEW)
fennec_add_definitions(FENNEC_GRAPHICS_OPENGL=1) fennec_add_definitions(FENNEC_GRAPHICS_OPENGL=1)

View File

@@ -21,6 +21,17 @@
# some of this code is based on SDL3's use of wayland-scanner # some of this code is based on SDL3's use of wayland-scanner
function(fennec_wayland_get_protocol)
set( _OPTIONS_ARGS )
set( _ONE_VALUE_ARGS )
set( _MULTI_VALUE_ARGS NAMES PATHS )
cmake_parse_arguments(_FINDPROTOCOLS "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN} )
find_file(_FINDPROTOCOLS_TEMP NAMES ${_FINDPROTOCOLS_NAMES} PATHS ${_FINDPROTOCOLS_PATHS})
file(COPY ${_FINDPROTOCOLS_TEMP} DESTINATION ${WAYLAND_PROTOCOLS_DIR})
endfunction()
macro(fennec_wayland_get_header _SCANNER _XML _FILE) macro(fennec_wayland_get_header _SCANNER _XML _FILE)
set(_WAYLAND_PROT_H_CODE "${WAYLAND_HEADERS_DIR}/${_FILE}-client-protocols.h") set(_WAYLAND_PROT_H_CODE "${WAYLAND_HEADERS_DIR}/${_FILE}-client-protocols.h")
set(_WAYLAND_PROT_C_CODE "${WAYLAND_SOURCES_DIR}/${_FILE}-client.c") set(_WAYLAND_PROT_C_CODE "${WAYLAND_SOURCES_DIR}/${_FILE}-client.c")
@@ -59,6 +70,7 @@ macro(fennec_check_wayland)
NAMES wayland-egl libwayland-egl NAMES wayland-egl libwayland-egl
) )
if( (WAYLAND_CLIENT_INCLUDE_DIR AND WAYLAND_CLIENT_LIBRARY AND WAYLAND_SCANNER) if( (WAYLAND_CLIENT_INCLUDE_DIR AND WAYLAND_CLIENT_LIBRARY AND WAYLAND_SCANNER)
AND (WAYLAND_EGL_INCLUDE_DIR AND WAYLAND_EGL_LIBRARY)) AND (WAYLAND_EGL_INCLUDE_DIR AND WAYLAND_EGL_LIBRARY))
message(STATUS "Found Wayland: ${WAYLAND_CLIENT_LIBRARY}") message(STATUS "Found Wayland: ${WAYLAND_CLIENT_LIBRARY}")
@@ -68,12 +80,8 @@ macro(fennec_check_wayland)
set(WAYLAND_SOURCES_DIR ${FENNEC_SOURCE_DIR}/source/platform/linux/wayland/lib/sources) set(WAYLAND_SOURCES_DIR ${FENNEC_SOURCE_DIR}/source/platform/linux/wayland/lib/sources)
# Search for base protocol xml # Search for base protocol xml
find_file(WAYLAND_PROTOCOL NAMES wayland.xml PATHS /usr/share/wayland /usr/share/wayland-protocols) fennec_wayland_get_protocol(NAMES "wayland.xml" PATHS "/usr/share/wayland" "/usr/share/wayland-protocols")
file(COPY ${WAYLAND_PROTOCOL} DESTINATION ${WAYLAND_PROTOCOLS_DIR}) fennec_wayland_get_protocol(NAMES "xdg-shell.xml" PATHS "/usr/share/wayland/stable/xdg-shell" "/usr/share/wayland-protocols/stable/xdg-shell")
# search for xdg protocols
find_file(XDG_SHELL_PROTOCOL NAMES xdg-shell.xml PATHS /usr/share/wayland-protocols/stable/xdg-shell)
file(COPY ${XDG_SHELL_PROTOCOL} DESTINATION ${WAYLAND_PROTOCOLS_DIR})
# include sub-dependencies # include sub-dependencies
include("${FENNEC_SOURCE_DIR}/cmake/xkb.cmake") include("${FENNEC_SOURCE_DIR}/cmake/xkb.cmake")
@@ -123,5 +131,38 @@ macro(fennec_check_wayland)
FENNEC_LIB_WAYLAND="${WAYLAND_CLIENT_LIBRARY}" FENNEC_LIB_WAYLAND="${WAYLAND_CLIENT_LIBRARY}"
FENNEC_LIB_WAYLAND_EGL="${WAYLAND_EGL_LIBRARY}" FENNEC_LIB_WAYLAND_EGL="${WAYLAND_EGL_LIBRARY}"
) )
# find libdecor
find_path(
LIBDECOR_INCLUDE_DIR
PATH_SUFFIXES libdecor libdecor-0
NAMES libdecor.h libdecor.h
)
find_library(
LIBDECOR_LIBRARY
PATH_SUFFIXES libdecor libdecor-0
NAMES libdecor.so libdecor-0.so
)
if(LIBDECOR_INCLUDE_DIR AND LIBDECOR_LIBRARY)
message(STATUS "Found libdecor: ${LIBDECOR_LIBRARY}")
fennec_add_definitions(
FENNEC_HAS_LIBDECOR=1
FENNEC_LIB_LIBDECOR="${LIBDECOR_LIBRARY}"
)
include_directories(
${LIBDECOR_INCLUDE_DIR}
)
fennec_add_sources(
include/fennec/platform/linux/wayland/libdecor/sym.h
include/fennec/platform/linux/wayland/libdecor/libdecor.h
include/fennec/platform/linux/wayland/libdecor/loader.h source/platform/linux/wayland/libdecor/loader.cpp
)
endif()
endif() endif()
endmacro() endmacro()

View File

@@ -20,6 +20,7 @@
# GDB CODE ============================================================================================================= # GDB CODE =============================================================================================================
import gdb import gdb
import gdb.printing
from . import containers from . import containers
from . import strings from . import strings

View File

@@ -24,7 +24,7 @@ from . import utility
class VectorPrinter: class VectorPrinter:
def __init__(self, val): def __init__(self, val):
self.val = val self.val = val
self.base = val['data']['elements'] self.base = val['data']['data']
self.len = self.base.type.range()[1] + 1 self.len = self.base.type.range()[1] + 1
def to_string(self): def to_string(self):
@@ -51,7 +51,7 @@ class VectorPrinter:
class QuaternionPrinter: class QuaternionPrinter:
def __init__(self, val): def __init__(self, val):
self.val = val self.val = val
self.base = val['data']['elements'] self.base = val['data']['data']
def to_string(self): def to_string(self):
res = ("< " res = ("< "
@@ -72,7 +72,7 @@ class QuaternionPrinter:
# VECTOR ================================================================================================================= # VECTOR =================================================================================================================
class MatrixPrinter: class MatrixPrinter:
def __init__(self, val): def __init__(self, val):
self.columns = val['data']['elements'] self.columns = val['data']['data']
self.num_columns = self.columns.type.range()[1] + 1 self.num_columns = self.columns.type.range()[1] + 1
self.num_rows = val.type.template_argument(1) self.num_rows = val.type.template_argument(1)

View File

@@ -43,7 +43,8 @@ namespace fennec
/// \tparam N The number of bits in the bitfield /// \tparam N The number of bits in the bitfield
template<size_t N> template<size_t N>
struct bitfield { struct bitfield {
static constexpr size_t size = N; static constexpr size_t bits = N;
static constexpr size_t bytes = (N + 7) / 8;
public: public:
constexpr bitfield() constexpr bitfield()
@@ -66,51 +67,79 @@ public:
} }
template<typename...ArgsT> template<typename...ArgsT>
constexpr bitfield(ArgsT&&...args)
: _bytes() {
(this->store(fennec::forward<ArgsT>(args), true), ...);
}
template<typename...ArgsT> requires((is_bool_v<ArgsT> or is_convertible_v<ArgsT, bool>) and ...)
constexpr bitfield(ArgsT&&...args) constexpr bitfield(ArgsT&&...args)
: _bytes() { : _bytes() {
size_t i = 0; size_t i = 0;
(this->store(i++, fennec::forward<ArgsT>(args)), ...); (this->store(i++, fennec::forward<ArgsT>(args)), ...);
} }
bitfield(const bitfield& bf)
: _bytes(bf._bytes) {
}
bitfield(bitfield&& bf) noexcept
: _bytes(bf._bytes) {
}
constexpr ~bitfield() = default; constexpr ~bitfield() = default;
bitfield& operator=(const bitfield& bf) = default;
bitfield& operator=(bitfield&& bf) noexcept = default;
bool test(size_t i) const { bool test(size_t i) const {
assertd(i < size, "Index out of Bounds!"); assertd(i < bits, "Index out of Bounds!");
size_t b = i / 8; size_t b = i / 8;
size_t o = i % 8; size_t o = i % 8;
return _bytes[b] & (1 << o); return _bytes[b] & (1 << o);
} }
void set(size_t i) { void set(size_t i) {
assertd(i < size, "Index out of Bounds!"); assertd(i < bits, "Index out of Bounds!");
size_t b = i / 8; size_t b = i / 8;
size_t o = i % 8; size_t o = i % 8;
_bytes[b] |= (1 << o); _bytes[b] |= (1 << o);
} }
void clear(size_t i) { void clear(size_t i) {
assertd(i < size, "Index out of Bounds!"); assertd(i < bits, "Index out of Bounds!");
size_t b = i / 8; size_t b = i / 8;
size_t o = i % 8; size_t o = i % 8;
_bytes[b] &= ~(1 << o); _bytes[b] &= ~(1 << o);
} }
void toggle(size_t i) { void toggle(size_t i) {
assertd(i < size, "Index out of Bounds!"); assertd(i < bits, "Index out of Bounds!");
size_t b = i / 8; size_t b = i / 8;
size_t o = i % 8; size_t o = i % 8;
_bytes[b] ^= (1 << o); _bytes[b] ^= (1 << o);
} }
void store(size_t i, bool v) { void store(size_t i, bool v) {
assertd(i < size, "Index out of Bounds!"); assertd(i < bits, "Index out of Bounds!");
size_t b = i / 8; size_t b = i / 8;
size_t o = i % 8; size_t o = i % 8;
(_bytes[b] &= ~((1 << o))) |= ((v << o)); (_bytes[b] &= ~((1 << o))) |= ((v << o));
} }
bitfield operator~() const {
bitfield res = *this;
res._inv_helper(make_index_metasequence_t<bytes>{});
return res;
}
private: private:
array<uint8_t, (N + 7) / 8> _bytes; array<uint8_t, bytes> _bytes;
template<size_t...I>
void _inv_helper(index_metasequence<I...>) {
((_bytes[I] = ~_bytes[I]), ...);
}
}; };

View File

@@ -24,8 +24,8 @@
namespace fennec namespace fennec
{ {
template<typename ScalarT, size_t...IndicesV> struct vector; // Forward def for vectors template<typename ScalarT, size_t...IndicesV> requires(is_scalar_v<ScalarT>) struct vector; // Forward def for vectors
template<typename ScalarT, size_t RowsV, size_t...ColIndicesV> struct matrix; // Forward def for matrices template<typename ScalarT, size_t RowsV, size_t...ColIndicesV> requires(is_scalar_v<ScalarT>) struct matrix; // Forward def for matrices
// Simplified interface for creating sized vectors or matrices // Simplified interface for creating sized vectors or matrices
template<typename ScalarT, size_t SizeV> using vec template<typename ScalarT, size_t SizeV> using vec

View File

@@ -0,0 +1,52 @@
// =====================================================================================================================
// 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 rect.h
/// \brief
///
///
/// \details
/// \author Medusa Slockbower
///
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
///
///
#ifndef FENNEC_MATH_EXT_RECT_H
#define FENNEC_MATH_EXT_RECT_H
#include <fennec/math/vector.h>
namespace fennec
{
template<typename ScalarT>
struct rectangle {
tvec2<ScalarT> position, size;
};
using rect = rectangle<float_t>;
using irect = rectangle<int32_t>;
using urect = rectangle<uint32_t>;
using drect = rectangle<double_t>;
}
#endif // FENNEC_MATH_EXT_RECT_H

View File

@@ -182,7 +182,7 @@ constexpr matrix<scalar, rows, cols...> inverse(const matrix<scalar, rows, cols.
/// \tparam ScalarT /// \tparam ScalarT
/// \tparam RowsV /// \tparam RowsV
/// \tparam ColIndicesV /// \tparam ColIndicesV
template<typename ScalarT, size_t RowsV, size_t...ColIndicesV> template<typename ScalarT, size_t RowsV, size_t...ColIndicesV> requires(is_scalar_v<ScalarT>)
struct matrix struct matrix
{ {
// Assertions ========================================================================================================== // Assertions ==========================================================================================================

View File

@@ -103,6 +103,7 @@
/// ///
/// ///
#include <fennec/containers/initializer_list.h>
#include <fennec/math/detail/_fwd.h> #include <fennec/math/detail/_fwd.h>
#include <fennec/math/vector_base.h> #include <fennec/math/vector_base.h>
@@ -177,7 +178,7 @@ using dvec4 = tvec4<double_t>;
/// \tparam ScalarT base \ref scalar type of each Component /// \tparam ScalarT base \ref scalar type of each Component
/// \tparam IndicesV index of each Component /// \tparam IndicesV index of each Component
/// \nosubgrouping /// \nosubgrouping
template<typename ScalarT, size_t... IndicesV> template<typename ScalarT, size_t... IndicesV> requires(is_scalar_v<ScalarT>)
struct vector : detail::vector_base_type<ScalarT, sizeof...(IndicesV)> struct vector : detail::vector_base_type<ScalarT, sizeof...(IndicesV)>
{ {
// Assertions ========================================================================================================== // Assertions ==========================================================================================================
@@ -337,6 +338,21 @@ struct vector : detail::vector_base_type<ScalarT, sizeof...(IndicesV)>
vector::_construct<0>(args...); vector::_construct<0>(args...);
} }
constexpr vector(initializer_list<ScalarT> init) {
size_t i = 0;
for (ScalarT x : init) {
data[i++] = x;
}
}
template<typename OScalarT>
constexpr vector(initializer_list<OScalarT> init) {
size_t i = 0;
for (OScalarT x : init) {
data[i++] = ScalarT(x);
}
}
/// @} /// @}

View File

@@ -32,8 +32,12 @@
#define FENNEC_PLATFORM_INTERFACE_DISPLAY_SERVER_H #define FENNEC_PLATFORM_INTERFACE_DISPLAY_SERVER_H
#include <fennec/containers/bitfield.h> #include <fennec/containers/bitfield.h>
#include <fennec/platform/interface/fwd.h> #include <fennec/platform/interface/fwd.h>
#include <fennec/platform/interface/window.h> #include <fennec/platform/interface/window.h>
#include <fennec/renderers/interface/gfxcontext.h>
#include <fennec/rtti/enable.h> #include <fennec/rtti/enable.h>
#include <fennec/rtti/type_registry.h> #include <fennec/rtti/type_registry.h>
@@ -89,6 +93,8 @@ enum feature_ : uint32_t {
}; };
using featureset_t = bitfield<feature_count>; using featureset_t = bitfield<feature_count>;
using window_id = uint32_t;
using window_pool = object_pool<window*>;
struct config { struct config {
}; };
@@ -109,10 +115,6 @@ enum feature_ : uint32_t {
return features.test(feature); return features.test(feature);
} }
gfxcontext* get_gfx_context() {
return gfx_context;
}
virtual window* create_window(const window::config& conf) = 0; virtual window* create_window(const window::config& conf) = 0;
window* get_window(size_t id) { window* get_window(size_t id) {
@@ -127,11 +129,14 @@ enum feature_ : uint32_t {
virtual void* get_native_handle() = 0; virtual void* get_native_handle() = 0;
gfxcontext* get_gfx_context() {
return gfx_context.get();
}
protected: protected:
featureset_t features; featureset_t features;
object_pool<window*> windows; window_pool windows;
gfxcontext* gfx_context; unique_ptr<gfxcontext> gfx_context;
FENNEC_RTTI_CLASS_ENABLE() { FENNEC_RTTI_CLASS_ENABLE() {
} }

View File

@@ -60,6 +60,8 @@
namespace fennec namespace fennec
{ {
///
/// \brief Main platform class
class platform : public singleton<platform*> { class platform : public singleton<platform*> {
public: public:
using shared_object = struct shared_object; using shared_object = struct shared_object;

View File

@@ -32,9 +32,13 @@
#define FENNEC_PLATFORM_INTERFACE_WINDOW_H #define FENNEC_PLATFORM_INTERFACE_WINDOW_H
#include <fennec/platform/interface/fwd.h> #include <fennec/platform/interface/fwd.h>
#include <fennec/math/vector.h>
#include <fennec/math/ext/rect.h>
#include <fennec/string/string.h> #include <fennec/string/string.h>
#include <fennec/containers/bitfield.h> #include <fennec/containers/bitfield.h>
#include <fennec/containers/optional.h>
namespace fennec namespace fennec
{ {
@@ -61,21 +65,27 @@ public:
enum flag_ : uint8_t { enum flag_ : uint8_t {
flag_always_on_top = 0, // Window always appears on top level flag_always_on_top = 0, // Window always appears on top level
flag_borderless, // Window has no border decorations flag_borderless, // Window has no border decorations
flag_child, // Window is a child window, and closes when the parent does
flag_decorations, // Window has a titlebar with basic functions
flag_modal, // Window always appears above parent and blocks input going to parent flag_modal, // Window always appears above parent and blocks input going to parent
flag_pass_mouse, // Mouse interaction passes to next underlying window in the application flag_pass_mouse, // Mouse interaction passes to next underlying window in the application
flag_popup, // Window does not show in taskbar and closes when loses focus flag_popup, // Window does not show in taskbar and closes when loses focus
flag_resizable, // Window can be resized through functions defined by Desktop Environment flag_resizable, // Window can be resized through functions defined by Desktop Environment
flag_transparent, // Window has an alpha value flag_transparent, // Window has an alpha value
flag_visible, // Window is visible
flag_running, // Window is running
flag_no_focus, // Window can be focused flag_no_focus, // Window can be focused
flag_count flag_count
}; };
enum state_ : uint8_t {
state_running = 0, // Window is running
state_child, // Window is a child
state_suspended, // Window is suspended
state_visible, // Window is visible
state_count
};
using flags_t = bitfield<flag_count>; using flags_t = bitfield<flag_count>;
using state_t = bitfield<state_count>;
struct accessibility { struct accessibility {
string name, description; string name, description;
@@ -87,15 +97,25 @@ public:
uint8_t mode; uint8_t mode;
size_t parent; size_t parent;
ivec2 size; irect rect;
double_t fractional_scaling;
accessibility accessibility; accessibility accessibility;
}; };
struct state {
uint8_t mode;
irect rect;
state_t flags;
int_t buffer_scale;
double_t fractional_scaling;
};
window(display_server* server, size_t id, const config& conf) window(display_server* server, size_t id, const config& conf)
: server(server), id(id) : server(server), id(id)
, cfg(conf), root(nullptr) { , cfg(conf), state(), root(nullptr) {
cfg.flags.clear(flag_visible); state.mode = conf.mode;
} }
virtual ~window() = default; virtual ~window() = default;
@@ -103,25 +123,33 @@ public:
size_t get_id() const { return id; } size_t get_id() const { return id; }
size_t get_parent_id() const { return cfg.parent; } size_t get_parent_id() const { return cfg.parent; }
const config& get_config() const { return cfg; }
window* get_parent() const; window* get_parent() const;
const ivec2& get_size() const { return cfg.size; } const ivec2& get_size() const { return state.rect.size; }
int get_width() const { return cfg.size.x; } const ivec2& get_position() const { return state.rect.position; }
int get_height() const { return cfg.size.y; }
int get_width() const { return state.rect.size.x; }
int get_height() const { return state.rect.size.y; }
int get_pos_x() const { return state.rect.position.x; }
int get_pos_y() const { return state.rect.position.y; }
bool is_visible() const { return state.flags.test(state_visible); }
bool is_child() const { return state.flags.test(state_child); }
bool is_running() const { return state.flags.test(state_running); }
bool is_suspended() const { return state.flags.test(state_suspended); }
bool get_flag(uint8_t flag) const { return cfg.flags.test(flag); } bool get_flag(uint8_t flag) const { return cfg.flags.test(flag); }
bool is_always_on_top() const { return get_flag(flag_always_on_top); } bool is_always_on_top() const { return get_flag(flag_always_on_top); }
bool is_borderless() const { return get_flag(flag_borderless); } bool is_borderless() const { return get_flag(flag_borderless); }
bool is_child() const { return get_flag(flag_child); }
bool has_decorations() const { return get_flag(flag_decorations); }
bool is_modal() const { return get_flag(flag_modal); } bool is_modal() const { return get_flag(flag_modal); }
bool is_passing_mouse() const { return get_flag(flag_pass_mouse); } bool is_passing_mouse() const { return get_flag(flag_pass_mouse); }
bool is_popup() const { return get_flag(flag_popup); } bool is_popup() const { return get_flag(flag_popup); }
bool is_resizable() const { return get_flag(flag_resizable); } bool is_resizable() const { return get_flag(flag_resizable); }
bool is_transparent() const { return get_flag(flag_transparent); } bool is_transparent() const { return get_flag(flag_transparent); }
bool is_visible() const { return get_flag(flag_visible); }
bool is_running() const { return get_flag(flag_running); }
bool is_no_focus() const { return get_flag(flag_no_focus); } bool is_no_focus() const { return get_flag(flag_no_focus); }
@@ -129,7 +157,6 @@ public:
bool set_always_on_top(bool val) { return set_flag(flag_always_on_top, val); } bool set_always_on_top(bool val) { return set_flag(flag_always_on_top, val); }
bool set_borderless(bool val) { return set_flag(flag_borderless, val); } bool set_borderless(bool val) { return set_flag(flag_borderless, val); }
bool set_decorations(bool val) { return set_flag(flag_decorations, val); }
bool set_modal(bool val) { return set_flag(flag_modal, val); } bool set_modal(bool val) { return set_flag(flag_modal, val); }
bool set_passing_mouse(bool val) { return set_flag(flag_pass_mouse, val); } bool set_passing_mouse(bool val) { return set_flag(flag_pass_mouse, val); }
bool set_popup(bool val) { return set_flag(flag_popup, val); } bool set_popup(bool val) { return set_flag(flag_popup, val); }
@@ -137,8 +164,8 @@ public:
bool set_transparent(bool val) { return set_flag(flag_transparent, val); } bool set_transparent(bool val) { return set_flag(flag_transparent, val); }
bool set_no_focus(bool val) { return set_flag(flag_no_focus, val); } bool set_no_focus(bool val) { return set_flag(flag_no_focus, val); }
virtual void show() = 0; virtual void initialize() = 0;
virtual void hide() = 0; virtual void shutdown() = 0;
virtual void begin_frame(); virtual void begin_frame();
virtual void end_frame(); virtual void end_frame();
@@ -149,6 +176,7 @@ protected:
display_server* const server; display_server* const server;
const size_t id; const size_t id;
config cfg; config cfg;
state state;
window* root; window* root;
gfxsurface* gfx_surface; gfxsurface* gfx_surface;
}; };

View File

@@ -0,0 +1,80 @@
// =====================================================================================================================
// 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 libdecor.h
/// \brief
///
///
/// \details
/// \author Medusa Slockbower
///
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
///
///
#ifndef FENNEC_PLATFORM_LINUX_WAYLAND_LIBDECOR_H
#define FENNEC_PLATFORM_LINUX_WAYLAND_LIBDECOR_H
#include <fennec/platform/linux/wayland/lib/wayland.h>
#include <libdecor.h>
#define FENNEC_LIB(name) extern "C" bool FENNEC_HAS_LIB_##name;
#define FENNEC_SYMBOL(ret, fn, ...) using LIBDECOR_sym_##fn = ret(*)(__VA_ARGS__); \
extern "C" LIBDECOR_sym_##fn LIBDECOR_##fn;
#define FENNEC_GLOBAL(type, name) extern "C" type* LIBDECOR_##name;
#include <fennec/platform/linux/wayland/libdecor/sym.h>
#define libdecor_unref LIBDECOR_libdecor_unref
#define libdecor_new LIBDECOR_libdecor_new
#define libdecor_decorate LIBDECOR_libdecor_decorate
#define libdecor_frame_unref LIBDECOR_libdecor_frame_unref
#define libdecor_frame_set_title LIBDECOR_libdecor_frame_set_title
#define libdecor_frame_set_app_id LIBDECOR_libdecor_frame_set_app_id
#define libdecor_frame_set_max_content_size LIBDECOR_libdecor_frame_set_max_content_size
#define libdecor_frame_get_max_content_size LIBDECOR_libdecor_frame_get_max_content_size
#define libdecor_frame_set_min_content_size LIBDECOR_libdecor_frame_set_min_content_size
#define libdecor_frame_get_min_content_size LIBDECOR_libdecor_frame_get_min_content_size
#define libdecor_frame_resize LIBDECOR_libdecor_frame_resize
#define libdecor_frame_move LIBDECOR_libdecor_frame_move
#define libdecor_frame_commit LIBDECOR_libdecor_frame_commit
#define libdecor_frame_set_minimized LIBDECOR_libdecor_frame_set_minimized
#define libdecor_frame_set_maximized LIBDECOR_libdecor_frame_set_maximized
#define libdecor_frame_unset_maximized LIBDECOR_libdecor_frame_unset_maximized
#define libdecor_frame_set_fullscreen LIBDECOR_libdecor_frame_set_fullscreen
#define libdecor_frame_unset_fullscreen LIBDECOR_libdecor_frame_unset_fullscreen
#define libdecor_frame_set_capabilities LIBDECOR_libdecor_frame_set_capabilities
#define libdecor_frame_unset_capabilities LIBDECOR_libdecor_frame_unset_capabilities
#define libdecor_frame_has_capability LIBDECOR_libdecor_frame_has_capability
#define libdecor_frame_set_visibility LIBDECOR_libdecor_frame_set_visibility
#define libdecor_frame_is_visible LIBDECOR_libdecor_frame_is_visible
#define libdecor_frame_is_floating LIBDECOR_libdecor_frame_is_floating
#define libdecor_frame_set_parent LIBDECOR_libdecor_frame_set_parent
#define libdecor_frame_show_window_menu LIBDECOR_libdecor_frame_show_window_menu
#define libdecor_frame_get_xdg_surface LIBDECOR_libdecor_frame_get_xdg_surface
#define libdecor_frame_get_xdg_toplevel LIBDECOR_libdecor_frame_get_xdg_toplevel
#define libdecor_frame_translate_coordinate LIBDECOR_libdecor_frame_translate_coordinate
#define libdecor_frame_map LIBDECOR_libdecor_frame_map
#define libdecor_state_new LIBDECOR_libdecor_state_new
#define libdecor_state_free LIBDECOR_libdecor_state_free
#define libdecor_configuration_get_content_size LIBDECOR_libdecor_configuration_get_content_size
#define libdecor_configuration_get_window_state LIBDECOR_libdecor_configuration_get_window_state
#define libdecor_dispatch LIBDECOR_libdecor_dispatch
#endif // FENNEC_PLATFORM_LINUX_WAYLAND_LIBDECOR_H

View File

@@ -0,0 +1,50 @@
// =====================================================================================================================
// 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 loader.h
/// \brief
///
///
/// \details
/// \author Medusa Slockbower
///
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
///
///
#ifndef FENNEC_PLATFORM_LINUX_WAYLAND_LIBDECOR_LOADER_H
#define FENNEC_PLATFORM_LINUX_WAYLAND_LIBDECOR_LOADER_H
#include <fennec/platform/interface/platform.h>
namespace fennec
{
namespace libdecor
{
bool load_symbols(platform* platform);
void unload_symbols(platform* platform);
}
}
#endif // FENNEC_PLATFORM_LINUX_WAYLAND_LIBDECOR_LOADER_H

View File

@@ -0,0 +1,88 @@
// =====================================================================================================================
// 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/lang/types.h>
#ifndef FENNEC_LIB
#define FENNEC_LIB(...)
#endif
#ifndef FENNEC_SYMBOL
#define FENNEC_SYMBOL(...)
#endif
#ifndef FENNEC_GLOBAL
#define FENNEC_GLOBAL(...)
#endif
FENNEC_LIB(LIBDECOR)
FENNEC_SYMBOL(void, libdecor_unref, struct libdecor*)
FENNEC_SYMBOL(int, libdecor_dispatch, struct libdecor*, int)
FENNEC_SYMBOL(struct libdecor*, libdecor_new, struct wl_display*, \
struct libdecor_interface*)
FENNEC_SYMBOL(struct libdecor_frame*, libdecor_decorate, struct libdecor*, \
struct wl_surface*, \
struct libdecor_frame_interface*, void*)
FENNEC_SYMBOL(void, libdecor_frame_unref, struct libdecor_frame*)
FENNEC_SYMBOL(void, libdecor_frame_set_title, struct libdecor_frame*, const char*)
FENNEC_SYMBOL(void, libdecor_frame_set_app_id, struct libdecor_frame*, const char*)
FENNEC_SYMBOL(void, libdecor_frame_set_max_content_size, struct libdecor_frame*, int, int)
FENNEC_SYMBOL(void, libdecor_frame_set_min_content_size, struct libdecor_frame*, int, int)
FENNEC_SYMBOL(void, libdecor_frame_get_min_content_size, const struct libdecor_frame*, int*, int*)
FENNEC_SYMBOL(void, libdecor_frame_get_max_content_size, const struct libdecor_frame*, int*, int*)
FENNEC_SYMBOL(void, libdecor_frame_resize, struct libdecor_frame*, struct wl_seat*, uint32_t, \
enum libdecor_resize_edge)
FENNEC_SYMBOL(void, libdecor_frame_move, struct libdecor_frame*, struct wl_seat*, uint32_t)
FENNEC_SYMBOL(void, libdecor_frame_commit, struct libdecor_frame*, struct libdecor_state*,\
struct libdecor_configuration*)
FENNEC_SYMBOL(void, libdecor_frame_set_minimized, struct libdecor_frame*)
FENNEC_SYMBOL(void, libdecor_frame_set_maximized, struct libdecor_frame*)
FENNEC_SYMBOL(void, libdecor_frame_unset_maximized, struct libdecor_frame*)
FENNEC_SYMBOL(void, libdecor_frame_set_fullscreen, struct libdecor_frame*, struct wl_output*)
FENNEC_SYMBOL(void, libdecor_frame_unset_fullscreen, struct libdecor_frame*)
FENNEC_SYMBOL(void, libdecor_frame_set_capabilities, struct libdecor_frame*, enum libdecor_capabilities)
FENNEC_SYMBOL(void, libdecor_frame_unset_capabilities, struct libdecor_frame*, enum libdecor_capabilities)
FENNEC_SYMBOL(bool, libdecor_frame_has_capability, struct libdecor_frame*, enum libdecor_capabilities)
FENNEC_SYMBOL(void, libdecor_frame_set_visibility, struct libdecor_frame*, bool)
FENNEC_SYMBOL(bool, libdecor_frame_is_visible, struct libdecor_frame*)
FENNEC_SYMBOL(bool, libdecor_frame_is_floating, struct libdecor_frame*)
FENNEC_SYMBOL(void, libdecor_frame_set_parent, struct libdecor_frame*,\
struct libdecor_frame*)
FENNEC_SYMBOL(void, libdecor_frame_show_window_menu, struct libdecor_frame*, struct wl_seat*, uint32_t, int, int)
FENNEC_SYMBOL(void, libdecor_frame_translate_coordinate, struct libdecor_frame*, int, int, int*, int*)
FENNEC_SYMBOL(void, libdecor_frame_map, struct libdecor_frame*)
FENNEC_SYMBOL(struct xdg_surface*, libdecor_frame_get_xdg_surface, struct libdecor_frame*)
FENNEC_SYMBOL(struct xdg_toplevel*, libdecor_frame_get_xdg_toplevel, struct libdecor_frame*)
FENNEC_SYMBOL(struct libdecor_state*, libdecor_state_new, int, int)
FENNEC_SYMBOL(void, libdecor_state_free, struct libdecor_state*)
FENNEC_SYMBOL(bool, libdecor_configuration_get_content_size, struct libdecor_configuration*,\
struct libdecor_frame*,\
int*,\
int*)
FENNEC_SYMBOL(bool, libdecor_configuration_get_window_state, struct libdecor_configuration*,\
enum libdecor_window_state*)
#undef FENNEC_LIB
#undef FENNEC_SYMBOL
#undef FENNEC_GLOBAL

View File

@@ -34,6 +34,10 @@
#include <fennec/platform/linux/wayland/fwd.h> #include <fennec/platform/linux/wayland/fwd.h>
#include <fennec/platform/interface/display_server.h> #include <fennec/platform/interface/display_server.h>
#if FENNEC_HAS_LIBDECOR
#include <fennec/platform/linux/wayland/libdecor/libdecor.h>
#endif
// forward defs to avoid flooding global namespace // forward defs to avoid flooding global namespace
struct wl_display; struct wl_display;
struct wl_shm; struct wl_shm;
@@ -64,6 +68,8 @@ public:
void* get_native_handle() override { return display; } void* get_native_handle() override { return display; }
// Fields ==============================================================================================================
private: private:
wl_display* display; wl_display* display;
wl_registry* registry; wl_registry* registry;
@@ -71,15 +77,26 @@ private:
wl_compositor* compositor; wl_compositor* compositor;
xdg_wm_base* xdg; xdg_wm_base* xdg;
wl_seat* seat; wl_seat* seat;
bool fifo; bool fifo, has_libdecor;
static void listen_global(void*, wl_registry*, uint32_t, const char*, uint32_t); #if FENNEC_HAS_LIBDECOR
static void listen_global_remove(void*, wl_registry*, uint32_t); libdecor* libdecor;
#endif
static void listen_seat_capabilities(void*, wl_seat*, uint32_t);
static void listen_seat_name(void*, wl_seat*, const char*);
static void listen_xdg_ping(void*, xdg_wm_base*, uint32_t); // Listeners ===========================================================================================================
static void _wl_registry_listen_global(void*, wl_registry*, uint32_t, const char*, uint32_t);
static void _wl_registry_on_global_remove(void*, wl_registry*, uint32_t);
static void _wl_seat_listen_capabilities(void*, wl_seat*, uint32_t);
static void _wl_seat_listen_name(void*, wl_seat*, const char*);
static void _xdg_listen_ping(void*, xdg_wm_base*, uint32_t);
#if FENNEC_HAS_LIBDECOR
static void _libdecor_on_error(struct libdecor*, libdecor_error error, const char* message);
#endif
FENNEC_RTTI_CLASS_ENABLE(display_server) { FENNEC_RTTI_CLASS_ENABLE(display_server) {
display_server::register_type<wayland_server>(1); display_server::register_type<wayland_server>(1);

View File

@@ -42,6 +42,9 @@ struct wl_surface;
struct xdg_surface; struct xdg_surface;
struct xdg_toplevel; struct xdg_toplevel;
struct libdecor_frame;
struct libdecor_configuration;
namespace fennec namespace fennec
{ {
@@ -50,32 +53,54 @@ public:
wayland_window(display_server* server, uint32_t id, const config& cfg); wayland_window(display_server* server, uint32_t id, const config& cfg);
~wayland_window(); ~wayland_window();
void show() override; void initialize() override;
void hide() override; void shutdown() override;
void* get_native_handle() override; void* get_native_handle() override;
bool set_flag(uint8_t flag, bool val) override; bool set_flag(uint8_t flag, bool val) override;
// Fields ==============================================================================================================
private: private:
wl_surface* surface; wl_surface* surface;
xdg_surface* xdgsurface; xdg_surface* xdgsurface;
xdg_toplevel* xdgtoplevel; xdg_toplevel* xdgtoplevel;
wl_callback* frame_callback; wl_callback* frame_callback;
static void listen_enter(void*, wl_surface*, wl_output*); #if FENNEC_HAS_LIBDECOR
static void listen_leave(void*, wl_surface*, wl_output*); libdecor_frame* libdecorframe;
static void listen_preferred_buffer_scale(void*, wl_surface*, int32_t); libdecor_configuration* libdecorcfg;
static void listen_preferred_buffer_transform(void*, wl_surface*, uint32_t); #endif
static void listen_frame_callback(void*, wl_callback*, uint32_t);
static void listen_xdg_surface_configure(void*, xdg_surface*, uint32_t); // Helpers =============================================================================================================
static void listen_xdg_toplevel_configure(void*, xdg_toplevel*, int32_t, int32_t, wl_array*); void _update_size(const ivec2& size);
static void listen_xdg_toplevel_configure_bounds(void*, xdg_toplevel*, int32_t, int32_t);
static void listen_xdg_toplevel_close(void*, xdg_toplevel*);
static void listen_xdg_toplevel_capabilities(void*, xdg_toplevel*, wl_array*); // Listeners ===========================================================================================================
static void _wl_surface_listen_enter(void*, wl_surface*, wl_output*);
static void _wl_surface_listen_leave(void*, wl_surface*, wl_output*);
static void _wl_surface_listen_preferred_buffer_scale(void*, wl_surface*, int32_t);
static void _wl_surface_listen_preferred_buffer_transform(void*, wl_surface*, uint32_t);
static void _wl_frame_listen_done(void*, wl_callback*, uint32_t);
static void _xdg_surface_listen_configure(void*, xdg_surface*, uint32_t);
static void _xdg_toplevel_listen_configure(void*, xdg_toplevel*, int32_t, int32_t, wl_array*);
static void _xdg_toplevel_listen_configure_bounds(void*, xdg_toplevel*, int32_t, int32_t);
static void _xdg_toplevel_listen_close(void*, xdg_toplevel*);
static void _xdg_toplevel_listen_wm_capabilities(void*, xdg_toplevel*, wl_array*);
#if FENNEC_HAS_LIBDECOR
static void _libdecor_frame_listen_configure(libdecor_frame*, libdecor_configuration*, void*);
static void _libdecor_frame_listen_close(libdecor_frame*, void*);
static void _libdecor_frame_listen_commit(libdecor_frame*, void*);
static void _libdecor_frame_listen_dismiss_popup(libdecor_frame*, const char*, void*);
#endif
}; };
} }

View File

@@ -33,6 +33,7 @@
#define FENNEC_PLATFORM_LINUX_WAYLAND_OPENGL_EGLCONTEXT_H #define FENNEC_PLATFORM_LINUX_WAYLAND_OPENGL_EGLCONTEXT_H
#include <EGL/egl.h> #include <EGL/egl.h>
#include <fennec/platform/opengl/egl/error.h>
#include <fennec/platform/linux/wayland/server.h> #include <fennec/platform/linux/wayland/server.h>
#include <fennec/renderers/opengl/glcontext.h> #include <fennec/renderers/opengl/glcontext.h>

View File

@@ -0,0 +1,59 @@
// =====================================================================================================================
// 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 error.h
/// \brief
///
///
/// \details
/// \author Medusa Slockbower
///
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
///
///
#ifndef FENNEC_PLATFORM_OPENGL_EGL_ERROR_H
#define FENNEC_PLATFORM_OPENGL_EGL_ERROR_H
#include <EGL/egl.h>
#include <fennec/string/cstring.h>
inline fennec::cstring eglErrorString(EGLint err) {
switch (err) {
case EGL_SUCCESS: return "None";
case EGL_NOT_INITIALIZED: return "Not Initialized";
case EGL_BAD_ACCESS: return "Bad Access";
case EGL_BAD_ALLOC: return "Bad Alloc";
case EGL_BAD_ATTRIBUTE: return "Bad Attribute";
case EGL_BAD_CONTEXT: return "Bad Context";
case EGL_BAD_CONFIG: return "Bad Config";
case EGL_BAD_CURRENT_SURFACE: return "Bad Current Surface";
case EGL_BAD_DISPLAY: return "Bad Display";
case EGL_BAD_SURFACE: return "Bad Surface";
case EGL_BAD_MATCH: return "Bad Match";
case EGL_BAD_PARAMETER: return "Bad Parameter";
case EGL_BAD_NATIVE_PIXMAP: return "Bad Native Pixmap";
case EGL_BAD_NATIVE_WINDOW: return "Bad Native Window";
case EGL_CONTEXT_LOST: return "Context Lost";
default: return "Unknown Error";
}
}
#endif // FENNEC_PLATFORM_OPENGL_EGL_ERROR_H

View File

@@ -33,6 +33,7 @@
#define FENNEC_PLATFORM_OPENGL_EGL_SURFACE_H #define FENNEC_PLATFORM_OPENGL_EGL_SURFACE_H
#include <EGL/egl.h> #include <EGL/egl.h>
#include <fennec/platform/opengl/egl/error.h>
#include <fennec/platform/opengl/egl/fwd.h> #include <fennec/platform/opengl/egl/fwd.h>
#include <fennec/renderers/interface/gfxsurface.h> #include <fennec/renderers/interface/gfxsurface.h>
@@ -42,14 +43,14 @@ namespace fennec
class eglsurface : public gfxsurface { class eglsurface : public gfxsurface {
public: public:
eglsurface(fennec::window* win, eglcontext* ctx, EGLNativeWindowType eglwindow); eglsurface(fennec::window* win, eglcontext* ctx, void* eglwindow);
~eglsurface(); ~eglsurface();
void make_current() override; void make_current() override;
void swap() override; void swap() override;
protected: protected:
EGLNativeWindowType _eglwindow; void* _eglwindow;
EGLSurface _eglsurface; EGLSurface _eglsurface;
}; };

View File

@@ -0,0 +1,48 @@
// =====================================================================================================================
// 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_manager.h
/// \brief
///
///
/// \details
/// \author Medusa Slockbower
///
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
///
///
#ifndef FENNEC_PLATFORM_WINDOW_MANAGER_H
#define FENNEC_PLATFORM_WINDOW_MANAGER_H
namespace fennec
{
///
/// \brief Thread-Safe wrapper for `display_server` and `window`
class window_manager {
public:
private:
};
}
#endif // FENNEC_PLATFORM_WINDOW_MANAGER_H

View File

@@ -31,10 +31,14 @@
#ifndef FENNEC_RENDERERS_INTERFACE_GFXCONTEXT_H #ifndef FENNEC_RENDERERS_INTERFACE_GFXCONTEXT_H
#define FENNEC_RENDERERS_INTERFACE_GFXCONTEXT_H #define FENNEC_RENDERERS_INTERFACE_GFXCONTEXT_H
#include <fennec/platform/interface/fwd.h>
#include <fennec/core/version.h> #include <fennec/core/version.h>
#include <fennec/lang/types.h> #include <fennec/lang/types.h>
#include <fennec/platform/interface/display_server.h>
#include <fennec/string/string.h> #include <fennec/string/string.h>
#include <fennec/rtti/enable.h>
#include <fennec/renderers/interface/forward.h> #include <fennec/renderers/interface/forward.h>
#include <fennec/renderers/interface/gfxresourcepool.h> #include <fennec/renderers/interface/gfxresourcepool.h>

View File

@@ -117,6 +117,14 @@ struct type {
template<typename TypeT> template<typename TypeT>
static type get_from_instance(TypeT* t) { return type(t); } static type get_from_instance(TypeT* t) { return type(t); }
///
/// \brief Get the type info of the provided object.
/// \tparam TypeT The type, automatically deduced
/// \param t A pointer to an object
/// \returns The type info of the provided type
template<typename TypeT>
static type get_from_instance(const TypeT*) { return type(static_cast<TypeT*>(nullptr)); }
private: private:
const type_data* _data; const type_data* _data;

View File

@@ -29,7 +29,7 @@ platform::platform() {
} }
void platform::initialize() { void platform::initialize() {
logger::log(fennec::format("Initializing platform {}", get_type().name())); logger::log(format("Initializing platform {}", get_type().name()));
display_server::entrylist_t display_servers = display_server::get_type_list(); display_server::entrylist_t display_servers = display_server::get_type_list();
while (not display_servers.empty()) { while (not display_servers.empty()) {
@@ -39,6 +39,7 @@ void platform::initialize() {
unique_ptr<display_server> server = unique_ptr(it.ctor(this)); unique_ptr<display_server> server = unique_ptr(it.ctor(this));
server->connect(); server->connect();
if (server->connected()) { if (server->connected()) {
logger::log(format("Selected {} for the display server.", server->get_type().name()));
display = move(server); display = move(server);
break; break;
} }

View File

@@ -25,11 +25,11 @@ namespace fennec
{ {
wayland_eglsurface::wayland_eglsurface(wayland_window* win, eglcontext* ctx) wayland_eglsurface::wayland_eglsurface(wayland_window* win, eglcontext* ctx)
: eglsurface(win, ctx, : eglsurface(
reinterpret_cast<EGLNativeWindowType>( win, ctx,
wl_egl_window_create( wl_egl_window_create(
static_cast<wl_surface*>(win->get_native_handle()), win->get_size().x, win->get_size().y static_cast<wl_surface*>(win->get_native_handle()),
) win->get_config().rect.size.x, win->get_config().rect.size.y
) )
) { ) {

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/core/logger.h>
#include <fennec/renderers/interface/gfxcontext.h>
#include <fennec/platform/linux/wayland/server.h> #include <fennec/platform/linux/wayland/server.h>
#include <fennec/platform/linux/wayland/window.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/wayland.h>
#include <fennec/platform/linux/wayland/lib/loader.h>
#include <fennec/platform/linux/wayland/lib/headers/xdg-shell-client-protocols.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 namespace fennec
{ {
wayland_server::wayland_server(fennec::platform* p) wayland_server::wayland_server(fennec::platform* p)
: display_server_base(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), has_libdecor(false) {
// load shared lib // load shared lib
if (libwayland::load_symbols(platform)) { assertf(libwayland::load_symbols(platform), "Failed to load libwayland.");
return;
} #if FENNEC_HAS_LIBDECOR
has_libdecor = libdecor::load_symbols(platform);
#endif
} }
wayland_server::~wayland_server() { wayland_server::~wayland_server() {
@@ -49,7 +58,7 @@ wayland_server::~wayland_server() {
void wayland_server::connect() { void wayland_server::connect() {
static constexpr wl_registry_listener listener = { static constexpr wl_registry_listener listener = {
listen_global, listen_global_remove _wl_registry_listen_global, _wl_registry_on_global_remove
}; };
if (display != nullptr) { if (display != nullptr) {
@@ -81,21 +90,42 @@ void wayland_server::connect() {
return; return;
} }
#if FENNEC_HAS_LIBDECOR
static libdecor_interface libdecor_listener = {
.error = _libdecor_on_error,
.reserved0 = nullptr,
.reserved1 = nullptr,
.reserved2 = nullptr,
.reserved3 = nullptr,
.reserved4 = nullptr,
.reserved5 = nullptr,
.reserved6 = nullptr,
.reserved7 = nullptr,
.reserved8 = nullptr,
.reserved9 = nullptr,
};
if (has_libdecor) {
libdecor = libdecor_new(display, &libdecor_listener);
}
#endif
auto contexts = ctx_registry::get_type_list(); auto contexts = ctx_registry::get_type_list();
while (not contexts.empty()) { while (not contexts.empty()) {
const auto& ctx = contexts.front(); const auto& ctx = contexts.front();
gfx_context = ctx.ctor(this); gfx_context = unique_ptr(ctx.ctor(this));
if (gfx_context->is_valid()) { if (gfx_context->is_valid()) {
break; break;
} else { } else {
delete gfx_context; gfx_context.reset();
gfx_context = nullptr; gfx_context = nullptr;
contexts.pop(); contexts.pop();
} }
} }
assertf(gfx_context != nullptr, "Failed to create graphics context."); assertf(not gfx_context.empty(), "Failed to create graphics context.");
} }
void wayland_server::disconnect() { void wayland_server::disconnect() {
@@ -106,7 +136,7 @@ void wayland_server::disconnect() {
} }
// delete the gfx context // delete the gfx context
delete gfx_context; gfx_context.reset();
// check compositor // check compositor
@@ -137,7 +167,14 @@ bool wayland_server::connected() const {
} }
void wayland_server::dispatch() { void wayland_server::dispatch() {
#if FENNEC_HAS_LIBDECOR
if (libdecor) {
libdecor_dispatch(libdecor, 0);
} else
#endif
{
wl_display_dispatch_pending(display); wl_display_dispatch_pending(display);
}
} }
window* wayland_server::create_window(const window::config& conf) { window* wayland_server::create_window(const window::config& conf) {
@@ -145,13 +182,13 @@ window* wayland_server::create_window(const window::config& conf) {
return windows[id]; return windows[id];
} }
void wayland_server::listen_global(void* data, wl_registry* reg, uint32_t id, const char* name, uint32_t version) { void wayland_server::_wl_registry_listen_global(void* data, wl_registry* reg, uint32_t id, const char* name, uint32_t version) {
static constexpr wl_seat_listener seat_listener = { static constexpr wl_seat_listener seat_listener = {
listen_seat_capabilities, listen_seat_name _wl_seat_listen_capabilities, _wl_seat_listen_name
}; };
static constexpr xdg_wm_base_listener xdg_listener = { static constexpr xdg_wm_base_listener xdg_listener = {
listen_xdg_ping _xdg_listen_ping
}; };
wayland_server* server = static_cast<wayland_server*>(data); wayland_server* server = static_cast<wayland_server*>(data);
@@ -180,20 +217,28 @@ void wayland_server::listen_global(void* data, wl_registry* reg, uint32_t id, co
} }
} }
void wayland_server::listen_global_remove(void*, wl_registry*, uint32_t) { void wayland_server::_wl_registry_on_global_remove(void*, wl_registry*, uint32_t) {
} }
void wayland_server::listen_seat_capabilities(void*, wl_seat*, uint32_t) { void wayland_server::_wl_seat_listen_capabilities(void*, wl_seat*, uint32_t) {
} }
void wayland_server::listen_seat_name(void*, wl_seat*, const char*) {} void wayland_server::_wl_seat_listen_name(void*, wl_seat*, const char*) {}
void wayland_server::listen_xdg_ping(void*, xdg_wm_base* xdg, uint32_t serial) { void wayland_server::_xdg_listen_ping(void*, xdg_wm_base* xdg, uint32_t serial) {
xdg_wm_base_pong(xdg, serial); xdg_wm_base_pong(xdg, serial);
} }
#if FENNEC_HAS_LIBDECOR
void wayland_server::_libdecor_on_error(struct libdecor*, libdecor_error error, const char* message) {
fennec::logger::log(
fennec::format("libdecor error ({}): {}", static_cast<int>(error), fennec::cstring(message, strlen(message)))
);
}
#endif
} }

View File

@@ -16,13 +16,22 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
// ===================================================================================================================== // =====================================================================================================================
#include <fennec/core/logger.h>
#include <fennec/math/relational.h>
#include <fennec/platform/interface/display_server.h> #include <fennec/platform/interface/display_server.h>
#include <fennec/renderers/interface/gfxcontext.h>
#include <fennec/platform/linux/wayland/server.h> #include <fennec/platform/linux/wayland/server.h>
#include <fennec/platform/linux/wayland/window.h> #include <fennec/platform/linux/wayland/window.h>
#include <fennec/platform/linux/wayland/lib/wayland.h> #include <fennec/platform/linux/wayland/lib/wayland.h>
#include <fennec/platform/linux/wayland/lib/headers/xdg-shell-client-protocols.h> #include <fennec/platform/linux/wayland/lib/headers/xdg-shell-client-protocols.h>
#include <fennec/renderers/interface/gfxcontext.h> #include <fennec/platform/linux/wayland/libdecor/libdecor.h>
#include <fennec/renderers/interface/gfxsurface.h>
#if FENNEC_HAS_LIBDECOR
#include <fennec/platform/linux/wayland/libdecor/libdecor.h>
#endif
using namespace fennec; using namespace fennec;
@@ -37,28 +46,39 @@ wayland_window::~wayland_window() {
} }
void wayland_window::show() { void wayland_window::initialize() {
static constexpr wl_surface_listener surface_listener = { static constexpr wl_surface_listener surface_listener = {
listen_enter, listen_leave, listen_preferred_buffer_scale, listen_preferred_buffer_transform .enter = _wl_surface_listen_enter,
.leave = _wl_surface_listen_leave,
.preferred_buffer_scale = _wl_surface_listen_preferred_buffer_scale,
.preferred_buffer_transform = _wl_surface_listen_preferred_buffer_transform
}; };
static constexpr xdg_surface_listener xdg_surface_listener = { static constexpr xdg_surface_listener xdg_surface_listener = {
listen_xdg_surface_configure .configure = _xdg_surface_listen_configure
}; };
static constexpr xdg_toplevel_listener xdg_toplevel_listener = { static constexpr xdg_toplevel_listener xdg_toplevel_listener = {
listen_xdg_toplevel_configure, listen_xdg_toplevel_close, listen_xdg_toplevel_configure_bounds, .configure = _xdg_toplevel_listen_configure,
listen_xdg_toplevel_capabilities .close = _xdg_toplevel_listen_close,
.configure_bounds = _xdg_toplevel_listen_configure_bounds,
.wm_capabilities = _xdg_toplevel_listen_wm_capabilities
}; };
static constexpr wl_callback_listener frame_callback_listener = { static constexpr wl_callback_listener frame_callback_listener = {
listen_frame_callback .done = _wl_frame_listen_done
}; };
if (is_visible()) { if (is_visible()) {
return; return;
} }
if (is_running()) {
// reshow window
return;
}
wayland_window* root = this; wayland_window* root = this;
while (root != nullptr and root->is_popup()) { while (root != nullptr and root->is_popup()) {
root = static_cast<wayland_window*>(root->get_parent()); root = static_cast<wayland_window*>(root->get_parent());
@@ -71,44 +91,84 @@ void wayland_window::show() {
surface = wl_compositor_create_surface(wl_server->compositor); surface = wl_compositor_create_surface(wl_server->compositor);
wl_surface_add_listener(surface, &surface_listener, this); wl_surface_add_listener(surface, &surface_listener, this);
#if FENNEC_HAS_LIBDECOR
static libdecor_frame_interface libdecor_frame_listener = {
.configure = _libdecor_frame_listen_configure,
.close = _libdecor_frame_listen_close,
.commit = _libdecor_frame_listen_commit,
.dismiss_popup = _libdecor_frame_listen_dismiss_popup,
.reserved0 = nullptr,
.reserved1 = nullptr,
.reserved2 = nullptr,
.reserved3 = nullptr,
.reserved4 = nullptr,
.reserved5 = nullptr,
.reserved6 = nullptr,
.reserved7 = nullptr,
.reserved8 = nullptr,
.reserved9 = nullptr,
};
gfx_surface = wl_server->get_gfx_context()->create_surface(this);
if (wl_server->has_libdecor) {
libdecorframe = libdecor_decorate(wl_server->libdecor, surface, &libdecor_frame_listener, this);
libdecor_frame_set_app_id(libdecorframe, cfg.title.cstr());
libdecor_frame_set_title(libdecorframe, cfg.title.cstr());
libdecor_frame_map(libdecorframe);
xdgsurface = libdecor_frame_get_xdg_surface(libdecorframe);
xdgtoplevel = libdecor_frame_get_xdg_toplevel(libdecorframe);
} else
#endif
{
xdgsurface = xdg_wm_base_get_xdg_surface(wl_server->xdg, surface); xdgsurface = xdg_wm_base_get_xdg_surface(wl_server->xdg, surface);
xdg_surface_add_listener(xdgsurface, &xdg_surface_listener, this); xdg_surface_add_listener(xdgsurface, &xdg_surface_listener, this);
xdgtoplevel = xdg_surface_get_toplevel(xdgsurface); xdgtoplevel = xdg_surface_get_toplevel(xdgsurface);
xdg_toplevel_add_listener(xdgtoplevel, &xdg_toplevel_listener, this); xdg_toplevel_add_listener(xdgtoplevel, &xdg_toplevel_listener, this);
frame_callback = wl_surface_frame(surface); frame_callback = wl_surface_frame(surface);
wl_callback_add_listener(frame_callback, &frame_callback_listener, this); wl_callback_add_listener(frame_callback, &frame_callback_listener, this);
wl_surface_commit(surface); wl_surface_commit(surface);
}
wl_display_roundtrip(wl_server->display);
wl_display_roundtrip(wl_server->display); wl_display_roundtrip(wl_server->display);
cfg.flags.set(flag_visible); state.flags.set(state_visible);
cfg.flags.set(flag_running); state.flags.set(state_running);
gfx_surface = wl_server->get_gfx_context()->create_surface(this);
} }
void wayland_window::hide() { void wayland_window::shutdown() {
if (not is_running()) { if (not is_running()) {
return; return;
} }
wayland_server* wl_server = static_cast<wayland_server*>(server); wayland_server* wl_server = static_cast<wayland_server*>(server);
if (xdgtoplevel) {
xdg_toplevel_destroy(xdgtoplevel);
xdgtoplevel = nullptr;
}
if (frame_callback) { if (frame_callback) {
wl_callback_destroy(frame_callback); wl_callback_destroy(frame_callback);
frame_callback = nullptr; frame_callback = nullptr;
} }
#if FENNEC_HAS_LIBDECOR
if (libdecorframe) {
libdecor_frame_unref(libdecorframe);
xdgtoplevel = nullptr;
xdgsurface = nullptr;
}
#endif
if (xdgtoplevel) {
xdg_toplevel_destroy(xdgtoplevel);
xdgtoplevel = nullptr;
}
if (xdgsurface) { if (xdgsurface) {
xdg_surface_destroy(xdgsurface); xdg_surface_destroy(xdgsurface);
xdgsurface = nullptr; xdgsurface = nullptr;
@@ -121,36 +181,181 @@ void wayland_window::hide() {
wl_display_roundtrip(wl_server->display); wl_display_roundtrip(wl_server->display);
cfg.flags.clear(flag_visible); state.flags.clear(state_visible);
cfg.flags.clear(flag_running); state.flags.clear(state_running);
} }
void* wayland_window::get_native_handle() { void* wayland_window::get_native_handle() {
return surface; return surface;
} }
bool wayland_window::set_flag(uint8_t, bool) { bool wayland_window::set_flag(uint8_t flag, bool value) {
// Do nothing if already set
if (cfg.flags.test(flag) == value) {
return false; return false;
}
if (not is_running()) {
return false;
}
switch (flag) {
case flag_always_on_top:
break;
case flag_borderless:
#if FENNEC_HAS_LIBDECOR
if (libdecorframe) {
bool vis = libdecor_frame_is_visible(libdecorframe);
bool tgt = not value;
if (vis != tgt) {
libdecor_frame_set_visibility(libdecorframe, tgt);
}
} else
#endif // FENNEC_HAS_LIBDECOR
{
}
break;
case flag_modal:
break;
case flag_pass_mouse:
break;
case flag_popup:
break;
case flag_resizable:
break;
case flag_transparent:
break;
case flag_no_focus:
break;
default:
logger::log("Invalid flag passed to window::set_flag.");
break;
}
// Store the value
cfg.flags.store(flag, value);
return true;
} }
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) {} // Helpers =============================================================================================================
void wayland_window::listen_xdg_surface_configure(void*, xdg_surface* xdg, uint32_t serial) { void wayland_window::_update_size(const ivec2& size) {
//bool size_changed = any(notEqual(size, state.rect.size));
state.rect.size = size;
if (gfx_surface) {
gfx_surface->resize(size);
}
#if FENNEC_HAS_LIBDECOR
if (libdecorframe) {
libdecor_state* state = libdecor_state_new(size.x, size.y);
libdecor_frame_commit(libdecorframe, state, libdecorcfg);
libdecor_state_free(state);
libdecorcfg = nullptr;
}
#endif
}
// Listeners ===========================================================================================================
// Surface Listeners
void wayland_window::_wl_surface_listen_enter(void*, wl_surface*, wl_output*) {}
void wayland_window::_wl_surface_listen_leave(void*, wl_surface*, wl_output*) {}
void wayland_window::_wl_surface_listen_preferred_buffer_scale(void*, wl_surface*, int32_t) {}
void wayland_window::_wl_surface_listen_preferred_buffer_transform(void*, wl_surface*, uint32_t) {}
// Frame Listeners
void wayland_window::_wl_frame_listen_done(void*, wl_callback*, uint32_t) {}
// XDG Listeners
void wayland_window::_xdg_surface_listen_configure(void*, xdg_surface* xdg, uint32_t serial) {
xdg_surface_ack_configure(xdg, 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::_xdg_toplevel_listen_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::_xdg_toplevel_listen_configure_bounds(void*, xdg_toplevel*, int32_t, int32_t) {}
void wayland_window::listen_xdg_toplevel_close(void* data, xdg_toplevel*) { void wayland_window::_xdg_toplevel_listen_close(void* data, xdg_toplevel*) {
wayland_window* window = static_cast<wayland_window*>(data); wayland_window* window = static_cast<wayland_window*>(data);
window->hide(); window->shutdown();
} }
void wayland_window::listen_xdg_toplevel_capabilities(void*, xdg_toplevel*, wl_array*) {} void wayland_window::_xdg_toplevel_listen_wm_capabilities(void*, xdg_toplevel*, wl_array*) {}
// Libdecor Listeners
#if FENNEC_HAS_LIBDECOR
void wayland_window::_libdecor_frame_listen_configure(libdecor_frame* frame, libdecor_configuration* cfg, void* data) {
wayland_window* window = static_cast<wayland_window*>(data);
ivec2 size = window->state.rect.size;
libdecor_configuration_get_content_size(cfg, frame, &size.x, &size.y);
size.x = size.x == 0 ? window->state.rect.size.x : size.x;
size.y = size.y == 0 ? window->state.rect.size.y : size.y;
size.x = size.x == 0 ? window->cfg.rect.size.x : size.x;
size.y = size.y == 0 ? window->cfg.rect.size.y : size.y;
assertf(size.x != 0 or size.y != 0, "Invalid window size!");
libdecor_window_state state = LIBDECOR_WINDOW_STATE_NONE;
window->state.mode = mode_windowed;
window->state.flags.clear(state_suspended);
window->libdecorcfg = cfg;
if (libdecor_configuration_get_window_state(cfg, &state)) {
if (state & LIBDECOR_WINDOW_STATE_MAXIMIZED) {
window->state.mode = mode_maximized;
}
if (state & LIBDECOR_WINDOW_STATE_FULLSCREEN) {
window->state.mode = mode_fullscreen;
}
if (state & LIBDECOR_WINDOW_STATE_SUSPENDED) {
window->state.flags.set(state_suspended);
}
}
window->_update_size(size);
}
void wayland_window::_libdecor_frame_listen_close(libdecor_frame*, void* data) {
wayland_window* window = static_cast<wayland_window*>(data);
window->shutdown();
}
void wayland_window::_libdecor_frame_listen_commit(libdecor_frame*, void* data) {
wayland_window* window = static_cast<wayland_window*>(data);
window->gfx_surface->swap();
}
void wayland_window::_libdecor_frame_listen_dismiss_popup(libdecor_frame*, const char*, void*) {}
#endif

View File

@@ -38,7 +38,13 @@ static const cstring& egl_translate_type(EGLint type) {
} }
eglcontext::eglcontext(display_server* display) eglcontext::eglcontext(display_server* display)
: glcontext(display) { : glcontext(display)
, _egldisplay(nullptr)
, _eglcontext(nullptr)
, _eglconfig(nullptr)
, _eglvmajor(0)
, _eglvminor(0)
, _eglctype(0){
EGLint config_attrs[] = { EGLint config_attrs[] = {
EGL_SURFACE_TYPE, EGL_SURFACE_TYPE,

View File

@@ -16,12 +16,13 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
// ===================================================================================================================== // =====================================================================================================================
#include <fennec/core/logger.h>
#include <fennec/platform/opengl/egl/context.h> #include <fennec/platform/opengl/egl/context.h>
#include <fennec/platform/opengl/egl/surface.h> #include <fennec/platform/opengl/egl/surface.h>
namespace fennec { namespace fennec {
eglsurface::eglsurface(fennec::window* win, eglcontext* ctx, EGLNativeWindowType eglwindow) eglsurface::eglsurface(fennec::window* win, eglcontext* ctx, void* eglwindow)
: gfxsurface(win, ctx) : gfxsurface(win, ctx)
, _eglwindow(eglwindow) , _eglwindow(eglwindow)
, _eglsurface(nullptr) { , _eglsurface(nullptr) {
@@ -31,25 +32,32 @@ eglsurface::eglsurface(fennec::window* win, eglcontext* ctx, EGLNativeWindowType
_eglsurface = eglCreateWindowSurface( _eglsurface = eglCreateWindowSurface(
ctx->_egldisplay, ctx->_egldisplay,
ctx->_eglconfig, ctx->_eglconfig,
_eglwindow, reinterpret_cast<EGLNativeWindowType>(_eglwindow),
nullptr nullptr
); );
if (not _eglsurface) {
int32_t err = eglGetError();
logger::log(format("EGL error: {}", eglErrorString(err)));
}
assertf(_eglsurface, "Failed to create EGL surface!"); assertf(_eglsurface, "Failed to create EGL surface!");
eglsurface::make_current();
} }
eglsurface::~eglsurface() { eglsurface::~eglsurface() {
eglcontext* ctx = static_cast<eglcontext*>(context); eglcontext* ctx = static_cast<eglcontext*>(context);
eglDestroySurface(ctx->_egldisplay, _eglsurface); assertf(eglDestroySurface(ctx->_egldisplay, _eglsurface), "Error destroying EGL surface!");
} }
void eglsurface::make_current() { void eglsurface::make_current() {
eglcontext* ctx = static_cast<eglcontext*>(context); eglcontext* ctx = static_cast<eglcontext*>(context);
eglMakeCurrent(ctx->_egldisplay, _eglsurface, _eglsurface, ctx->_eglcontext); assertf(eglMakeCurrent(ctx->_egldisplay, _eglsurface, _eglsurface, ctx->_eglcontext), "Error setting the current surface!");
} }
void eglsurface::swap() { void eglsurface::swap() {
eglcontext* ctx = static_cast<eglcontext*>(context); eglcontext* ctx = static_cast<eglcontext*>(context);
eglSwapBuffers(ctx->_egldisplay, _eglsurface); assertf(eglSwapBuffers(ctx->_egldisplay, _eglsurface), "Error swapping surface buffers!");
} }
} // fennec } // fennec

View File

@@ -34,18 +34,22 @@ inline void fennec_test_platform() {
display_server* display = platform->get_display_server(); display_server* display = platform->get_display_server();
window* window = display->create_window({ window* window = display->create_window(window::config {
.title = string("test window"), .title = string("fennec-test"),
.flags = {}, .flags = { },
.mode = window::mode_windowed, .mode = window::mode_windowed,
.parent = window::nullid, .parent = window::nullid,
.size = ivec2{ 720, 480 }, .rect = {
.position = { 0, 0 },
.size = { 720, 480 },
},
.fractional_scaling = 0,
.accessibility = { string("test window"), string("test window description") } .accessibility = { string("test window"), string("test window description") }
}); });
assertf(window != nullptr, "Failed to create test window."); assertf(window != nullptr, "Failed to create test window.");
window->show(); window->initialize();
while (window->is_running()) { while (window->is_running()) {
window->begin_frame(); window->begin_frame();
@@ -54,7 +58,7 @@ inline void fennec_test_platform() {
display->dispatch(); display->dispatch();
} }
window->hide(); window->shutdown();
delete window; delete window;