summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFabrice <fabrice@schaub-dev.xyz>2026-02-10 15:24:38 +0100
committerFabrice <fabrice@schaub-dev.xyz>2026-02-10 15:24:38 +0100
commit88c7b19267e968760fdd350eea77b3199eafe28b (patch)
tree06be4cfcb57766a8a1207fff62ca84dce5988589 /src
parent78bb68168b296c3d7d00b2e5b0714510b5ba3999 (diff)
adjusting context
Diffstat (limited to 'src')
-rw-r--r--src/graphics.cc18
-rw-r--r--src/graphics.h4
-rw-r--r--src/wayclock.cc15
3 files changed, 25 insertions, 12 deletions
diff --git a/src/graphics.cc b/src/graphics.cc
index 68fee14..d9db4c8 100644
--- a/src/graphics.cc
+++ b/src/graphics.cc
@@ -1,16 +1,28 @@
#include "graphics.h"
-#include <cstring>
+#include <EGL/egl.h>
#include "utils.h"
+#include "wlstate.h"
-enum graphics_error_e wayc_graphics_init(struct graphics_s* graphics) {
+enum graphics_error_e wayc_graphics_init(struct graphics_s* graphics,
+ struct wlstate_s* state) {
wayc_notnull(graphics);
- memset(graphics, 0, sizeof(*graphics));
+ wayc_notnull(state);
+ EGLDisplay display = eglGetDisplay(state->display);
+ if (display == EGL_NO_DISPLAY) return GRAPHICS_ERROR_DISPLAY;
+
+ graphics->display = display;
return GRAPHICS_ERROR_NONE;
}
void wayc_graphics_deinit(struct graphics_s* graphics) {
wayc_notnull(graphics);
+
+ if (graphics->display == nullptr) return;
+
+ eglMakeCurrent(graphics->display, EGL_NO_SURFACE, EGL_NO_SURFACE,
+ EGL_NO_CONTEXT);
+ eglTerminate(graphics->display);
}
diff --git a/src/graphics.h b/src/graphics.h
index 8c998f5..1ab4651 100644
--- a/src/graphics.h
+++ b/src/graphics.h
@@ -5,6 +5,7 @@
enum graphics_error_e {
GRAPHICS_ERROR_NONE = 0,
+ GRAPHICS_ERROR_DISPLAY,
};
struct graphics_s {
@@ -13,5 +14,6 @@ struct graphics_s {
EGLConfig config;
};
-enum graphics_error_e wayc_graphics_init(struct graphics_s* graphics);
+enum graphics_error_e wayc_graphics_init(struct graphics_s* graphics,
+ struct wlstate_s* state);
void wayc_graphics_deinit(struct graphics_s* graphics);
diff --git a/src/wayclock.cc b/src/wayclock.cc
index 2d3f9c7..348b122 100644
--- a/src/wayclock.cc
+++ b/src/wayclock.cc
@@ -40,18 +40,17 @@ void handle(struct eventloop_s* loop, struct event_s* event) {
}
int main() {
- struct graphics_s graphics;
- if (wayc_graphics_init(&graphics) != GRAPHICS_ERROR_NONE)
- wayc_panic("Failed to initialize graphics");
-
struct eventloop_s loop;
- if (wayc_eventloop_init(&loop, handle) != EVENTLOOP_ERROR_NONE) {
- wayc_graphics_deinit(&graphics);
+ if (wayc_eventloop_init(&loop, handle) != EVENTLOOP_ERROR_NONE)
wayc_panic("Failed to initialize event loop");
- }
+
+ struct graphics_s graphics;
+ if (wayc_graphics_init(&graphics, &loop.state) != GRAPHICS_ERROR_NONE)
+ wayc_panic("Failed to initialize graphics");
struct window_s window;
if (wayc_window_init(&window, WAYC_APP_NAME, &loop) != WINDOW_ERROR_NONE) {
+ wayc_graphics_deinit(&graphics);
wayc_eventloop_deinit(&loop);
wayc_panic("Failed to initialize window");
}
@@ -62,7 +61,7 @@ int main() {
while (wayc_eventloop_running(&loop)) wayc_eventloop_update(&loop);
wayc_window_deinit(&window);
- wayc_eventloop_deinit(&loop);
wayc_graphics_deinit(&graphics);
+ wayc_eventloop_deinit(&loop);
return 0;
} \ No newline at end of file