- Setup libdecor, which is used automatically when available.
TODO: - xdg decorations - threading - thread-safe window manager
This commit is contained in:
@@ -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() {
|
||||
}
|
||||
|
||||
@@ -60,6 +60,8 @@
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
///
|
||||
/// \brief Main platform class
|
||||
class platform : public singleton<platform*> {
|
||||
public:
|
||||
using shared_object = struct shared_object;
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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>
|
||||
|
||||
59
include/fennec/platform/opengl/egl/error.h
Normal file
59
include/fennec/platform/opengl/egl/error.h
Normal 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
|
||||
@@ -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
|
||||
|
||||
48
include/fennec/platform/window_manager.h
Normal file
48
include/fennec/platform/window_manager.h
Normal 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
|
||||
Reference in New Issue
Block a user