diff options
| -rw-r--r-- | src/events.cc | 20 | ||||
| -rw-r--r-- | src/events.h | 3 | ||||
| -rw-r--r-- | src/hashm.h | 18 |
3 files changed, 38 insertions, 3 deletions
diff --git a/src/events.cc b/src/events.cc index 6a3190c..edc47db 100644 --- a/src/events.cc +++ b/src/events.cc @@ -3,6 +3,11 @@ #include "vec.h" #include <cstring> +static inline window_id_t wayc_eventloop_genid(struct eventloop_s *loop) { + wayc_notnull(loop); + return loop->winid++; +} + bool wayc_eventloop_init(struct eventloop_s *loop) { wayc_notnull(loop); memset(loop, 0, sizeof(*loop)); @@ -22,3 +27,18 @@ void wayc_eventloop_deinit(struct eventloop_s *loop) { wayc_wlstate_deinit(&loop->state); wayc_vec_deinit(&loop->events); } + +window_id_t wayc_eventloop_register(struct eventloop_s *loop, + struct window_s *window) { + wayc_notnull(loop); + wayc_notnull(window); + + window_id_t winid = wayc_eventloop_genid(loop); + wayc_hashmap_insert(&loop->windows, &winid, &window); + return winid; +} + +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 diff --git a/src/events.h b/src/events.h index bdbe6d2..0af78b3 100644 --- a/src/events.h +++ b/src/events.h @@ -23,3 +23,6 @@ struct eventloop_s { bool wayc_eventloop_init(struct eventloop_s *loop); 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); diff --git a/src/hashm.h b/src/hashm.h index e1ed720..5e5e802 100644 --- a/src/hashm.h +++ b/src/hashm.h @@ -62,15 +62,17 @@ inline void wayc_hashmap_deinit(hashmap_s<K, V> *map) { } template <typename K, typename V> -inline V *wayc_hashmap_insert(hashmap_s<K, V> *map, const K *key) { +inline V *wayc_hashmap_insert(hashmap_s<K, V> *map, const K *key, + const V *value) { wayc_notnull(map); wayc_notnull(key); + wayc_notnull(value); hashentry_s<K, V> entry{}; entry.key = *key; - auto *stored = (hashentry_s<K, V> *)hashmap_set(map->inner, &entry); + entry.value = *value; + auto *stored = (hashentry_s<K, V> *)hashmap_insert(map->inner, &entry); - wayc_notnull(stored); return &stored->value; } @@ -87,3 +89,13 @@ inline V *wayc_hashmap_get(hashmap_s<K, V> *map, const K *key) { return &stored->value; } + +template <typename K, typename V> +inline void wayc_hashmap_remove(hashmap_s<K, V> *map, const K *key) { + wayc_notnull(map); + wayc_notnull(key); + + hashentry_s<K, V> entry{}; + entry.key = *key; + hashmap_remove(map->inner, &entry); +}
\ No newline at end of file |
