From eecbacdc1ab1b29fee71f3a689e01cabe12b3730 Mon Sep 17 00:00:00 2001 From: Mikhail Burakov Date: Sun, 2 Apr 2023 12:09:20 +0200 Subject: Major rewrite of window to support input events --- main.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'main.c') diff --git a/main.c b/main.c index 2a5e7ff..c650ea2 100644 --- a/main.c +++ b/main.c @@ -31,11 +31,31 @@ static volatile sig_atomic_t g_signal; static void OnSignal(int status) { g_signal = status; } +static void OnWindowClose(void* user) { + (void)user; + g_signal = SIGINT; +} + +static void OnWindowKey(void* user, unsigned key, bool pressed) { + // TODO +} + +static void WindowDtor(struct Window** window) { + if (!*window) return; + WindowDestroy(*window); + *window = NULL; +} + int main(int argc, char* argv[]) { (void)argc; (void)argv; - struct AUTO(Window)* window = WindowCreate(); + static const struct WindowEventHandlers window_event_handlers = { + .OnClose = OnWindowClose, + .OnKey = OnWindowKey, + }; + struct Window __attribute__((cleanup(WindowDtor)))* window = + WindowCreate(&window_event_handlers, NULL); if (!window) { LOG("Failed to create window"); return EXIT_FAILURE; -- cgit v1.2.3