- Setup libdecor, which is used automatically when available.

TODO:
 - xdg decorations
 - threading
 - thread-safe window manager
This commit is contained in:
2025-12-15 23:40:06 -05:00
parent 97f5bbfe00
commit 520a0e1363
25 changed files with 508 additions and 90 deletions

View File

@@ -43,7 +43,8 @@ namespace fennec
/// \tparam N The number of bits in the bitfield
template<size_t N>
struct bitfield {
static constexpr size_t size = N;
static constexpr size_t bits = N;
static constexpr size_t bytes = (N + 7) / 8;
public:
constexpr bitfield()
@@ -66,51 +67,79 @@ public:
}
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)
: _bytes() {
size_t i = 0;
(this->store(i++, fennec::forward<ArgsT>(args)), ...);
}
bitfield(const bitfield& bf)
: _bytes(bf._bytes) {
}
bitfield(bitfield&& bf) noexcept
: _bytes(bf._bytes) {
}
constexpr ~bitfield() = default;
bitfield& operator=(const bitfield& bf) = default;
bitfield& operator=(bitfield&& bf) noexcept = default;
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 o = i % 8;
return _bytes[b] & (1 << o);
}
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 o = i % 8;
_bytes[b] |= (1 << o);
}
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 o = i % 8;
_bytes[b] &= ~(1 << o);
}
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 o = i % 8;
_bytes[b] ^= (1 << o);
}
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 o = i % 8;
(_bytes[b] &= ~((1 << o))) |= ((v << o));
}
bitfield operator~() const {
bitfield res = *this;
res._inv_helper(make_index_metasequence_t<bytes>{});
return res;
}
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
{
template<typename ScalarT, size_t...IndicesV> 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...IndicesV> requires(is_scalar_v<ScalarT>) struct vector; // Forward def for vectors
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
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 RowsV
/// \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
{
// Assertions ==========================================================================================================

View File

@@ -103,6 +103,7 @@
///
///
#include <fennec/containers/initializer_list.h>
#include <fennec/math/detail/_fwd.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 IndicesV index of each Component
/// \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)>
{
// Assertions ==========================================================================================================
@@ -337,6 +338,21 @@ struct vector : detail::vector_base_type<ScalarT, sizeof...(IndicesV)>
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
#include <fennec/containers/bitfield.h>
#include <fennec/platform/interface/fwd.h>
#include <fennec/platform/interface/window.h>
#include <fennec/renderers/interface/gfxcontext.h>
#include <fennec/rtti/enable.h>
#include <fennec/rtti/type_registry.h>
@@ -89,6 +93,8 @@ enum feature_ : uint32_t {
};
using featureset_t = bitfield<feature_count>;
using window_id = uint32_t;
using window_pool = object_pool<window*>;
struct config {
};
@@ -109,10 +115,6 @@ enum feature_ : uint32_t {
return features.test(feature);
}
gfxcontext* get_gfx_context() {
return gfx_context;
}
virtual window* create_window(const window::config& conf) = 0;
window* get_window(size_t id) {
@@ -127,11 +129,14 @@ enum feature_ : uint32_t {
virtual void* get_native_handle() = 0;
gfxcontext* get_gfx_context() {
return gfx_context.get();
}
protected:
featureset_t features;
object_pool<window*> windows;
gfxcontext* gfx_context;
featureset_t features;
window_pool windows;
unique_ptr<gfxcontext> gfx_context;
FENNEC_RTTI_CLASS_ENABLE() {
}

View File

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

View File

@@ -32,9 +32,13 @@
#define FENNEC_PLATFORM_INTERFACE_WINDOW_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/containers/bitfield.h>
#include <fennec/containers/optional.h>
namespace fennec
{
@@ -61,21 +65,27 @@ public:
enum flag_ : uint8_t {
flag_always_on_top = 0, // Window always appears on top level
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_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_resizable, // Window can be resized through functions defined by Desktop Environment
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_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 state_t = bitfield<state_count>;
struct accessibility {
string name, description;
@@ -87,15 +97,25 @@ public:
uint8_t mode;
size_t parent;
ivec2 size;
irect rect;
double_t fractional_scaling;
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)
: server(server), id(id)
, cfg(conf), root(nullptr) {
cfg.flags.clear(flag_visible);
, cfg(conf), state(), root(nullptr) {
state.mode = conf.mode;
}
virtual ~window() = default;
@@ -103,25 +123,33 @@ public:
size_t get_id() const { return id; }
size_t get_parent_id() const { return cfg.parent; }
const config& get_config() const { return cfg; }
window* get_parent() const;
const ivec2& get_size() const { return cfg.size; }
int get_width() const { return cfg.size.x; }
int get_height() const { return cfg.size.y; }
const ivec2& get_size() const { return state.rect.size; }
const ivec2& get_position() const { return state.rect.position; }
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 is_always_on_top() const { return get_flag(flag_always_on_top); }
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_passing_mouse() const { return get_flag(flag_pass_mouse); }
bool is_popup() const { return get_flag(flag_popup); }
bool is_resizable() const { return get_flag(flag_resizable); }
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); }
@@ -129,7 +157,6 @@ public:
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_decorations(bool val) { return set_flag(flag_decorations, 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_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_no_focus(bool val) { return set_flag(flag_no_focus, val); }
virtual void show() = 0;
virtual void hide() = 0;
virtual void initialize() = 0;
virtual void shutdown() = 0;
virtual void begin_frame();
virtual void end_frame();
@@ -149,6 +176,7 @@ protected:
display_server* const server;
const size_t id;
config cfg;
state state;
window* root;
gfxsurface* gfx_surface;
};

View File

@@ -53,13 +53,15 @@ public:
wayland_window(display_server* server, uint32_t id, const config& cfg);
~wayland_window();
void show() override;
void hide() override;
void initialize() override;
void shutdown() override;
void* get_native_handle() override;
bool set_flag(uint8_t flag, bool val) override;
// Fields ==============================================================================================================
private:
wl_surface* surface;
xdg_surface* xdgsurface;
@@ -67,9 +69,18 @@ private:
wl_callback* frame_callback;
#if FENNEC_HAS_LIBDECOR
libdecor_frame* libdecorframe;
libdecor_frame* libdecorframe;
libdecor_configuration* libdecorcfg;
#endif
// Helpers =============================================================================================================
void _update_size(const ivec2& size);
// 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);

View File

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

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
#define FENNEC_RENDERERS_INTERFACE_GFXCONTEXT_H
#include <fennec/platform/interface/fwd.h>
#include <fennec/core/version.h>
#include <fennec/lang/types.h>
#include <fennec/platform/interface/display_server.h>
#include <fennec/string/string.h>
#include <fennec/rtti/enable.h>
#include <fennec/renderers/interface/forward.h>
#include <fennec/renderers/interface/gfxresourcepool.h>

View File

@@ -117,6 +117,14 @@ struct type {
template<typename TypeT>
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:
const type_data* _data;