diff options
author | 2025-05-17 00:38:04 +0200 | |
---|---|---|
committer | 2025-05-17 00:38:04 +0200 | |
commit | c1479866e3254dae4891f85e5d9f35fda76fd387 (patch) | |
tree | 40f1c4209ba33a7ad789cd2da3d9e1f96a15a9db | |
parent | 0e90703b5a44445955560f6f2cddf2ff8dbd1a58 (diff) | |
download | tris-c1479866e3254dae4891f85e5d9f35fda76fd387.tar.gz tris-c1479866e3254dae4891f85e5d9f35fda76fd387.zip |
Add ui_on_keypress function
-rw-r--r-- | src/main/ui/x11/ui.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/main/ui/x11/ui.c b/src/main/ui/x11/ui.c index 369eb7d..49ac978 100644 --- a/src/main/ui/x11/ui.c +++ b/src/main/ui/x11/ui.c @@ -22,11 +22,14 @@ #include <GL/gl.h> #include <GL/glx.h> #include <X11/Xlib.h> +#include <unistd.h> +#include <time.h> #include "../../util.h" static Display *display; static Window window; static GLXContext gl_context; +static int close_window = 0; void cleanup(void); @@ -117,17 +120,23 @@ ui_on_resize(XEvent event) glViewport(0, 0, event.xconfigure.width, event.xconfigure.height); } +static void +ui_on_keypress(XEvent event) +{ + if (event.type != KeyPress) return; + close_window = 1; +} + void ui_loop(void (*draw_frame)()) { XEvent event; - while (1) { + while (!close_window) { XNextEvent(display, &event); ui_on_expose(event, draw_frame); ui_on_resize(event); - if (event.type == KeyPress) { - break; - } + ui_on_keypress(event); + } cleanup(); |