1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
#pragma once
#include "hash.h"
#include "vec.h"
#include "window.h"
#include "wlstate.h"
enum event_kind_e {
EVENT_KIND_RESIZE,
EVENT_KIND_CLOSE,
EVENT_KIND_FRAME,
};
struct event_kind_resize_s {
i32 width, height;
};
union event_data_u {
struct event_kind_resize_s resize;
};
struct event_s {
enum event_kind_e kind;
struct window_s *window;
union event_data_u data;
};
#define WAYC_EVENT_INIT(kind, window, ...) \
event_s { kind, window, __VA_ARGS__ }
#define WAYC_EVENT_CLOSE(window) \
WAYC_EVENT_INIT(EVENT_KIND_CLOSE, window, event_data_u{})
#define WAYC_EVENT_RESIZE(window, width, height) \
WAYC_EVENT_INIT(EVENT_KIND_RESIZE, window, \
event_data_u{event_kind_resize_s{width, height}})
#define WAYC_EVENT_FRAME(window) \
WAYC_EVENT_INIT(EVENT_KIND_FRAME, window, event_data_u{})
struct eventloop_s;
typedef void (*event_handler_t)(struct eventloop_s *loop,
struct event_s *event);
struct eventloop_s {
window_id_t winid;
struct wlstate_s state;
struct vec_s<struct event_s> events;
struct hashmap_s<window_id_t, struct window_s *> windows;
event_handler_t handler;
bool running;
};
bool wayc_eventloop_init(struct eventloop_s *loop, event_handler_t handler);
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_update(struct eventloop_s *loop);
|