- testing for current threading structures

This commit is contained in:
2025-12-20 17:35:54 -05:00
parent 9f499c933d
commit 1f6637408d
14 changed files with 360 additions and 44 deletions

View File

@@ -36,6 +36,9 @@
#include <fennec/memory/pointers.h>
#include <fennec/containers/object_pool.h>
#include <fennec/platform/interface/window.h>
#include <fennec/threading/lock_guard.h>
#include <fennec/threading/mutex.h>
#include <fennec/threading/thread.h>
namespace fennec
@@ -45,14 +48,33 @@ namespace fennec
/// \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
};
struct command {
uint8_t cmd;
window_id win;
void* data;
};
// Constructors & Destructor ===========================================================================================
public:
///
/// \brief constructor
/// \param platform the platform
@@ -71,16 +93,82 @@ public:
void shutdown(); //!< shutdown the window system
void dispatch(); //!< dispatch the commands to the system
window_id create_window(const config& config, window_id parent = nullid);
void begin(window_id window);
void end(window_id window);
// Thread-Safe Functions ===============================================================================================
window_id get_parent(window_id window) const {
lock_guard guard(_lock);
return _parent(window);
}
window_id get_root(window_id window) const {
lock_guard guard(_lock);
return _root(window);
}
ivec2 get_size(window_id window) const {
lock_guard guard(_lock);
return _size(window);
}
ivec2 get_position(window_id window) const {
lock_guard guard(_lock);
return _position(window);
}
bool is_visible(window_id window) const { lock_guard guard(_lock); return _check_state(window, window::state_visible); }
bool is_child(window_id window) const { lock_guard guard(_lock); return _check_state(window, window::state_child); }
bool is_running(window_id window) const { lock_guard guard(_lock); return _check_state(window, window::state_running); }
bool is_suspended(window_id window) const { lock_guard guard(_lock); return _check_state(window, window::state_suspended); }
bool get_flag(window_id window, uint8_t flag) {
lock_guard guard(_lock);
return _get_flag(window, flag);
}
bool is_always_on_top(window_id window) { return get_flag(window, window::flag_always_on_top); }
bool is_borderless(window_id window) { return get_flag(window, window::flag_borderless); }
bool is_modal(window_id window) { return get_flag(window, window::flag_modal); }
bool is_passing_mouse(window_id window) { return get_flag(window, window::flag_pass_mouse); }
bool is_popup(window_id window) { return get_flag(window, window::flag_popup); }
bool is_resizable(window_id window) { return get_flag(window, window::flag_resizable); }
bool is_transparent(window_id window) { return get_flag(window, window::flag_transparent); }
bool is_no_focus(window_id window) { return get_flag(window, window::flag_no_focus); }
bool set_flag(window_id window, uint8_t flag, bool val);
bool set_always_on_top(window_id window, bool val) { return set_flag(window, window::flag_always_on_top, val); }
bool set_borderless(window_id window, bool val) { return set_flag(window, window::flag_borderless, val); }
bool set_modal(window_id window, bool val) { return set_flag(window, window::flag_modal, val); }
bool set_passing_mouse(window_id window, bool val) { return set_flag(window, window::flag_pass_mouse, val); }
bool set_popup(window_id window, bool val) { return set_flag(window, window::flag_popup, val); }
bool set_resizable(window_id window, bool val) { return set_flag(window, window::flag_resizable, val); }
bool set_transparent(window_id window, bool val) { return set_flag(window, window::flag_transparent, val); }
bool set_no_focus(window_id window, bool val) { return set_flag(window, window::flag_no_focus, val); }
private:
mutable mutex _lock;
thread::id _thread;
platform* _platform;
server_t _display;
window_pool_t _windows;
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;
bool _check_state(window_id id, uint8_t state) const;
bool _get_flag(window_id id, uint8_t flag) const;
bool _set_flag(window_id id, uint8_t flag, bool val);
};
} // fennec