commit bf34812

uint  ·  2026-06-03 18:51:55 +0000 UTC
parent 25b45bc
Update basic-window to also poll for events
2 files changed,  +30, -4
+1, -0
1@@ -1,5 +1,6 @@
2 CC = cc
3 CFLAGS = -std=c99 -Wall -Wextra -O2
4+CPPFLAGS = -DBACKEND_X11
5 LIBS = -lX11
6 
7 SRC = main.c \
+29, -4
 1@@ -1,14 +1,39 @@
 2-#define BACKEND_X11
 3+#include <stdlib.h>
 4+
 5 #include "../../maus.h"
 6 
 7+void handle_ev(MausEvent* ev, Maus* mw)
 8+{
 9+	switch (ev->type) {
10+		case MAUS_EV_CLOSE:
11+			maus_close(mw);
12+			exit(EXIT_SUCCESS);
13+		case MAUS_EV_KEY:
14+			if (ev->key.code == 24) { /* quit */
15+				maus_close(mw);
16+				exit(EXIT_SUCCESS);
17+			}
18+		case MAUS_EV_MOUSE_BUTTON:
19+			break;
20+		case MAUS_EV_MOUSE_MOTION:
21+			break;
22+		case MAUS_EV_RESIZE:
23+			break;
24+		case MAUS_EV_NONE:
25+			break;
26+	}
27+}
28+
29 int main(void)
30 {
31 	Maus* mw = maus_init("basic window", 0, 0, 800, 600);
32 	maus_create_window(mw);
33 
34-	XEvent e;
35-	for (;;)
36-		XNextEvent(mw->display, &e);
37+	MausEvent ev;
38+	for (;;) {
39+		while (maus_poll(mw, &ev))
40+			handle_ev(&ev, mw);
41+	}
42 
43 	maus_close(mw);
44 }