From d0e898ea995c681c92c2f6ccb7be782e05b17fe7 Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Mon, 23 Oct 2023 20:49:45 +0200 Subject: ante: Make use of the LibGUI event loop. --- userland/ante/ante.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/userland/ante/ante.c b/userland/ante/ante.c index 760db28..003b03c 100644 --- a/userland/ante/ante.c +++ b/userland/ante/ante.c @@ -260,25 +260,18 @@ int open_file(const char *file) { return 1; } -void run() { - struct pollfd fds[1]; - fds[0].fd = global_w->ws_socket; - fds[0].events = POLLIN; - fds[0].revents = 0; - for (;; fds[0].revents = 0) { - poll(fds, 1, 0); - if (fds[0].revents & POLLIN) { - WS_EVENT e; - int rc; - if (0 >= (rc = read(global_w->ws_socket, &e, sizeof(e)))) - continue; - if (e.ev.release) - continue; - if (0 == e.ev.c) - continue; - key_event(e.ev.c); - } - } +void event_handler(WS_EVENT e) { + if (WINDOWSERVER_EVENT_WINDOW_EXIT == e.type) + exit(0); + + if (WINDOWSERVER_EVENT_KEYPRESS != e.type) + return; + + if (e.ev.release) + return; + if (0 == e.ev.c) + return; + key_event(e.ev.c); } int main(int argc, char **argv) { @@ -293,6 +286,6 @@ int main(int argc, char **argv) { assert(open_file(argv[1])); draw_file(); - run(); + GUI_EventLoop(global_w, event_handler); return 0; } -- cgit v1.2.3