- fleshing out event system and window manager
- added tests back in for window management
This commit is contained in:
@@ -30,7 +30,11 @@ namespace fennec
|
||||
|
||||
static mutex lock;
|
||||
static dynarray<set<event_listener*>> listeners;
|
||||
static mpscq<event> queue(FENNEC_EVENT_QUEUE_SIZE);
|
||||
static mpscq<event> queue(FENNEC_EVENT_QUEUE_SIZE);
|
||||
|
||||
event_listener::~event_listener() {
|
||||
event::remove_listener(this);
|
||||
}
|
||||
|
||||
void event::handle_events() {
|
||||
lock_guard guard(lock);
|
||||
|
||||
@@ -24,9 +24,14 @@ namespace fennec
|
||||
{
|
||||
|
||||
window::window(display_server* server, const config& conf, window* parent)
|
||||
: server(server), parent(parent)
|
||||
, cfg(conf), state(), root(nullptr) {
|
||||
: server(server), parent(parent), root(parent ? parent : this)
|
||||
, cfg(conf), state() {
|
||||
state.mode = conf.mode;
|
||||
while (root != nullptr and root->is_popup()) {
|
||||
root = root->get_parent();
|
||||
}
|
||||
|
||||
assertf(root != nullptr, "Failed to find appropriate top-level window.");
|
||||
}
|
||||
|
||||
window::~window() {
|
||||
|
||||
@@ -77,14 +77,6 @@ void wayland_window::initialize() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
root = parent;
|
||||
while (root != nullptr and root->is_popup()) {
|
||||
root = static_cast<wayland_window*>(root->get_parent());
|
||||
}
|
||||
|
||||
assertf(root != nullptr, "Failed to find appropriate top-level window.");
|
||||
|
||||
wayland_server* wl_server = static_cast<wayland_server*>(server);
|
||||
|
||||
surface = wl_compositor_create_surface(wl_server->compositor);
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
namespace fennec {
|
||||
|
||||
window_manager::window_manager(platform* platform)
|
||||
: _platform(platform) {
|
||||
}
|
||||
: _platform(platform)
|
||||
, _commands(max_commands) {}
|
||||
|
||||
window_manager::~window_manager() {
|
||||
shutdown();
|
||||
@@ -95,7 +95,7 @@ void window_manager::dispatch() {
|
||||
_display->dispatch();
|
||||
}
|
||||
|
||||
window_manager::window_id window_manager::create_window(const window::config& config, window_id parent) {
|
||||
window_id window_manager::create_window(const window::config& config, window_id parent) {
|
||||
if (not _display) {
|
||||
return nullid;
|
||||
}
|
||||
@@ -104,7 +104,9 @@ window_manager::window_id window_manager::create_window(const window::config& co
|
||||
lock_guard guard(_lock);
|
||||
|
||||
window* p = parent == nullid ? nullptr : _windows[parent].get();
|
||||
return _windows.emplace(_display->create_window(config, p));
|
||||
window_id id = _windows.emplace(_display->create_window(config, p));
|
||||
_windows[id]->initialize();
|
||||
return id;
|
||||
}
|
||||
|
||||
void window_manager::begin(window_id window) {
|
||||
@@ -128,4 +130,52 @@ void window_manager::end(window_id window) {
|
||||
|
||||
_windows[window]->end_frame();
|
||||
}
|
||||
|
||||
void window_manager::close(window_id window) {
|
||||
if (not _display) {
|
||||
return;
|
||||
}
|
||||
|
||||
assertf(_thread == thread::current(), "Attempted to set window context on a different thread!");
|
||||
lock_guard guard(_lock);
|
||||
|
||||
_windows[window]->shutdown();
|
||||
_windows[window] = nullptr;
|
||||
_windows.erase(window);
|
||||
}
|
||||
|
||||
window_id window_manager::_parent(window_id) const {
|
||||
return nullid;
|
||||
}
|
||||
|
||||
window_id window_manager::_root(window_id) const {
|
||||
return nullid;
|
||||
}
|
||||
|
||||
ivec2 window_manager::_get_size(window_id id) const {
|
||||
return _windows[id]->get_size();
|
||||
}
|
||||
|
||||
ivec2 window_manager::_get_position(window_id id) const {
|
||||
return _windows[id]->get_position();
|
||||
}
|
||||
|
||||
bool window_manager::_check_state(window_id id, uint8_t state) const {
|
||||
switch (state) {
|
||||
case window::state_running: return _windows[id]->is_running();
|
||||
case window::state_child: return _windows[id]->is_child();
|
||||
case window::state_suspended: return _windows[id]->is_suspended();
|
||||
case window::state_visible: return _windows[id]->is_visible();
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool window_manager::_get_flag(window_id id, uint8_t flag) const {
|
||||
return _windows[id]->get_flag(flag);
|
||||
}
|
||||
|
||||
bool window_manager::_set_flag(window_id, uint8_t, bool) {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // fennec
|
||||
Reference in New Issue
Block a user