summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2025-03-31 19:12:11 -0400
committerAndrew Opalach <andrew@akon.city> 2025-03-31 19:12:11 -0400
commita3fb42db50542a7e1fca8662d08d3764006c9887 (patch)
tree6863f361d63bc9fe58fd6c220732e7b97c050800 /src
parentd7f90f660e2a944cd60f3c72906e2c7cd0ab4203 (diff)
downloadstela-a3fb42db50542a7e1fca8662d08d3764006c9887.tar.gz
stela-a3fb42db50542a7e1fca8662d08d3764006c9887.tar.bz2
stela-a3fb42db50542a7e1fca8662d08d3764006c9887.zip
Style tweaks, more "platform main" experiments
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src')
-rw-r--r--src/common.h6
-rw-r--r--src/egl_common.c27
-rw-r--r--src/gl_common.c5
-rw-r--r--src/platform.h6
-rw-r--r--src/poll_common.c8
-rw-r--r--src/window.c5
-rw-r--r--src/window.h14
-rw-r--r--src/window_glfm.c40
-rw-r--r--src/window_glfm.h1
-rw-r--r--src/window_glfw.c40
-rw-r--r--src/window_kms.c18
-rw-r--r--src/window_wayland.c43
-rw-r--r--src/window_win32.c41
-rw-r--r--src/window_win32.h5
-rw-r--r--src/window_x11.c43
15 files changed, 164 insertions, 138 deletions
diff --git a/src/common.h b/src/common.h
index b986ab8..c3f35d1 100644
--- a/src/common.h
+++ b/src/common.h
@@ -2,10 +2,8 @@
#include "window.h"
-AL_UNUSED_FUNCTION_PUSH
-
#ifdef STELA_PAUSE
-static bool stl_should_refresh_common(struct stl_window *window)
+static inline bool stl_should_refresh_common(struct stl_window *window)
{
if (window->pending_refresh) {
window->pending_refresh = false;
@@ -14,5 +12,3 @@ static bool stl_should_refresh_common(struct stl_window *window)
return false;
}
#endif
-
-AL_UNUSED_FUNCTION_POP
diff --git a/src/egl_common.c b/src/egl_common.c
index b2f0688..ae37f67 100644
--- a/src/egl_common.c
+++ b/src/egl_common.c
@@ -1,3 +1,4 @@
+#define AL_LOG_SECTION "egl"
#include <al/log.h>
#include <al/macros.h>
@@ -21,7 +22,7 @@ bool stl_maybe_load_egl(void)
#ifdef STELA_USE_GLAD
s32 egl_version = gladLoaderLoadEGL(NULL);
if (!egl_version) {
- al_log_error("egl", "Failed to pre-load EGL (glad).");
+ error("Failed to pre-load EGL (glad).");
return false;
}
#endif
@@ -32,20 +33,20 @@ bool stl_load_egl(struct stl_egl_global *global)
{
EGLint major, minor;
if (!eglInitialize(global->display, &major, &minor)) {
- al_log_error("egl", "Failed to initialize.");
+ error("Failed to initialize.");
return false;
}
- al_log_info("egl", "Initialized EGL version %d.%d.", major, minor);
+ info("Initialized EGL version %d.%d.", major, minor);
#ifdef STELA_USE_GLAD
s32 egl_version = gladLoaderLoadEGL(global->display);
if (!egl_version) {
- al_log_error("egl", "Failed to load EGL (glad).");
+ error("Failed to load EGL (glad).");
return false;
}
- al_log_info("egl", "Using EGL (glad) version %s.", eglQueryString(global->display, EGL_VERSION));
+ info("Using EGL (glad) version %s.", eglQueryString(global->display, EGL_VERSION));
#else
- al_log_info("egl", "Using EGL version %s.", eglQueryString(global->display, EGL_VERSION));
+ info("Using EGL version %s.", eglQueryString(global->display, EGL_VERSION));
#endif
return true;
@@ -79,14 +80,14 @@ static bool egl_choose_config(EGLDisplay display, const EGLint *attribs, EGLint
EGLint count = 0;
if (!eglGetConfigs(display, NULL, 0, &count) || count <= 0) {
- al_log_error("egl", "No configs to choose from.");
+ error("No configs to choose from.");
return false;
}
EGLint matched = 0;
EGLConfig *configs = (EGLConfig *)al_malloc(count * sizeof(EGLConfig));
if (!eglChooseConfig(display, attribs, configs, count, &matched) || !matched) {
- al_log_error("egl", "No configs with appropriate attributes.");
+ error("No configs with appropriate attributes.");
goto out;
}
@@ -136,11 +137,11 @@ bool stl_init_egl_context(struct stl_egl *egl, struct stl_egl_global *global, EG
};
if (!egl_choose_config(egl->display, window_attr, visual_id, config)) {
- al_log_error("egl", "Failed to get config.");
+ error("Failed to get config.");
continue;
}
- al_log_info("egl", "Trying to create a %s context of version %i.%i (GLSL %i).",
+ info("Trying to create a %s context of version %i.%i (GLSL %i).",
stl_gl_vers[i].api == STELA_GL_API ? "GL" : "GLES",
stl_gl_vers[i].major, stl_gl_vers[i].minor, stl_gl_vers[i].glsl_ver);
@@ -149,13 +150,13 @@ bool stl_init_egl_context(struct stl_egl *egl, struct stl_egl_global *global, EG
if (egl->context == EGL_NO_CONTEXT) {
continue;
} else {
- al_log_info("egl", "Context successfully created.");
+ info("Context successfully created.");
break;
}
}
if (egl->context == EGL_NO_CONTEXT) {
- al_log_info("egl", "Failed to create context.");
+ info("Failed to create context.");
return false;
}
@@ -246,6 +247,6 @@ void stl_egl_check_error()
{
EGLint error;
while ((error = eglGetError()) != EGL_SUCCESS) {
- al_log_error("egl", "EGL error %s, %d.", eglGetErrorString(error), error);
+ error("EGL error %s, %d.", eglGetErrorString(error), error);
}
}
diff --git a/src/gl_common.c b/src/gl_common.c
index 59a1ab0..93d1384 100644
--- a/src/gl_common.c
+++ b/src/gl_common.c
@@ -1,5 +1,6 @@
-#include <al/lib.h>
+#define AL_LOG_SECTION "gl"
#include <al/log.h>
+#include <al/lib.h>
#include "gl_common.h"
@@ -23,7 +24,7 @@ bool stl_gl_check_error()
GLenum error;
bool any_error = false;
while ((error = glGetError()) != GL_NO_ERROR) {
- al_log_error("egl", "GL error %s, %d.", glGetErrorString(error), error);
+ error("GL error %s, %d.", glGetErrorString(error), error);
any_error = true;
}
return any_error;
diff --git a/src/platform.h b/src/platform.h
deleted file mode 100644
index f87f4b6..0000000
--- a/src/platform.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#pragma once
-
-#ifdef STELA_WINDOW_GLFM
-#include <glfm.h>
-#include <android/log.h>
-#endif
diff --git a/src/poll_common.c b/src/poll_common.c
index a592b55..a575bf5 100644
--- a/src/poll_common.c
+++ b/src/poll_common.c
@@ -1,3 +1,4 @@
+#define AL_LOG_SECTION "poll"
#include <al/log.h>
#include <nnwt/common.h>
@@ -16,15 +17,14 @@ bool stl_poll_common(struct nn_pollfd *fds, bool block)
#else
if (nn_poll_fds(fds, 1, (block) ? -1 : 0) < 0 && errno != EINTR) {
#endif
- al_log_error("poll_common", "poll() failed %s (%d).", nn_strerror(errno), errno);
+ error("poll() failed %s (%d).", nn_strerror(errno), errno);
return false;
}
- // This will happen consistantly if a program is lagging too hard.
+ // On Wayland this will happen consistantly if the program is lagging too hard.
// https://github.com/swaywm/sway/commit/e3f0ba4cd9ca709cac115ade54958885614d889c
- // @TODO: Recovery.
if (fds[0].revents & (POLLERR | POLLHUP | POLLNVAL)) { // Fatal error.
- al_log_error("poll_common", "poll() returned error in revents (%d).", fds[0].revents);
+ error("poll() returned error in revents (%d).", fds[0].revents);
al_assert(false);
exit(0);
return false;
diff --git a/src/window.c b/src/window.c
index db0eb45..505e1a7 100644
--- a/src/window.c
+++ b/src/window.c
@@ -1,8 +1,9 @@
+#define AL_LOG_SECTION "window"
#include <al/log.h>
#include "window.h"
-void stl_window_common_init(struct stl_window *window)
+void stl_window_init(struct stl_window *window)
{
#ifdef STELA_EVENT_BUFFER
window->data = al_malloc(STELA_EVENTS_SIZE);
@@ -17,7 +18,7 @@ void stl_window_common_init(struct stl_window *window)
size_t size; \
u8 *ptr = al_ring_buffer_write_chunk(&window->events, &size); \
if (size < STELA_EVENT_SIZE) { \
- al_log_warn("window", "Buffer full, discarding event."); \
+ warn("Buffer full, discarding event."); \
return; \
} \
ptr[0] = op
diff --git a/src/window.h b/src/window.h
index 57f906f..068f433 100644
--- a/src/window.h
+++ b/src/window.h
@@ -140,16 +140,18 @@ enum {
#define STELA_EVENTS_SIZE (STELA_EVENT_SIZE * 128)
#endif
-extern s32 window_system_main(s32 argc, str *argv);
+extern s32 stl_platform_main(u32 argc, str *argv);
void stl_set_output_discovered_callback(void (*output_discovered)(void *, struct stl_monitor *), void *userdata);
-s32 stl_global_init(s32 argc, str *argv, s32 (*main)(s32, str *), bool skip_graphics);
-s32 stl_global_get_poll_fd();
-void stl_global_process_events();
+
+bool stl_global_init(bool skip_graphics);
+s32 stl_global_get_poll_fd(void);
+void stl_global_process_events(void);
+s32 stl_swallow_main(u32 argc, str *argv, s32 (*main)(u32, str *, void *), void *extra);
void stl_global_close(void);
-void stl_window_common_init(struct stl_window *window);
-struct stl_window *stl_window_create(void *context);
+struct stl_window *stl_window_create(void);
+void stl_window_init(struct stl_window *window);
void stl_window_send_pointer_pos_event(struct stl_window *window, f64 x, f64 y);
void stl_window_send_scroll_event(struct stl_window *window, f64 y);
void stl_window_send_mouse_button_event(struct stl_window *window, u8 state, u8 button);
diff --git a/src/window_glfm.c b/src/window_glfm.c
index d61eef3..34a631e 100644
--- a/src/window_glfm.c
+++ b/src/window_glfm.c
@@ -1,9 +1,10 @@
+#define AL_LOG_SECTION "glfm"
#include <al/log.h>
#include <nnwt/common.h>
#include "window_glfm.h"
-static struct stl_glfm_global global;
+static struct stl_glfm_global global = { 0 };
void stl_set_output_discovered_callback(void (*output_discovered)(void *, struct stl_monitor *), void *userdata)
{
@@ -11,41 +12,40 @@ void stl_set_output_discovered_callback(void (*output_discovered)(void *, struct
(void)userdata;
}
-s32 stl_global_init(s32 argc, str *argv, s32 (*main)(s32, str *), bool skip_graphics)
+bool stl_global_init(bool skip_graphics)
{
- (void)argc;
- (void)argv;
- (void)main;
(void)skip_graphics;
+ global.did_main = false;
return false;
}
-s32 stl_global_get_poll_fd()
+s32 stl_global_get_poll_fd(void)
{
- return -1;
+ al_assert_and_return(-1);
}
-void stl_global_process_events()
+void stl_global_process_events(void)
{
+ al_assert(false);
}
void stl_global_close(void)
{
}
-static bool one_main = false;
-
static void onSurfaceCreated(GLFMDisplay *display, s32 width, s32 height)
{
GLFMRenderingAPI api = glfmGetRenderingAPI(display);
- if (!one_main) {
- window_system_main(0, NULL);
- one_main = true;
- }
- al_log_info("window_glfm", "Created GLES context of version %s.",
+ (void)width;
+ (void)height;
+ info("Created GLES context of version %s.",
api == GLFMRenderingAPIOpenGLES32 ? "3.2" :
api == GLFMRenderingAPIOpenGLES31 ? "3.1" :
api == GLFMRenderingAPIOpenGLES3 ? "3.0" : "2.0");
+ if (!global.did_main) {
+ stl_platform_main(0, NULL);
+ global.did_main = true;
+ }
}
static void onSurfaceDestroyed(GLFMDisplay *display)
@@ -64,6 +64,7 @@ static void onDraw(GLFMDisplay *display)
void glfmMain(GLFMDisplay *display)
{
nn_common_init();
+ stl_global_init(false);
global.display = display;
glfmSetDisplayConfig(display,
GLFMRenderingAPIOpenGLES2,
@@ -80,6 +81,8 @@ static bool window_glfm_create_window(struct stl_window *window, u32 width, u32
const char *monitor, const char *name, u32 flags)
{
struct stl_window_glfm *glfm = (struct stl_window_glfm *)window;
+ (void)width;
+ (void)height;
(void)monitor;
(void)name;
(void)flags;
@@ -171,15 +174,16 @@ static void window_glfm_gl_release_current(void *data)
static void window_glfm_gl_swap_buffers(void *data)
{
struct stl_window_glfm *glfm = (struct stl_window_glfm *)data;
+ (void)glfm;
glfmSwapBuffers(global.display);
}
#endif
-struct stl_window *stl_window_create(void *context)
+struct stl_window *stl_window_create(void)
{
- al_log_info("stela", "Wrapping GLFM window.");
+ info("Wrapping GLFM window.");
struct stl_window_glfm *glfm = al_alloc_object(struct stl_window_glfm);
- stl_window_common_init(&glfm->w);
+ stl_window_init(&glfm->w);
glfm->w.fullscreen = false;
glfm->w.create_window = window_glfm_create_window;
glfm->w.resize_internal = window_glfm_resize_internal;
diff --git a/src/window_glfm.h b/src/window_glfm.h
index 9513c45..f3703b9 100644
--- a/src/window_glfm.h
+++ b/src/window_glfm.h
@@ -6,6 +6,7 @@
struct stl_glfm_global {
GLFMDisplay *display;
+ bool did_main;
};
struct stl_window_glfm {
diff --git a/src/window_glfw.c b/src/window_glfw.c
index 0d381a5..5ea00ac 100644
--- a/src/window_glfw.c
+++ b/src/window_glfw.c
@@ -1,5 +1,6 @@
-#include <al/lib.h>
+#define AL_LOG_SECTION "glfw"
#include <al/log.h>
+#include <al/lib.h>
#include "window_glfw.h"
#include "common.h"
@@ -33,31 +34,37 @@ void stl_set_output_discovered_callback(void (*output_discovered)(void *, struct
static void error_callback(s32 error_code, const char *description)
{
- al_log_error("glfw", "GLFW Error %d: %s.", error_code, description);
+ error("GLFW Error %d: %s.", error_code, description);
}
-s32 stl_global_init(s32 argc, str *argv, s32 (*main)(s32, str *), bool skip_graphics)
+bool stl_global_init(bool skip_graphics)
{
(void)skip_graphics;
glfwSetErrorCallback(error_callback);
if (!glfwInit()) {
- al_log_error("glfw", "Failed to initialize GLFW.");
+ error("Failed to initialize GLFW.");
return false;
}
global.master_window = NULL;
- return main(argc, argv);
+ return true;
+}
+
+s32 stl_global_get_poll_fd(void)
+{
+ al_assert_and_return(-1);
}
-s32 stl_global_get_poll_fd()
+void stl_global_process_events(void)
{
- return -1;
+ al_assert(false);
}
-void stl_global_process_events()
+s32 stl_swallow_main(u32 argc, str *argv, s32 (*main)(u32, str *, void *), void *extra)
{
+ return main(argc, argv, extra);
}
void stl_global_close(void)
@@ -72,7 +79,7 @@ static void key_callback(GLFWwindow *window, s32 key, s32 scancode, s32 action,
(void)mods;
al_assert(key >= 0 && key <= UINT16_MAX);
if (key == GLFW_KEY_F25 || key == GLFW_KEY_WORLD_1 || key == GLFW_KEY_WORLD_2) {
- al_log_warn("window_glfw", "Unmapped GLFW key pressed (%hu).", (u16)key);
+ warn("Unmapped GLFW key pressed (%hu).", (u16)key);
return;
}
if (action == GLFW_PRESS) {
@@ -180,7 +187,7 @@ static bool window_glfw_create_window(struct stl_window *window, u32 width, u32
#if defined STELA_API_VULKAN
if (!glfwVulkanSupported()) {
- al_log_error("window_glfw", "Vulkan not supported.");
+ error("Vulkan not supported.");
return false;
}
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
@@ -200,21 +207,21 @@ static bool window_glfw_create_window(struct stl_window *window, u32 width, u32
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
}
#endif
- al_log_info("window_glfw", "Trying to make a %s context of version %i.%i (GLSL %i).",
+ info("Trying to make a %s context of version %i.%i (GLSL %i).",
stl_gl_vers[i].api == STELA_GL_API ? "GL" : "GLES",
stl_gl_vers[i].major, stl_gl_vers[i].minor, stl_gl_vers[i].glsl_ver);
#endif
glfw->window = glfwCreateWindow(width, height, name, NULL, global.master_window);
#ifdef STELA_API_OPENGL
if (glfw->window) {
- al_log_info("window_glfw", "Context successfully created.");
+ info("Context successfully created.");
break;
}
}
#endif
if (!glfw->window) {
- al_log_info("window_glfw", "Failed to create window.");
+ info("Failed to create window.");
return false;
}
@@ -447,12 +454,11 @@ static void window_glfw_gl_swap_buffers(void *data)
}
#endif
-struct stl_window *stl_window_create(void *context)
+struct stl_window *stl_window_create(void)
{
- (void)context;
- al_log_info("stela", "Creating GLFW3 window.");
+ info("Creating GLFW3 window.");
struct stl_window_glfw *glfw = al_alloc_object(struct stl_window_glfw);
- stl_window_common_init(&glfw->w);
+ stl_window_init(&glfw->w);
glfw->w.fullscreen = false;
glfw->w.create_window = window_glfw_create_window;
glfw->w.resize_internal = window_glfw_resize_internal;
diff --git a/src/window_kms.c b/src/window_kms.c
index 3a4e1a7..8261d75 100644
--- a/src/window_kms.c
+++ b/src/window_kms.c
@@ -6,22 +6,25 @@ void stl_set_output_discovered_callback(void (*output_discovered)(void *, struct
(void)userdata;
}
-s32 stl_global_init(s32 argc, str *argv, s32 (*main)(s32, str *), bool skip_graphics)
+bool stl_global_init(bool skip_graphics)
{
- (void)argc;
- (void)argv;
- (void)main;
(void)skip_graphics;
return false;
}
s32 stl_global_get_poll_fd()
{
- return -1;
+ al_assert_and_return(-1);
}
void stl_global_process_events()
{
+ al_assert(false);
+}
+
+s32 stl_swallow_main(u32 argc, str *argv, s32 (*main)(u32, str *, void *), void *extra)
+{
+ return main(argc, argv, extra);
}
void stl_global_close(void)
@@ -120,11 +123,10 @@ static void window_kms_gl_swap_buffers(void *data)
}
#endif
-struct stl_window *stl_window_create(void *context)
+struct stl_window *stl_window_create(void)
{
- (void)context;
struct stl_window_kms *kms = al_alloc_object(struct stl_window_kms);
- stl_window_common_init(&kms->w);
+ stl_window_init(&kms->w);
kms->w.fullscreen = true;
kms->w.create_window = window_kms_create_window;
kms->w.resize_internal = window_kms_resize_internal;
diff --git a/src/window_wayland.c b/src/window_wayland.c
index b289843..e047363 100644
--- a/src/window_wayland.c
+++ b/src/window_wayland.c
@@ -1,3 +1,4 @@
+#define AL_LOG_SECTION "wayland"
#include <al/log.h>
#include <al/lib.h>
@@ -55,7 +56,7 @@ static void handle_output_done(void *data, struct wl_output *output)
{
struct stl_monitor_wayland *monitor = (struct stl_monitor_wayland *)data;
(void)output;
- al_log_info("window_wayland", "Output discovered: %s (%ux%u) (vertical: %s).",
+ info("Output discovered: %s (%ux%u) (vertical: %s).",
monitor->m.name, monitor->m.width, monitor->m.height, BOOLSTR(monitor->m.vertical));
if (global.output_discovered) {
global.output_discovered(global.userdata, (struct stl_monitor *)monitor);
@@ -128,7 +129,7 @@ void stl_set_output_discovered_callback(void (*output_discovered)(void *, struct
global.userdata = userdata;
}
-static void set_keycodes(void)
+static void set_keycodes_for_wayland(void)
{
al_memset(global.keycodes, 0, sizeof(global.keycodes));
@@ -257,31 +258,28 @@ static void set_keycodes(void)
global.keycodes[KEY_COMPOSE] = STELA_KEY_MENU;
}
-s32 stl_global_init(s32 argc, str *argv, s32 (*main)(s32, str *), bool skip_graphics)
+bool stl_global_init(bool skip_graphics)
{
global.display = wl_display_connect(NULL);
if (!global.display) {
- al_log_error("wayland", "Failed to connect to the display.");
+ error("Failed to connect to the display.");
return false;
}
global.display_fd = wl_display_get_fd(global.display);
if (!skip_graphics) {
#ifdef STELA_API_OPENGL
- if (!stl_maybe_load_egl()) {
- return false;
- }
+ if (!stl_maybe_load_egl()) return false;
global.egl.display = eglGetDisplay((EGLNativeDisplayType)global.display);
if (!global.egl.display) {
- al_log_error("wayland", "Failed to get wayland-native EGL display.");
- return false;
- }
- if (!stl_load_egl(&global.egl)) {
+ error("Failed to get wayland-native EGL display.");
return false;
}
+ if (!stl_load_egl(&global.egl)) return false;
#endif
} else {
#ifdef STELA_API_OPENGL
+ // So global_close() knows we skipped graphics.
global.egl.display = EGL_NO_DISPLAY;
#endif
}
@@ -294,9 +292,9 @@ s32 stl_global_init(s32 argc, str *argv, s32 (*main)(s32, str *), bool skip_grap
wl_display_roundtrip(global.display);
wl_display_roundtrip(global.display);
- set_keycodes();
+ set_keycodes_for_wayland();
- return main(argc, argv);
+ return true;
}
s32 stl_global_get_poll_fd()
@@ -319,6 +317,11 @@ void stl_global_process_events()
wl_display_dispatch_pending(global.display);
}
+s32 stl_swallow_main(u32 argc, str *argv, s32 (*main)(u32, str *, void *), void *extra)
+{
+ return main(argc, argv, extra);
+}
+
void stl_global_close(void)
{
#ifdef STELA_API_OPENGL
@@ -349,6 +352,7 @@ static void pointer_enter(void *data, struct wl_pointer *pointer,
struct stl_window_wayland *wl = (struct stl_window_wayland *)data;
(void)pointer;
global.active_surface = surface;
+ // @TODO: Hide cursor.
//wl_pointer_set_cursor(wl->pointer, serial, NULL, 0, 0);
if (wl->cursor_shape_device) {
wp_cursor_shape_device_v1_set_shape(wl->cursor_shape_device, serial, WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DEFAULT);
@@ -969,7 +973,7 @@ static bool window_wayland_create_window(struct stl_window *window, u32 width, u
return true;
err:
- al_log_error("window_wayland", "Failed to create window.");
+ error("Failed to create window.");
wl->w.free((struct stl_window **)&wl);
return false;
}
@@ -987,7 +991,9 @@ static void window_wayland_resize_internal(struct stl_window *window, u32 width,
struct stl_window_wayland *wl = (struct stl_window_wayland *)window;
#ifdef STELA_API_OPENGL
u32 scale = wl->w.scale;
- xdg_surface_set_window_geometry(wl->xdg_surface, 0, 0, width / scale, height / scale);
+ if (wl->xdg_surface) {
+ xdg_surface_set_window_geometry(wl->xdg_surface, 0, 0, width / scale, height / scale);
+ }
if (stl_egl_is_ready(&wl->egl)) {
wl_egl_window_resize(wl->egl_window, width, height, 0, 0);
}
@@ -1119,12 +1125,11 @@ static void window_wayland_gl_swap_buffers(void *data)
}
#endif
-struct stl_window *stl_window_create(void *context)
+struct stl_window *stl_window_create(void)
{
- (void)context;
- al_log_info("stela", "Creating Wayland (EGL) window.");
+ info("Creating Wayland (EGL) window.");
struct stl_window_wayland *wl = al_alloc_object(struct stl_window_wayland);
- stl_window_common_init(&wl->w);
+ stl_window_init(&wl->w);
wl->w.fullscreen = false;
wl->w.create_window = window_wayland_create_window;
wl->w.resize = window_wayland_resize;
diff --git a/src/window_win32.c b/src/window_win32.c
index 5ff9f3c..a1ab236 100644
--- a/src/window_win32.c
+++ b/src/window_win32.c
@@ -1,3 +1,4 @@
+#define AL_LOG_SECTION "win32"
#include <al/log.h>
#include "window_win32.h"
@@ -73,12 +74,12 @@ static LRESULT CALLBACK ServiceWndProc(HWND Window, UINT Message, WPARAM WParam,
static DWORD WINAPI MainThread(LPVOID Param)
{
(void)Param;
- s32 ret = global.main(global.argc, global.argv);
+ s32 ret = global.main(global.argc, global.argv, global.extra);
SendMessageW(global.ServiceWindow, EXIT_PROCESS, (WPARAM)ret, 0);
return 0;
}
-static void set_keycodes(void)
+static void set_keycodes_for_win32(void)
{
al_memset(global.keycodes, 0, sizeof(global.keycodes));
@@ -206,12 +207,25 @@ static void set_keycodes(void)
global.keycodes[VK_RWIN] = STELA_KEY_RIGHT_SUPER;
}
-s32 stl_global_init(s32 argc, str *argv, s32 (*main)(s32, str *), bool skip_graphics)
+bool stl_global_init(bool skip_graphics)
{
(void)skip_graphics;
+ set_keycodes_for_win32();
+ return true;
+}
+
+s32 stl_global_get_poll_fd()
+{
+ al_assert_and_return(-1);
+}
- set_keycodes();
+void stl_global_process_events()
+{
+ al_assert(false);
+}
+s32 stl_swallow_main(u32 argc, str *argv, s32 (*main)(u32, str *, void *), void *extra)
+{
WNDCLASSEXW WindowClass = { 0 };
WindowClass.cbSize = sizeof(WindowClass);
WindowClass.lpfnWndProc = &ServiceWndProc;
@@ -226,6 +240,7 @@ s32 stl_global_init(s32 argc, str *argv, s32 (*main)(s32, str *), bool skip_grap
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, WindowClass.hInstance, 0);
global.argc = argc;
global.argv = argv;
+ global.extra = extra;
global.main = main;
CreateThread(0, 0, MainThread, NULL, 0, &MainThreadID);
@@ -239,17 +254,6 @@ s32 stl_global_init(s32 argc, str *argv, s32 (*main)(s32, str *), bool skip_grap
}
DispatchMessageW(&Message);
}
-
- return EXIT_FAILURE;
-}
-
-s32 stl_global_get_poll_fd()
-{
- return -1;
-}
-
-void stl_global_process_events()
-{
}
void stl_global_close(void)
@@ -446,12 +450,11 @@ static void window_win32_free(struct stl_window **window)
al_wstr_free(&w32->WindowName);
}
-struct stl_window *stl_window_create(void *context)
+struct stl_window *stl_window_create(void)
{
- (void)context;
- al_log_info("stela", "Creating Win32 window.");
+ info("Creating Win32 window.");
struct stl_window_win32 *w32 = al_alloc_object(struct stl_window_win32);
- stl_window_common_init(&w32->w);
+ stl_window_init(&w32->w);
w32->w.fullscreen = true;
w32->w.create_window = window_win32_create_window;
w32->w.resize_internal = window_win32_resize_internal;
diff --git a/src/window_win32.h b/src/window_win32.h
index 26ec5cc..f6f917d 100644
--- a/src/window_win32.h
+++ b/src/window_win32.h
@@ -13,9 +13,10 @@
struct stl_win32_global {
HWND ServiceWindow;
u16 keycodes[STELA_WIN32_KEY_MAX];
- s32 argc;
+ u32 argc;
str *argv;
- s32 (*main)(s32, str *);
+ void *extra;
+ s32 (*main)(u32, str *, void *);
};
struct stl_window_win32 {
diff --git a/src/window_x11.c b/src/window_x11.c
index f0a4559..2dc62ee 100644
--- a/src/window_x11.c
+++ b/src/window_x11.c
@@ -1,3 +1,4 @@
+#define AL_LOG_SECTION "x11"
#include <al/log.h>
#include <sys/eventfd.h>
@@ -21,29 +22,29 @@ void stl_set_output_discovered_callback(void (*output_discovered)(void *, struct
global.userdata = userdata;
}
-s32 stl_global_init(s32 argc, str *argv, s32 (*main)(s32, str *), bool skip_graphics)
+bool stl_global_init(bool skip_graphics)
{
global.x11_d = XOpenDisplay(NULL);
if (!global.x11_d) {
- al_log_error("x11", "Couldn't open display.");
+ error("Couldn't open display.");
return false;
}
global.root = XRootWindow(global.x11_d, XDefaultScreen(global.x11_d));
-#ifdef STELA_API_OPENGL
if (!skip_graphics) {
- if (!stl_maybe_load_egl()) {
- return false;
- }
+#ifdef STELA_API_OPENGL
+ if (!stl_maybe_load_egl()) return false;
global.egl.display = eglGetDisplay((EGLNativeDisplayType)global.x11_d);
if (!global.egl.display) {
- al_log_error("x11", "Failed to get x11 EGL display.");
- }
- if (!stl_load_egl(&global.egl)) {
- return false;
+ error("Failed to get x11 EGL display.");
}
- }
+ if (!stl_load_egl(&global.egl)) return false;
+#endif
+ } else {
+#ifdef STELA_API_OPENGL
+ global.egl.display = EGL_NO_DISPLAY;
#endif
+ }
s32 monitor_count;
XRRMonitorInfo *info = XRRGetMonitors(global.x11_d, global.root, 0, &monitor_count);
@@ -70,20 +71,29 @@ s32 stl_global_init(s32 argc, str *argv, s32 (*main)(s32, str *), bool skip_grap
}
XRRFreeMonitors(info);
- return main(argc, argv);
+ return true;
}
s32 stl_global_get_poll_fd()
{
- return -1;
+ al_assert_and_return(-1);
}
void stl_global_process_events()
{
+ al_assert(false);
+}
+
+s32 stl_swallow_main(u32 argc, str *argv, s32 (*main)(u32, str *, void *), void *extra)
+{
+ return main(argc, argv, extra);
}
void stl_global_close(void)
{
+#ifdef STELA_API_OPENGL
+ stl_terminate_egl(&global.egl);
+#endif
for (u32 i = 0; i < global.monitors.count; i++) {
struct stl_monitor *monitor = al_array_at(global.monitors, i);
al_free(monitor);
@@ -348,12 +358,11 @@ static void window_x11_gl_swap_buffers(void *data)
}
#endif
-struct stl_window *stl_window_create(void *context)
+struct stl_window *stl_window_create(void)
{
- (void)context;
- al_log_info("stela", "Creating X11 (EGL) window.");
+ info("Creating X11 (EGL) window.");
struct stl_window_x11 *xw = al_alloc_object(struct stl_window_x11);
- stl_window_common_init(&xw->w);
+ stl_window_init(&xw->w);
xw->w.fullscreen = false;
xw->w.create_window = window_x11_create_window;
xw->w.resize_internal = window_x11_resize_internal;