commit 852cf31

uint  ·  2026-06-03 17:16:59 +0000 UTC
parent 3ce2e81
Add create window, close window, close functions
2 files changed,  +54, -2
+43, -1
 1@@ -1,3 +1,4 @@
 2+#include <stdbool.h>
 3 #include <stdio.h>
 4 #include <stdlib.h>
 5 
 6@@ -5,6 +6,47 @@
 7 
 8 #include "mauswin.h"
 9 
10+bool maus_close(MausWindow* mw)
11+{
12+	if (mw->pixels)
13+		free(mw->pixels);
14+	if (mw->win != None) {
15+		(void) maus_close_window(mw);
16+	}
17+	if (mw->display)
18+		XCloseDisplay(mw->display);
19+
20+	return true;
21+}
22+
23+bool maus_close_window(MausWindow* mw)
24+{
25+	if (mw->win != None) {
26+		XUnmapWindow(mw->display, mw->win);
27+		XDestroyWindow(mw->display, mw->win);
28+	}
29+
30+	return true;
31+}
32+
33+bool maus_create_window(MausWindow* mw)
34+{
35+	mw->win = XCreateSimpleWindow(
36+		mw->display, mw->root,
37+		mw->x, mw->y,
38+		mw->width, mw->height,
39+		0u, 0u, 0u
40+	);
41+
42+	if (mw->win == None)
43+		return false;
44+
45+	XMapWindow(mw->display, mw->win);
46+	XFlush(mw->display);
47+
48+	return true;
49+}
50+
51 MausWindow* maus_init(const char* title, int x, int y, int width, int height)
52 {
53 	if (MAUS_WARN_BACKEND_AUTO_SEL)
54@@ -30,7 +72,7 @@ MausWindow* maus_init(const char* title, int x, int y, int width, int height)
55 	win->width = width;
56 	win->height = height;
57 	win->x = x;
58-	win->y = x;
59+	win->y = y;
60 	win->pixels = px;
61 
62 	return win;
+11, -1
 1@@ -1,6 +1,7 @@
 2 #ifndef MAUSWIN_H
 3 #define MAUSWIN_H
 4 
 5+#include <stdbool.h>
 6 #include <stdio.h>
 7 
 8 /* auto selection */
 9@@ -35,10 +36,19 @@
10 
11 #endif
12 
13+/* close a Maus. returns false on fail */
14+bool maus_close(MausWindow* mw);
15+
16+/* close a window without the whole Maus. returns false on fail */
17+bool maus_close_window(MausWindow* mw);
18+
19+/* create window from MausWindow. returns false on fail */
20+bool maus_create_window(MausWindow* mw);
21+
22 /* log message to output `fd` and die */
23 void maus_die(const char* fmt, ...);
24 
25-/* initialise and create the window. returns NULL on fail */
26+/* initialise and fills the MausWindow. returns NULL on fail */
27 MausWindow* maus_init(const char* title, int x, int y, int width, int height);
28 
29 /* log message to output `fd` */