commit 2f8879e
uint
·
2026-08-03 17:33:25 +0000 UTC
parent 99d028e
Wayland: init window
4 files changed,
+91,
-16
M
TODO
+1,
-0
1@@ -1,4 +1,5 @@
2 Maus:
3+[ ] Rename mw->ctx internally
4 [?] Cursor warping
5 [?] Custom cursor
6
+2,
-1
1@@ -131,7 +131,8 @@ void maus_clipboard_set_text(Maus* mw, const char* text);
2 /* get text from system clipboard */
3 char* maus_clipboard_get_text(Maus* mw);
4
5-/* close a Maus. returns 0 on fail */
6+/* close a Maus. returns 0 on fail
7+ TODO also free mw */
8 void maus_close(Maus* mw);
9
10 /* close a window without the whole Maus. returns 0 on fail */
+17,
-0
1@@ -1,4 +1,21 @@
2 #ifndef MAUS_WAYLAND_H
3 #define MAUS_WAYLAND_H
4
5+/* must forward declare so that other
6+ ANSI abiding files arent affected */
7+struct wl_display;
8+struct wl_registry;
9+struct wl_compositor;
10+struct wl_shm;
11+struct xdg_wm_base;
12+
13+typedef struct {
14+ struct wl_display* display;
15+ struct wl_compositor* compositor;
16+ struct wl_shm* shm;
17+ struct xdg_wm_base* wm_base;
18+
19+ struct wl_registry* registry;
20+} MausBackend;
21+
22 #endif /* MAUS_WAYLAND_H */
+71,
-15
1@@ -1,6 +1,45 @@
2+#include <stdlib.h>
3+#include <string.h>
4+
5+#include <wayland-client.h>
6+#include <xdg-shell-client-protocol.h>
7+
8 #include "maus.h"
9 #include "maus_wayland.h"
10
11+static void registry_global(void* data, struct wl_registry* registry,
12+ uint32_t name, const char* interface,
13+ uint32_t version);
14+static void registry_global_remove(void *data, struct wl_registry *wl_registry,
15+ uint32_t name);
16+
17+static struct wl_registry_listener registry_listener = {
18+ registry_global, registry_global_remove
19+};
20+
21+static void registry_global(void* data, struct wl_registry* registry,
22+ uint32_t name, const char* interface,
23+ uint32_t version)
24+{
25+ Maus* mw = data;
26+ MausBackend* be = &mw->backend;
27+
28+ (void) version;
29+
30+ if (strcmp(interface, wl_compositor_interface.name) == 0)
31+ be->compositor = wl_registry_bind(registry, name, &wl_compositor_interface, 4);
32+ else if (strcmp(interface, wl_shm_interface.name) == 0)
33+ be->shm = wl_registry_bind(registry, name, &wl_shm_interface, 1);
34+ else if (strcmp(interface, xdg_wm_base_interface.name) == 0)
35+ be->wm_base = wl_registry_bind(registry, name, &xdg_wm_base_interface, 1);
36+}
37+
38+static void registry_global_remove(void *data, struct wl_registry *wl_registry,
39+ uint32_t name)
40+{
41+
42+}
43+
44 void maus_clear(Maus* mw, MausColor col)
45 {
46
47@@ -31,24 +70,46 @@ int8_t maus_create_window(Maus* mw)
48
49 }
50
51-void maus_die(const char* fmt, ...)
52+Maus* maus_init(const char* title, int x, int y, int width, int height)
53 {
54+ Maus* mw = calloc(1, sizeof(Maus));
55+ MausBackend* be = &mw->backend;
56
57-}
58+ if (!mw)
59+ return NULL;
60
61-uint64_t maus_get_time_ns(void)
62-{
63+ be->display = wl_display_connect(NULL);
64+ if (!be->display) {
65+ free(mw);
66+ return NULL;
67+ }
68
69-}
70+ be->registry = wl_display_get_registry(be->display);
71+ wl_registry_add_listener(be->registry, ®istry_listener, mw);
72+ wl_display_roundtrip(be->display);
73
74-Maus* maus_init(const char* title, int x, int y, int width, int height)
75-{
76+ if (!be->compositor || !be->shm || !be->wm_base) {
77+ maus_close(mw);
78+ free(mw);
79+ return NULL;
80+ }
81
82-}
83+ mw->frame_time_last = maus_get_time_ns();
84+ mw->title = title;
85+ mw->x = x;
86+ mw->y = y;
87+ mw->width = width;
88+ mw->height = height;
89+ mw->stride = width;
90
91-void maus_log(FILE* fd, const char* fmt, ...)
92-{
93+ mw->bfb = calloc(mw->stride * mw->height, sizeof(uint32_t));
94+ if (!mw->bfb) {
95+ maus_close(mw);
96+ free(mw);
97+ return NULL;
98+ }
99
100+ return mw;
101 }
102
103 int8_t maus_event_poll(Maus* mw, MausEvent* ev)
104@@ -71,11 +132,6 @@ int8_t maus_resize(Maus* mw, uint32_t width, uint32_t height)
105
106 }
107
108-void maus_target_fps(Maus* mw, uint32_t fps)
109-{
110-
111-}
112-
113 void maus_cur_set_mode(Maus* mw, MausCursorState state)
114 {
115