commit fbfe662

uint  ·  2026-08-04 00:37:21 +0000 UTC
parent 9f8acc0
Wayland: handle resizes
1 files changed,  +45, -6
+45, -6
 1@@ -87,8 +87,10 @@ static void xdg_surface_configure(void* data, struct xdg_surface* xdg_surface, u
 2 	Maus* mw = data;
 3 	xdg_surface_ack_configure(xdg_surface, serial);
 4 	mw->backend.configured = 1;
 5-	mw->backend.pending.pending = 1;
 6-	mw->backend.pending.type = MAUS_EV_REDRAW;
 7+	if (!mw->backend.pending.pending) {
 8+		mw->backend.pending.pending = 1;
 9+		mw->backend.pending.type = MAUS_EV_REDRAW;
10+	}
11 }
12 
13 static void xdg_toplevel_configure(void* data, struct xdg_toplevel* xdg_toplevel,
14@@ -365,6 +367,7 @@ static void keyboard_repeat_info(void* data, struct wl_keyboard* keyboard,
15 
16 static int8_t fb_create(Maus* mw);
17 static int8_t fb_create_shm(size_t size);
18+static void fb_destroy(Maus* mw);
19 static int8_t handle_event(Maus* mw, MausEvent* ev);
20 
21 static int8_t fb_create(Maus* mw)
22@@ -431,6 +434,22 @@ static int8_t fb_create_shm(size_t size)
23 	return -1;
24 }
25 
26+static void fb_destroy(Maus* mw)
27+{
28+	MausBackend* be = &mw->backend;
29+
30+	if (be->buffer)
31+		wl_buffer_destroy(be->buffer);
32+
33+	if (be->shm_data && be->shm_size > 0)
34+		munmap(be->shm_data, be->shm_size);
35+
36+	be->buffer = NULL;
37+	be->shm_data = NULL;
38+	be->shm_size = 0;
39+	mw->fb = NULL;
40+}
41+
42 static int8_t handle_event(Maus* mw, MausEvent* ev)
43 {
44 	MausBackend* be = &mw->backend;
45@@ -620,10 +639,7 @@ int8_t maus_close_window(Maus* mw)
46 {
47 	MausBackend* be = &mw->backend;
48 
49-	if (be->buffer)
50-		wl_buffer_destroy(be->buffer);
51-	if (be->shm_data && be->shm_size > 0)
52-		munmap(be->shm_data, be->shm_size);
53+	fb_destroy(mw);
54 
55 	if (be->xdg_toplevel)
56 		xdg_toplevel_destroy(be->xdg_toplevel);
57@@ -804,7 +820,30 @@ void maus_present(Maus* mw)
58 
59 int8_t maus_resize(Maus* mw, uint32_t width, uint32_t height)
60 {
61+	uint32_t* bfb;
62+
63+	if (width == 0 || height == 0)
64+		return 0;
65+
66+	bfb = calloc(width * height, sizeof(uint32_t));
67+	if (!bfb)
68+		return 0;
69+
70+	fb_destroy(mw);
71+	free(mw->bfb);
72 
73+	mw->width = width;
74+	mw->height = height;
75+	mw->stride = width;
76+	mw->bfb = bfb;
77+
78+	if (!fb_create(mw)) {
79+		free(mw->bfb);
80+		mw->bfb = NULL;
81+		return 0;
82+	}
83+
84+	return 1;
85 }
86 
87 void maus_cur_set_mode(Maus* mw, MausCursorState state)