summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabrice <fabrice@schaub-dev.xyz>2026-02-10 10:51:12 +0100
committerFabrice <fabrice@schaub-dev.xyz>2026-02-10 10:51:12 +0100
commit15159fb02332b33f2d239190e2233d41b63f8d6c (patch)
treecc8e623cb7bbaa01566e529c1ce80c9f77b1a531
parentb4f74dc349f024ed44d4228501d500ebb113d146 (diff)
creating windows
-rw-r--r--src/events.cc2
-rw-r--r--src/events.h2
-rw-r--r--src/wayclock.cc19
-rw-r--r--src/window.cc84
-rw-r--r--src/window.h3
5 files changed, 105 insertions, 5 deletions
diff --git a/src/events.cc b/src/events.cc
index aed9de3..1795c85 100644
--- a/src/events.cc
+++ b/src/events.cc
@@ -49,7 +49,7 @@ bool wayc_eventloop_running(struct eventloop_s *loop) {
return loop->running;
}
-void wayc_eventloop_upate(struct eventloop_s *loop) {
+void wayc_eventloop_update(struct eventloop_s *loop) {
wayc_notnull(loop);
if (wayc_hashmap_count(&loop->windows) == 0)
loop->running = false;
diff --git a/src/events.h b/src/events.h
index a58b7a1..3bef775 100644
--- a/src/events.h
+++ b/src/events.h
@@ -28,4 +28,4 @@ window_id_t wayc_eventloop_register(struct eventloop_s *loop,
struct window_s *window);
void wayc_eventloop_unregister(struct eventloop_s *loop, window_id_t winid);
bool wayc_eventloop_running(struct eventloop_s *loop);
-void wayc_eventloop_upate(struct eventloop_s *loop);
+void wayc_eventloop_update(struct eventloop_s *loop);
diff --git a/src/wayclock.cc b/src/wayclock.cc
index 63ca323..f4d170b 100644
--- a/src/wayclock.cc
+++ b/src/wayclock.cc
@@ -1,13 +1,26 @@
#include "events.h"
+#include "window.h"
int main() {
- eventloop_s loop;
+ struct eventloop_s loop;
if (!wayc_eventloop_init(&loop))
wayc_panic("Failed to initialize event loop");
- while (wayc_eventloop_running(&loop))
- wayc_eventloop_upate(&loop);
+ struct window_s window;
+ if (!wayc_window_init(&window, &loop)) {
+ wayc_eventloop_deinit(&loop);
+ wayc_panic("Failed to initialize window");
+ }
+ window_id_t winid = wayc_eventloop_register(&loop, &window);
+ window.id = winid;
+
+ while (wayc_eventloop_running(&loop)) {
+ wayc_eventloop_update(&loop);
+ wayc_eventloop_unregister(&loop, winid);
+ }
+
+ wayc_window_deinit(&window);
wayc_eventloop_deinit(&loop);
return 0;
} \ No newline at end of file
diff --git a/src/window.cc b/src/window.cc
index 32055b1..e7f6397 100644
--- a/src/window.cc
+++ b/src/window.cc
@@ -1,2 +1,86 @@
#include "window.h"
+#include "events.h"
+#include "utils.h"
+#include "wlstate.h"
+#include "xdg-shell.h"
+#include <cstring>
+static void wayc_surface_configure(void *data, struct xdg_surface *xdg_surface,
+ u32 serial) {
+ (void)data;
+ xdg_surface_ack_configure(xdg_surface, serial);
+}
+
+static void wayc_toplevel_configure(void *data,
+ struct xdg_toplevel *xdg_toplevel,
+ i32 width, i32 height,
+ struct wl_array *states) {
+ (void)data;
+ (void)xdg_toplevel;
+ (void)width;
+ (void)height;
+ (void)states;
+}
+
+static void wayc_toplevel_close(void *data, struct xdg_toplevel *xdg_toplevel) {
+ (void)data;
+ (void)xdg_toplevel;
+}
+
+static struct xdg_surface_listener WAYC_SURFACE_LISTENER = {
+ wayc_surface_configure,
+};
+
+static struct xdg_toplevel_listener WAYC_TOPLEVEL_LISTENER = {
+ wayc_toplevel_configure, wayc_toplevel_close, nullptr, nullptr};
+
+bool wayc_window_init(struct window_s *window, struct eventloop_s *loop) {
+ wayc_notnull(window);
+ wayc_notnull(loop);
+ memset(window, 0, sizeof(*window));
+
+ struct wlstate_s *wlstate = &loop->state;
+
+ wl_surface_t surface = wl_compositor_create_surface(wlstate->compositor);
+ if (surface == nullptr)
+ return false;
+
+ xdg_surface_t xdg_surface =
+ xdg_wm_base_get_xdg_surface(wlstate->wm_base, surface);
+ if (xdg_surface == nullptr) {
+ wl_surface_destroy(surface);
+ return false;
+ }
+
+ xdg_surface_add_listener(xdg_surface, &WAYC_SURFACE_LISTENER, window);
+
+ xdg_toplevel_t xdg_toplevel = xdg_surface_get_toplevel(xdg_surface);
+ if (xdg_toplevel == nullptr) {
+ xdg_surface_destroy(xdg_surface);
+ wl_surface_destroy(surface);
+ return false;
+ }
+
+ xdg_toplevel_add_listener(xdg_toplevel, &WAYC_TOPLEVEL_LISTENER, window);
+
+ window->surface = surface;
+ window->xdg_surface = xdg_surface;
+ window->loop = loop;
+ return true;
+}
+
+void wayc_window_deinit(struct window_s *window) {
+ wayc_notnull(window);
+
+ if (window->surface == nullptr || window->xdg_surface == nullptr ||
+ window->xdg_toplevel == nullptr)
+ return;
+
+ xdg_toplevel_destroy(window->xdg_toplevel);
+ xdg_surface_destroy(window->xdg_surface);
+ wl_surface_destroy(window->surface);
+
+ window->xdg_toplevel = nullptr;
+ window->xdg_surface = nullptr;
+ window->surface = nullptr;
+}
diff --git a/src/window.h b/src/window.h
index 88be5f0..41a4eaa 100644
--- a/src/window.h
+++ b/src/window.h
@@ -6,6 +6,9 @@ struct eventloop_s;
typedef u32 window_id_t;
struct window_s {
+ struct eventloop_s *loop;
+ window_id_t id;
+
wl_surface_t surface;
xdg_surface_t xdg_surface;
xdg_toplevel_t xdg_toplevel;