commit 5872872
uint
·
2026-06-06 16:28:57 +0000 UTC
parent f62fbc5
Handle framebuffer resizes
3 files changed,
+24,
-8
M
maus.h
+4,
-0
1@@ -124,5 +124,9 @@ void maus_event_wait(Maus* mw, MausEvent* ev);
2 /* present the pixelbuffer to the screen */
3 void maus_present(Maus* mw);
4
5+/* resize window to specified width and height. returns true
6+ on resize success, else false */
7+bool maus_resize(Maus* mw, uint32_t width, uint32_t height);
8+
9 #endif /* MAUSWIN_H */
10
+15,
-4
1@@ -278,10 +278,6 @@ static bool handle_event(XEvent* xev, MausEvent* ev, Maus* mw)
2 ev->type = MAUS_EV_RESIZE;
3 ev->resize.width = xev->xconfigure.width;
4 ev->resize.height = xev->xconfigure.height;
5-
6- /* TODO put into maus_resize */
7- /* mw->width = xev->xconfigure.width; */
8- /* mw->height = xev->xconfigure.height; */
9 return true;
10 }
11
12@@ -469,3 +465,18 @@ void maus_present(Maus* mw)
13 XFlush(mw->display);
14 }
15
16+bool maus_resize(Maus* mw, uint32_t width, uint32_t height)
17+{
18+ if (width == 0 || height == 0 ||
19+ mw->width == width || mw->height == height)
20+ return false;
21+ fb_destroy(mw);
22+
23+ mw->width = width;
24+ mw->height = height;
25+
26+ XSync(mw->display, False);
27+ XFlush(mw->display);
28+ return fb_create(mw);
29+}
30+
+5,
-4
1@@ -2,7 +2,7 @@
2
3 #include "../../maus.h"
4
5-void handle_ev(MausEvent* ev, Maus* mw)
6+void handle_ev(Maus* mw, MausEvent* ev)
7 {
8 switch (ev->type) {
9 case MAUS_EV_CLOSE:
10@@ -17,8 +17,9 @@ void handle_ev(MausEvent* ev, Maus* mw)
11 break;
12 case MAUS_EV_MOUSE_MOTION:
13 break;
14- case MAUS_EV_RESIZE:
15- break;
16+ case MAUS_EV_RESIZE: {
17+ maus_resize(mw, ev->resize.width, ev->resize.height);
18+ }
19 case MAUS_EV_NONE:
20 break;
21 }
22@@ -42,7 +43,7 @@ int main(void)
23 /* constant polling -- used in games */
24 for (;;) {
25 while (maus_event_poll(mw, &ev))
26- (void) handle_ev(&ev, mw);
27+ (void) handle_ev(mw, &ev);
28 maus_fb_clear(mw, MAUS_COL_RGBA(255, 255, 255, 255));
29 maus_present(mw);
30 }