diff options
| author | Fabrice <fabrice@schaub-dev.xyz> | 2026-02-10 10:32:20 +0100 |
|---|---|---|
| committer | Fabrice <fabrice@schaub-dev.xyz> | 2026-02-10 10:32:20 +0100 |
| commit | 22a45a63c1738e68c50eebe704fa7158f7a049cd (patch) | |
| tree | 3c505474d72c552fa58364d6e803420ba25a9098 | |
| parent | 17cd02e7a535930db9bbc6ed8084830f50f7be84 (diff) | |
eventloop update and looping
| -rw-r--r-- | src/events.cc | 18 | ||||
| -rw-r--r-- | src/events.h | 5 | ||||
| -rw-r--r-- | src/hash.h (renamed from src/hashm.h) | 6 | ||||
| -rw-r--r-- | src/wayclock.cc | 3 |
4 files changed, 29 insertions, 3 deletions
diff --git a/src/events.cc b/src/events.cc index edc47db..aed9de3 100644 --- a/src/events.cc +++ b/src/events.cc @@ -1,5 +1,5 @@ #include "events.h" -#include "hashm.h" +#include "hash.h" #include "vec.h" #include <cstring> @@ -16,6 +16,7 @@ bool wayc_eventloop_init(struct eventloop_s *loop) { return false; loop->events = WAYC_VEC_INIT(struct event_s); + loop->running = true; wayc_hashmap_init(&loop->windows); return true; @@ -41,4 +42,17 @@ window_id_t wayc_eventloop_register(struct eventloop_s *loop, void wayc_eventloop_unregister(struct eventloop_s *loop, window_id_t winid) { wayc_notnull(loop); wayc_hashmap_remove(&loop->windows, &winid); -}
\ No newline at end of file +} + +bool wayc_eventloop_running(struct eventloop_s *loop) { + wayc_notnull(loop); + return loop->running; +} + +void wayc_eventloop_upate(struct eventloop_s *loop) { + wayc_notnull(loop); + if (wayc_hashmap_count(&loop->windows) == 0) + loop->running = false; + + wayc_wlstate_update(&loop->state); +} diff --git a/src/events.h b/src/events.h index 0af78b3..a58b7a1 100644 --- a/src/events.h +++ b/src/events.h @@ -1,6 +1,6 @@ #pragma once -#include "hashm.h" +#include "hash.h" #include "vec.h" #include "window.h" #include "wlstate.h" @@ -19,6 +19,7 @@ struct eventloop_s { struct vec_s<struct event_s> events; window_id_t winid; struct hashmap_s<window_id_t, struct window_s *> windows; + bool running; }; bool wayc_eventloop_init(struct eventloop_s *loop); @@ -26,3 +27,5 @@ void wayc_eventloop_deinit(struct eventloop_s *loop); window_id_t wayc_eventloop_register(struct eventloop_s *loop, struct window_s *window); void wayc_eventloop_unregister(struct eventloop_s *loop, window_id_t winid); +bool wayc_eventloop_running(struct eventloop_s *loop); +void wayc_eventloop_upate(struct eventloop_s *loop); @@ -98,4 +98,10 @@ inline void wayc_hashmap_remove(hashmap_s<K, V> *map, const K *key) { hashentry_s<K, V> entry{}; entry.key = *key; hashmap_delete(map->inner, &entry); +} + +template <typename K, typename V> +inline usize wayc_hashmap_count(hashmap_s<K, V> *map) { + wayc_notnull(map); + return hashmap_count(map->inner); }
\ No newline at end of file diff --git a/src/wayclock.cc b/src/wayclock.cc index 6114cbe..63ca323 100644 --- a/src/wayclock.cc +++ b/src/wayclock.cc @@ -5,6 +5,9 @@ int main() { if (!wayc_eventloop_init(&loop)) wayc_panic("Failed to initialize event loop"); + while (wayc_eventloop_running(&loop)) + wayc_eventloop_upate(&loop); + wayc_eventloop_deinit(&loop); return 0; }
\ No newline at end of file |
