- fleshing out event system and window manager

- added tests back in for window management
This commit is contained in:
2025-12-27 07:19:53 -05:00
parent 184bc7fcdf
commit ecf1cfc29c
12 changed files with 116 additions and 52 deletions

View File

@@ -137,6 +137,11 @@ public:
return *_table[i];
}
constexpr bool operator()(size_t i) const {
assert(i < capacity(), "Index out of Bounds!");
return _table[i];
}
/// @}
@@ -205,7 +210,7 @@ public:
/// \brief C++ Iterator Specification `begin()`
/// \returns an iterator at the start of the object pool
const_iterator begin() const {
return iterator(this, 0);
return const_iterator(this, 0);
}
///
@@ -218,7 +223,7 @@ public:
/// \brief C++ Iterator Specification `end()`
/// \returns an iterator at the start of the end of the object pool
const_iterator end() const {
return iterator(this, _size);
return const_iterator(this, _size);
}
///

View File

@@ -33,7 +33,7 @@ struct event;
/// \brief Class outlining the interface for an object that listens for events
class event_listener {
public:
virtual ~event_listener() = default;
virtual ~event_listener();
///
/// \brief event handler callback

View File

@@ -212,6 +212,9 @@ public:
return _handle != nullptr;
}
///
/// \brief dereference operator
/// \returns a reference to the held value
element_t& operator*() const {
return *_handle;
}

View File

@@ -87,18 +87,20 @@ public:
///
/// \brief shared object release
/// \param obj the shared object to release
virtual void unload_object(shared_object* obj) = 0;
virtual void unload_object(shared_object* obj) = 0;
///
/// \brief shared object symbol locator
/// \param obj the shared object to search
/// \param name the name of the symbol to search for
/// \returns a reference to the symbol
virtual symbol find_symbol(shared_object* obj, const cstring& name) = 0;
virtual symbol find_symbol(shared_object* obj, const cstring& name) = 0;
virtual void initialize(); //!< Initialize Drivers and Contexts
virtual void shutdown(); //!< Close Drivers and Contexts
virtual window_manager& get_window_manager() const { return *wmanager; }
protected:
unique_ptr<window_manager> wmanager; //!< the window manager

View File

@@ -336,9 +336,9 @@ public:
protected:
display_server* const server; //!< the display server the window belongs to
window* const parent; //!< the parent window
window* root; //!< the nearest top-level window in the hierarchy
config cfg; //!< the current configuration
state state; //!< the current state
window* root; //!< the nearest top-level window in the hierarchy
unique_ptr<gfxsurface> gfx_surface; //!< the corresponding graphics surface
};

View File

@@ -38,28 +38,23 @@
#include <fennec/containers/object_pool.h>
#include <fennec/platform/interface/window.h>
#include <fennec/threading/lock_guard.h>
#include <fennec/threading/mpscq.h>
#include <fennec/threading/mutex.h>
#include <fennec/threading/thread.h>
namespace fennec
{
using window_id = size_t; //!< type representing an id for a window
///
/// \brief class for handling display servers and windows
class window_manager {
// Definitions =========================================================================================================
public:
using window_id = size_t; //!< type representing an id for a window
static constexpr window_id nullid = -1; //!< constant representing a null window
private:
using server_t = unique_ptr<display_server>;
using window_t = unique_ptr<window>;
using window_pool_t = object_pool<window_t>;
using config = window::config;
enum command_ : uint8_t {
command_set_flag = 0,
command_resize
@@ -71,6 +66,14 @@ private:
void* data;
};
static constexpr size_t max_commands = 512;
using server_t = unique_ptr<display_server>;
using window_t = unique_ptr<window>;
using window_pool_t = object_pool<window_t>;
using command_queue_t = mpscq<command>;
using config = window::config;
// Constructors & Destructor ===========================================================================================
public:
@@ -96,6 +99,7 @@ public:
window_id create_window(const config& config, window_id parent = nullid);
void begin(window_id window);
void end(window_id window);
void close(window_id window);
// Thread-Safe Functions ===============================================================================================
@@ -111,11 +115,11 @@ public:
ivec2 get_size(window_id window) const {
lock_guard guard(_lock);
return _size(window);
return _get_size(window);
}
ivec2 get_position(window_id window) const {
lock_guard guard(_lock);
return _position(window);
return _get_position(window);
}
bool is_visible(window_id window) const { lock_guard guard(_lock); return _check_state(window, window::state_visible); }
@@ -151,18 +155,20 @@ public:
private:
mutable mutex _lock;
thread::id _thread;
platform* _platform;
server_t _display;
window_pool_t _windows;
mutable mutex _lock;
thread::id _thread;
platform* _platform;
server_t _display;
window_pool_t _windows;
command_queue_t _commands;
window_id _parent(window_id id) const;
window_id _root(window_id id) const;
ivec2 _size(window_id id) const;
ivec2 _position(window_id id) const;
ivec2 _get_size(window_id id) const;
ivec2 _get_position(window_id id) const;
bool _check_state(window_id id, uint8_t state) const;