commit 3e167e3

uint  ·  2026-06-23 01:11:01 +0000 UTC
parent c9839fb
Implement win32 maus_cur_set_mode
1 files changed,  +39, -0
+39, -0
 1@@ -468,6 +468,45 @@ bool maus_resize(Maus* mw, uint32_t width, uint32_t height)
 2 
 3 void maus_cur_set_mode(Maus* mw, MausCursorState state)
 4 {
 5+	MausBackend* be = &mw->backend;
 6+	HWND hwnd = be->hwnd;
 7+
 8+	if (!hwnd) {
 9+		maus_log(stderr, "hwnd is NULL");
10+		return;
11+	}
12+
13+	/* show cursor */
14+	if (state == MAUS_CURSOR_STATE_VISIBLE) {
15+		while (ShowCursor(TRUE) < 0);
16+		return;
17+	}
18+
19+	/* hide cursor */
20+	if (state == MAUS_CURSOR_STATE_HIDDEN) {
21+		while (ShowCursor(FALSE) >= 0);
22+		return;
23+	}
24 
25+
26+	/* lock cursor */
27+	if (state == MAUS_CURSOR_STATE_LOCKED) {
28+		RECT r;
29+		GetClientRect(hwnd, &r);
30+		MapWindowPoints(hwnd, NULL, (POINT*)&r, 2);
31+
32+		if (!ClipCursor(&r)) {
33+			maus_log(stderr, "failed to grab mouse pointer");
34+			return;
35+		}
36+
37+		return;
38+	}
39+
40+	/* unlock cursor */
41+	if (state == MAUS_CURSOR_STATE_FREE) {
42+		ClipCursor(NULL);
43+		return;
44+	}
45 }
46