diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/common.h | 4 | ||||
| -rw-r--r-- | src/egl_common.c | 62 | ||||
| -rw-r--r-- | src/egl_common.h | 26 | ||||
| -rw-r--r-- | src/gl_common.c | 10 | ||||
| -rw-r--r-- | src/gl_common.h | 14 | ||||
| -rw-r--r-- | src/gl_versions.h | 64 | ||||
| -rw-r--r-- | src/poll_common.c | 22 | ||||
| -rw-r--r-- | src/poll_common.h | 10 | ||||
| -rw-r--r-- | src/sekihi.c | 27 | ||||
| -rw-r--r-- | src/stela.c | 27 | ||||
| -rw-r--r-- | src/window.c | 88 | ||||
| -rw-r--r-- | src/window.h | 133 | ||||
| -rw-r--r-- | src/window_glfw.c | 158 | ||||
| -rw-r--r-- | src/window_glfw.h | 8 | ||||
| -rw-r--r-- | src/window_wayland.c | 296 | ||||
| -rw-r--r-- | src/window_wayland.h | 16 | ||||
| -rw-r--r-- | src/window_x11.c | 144 | ||||
| -rw-r--r-- | src/window_x11.h | 10 |
18 files changed, 557 insertions, 562 deletions
diff --git a/src/common.h b/src/common.h index 36856da..acbb2e5 100644 --- a/src/common.h +++ b/src/common.h @@ -4,8 +4,8 @@ AL_UNUSED_FUNCTION_PUSH -#if defined SEKIHI_PAUSE -static bool skh_should_refresh_common(struct skh_window *window) +#if defined STELA_PAUSE +static bool stl_should_refresh_common(struct stl_window *window) { if (window->pending_refresh) { window->pending_refresh = false; diff --git a/src/egl_common.c b/src/egl_common.c index 44c2ccb..dbde5da 100644 --- a/src/egl_common.c +++ b/src/egl_common.c @@ -3,14 +3,14 @@ #include "egl_common.h" -#define SEKIHI_GL_API EGL_OPENGL_API -#define SEKIHI_GLES_API EGL_OPENGL_ES_API +#define STELA_GL_API EGL_OPENGL_API +#define STELA_GLES_API EGL_OPENGL_ES_API -#define SEKIHI_GL_BIT EGL_OPENGL_BIT -#define SEKIHI_GLES2_BIT EGL_OPENGL_ES2_BIT -#define SEKIHI_GLES3_BIT EGL_OPENGL_ES3_BIT +#define STELA_GL_BIT EGL_OPENGL_BIT +#define STELA_GLES2_BIT EGL_OPENGL_ES2_BIT +#define STELA_GLES3_BIT EGL_OPENGL_ES3_BIT -#define SEKIHI_GL_CORE_PROFILE_BIT EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT +#define STELA_GL_CORE_PROFILE_BIT EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT #include "gl_versions.h" @@ -62,10 +62,10 @@ out: return index != -1; } -bool skh_maybe_load_egl(struct skh_egl *egl) +bool stl_maybe_load_egl(struct stl_egl *egl) { (void)egl; -#ifdef SEKIHI_USE_GLAD +#ifdef STELA_USE_GLAD s32 egl_version = gladLoaderLoadEGL(NULL); if (!egl_version) { al_log_error("egl", "Failed to pre-load EGL (glad)."); @@ -75,7 +75,7 @@ bool skh_maybe_load_egl(struct skh_egl *egl) return true; } -bool skh_init_egl(struct skh_egl *egl, EGLint visual_id, EGLConfig *config) +bool stl_init_egl(struct stl_egl *egl, EGLint visual_id, EGLConfig *config) { s32 minor, major; if (!eglInitialize(egl->display, &major, &minor)) { @@ -84,7 +84,7 @@ bool skh_init_egl(struct skh_egl *egl, EGLint visual_id, EGLConfig *config) } al_log_info("egl", "Initialized EGL version %i.%i.", major, minor); -#ifdef SEKIHI_USE_GLAD +#ifdef STELA_USE_GLAD s32 egl_version = gladLoaderLoadEGL(egl->display); if (!egl_version) { al_log_error("egl", "Failed to load EGL (glad)."); @@ -96,23 +96,23 @@ bool skh_init_egl(struct skh_egl *egl, EGLint visual_id, EGLConfig *config) egl->context = EGL_NO_CONTEXT; - for (u32 i = 0; i < AL_ARRAY_SIZE(skh_gl_vers); i++) { + for (u32 i = 0; i < AL_ARRAY_SIZE(stl_gl_vers); i++) { const EGLint context_attr_gles[] = { - EGL_CONTEXT_CLIENT_VERSION, skh_gl_vers[i].major, + EGL_CONTEXT_CLIENT_VERSION, stl_gl_vers[i].major, EGL_NONE }; const EGLint context_attr_gl[] = { - EGL_CONTEXT_MAJOR_VERSION, skh_gl_vers[i].major, - EGL_CONTEXT_MINOR_VERSION, skh_gl_vers[i].minor, - EGL_CONTEXT_OPENGL_PROFILE_MASK, skh_gl_vers[i].profile, + EGL_CONTEXT_MAJOR_VERSION, stl_gl_vers[i].major, + EGL_CONTEXT_MINOR_VERSION, stl_gl_vers[i].minor, + EGL_CONTEXT_OPENGL_PROFILE_MASK, stl_gl_vers[i].profile, EGL_NONE }; - const EGLint *context_attr = (skh_gl_vers[i].api == SEKIHI_GL_API) ? + const EGLint *context_attr = (stl_gl_vers[i].api == STELA_GL_API) ? context_attr_gl : context_attr_gles; - eglBindAPI(skh_gl_vers[i].api); + eglBindAPI(stl_gl_vers[i].api); const EGLint window_attr[] = { EGL_SURFACE_TYPE, EGL_WINDOW_BIT, @@ -120,7 +120,7 @@ bool skh_init_egl(struct skh_egl *egl, EGLint visual_id, EGLConfig *config) EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 0, - EGL_RENDERABLE_TYPE, skh_gl_vers[i].type, + EGL_RENDERABLE_TYPE, stl_gl_vers[i].type, EGL_SAMPLES, 0, EGL_NONE }; @@ -131,8 +131,8 @@ bool skh_init_egl(struct skh_egl *egl, EGLint visual_id, EGLConfig *config) } al_log_info("egl", "Trying to create a %s context of version %i.%i (GLSL %i).", - skh_gl_vers[i].api == SEKIHI_GL_API ? "GL" : "GLES", - skh_gl_vers[i].major, skh_gl_vers[i].minor, skh_gl_vers[i].glsl_ver); + 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); egl->context = eglCreateContext(egl->display, *config, EGL_NO_CONTEXT, context_attr); @@ -154,43 +154,43 @@ bool skh_init_egl(struct skh_egl *egl, EGLint visual_id, EGLConfig *config) return true; } -void skh_egl_make_current(struct skh_egl *egl) +void stl_egl_make_current(struct stl_egl *egl) { eglMakeCurrent(egl->display, egl->surface, egl->surface, egl->context); } -void skh_egl_release_current(struct skh_egl *egl) +void stl_egl_release_current(struct stl_egl *egl) { eglMakeCurrent(egl->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); } -void skh_egl_swap_interval(struct skh_egl *egl, s32 interval) +void stl_egl_swap_interval(struct stl_egl *egl, s32 interval) { eglSwapInterval(egl->display, interval); } -void skh_egl_swap_buffers(struct skh_egl *egl) +void stl_egl_swap_buffers(struct stl_egl *egl) { eglSwapBuffers(egl->display, egl->surface); } -bool skh_egl_is_ready(struct skh_egl *egl) +bool stl_egl_is_ready(struct stl_egl *egl) { return egl->context != EGL_NO_CONTEXT; } -void skh_egl_destroy_surface(struct skh_egl *egl) +void stl_egl_destroy_surface(struct stl_egl *egl) { - skh_egl_release_current(egl); + stl_egl_release_current(egl); eglDestroySurface(egl->display, egl->surface); } -void skh_egl_destroy_context(struct skh_egl *egl) +void stl_egl_destroy_context(struct stl_egl *egl) { eglDestroyContext(egl->display, egl->context); } -void skh_egl_terminate(struct skh_egl *egl) +void stl_egl_terminate(struct stl_egl *egl) { eglTerminate(egl->display); } @@ -198,7 +198,7 @@ void skh_egl_terminate(struct skh_egl *egl) #define ERROR_CASE_STR(value) case value: return #value; static const char *eglGetErrorString(EGLint error) { - switch(error) { + switch (error) { ERROR_CASE_STR(EGL_SUCCESS) ERROR_CASE_STR(EGL_NOT_INITIALIZED) ERROR_CASE_STR(EGL_BAD_ACCESS) @@ -219,7 +219,7 @@ static const char *eglGetErrorString(EGLint error) } #undef ERROR_CASE_STR -void skh_egl_check_error() +void stl_egl_check_error() { EGLint error; while ((error = eglGetError()) != EGL_SUCCESS) { diff --git a/src/egl_common.h b/src/egl_common.h index e021ea6..fabb2ef 100644 --- a/src/egl_common.h +++ b/src/egl_common.h @@ -2,28 +2,28 @@ #include "gl_common.h" -#ifdef SEKIHI_USE_GLAD +#ifdef STELA_USE_GLAD #include <glad/egl.h> #else #include <EGL/egl.h> #include <EGL/eglext.h> #endif -struct skh_egl { +struct stl_egl { EGLDisplay display; EGLSurface surface; EGLContext context; }; -bool skh_maybe_load_egl(struct skh_egl *egl); -bool skh_init_egl(struct skh_egl *egl, EGLint visual_id, EGLConfig *config); -void skh_egl_make_current(struct skh_egl *egl); -void skh_egl_release_current(struct skh_egl *egl); -void skh_egl_swap_interval(struct skh_egl *egl, s32 interval); -void skh_egl_swap_buffers(struct skh_egl *egl); -bool skh_egl_is_ready(struct skh_egl *egl); -void skh_egl_destroy_surface(struct skh_egl *egl); -void skh_egl_destroy_context(struct skh_egl *egl); -void skh_egl_terminate(struct skh_egl *egl); +bool stl_maybe_load_egl(struct stl_egl *egl); +bool stl_init_egl(struct stl_egl *egl, EGLint visual_id, EGLConfig *config); +void stl_egl_make_current(struct stl_egl *egl); +void stl_egl_release_current(struct stl_egl *egl); +void stl_egl_swap_interval(struct stl_egl *egl, s32 interval); +void stl_egl_swap_buffers(struct stl_egl *egl); +bool stl_egl_is_ready(struct stl_egl *egl); +void stl_egl_destroy_surface(struct stl_egl *egl); +void stl_egl_destroy_context(struct stl_egl *egl); +void stl_egl_terminate(struct stl_egl *egl); -void skh_egl_check_error(); +void stl_egl_check_error(); diff --git a/src/gl_common.c b/src/gl_common.c index 2a2fd53..51118b3 100644 --- a/src/gl_common.c +++ b/src/gl_common.c @@ -7,7 +7,7 @@ #define ERROR_CASE_STR(value) case value: return #value; static const char *glGetErrorString(GLenum error) { - switch(error) { + switch (error) { ERROR_CASE_STR(GL_INVALID_ENUM) ERROR_CASE_STR(GL_INVALID_VALUE) ERROR_CASE_STR(GL_INVALID_OPERATION) @@ -18,7 +18,7 @@ static const char *glGetErrorString(GLenum error) } #undef ERROR_CASE_STR -void skh_gl_check_error() +void stl_gl_check_error() { GLenum error; while ((error = glGetError()) != GL_NO_ERROR) { @@ -26,11 +26,11 @@ void skh_gl_check_error() } } -bool skh_gl_loader_load(void (*(*get_proc_address)(const char *))(void)) +bool stl_gl_loader_load(void (*(*get_proc_address)(const char *))(void)) { -#ifdef SEKIHI_USE_GLAD +#ifdef STELA_USE_GLAD al_assert(get_proc_address); -#ifdef SEKIHI_USE_GLES +#ifdef STELA_USE_GLES if (!gladLoadGLES2((GLADloadfunc)get_proc_address)) { return false; } diff --git a/src/gl_common.h b/src/gl_common.h index bbab137..57eb5e5 100644 --- a/src/gl_common.h +++ b/src/gl_common.h @@ -1,16 +1,16 @@ -//#define SEKIHI_USE_GLAD -//#define SEKIHI_USE_GLES +//#define STELA_USE_GLAD +//#define STELA_USE_GLES #include <al/types.h> -#ifdef SEKIHI_USE_GLAD -#ifdef SEKIHI_USE_GLES +#ifdef STELA_USE_GLAD +#ifdef STELA_USE_GLES #include <glad/gles2.h> #else #include <glad/gl.h> #endif #else -#ifdef SEKIHI_USE_GLES +#ifdef STELA_USE_GLES #include <GLES2/gl2.h> #else #define GL_GLEXT_PROTOTYPES @@ -20,5 +20,5 @@ #endif #endif -void skh_gl_check_error(); -bool skh_gl_loader_load(void (*(*get_proc_address)(const char *))(void)); +void stl_gl_check_error(); +bool stl_gl_loader_load(void (*(*get_proc_address)(const char *))(void)); diff --git a/src/gl_versions.h b/src/gl_versions.h index e999682..2f45bbc 100644 --- a/src/gl_versions.h +++ b/src/gl_versions.h @@ -1,18 +1,18 @@ #pragma once // https://github.com/haasn/libplacebo/blob/795600a44b03fcd52c055981a403ad60ee5d027a/demos/window_glfw.c#L194 -#ifdef SEKIHI_USE_GLES +#ifdef STELA_USE_GLES #define PASTE_GL_VERSIONS() static struct { \ s32 api; \ s32 type; \ s32 major, minor; \ s32 glsl_ver; \ s32 profile; \ -} skh_gl_vers[] = { \ - { SEKIHI_GLES_API, SEKIHI_GLES3_BIT, 3, 2, 320, 0 }, \ - { SEKIHI_GLES_API, SEKIHI_GLES3_BIT, 3, 1, 310, 0 }, \ - { SEKIHI_GLES_API, SEKIHI_GLES3_BIT, 3, 0, 300, 0 }, \ - { SEKIHI_GLES_API, SEKIHI_GLES2_BIT, 2, 0, 100, 0 }, \ +} stl_gl_vers[] = { \ + { STELA_GLES_API, STELA_GLES3_BIT, 3, 2, 320, 0 }, \ + { STELA_GLES_API, STELA_GLES3_BIT, 3, 1, 310, 0 }, \ + { STELA_GLES_API, STELA_GLES3_BIT, 3, 0, 300, 0 }, \ + { STELA_GLES_API, STELA_GLES2_BIT, 2, 0, 100, 0 }, \ }; #else #define PASTE_GL_VERSIONS() static struct { \ @@ -21,17 +21,17 @@ s32 major, minor; \ s32 glsl_ver; \ s32 profile; \ -} skh_gl_vers[] = { \ - { SEKIHI_GL_API, SEKIHI_GL_BIT, 4, 6, 460, SEKIHI_GL_CORE_PROFILE_BIT }, \ - { SEKIHI_GL_API, SEKIHI_GL_BIT, 4, 5, 450, SEKIHI_GL_CORE_PROFILE_BIT }, \ - { SEKIHI_GL_API, SEKIHI_GL_BIT, 4, 4, 440, SEKIHI_GL_CORE_PROFILE_BIT }, \ - { SEKIHI_GL_API, SEKIHI_GL_BIT, 4, 0, 400, SEKIHI_GL_CORE_PROFILE_BIT }, \ - { SEKIHI_GL_API, SEKIHI_GL_BIT, 3, 3, 330, SEKIHI_GL_CORE_PROFILE_BIT }, \ - { SEKIHI_GL_API, SEKIHI_GL_BIT, 3, 2, 150, SEKIHI_GL_CORE_PROFILE_BIT }, \ - { SEKIHI_GL_API, SEKIHI_GL_BIT, 3, 1, 140, 0 }, \ - { SEKIHI_GL_API, SEKIHI_GL_BIT, 3, 0, 130, 0 }, \ - { SEKIHI_GL_API, SEKIHI_GL_BIT, 2, 1, 120, 0 }, \ - { SEKIHI_GL_API, SEKIHI_GL_BIT, 2, 0, 110, 0 }, \ +} stl_gl_vers[] = { \ + { STELA_GL_API, STELA_GL_BIT, 4, 6, 460, STELA_GL_CORE_PROFILE_BIT }, \ + { STELA_GL_API, STELA_GL_BIT, 4, 5, 450, STELA_GL_CORE_PROFILE_BIT }, \ + { STELA_GL_API, STELA_GL_BIT, 4, 4, 440, STELA_GL_CORE_PROFILE_BIT }, \ + { STELA_GL_API, STELA_GL_BIT, 4, 0, 400, STELA_GL_CORE_PROFILE_BIT }, \ + { STELA_GL_API, STELA_GL_BIT, 3, 3, 330, STELA_GL_CORE_PROFILE_BIT }, \ + { STELA_GL_API, STELA_GL_BIT, 3, 2, 150, STELA_GL_CORE_PROFILE_BIT }, \ + { STELA_GL_API, STELA_GL_BIT, 3, 1, 140, 0 }, \ + { STELA_GL_API, STELA_GL_BIT, 3, 0, 130, 0 }, \ + { STELA_GL_API, STELA_GL_BIT, 2, 1, 120, 0 }, \ + { STELA_GL_API, STELA_GL_BIT, 2, 0, 110, 0 }, \ }; #endif /* @@ -41,20 +41,20 @@ s32 major, minor; \ s32 glsl_ver; \ s32 profile; \ -} skh_gl_vers[] = { \ - { SEKIHI_GL_API, SEKIHI_GL_BIT, 4, 6, 460, SEKIHI_GL_CORE_PROFILE_BIT }, \ - { SEKIHI_GL_API, SEKIHI_GL_BIT, 4, 5, 450, SEKIHI_GL_CORE_PROFILE_BIT }, \ - { SEKIHI_GL_API, SEKIHI_GL_BIT, 4, 4, 440, SEKIHI_GL_CORE_PROFILE_BIT }, \ - { SEKIHI_GL_API, SEKIHI_GL_BIT, 4, 0, 400, SEKIHI_GL_CORE_PROFILE_BIT }, \ - { SEKIHI_GL_API, SEKIHI_GL_BIT, 3, 3, 330, SEKIHI_GL_CORE_PROFILE_BIT }, \ - { SEKIHI_GL_API, SEKIHI_GL_BIT, 3, 2, 150, SEKIHI_GL_CORE_PROFILE_BIT }, \ - { SEKIHI_GLES_API, SEKIHI_GLES3_BIT, 3, 2, 320, 0 }, \ - { SEKIHI_GL_API, SEKIHI_GL_BIT, 3, 1, 140, 0 }, \ - { SEKIHI_GLES_API, SEKIHI_GLES3_BIT, 3, 1, 310, 0 }, \ - { SEKIHI_GL_API, SEKIHI_GL_BIT, 3, 0, 130, 0 }, \ - { SEKIHI_GLES_API, SEKIHI_GLES3_BIT, 3, 0, 300, 0 }, \ - { SEKIHI_GLES_API, SEKIHI_GLES2_BIT, 2, 0, 100, 0 }, \ - { SEKIHI_GL_API, SEKIHI_GL_BIT, 2, 1, 120, 0 }, \ - { SEKIHI_GL_API, SEKIHI_GL_BIT, 2, 0, 110, 0 }, \ +} stl_gl_vers[] = { \ + { STELA_GL_API, STELA_GL_BIT, 4, 6, 460, STELA_GL_CORE_PROFILE_BIT }, \ + { STELA_GL_API, STELA_GL_BIT, 4, 5, 450, STELA_GL_CORE_PROFILE_BIT }, \ + { STELA_GL_API, STELA_GL_BIT, 4, 4, 440, STELA_GL_CORE_PROFILE_BIT }, \ + { STELA_GL_API, STELA_GL_BIT, 4, 0, 400, STELA_GL_CORE_PROFILE_BIT }, \ + { STELA_GL_API, STELA_GL_BIT, 3, 3, 330, STELA_GL_CORE_PROFILE_BIT }, \ + { STELA_GL_API, STELA_GL_BIT, 3, 2, 150, STELA_GL_CORE_PROFILE_BIT }, \ + { STELA_GLES_API, STELA_GLES3_BIT, 3, 2, 320, 0 }, \ + { STELA_GL_API, STELA_GL_BIT, 3, 1, 140, 0 }, \ + { STELA_GLES_API, STELA_GLES3_BIT, 3, 1, 310, 0 }, \ + { STELA_GL_API, STELA_GL_BIT, 3, 0, 130, 0 }, \ + { STELA_GLES_API, STELA_GLES3_BIT, 3, 0, 300, 0 }, \ + { STELA_GLES_API, STELA_GLES2_BIT, 2, 0, 100, 0 }, \ + { STELA_GL_API, STELA_GL_BIT, 2, 1, 120, 0 }, \ + { STELA_GL_API, STELA_GL_BIT, 2, 0, 110, 0 }, \ }; */ diff --git a/src/poll_common.c b/src/poll_common.c index 0b9cd61..9255ad9 100644 --- a/src/poll_common.c +++ b/src/poll_common.c @@ -3,15 +3,15 @@ #include "poll_common.h" -#if defined SEKIHI_POLL_INLINE -bool skh_poll_common(struct aki_pollfd *fds, bool block) +#if defined STELA_POLL_INLINE +bool stl_poll_common(struct aki_pollfd *fds, bool block) { fds[0].revents = 0; -#if defined SEKIHI_PAUSE +#if defined STELA_PAUSE fds[1].revents = 0; #endif -#if defined SEKIHI_PAUSE +#if defined STELA_PAUSE if (aki_poll_fds(fds, 2, (block) ? -1 : 0) < 0 && errno != EINTR) { #else if (aki_poll_fds(fds, 1, (block) ? -1 : 0) < 0 && errno != EINTR) { @@ -22,14 +22,14 @@ bool skh_poll_common(struct aki_pollfd *fds, bool block) if (fds[0].revents & (POLLERR | POLLHUP | POLLNVAL)) { // Fatal error. al_log_error("poll_common", "poll() returned error in revents (%d).", fds[0].revents); - al_assert(false); + exit(0); return false; } return true; } -#if defined SEKIHI_PAUSE -void skh_wake_common(struct skh_window *window, struct aki_pollfd *fds) +#if defined STELA_PAUSE +void stl_wake_common(struct stl_window *window, struct aki_pollfd *fds) { window->pending_refresh = true; // If we are already in poll, don't try to wake again instead @@ -43,17 +43,17 @@ void skh_wake_common(struct skh_window *window, struct aki_pollfd *fds) #endif #endif -bool skh_process_events_common(struct aki_pollfd *fds) +bool stl_process_events_common(struct aki_pollfd *fds) { -#if defined SEKIHI_POLL_INLINE -#if defined SEKIHI_PAUSE +#if defined STELA_POLL_INLINE +#if defined STELA_PAUSE if (fds[1].revents & POLLIN) { s64 val = aki_read(fds[1].fd, &val, sizeof(s64)); al_assert(val == sizeof(s64)); } #endif return (fds[0].revents & POLLIN); -#elif defined SEKIHI_POLL_FD +#elif defined STELA_POLL_FD return true; #endif } diff --git a/src/poll_common.h b/src/poll_common.h index c4ff4ea..02ec2ee 100644 --- a/src/poll_common.h +++ b/src/poll_common.h @@ -4,10 +4,10 @@ #include "window.h" -#if defined SEKIHI_POLL_INLINE -bool skh_poll_common(struct aki_pollfd *fds, bool block); -#if defined SEKIHI_PAUSE -void skh_wake_common(struct skh_window *window, struct aki_pollfd *fds); +#if defined STELA_POLL_INLINE +bool stl_poll_common(struct aki_pollfd *fds, bool block); +#if defined STELA_PAUSE +void stl_wake_common(struct stl_window *window, struct aki_pollfd *fds); #endif #endif -bool skh_process_events_common(struct aki_pollfd *fds); +bool stl_process_events_common(struct aki_pollfd *fds); diff --git a/src/sekihi.c b/src/sekihi.c deleted file mode 100644 index 11f1982..0000000 --- a/src/sekihi.c +++ /dev/null @@ -1,27 +0,0 @@ -#include <al/log.h> - -#include "window.h" - -#if defined SEKIHI_WINDOW_WAYLAND -#include "window_wayland.h" -#elif defined SEKIHI_WINDOW_X11 -#include "window_x11.h" -#elif defined SEKIHI_WINDOW_GLFW -#include "window_glfw.h" -#endif - -#if defined SEKIHI_WINDOW_WAYLAND || defined SEKIHI_WINDOW_X11 || defined SEKIHI_WINDOW_GLFW -struct skh_window *skh_window_create(void) -{ -#if defined SEKIHI_WINDOW_WAYLAND - al_log_info("sekihi", "Creating wayland (EGL) window."); - return skh_window_wayland_create(); -#elif defined SEKIHI_WINDOW_X11 - al_log_info("sekihi", "Creating X11 (EGL) window."); - return skh_window_x11_create(); -#elif defined SEKIHI_WINDOW_GLFW - al_log_info("sekihi", "Creating GLFW3 window."); - return skh_window_glfw_create(); -#endif -} -#endif diff --git a/src/stela.c b/src/stela.c new file mode 100644 index 0000000..8203da4 --- /dev/null +++ b/src/stela.c @@ -0,0 +1,27 @@ +#include <al/log.h> + +#include "window.h" + +#if defined STELA_WINDOW_WAYLAND +#include "window_wayland.h" +#elif defined STELA_WINDOW_X11 +#include "window_x11.h" +#elif defined STELA_WINDOW_GLFW +#include "window_glfw.h" +#endif + +#if defined STELA_WINDOW_WAYLAND || defined STELA_WINDOW_X11 || defined STELA_WINDOW_GLFW +struct stl_window *stl_window_create(void) +{ +#if defined STELA_WINDOW_WAYLAND + al_log_info("stela", "Creating wayland (EGL) window."); + return stl_window_wayland_create(); +#elif defined STELA_WINDOW_X11 + al_log_info("stela", "Creating X11 (EGL) window."); + return stl_window_x11_create(); +#elif defined STELA_WINDOW_GLFW + al_log_info("stela", "Creating GLFW3 window."); + return stl_window_glfw_create(); +#endif +} +#endif diff --git a/src/window.c b/src/window.c index 40e7f41..5efafdd 100644 --- a/src/window.c +++ b/src/window.c @@ -3,25 +3,25 @@ #define GET_EVENT_CHUNK(op) \ size_t size; \ u8 *ptr = al_ring_buffer_write_chunk(&window->events, &size); \ - if (size < SEKIHI_EVENT_SIZE) { \ + if (size < STELA_EVENT_SIZE) { \ return; \ } \ ptr[0] = op #define APPEND_EVENT_CHUNK() \ - al_ring_buffer_append(&window->events, ptr, SEKIHI_EVENT_SIZE) + al_ring_buffer_append(&window->events, ptr, STELA_EVENT_SIZE) -void skh_window_send_pointer_pos_event(struct skh_window *window, f64 x, f64 y) +void stl_window_send_pointer_pos_event(struct stl_window *window, f64 x, f64 y) { -#if defined SEKIHI_EVENT_BUFFER - GET_EVENT_CHUNK(SEKIHI_EVENT_POINTER_POS); +#if defined STELA_EVENT_BUFFER + GET_EVENT_CHUNK(STELA_EVENT_POINTER_POS); ((f64 *)(&ptr[1]))[0] = x; ((f64 *)(&ptr[9]))[0] = y; APPEND_EVENT_CHUNK(); #else if (window->pointer_pos_callback) { if (window->pointer_pos_callback(window->userdata, x, y)) { -#if defined SEKIHI_PAUSE +#if defined STELA_PAUSE window->pending_refresh = true; #endif } @@ -29,16 +29,16 @@ void skh_window_send_pointer_pos_event(struct skh_window *window, f64 x, f64 y) #endif } -void skh_window_send_scroll_event(struct skh_window *window, f64 y) +void stl_window_send_scroll_event(struct stl_window *window, f64 y) { -#if defined SEKIHI_EVENT_BUFFER - GET_EVENT_CHUNK(SEKIHI_EVENT_SCROLL); +#if defined STELA_EVENT_BUFFER + GET_EVENT_CHUNK(STELA_EVENT_SCROLL); ((f64 *)(&ptr[1]))[0] = y; APPEND_EVENT_CHUNK(); #else if (window->scroll_callback) { if (window->scroll_callback(window->userdata, y)) { -#if defined SEKIHI_PAUSE +#if defined STELA_PAUSE window->pending_refresh = true; #endif } @@ -46,17 +46,17 @@ void skh_window_send_scroll_event(struct skh_window *window, f64 y) #endif } -void skh_window_send_mouse_button_event(struct skh_window *window, u8 state, u8 button) +void stl_window_send_mouse_button_event(struct stl_window *window, u8 state, u8 button) { -#if defined SEKIHI_EVENT_BUFFER - GET_EVENT_CHUNK(SEKIHI_EVENT_MOUSE_BUTTON); +#if defined STELA_EVENT_BUFFER + GET_EVENT_CHUNK(STELA_EVENT_MOUSE_BUTTON); ptr[1] = state; ptr[2] = button; APPEND_EVENT_CHUNK(); #else if (window->mouse_button_callback) { if (window->mouse_button_callback(window->userdata, state, button)) { -#if defined SEKIHI_PAUSE +#if defined STELA_PAUSE window->pending_refresh = true; #endif } @@ -64,20 +64,20 @@ void skh_window_send_mouse_button_event(struct skh_window *window, u8 state, u8 #endif } -void skh_window_send_key_event(struct skh_window *window, u8 state, u8 button) +void stl_window_send_key_event(struct stl_window *window, u8 state, u8 button) { if (window->key_immediate_callback) { window->key_immediate_callback(window->userdata, state, button); } -#if defined SEKIHI_EVENT_BUFFER - GET_EVENT_CHUNK(SEKIHI_EVENT_KEY); +#if defined STELA_EVENT_BUFFER + GET_EVENT_CHUNK(STELA_EVENT_KEY); ptr[1] = state; ptr[2] = button; APPEND_EVENT_CHUNK(); #else if (window->key_callback) { if (window->key_callback(window->userdata, state, button)) { -#if defined SEKIHI_PAUSE +#if defined STELA_PAUSE window->pending_refresh = true; #endif } @@ -85,10 +85,10 @@ void skh_window_send_key_event(struct skh_window *window, u8 state, u8 button) #endif } -void skh_window_send_resize_event(struct skh_window *window, s32 width, s32 height) +void stl_window_send_resize_event(struct stl_window *window, s32 width, s32 height) { -#if defined SEKIHI_EVENT_BUFFER - GET_EVENT_CHUNK(SEKIHI_EVENT_RESIZE); +#if defined STELA_EVENT_BUFFER + GET_EVENT_CHUNK(STELA_EVENT_RESIZE); ((s32 *)(&ptr[1]))[0] = width; ((s32 *)(&ptr[5]))[0] = height; APPEND_EVENT_CHUNK(); @@ -96,28 +96,28 @@ void skh_window_send_resize_event(struct skh_window *window, s32 width, s32 heig if (window->resize_callback) { window->resize_callback(window->userdata, width, height); } -#if defined SEKIHI_PAUSE +#if defined STELA_PAUSE window->pending_refresh = true; #endif #endif } -#if defined SEKIHI_POLL_INLINE -void skh_window_send_refresh_event(struct skh_window *window) +#if defined STELA_POLL_INLINE +void stl_window_send_refresh_event(struct stl_window *window) { if (window->refresh_callback) { window->refresh_callback(window->userdata); } -#if defined SEKIHI_PAUSE +#if defined STELA_PAUSE window->pending_refresh = true; #endif } #endif -void skh_window_send_should_close_event(struct skh_window *window) +void stl_window_send_should_close_event(struct stl_window *window) { -#if defined SEKIHI_EVENT_BUFFER - GET_EVENT_CHUNK(SEKIHI_EVENT_SHOULD_CLOSE); +#if defined STELA_EVENT_BUFFER + GET_EVENT_CHUNK(STELA_EVENT_SHOULD_CLOSE); APPEND_EVENT_CHUNK(); #else if (window->should_close_callback) { @@ -126,75 +126,75 @@ void skh_window_send_should_close_event(struct skh_window *window) #endif } -#if defined SEKIHI_EVENT_BUFFER -bool skh_window_read_events(struct skh_window *window) +#if defined STELA_EVENT_BUFFER +bool stl_window_read_events(struct stl_window *window) { - u8 op = SEKIHI_EVENT_NONE; + u8 op = STELA_EVENT_NONE; size_t size; u8 *ptr = al_ring_buffer_read_chunk(&window->events, &size); u8 *bc = ptr; while ((size_t)(bc - ptr) < size) { op = *bc; switch (op) { - case SEKIHI_EVENT_POINTER_POS: { + case STELA_EVENT_POINTER_POS: { f64 x = ((f64 *)(&bc[1]))[0]; f64 y = ((f64 *)(&bc[9]))[0]; if (window->pointer_pos_callback) { if (window->pointer_pos_callback(window->userdata, x, y)) { -#if defined SEKIHI_PAUSE +#if defined STELA_PAUSE window->pending_refresh = true; #endif } } break; } - case SEKIHI_EVENT_SCROLL: { + case STELA_EVENT_SCROLL: { f64 y = ((f64 *)(&bc[1]))[0]; if (window->scroll_callback) { if (window->scroll_callback(window->userdata, y)) { -#if defined SEKIHI_PAUSE +#if defined STELA_PAUSE window->pending_refresh = true; #endif } } break; } - case SEKIHI_EVENT_MOUSE_BUTTON: { + case STELA_EVENT_MOUSE_BUTTON: { u8 state = bc[1]; u8 button = bc[2]; if (window->mouse_button_callback) { if (window->mouse_button_callback(window->userdata, state, button)) { -#if defined SEKIHI_PAUSE +#if defined STELA_PAUSE window->pending_refresh = true; #endif } } break; } - case SEKIHI_EVENT_KEY: { + case STELA_EVENT_KEY: { u8 state = bc[1]; u8 button = bc[2]; if (window->key_callback) { if (window->key_callback(window->userdata, state, button)) { -#if defined SEKIHI_PAUSE +#if defined STELA_PAUSE window->pending_refresh = true; #endif } } break; } - case SEKIHI_EVENT_RESIZE: { + case STELA_EVENT_RESIZE: { s32 width = ((s32 *)(&bc[1]))[0]; s32 height = ((s32 *)(&bc[5]))[0]; if (window->resize_callback) { window->resize_callback(window->userdata, width, height); } -#if defined SEKIHI_PAUSE +#if defined STELA_PAUSE window->pending_refresh = true; #endif break; } - case SEKIHI_EVENT_SHOULD_CLOSE: { + case STELA_EVENT_SHOULD_CLOSE: { if (window->should_close_callback) { window->should_close_callback(window->userdata); } @@ -203,10 +203,10 @@ bool skh_window_read_events(struct skh_window *window) default: break; } - bc += SEKIHI_EVENT_SIZE; + bc += STELA_EVENT_SIZE; } al_assert((size_t)(bc - ptr) == size); al_ring_buffer_consume(&window->events, ptr, size); - return op != SEKIHI_EVENT_NONE; + return op != STELA_EVENT_NONE; } #endif diff --git a/src/window.h b/src/window.h index 753b062..7919983 100644 --- a/src/window.h +++ b/src/window.h @@ -1,16 +1,16 @@ #pragma once -#if !(defined(SEKIHI_API_NULL) || defined(SEKIHI_API_OPENGL) || \ - defined(SEKIHI_API_VULKAN) || defined(SEKIHI_API_DX11)) +#if !(defined(STELA_API_NULL) || defined(STELA_API_OPENGL) || \ + defined(STELA_API_VULKAN) || defined(STELA_API_DX11)) #error "No graphics API defined." #endif -#if defined(SEKIHI_API_NULL) + defined(SEKIHI_API_OPENGL) + \ - defined(SEKIHI_API_VULKAN) + defined(SEKIHI_API_DX11) != 1 +#if defined(STELA_API_NULL) + defined(STELA_API_OPENGL) + \ + defined(STELA_API_VULKAN) + defined(STELA_API_DX11) != 1 #error "Conflicting graphics APIs." #endif -#if !(defined(SEKIHI_POLL_FD) || defined(SEKIHI_POLL_INLINE)) +#if !(defined(STELA_POLL_FD) || defined(STELA_POLL_INLINE)) #error "No poll method defined." #endif @@ -19,84 +19,85 @@ #include <al/lib.h> #include <al/ring_buffer.h> -#if defined SEKIHI_API_VULKAN +#if defined STELA_API_VULKAN #include <vulkan/vulkan.h> #endif -#ifndef SEKIHI_MIN_WIDTH -#define SEKIHI_MIN_WIDTH 16 +#ifndef STELA_MIN_WIDTH +#define STELA_MIN_WIDTH 16 #endif -#ifndef SEKIHI_MIN_HEIGHT -#define SEKIHI_MIN_HEIGHT 16 +#ifndef STELA_MIN_HEIGHT +#define STELA_MIN_HEIGHT 16 #endif enum { - SEKIHI_WINDOW_VSYNC = 1, - SEKIHI_WINDOW_WALLPAPER = 1 << 1 + STELA_WINDOW_VSYNC = 1, + STELA_WINDOW_WALLPAPER = 1 << 1 }; -#define SEKIHI_MAX_MONITOR_NAME 255u +#define STELA_MAX_MONITOR_NAME 255u -struct skh_window; -struct skh_monitor { +struct stl_window; +struct stl_monitor { u32 x; u32 y; u32 width; u32 height; s32 scale; bool vertical; - char name[SEKIHI_MAX_MONITOR_NAME]; - struct skh_window *window; + char name[STELA_MAX_MONITOR_NAME]; + struct stl_window *window; }; -struct skh_window { +struct stl_window { s32 width; s32 height; + s32 scale; bool fullscreen; - array(struct skh_monitor *) monitors; -#if defined SEKIHI_EVENT_BUFFER + array(struct stl_monitor *) monitors; +#if defined STELA_EVENT_BUFFER u8 *data; // Render thread events. struct al_ring_buffer events; #endif -#if defined SEKIHI_PAUSE +#if defined STELA_PAUSE bool pending_refresh; #endif // Methods. - bool (*create_context)(struct skh_window *, s32); - bool (*create_window)(struct skh_window *, s32, s32, const char *, const char *, s32); - void (*resize)(struct skh_window *, s32, s32); - void (*toggle_fullscreen)(struct skh_window *); - void (*prepare_read)(struct skh_window *); -#if defined SEKIHI_POLL_FD - s32 (*get_poll_fd)(struct skh_window *); -#elif defined SEKIHI_POLL_INLINE - bool (*poll)(struct skh_window *, bool); -#if defined SEKIHI_PAUSE - void (*wake)(struct skh_window *); + bool (*create_context)(struct stl_window *, s32); + bool (*create_window)(struct stl_window *, s32, s32, const char *, const char *, s32); + void (*resize)(struct stl_window *, s32, s32); + void (*toggle_fullscreen)(struct stl_window *); + void (*prepare_read)(struct stl_window *); +#if defined STELA_POLL_FD + s32 (*get_poll_fd)(struct stl_window *); +#elif defined STELA_POLL_INLINE + bool (*poll)(struct stl_window *, bool); +#if defined STELA_PAUSE + void (*wake)(struct stl_window *); #endif #endif - void (*process_events)(struct skh_window *); -#if defined SEKIHI_PAUSE - bool (*should_refresh)(struct skh_window *); + void (*process_events)(struct stl_window *); +#if defined STELA_PAUSE + bool (*should_refresh)(struct stl_window *); #endif - void (*free)(struct skh_window **); + void (*free)(struct stl_window **); // Context specific. -#if defined SEKIHI_API_VULKAN +#if defined STELA_API_VULKAN VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL (*get_vk_proc_address)(VkInstance, const char *); VkResult (*vk_create_surface)(void *, VkInstance, VkSurfaceKHR *); const char *const *(*vk_get_extensions)(u32 *); -#elif defined SEKIHI_API_OPENGL +#elif defined STELA_API_OPENGL void (*(*get_gl_proc_address)(const char *))(void); bool (*gl_loader_load)(void *); bool (*gl_make_current)(void *); void (*gl_release_current)(void *); void (*gl_swap_buffers)(void *); -#elif defined SEKIHI_API_DX11 +#elif defined STELA_API_DX11 #endif // Callbacks. - void (*output_discovered_callback)(void *, struct skh_monitor *); + void (*output_discovered_callback)(void *, struct stl_monitor *); bool (*pointer_pos_callback)(void *, f64, f64); bool (*scroll_callback)(void *, f64); bool (*mouse_button_callback)(void *, u8, u8); @@ -110,41 +111,41 @@ struct skh_window { }; enum { - SEKIHI_EVENT_POINTER_POS = 0, - SEKIHI_EVENT_SCROLL, - SEKIHI_EVENT_MOUSE_BUTTON, - SEKIHI_EVENT_KEY, - SEKIHI_EVENT_RESIZE, - SEKIHI_EVENT_SHOULD_CLOSE, - SEKIHI_EVENT_NONE = 255 + STELA_EVENT_POINTER_POS = 0, + STELA_EVENT_SCROLL, + STELA_EVENT_MOUSE_BUTTON, + STELA_EVENT_KEY, + STELA_EVENT_RESIZE, + STELA_EVENT_SHOULD_CLOSE, + STELA_EVENT_NONE = 255 }; enum { - SEKIHI_BUTTON_PRESSED = 0, - SEKIHI_BUTTON_RELEASED + STELA_BUTTON_PRESSED = 0, + STELA_BUTTON_RELEASED }; enum { - SEKIHI_MOUSE1 = 0, - SEKIHI_MOUSE2, - SEKIHI_MOUSE3 + STELA_MOUSE1 = 0, + STELA_MOUSE2, + STELA_MOUSE3 }; -#define SEKIHI_EVENT_SIZE 32 -#ifndef SEKIHI_EVENTS_SIZE -#define SEKIHI_EVENTS_SIZE (SEKIHI_EVENT_SIZE * 288) +#define STELA_EVENT_SIZE 32 +#ifndef STELA_EVENTS_SIZE +#define STELA_EVENTS_SIZE (STELA_EVENT_SIZE * 288) #endif -struct skh_window *skh_window_create(void); -void skh_window_send_pointer_pos_event(struct skh_window *window, f64 x, f64 y); -void skh_window_send_scroll_event(struct skh_window *window, f64 y); -void skh_window_send_mouse_button_event(struct skh_window *window, u8 state, u8 button); -void skh_window_send_key_event(struct skh_window *window, u8 state, u8 button); -void skh_window_send_resize_event(struct skh_window *window, s32 width, s32 height); -#if defined SEKIHI_POLL_INLINE -void skh_window_send_refresh_event(struct skh_window *window); +struct stl_window *stl_window_create(void); +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); +void stl_window_send_key_event(struct stl_window *window, u8 state, u8 button); +void stl_window_send_resize_event(struct stl_window *window, s32 width, s32 height); +#if defined STELA_POLL_INLINE +void stl_window_send_refresh_event(struct stl_window *window); #endif -void skh_window_send_should_close_event(struct skh_window *window); -#if defined SEKIHI_EVENT_BUFFER -bool skh_window_read_events(struct skh_window *window); +void stl_window_send_should_close_event(struct stl_window *window); +#if defined STELA_EVENT_BUFFER +bool stl_window_read_events(struct stl_window *window); #endif diff --git a/src/window_glfw.c b/src/window_glfw.c index 3858515..7697729 100644 --- a/src/window_glfw.c +++ b/src/window_glfw.c @@ -4,16 +4,16 @@ #include "window_glfw.h" #include "common.h" -#if defined SEKIHI_API_OPENGL -#define SEKIHI_GL_API GLFW_OPENGL_API -#define SEKIHI_GLES_API GLFW_OPENGL_ES_API +#if defined STELA_API_OPENGL +#define STELA_GL_API GLFW_OPENGL_API +#define STELA_GLES_API GLFW_OPENGL_ES_API // Unused. -#define SEKIHI_GL_BIT 0 -#define SEKIHI_GLES2_BIT 0 -#define SEKIHI_GLES3_BIT 0 +#define STELA_GL_BIT 0 +#define STELA_GLES2_BIT 0 +#define STELA_GLES3_BIT 0 -#define SEKIHI_GL_CORE_PROFILE_BIT GLFW_OPENGL_CORE_PROFILE +#define STELA_GL_CORE_PROFILE_BIT GLFW_OPENGL_CORE_PROFILE #include "gl_versions.h" @@ -22,68 +22,68 @@ PASTE_GL_VERSIONS() static void key_callback(GLFWwindow *window, s32 key, s32 scancode, s32 action, s32 mods) { - struct skh_window_glfw *glfw = glfwGetWindowUserPointer(window); + struct stl_window_glfw *glfw = glfwGetWindowUserPointer(window); (void)key; (void)mods; if (action == GLFW_PRESS) { - skh_window_send_key_event(&glfw->w, SEKIHI_BUTTON_PRESSED, scancode); + stl_window_send_key_event(&glfw->w, STELA_BUTTON_PRESSED, scancode); } else if (action == GLFW_RELEASE) { - skh_window_send_key_event(&glfw->w, SEKIHI_BUTTON_RELEASED, scancode); + stl_window_send_key_event(&glfw->w, STELA_BUTTON_RELEASED, scancode); } } static void cursor_position_callback(GLFWwindow *window, f64 xpos, f64 ypos) { - struct skh_window_glfw *glfw = glfwGetWindowUserPointer(window); - skh_window_send_pointer_pos_event(&glfw->w, xpos, ypos); + struct stl_window_glfw *glfw = glfwGetWindowUserPointer(window); + stl_window_send_pointer_pos_event(&glfw->w, xpos, ypos); } static void mouse_button_callback(GLFWwindow *window, s32 button, s32 action, s32 mods) { - struct skh_window_glfw *glfw = glfwGetWindowUserPointer(window); + struct stl_window_glfw *glfw = glfwGetWindowUserPointer(window); (void)mods; if (button == GLFW_MOUSE_BUTTON_1) { if (action == GLFW_PRESS) { - skh_window_send_mouse_button_event(&glfw->w, SEKIHI_BUTTON_PRESSED, SEKIHI_MOUSE1); + stl_window_send_mouse_button_event(&glfw->w, STELA_BUTTON_PRESSED, STELA_MOUSE1); } else if (action == GLFW_RELEASE) { - skh_window_send_mouse_button_event(&glfw->w, SEKIHI_BUTTON_RELEASED, SEKIHI_MOUSE1); + stl_window_send_mouse_button_event(&glfw->w, STELA_BUTTON_RELEASED, STELA_MOUSE1); } } } static void scroll_callback(GLFWwindow *window, f64 xoffset, f64 yoffset) { - struct skh_window_glfw *glfw = glfwGetWindowUserPointer(window); + struct stl_window_glfw *glfw = glfwGetWindowUserPointer(window); (void)xoffset; - skh_window_send_scroll_event(&glfw->w, -yoffset); + stl_window_send_scroll_event(&glfw->w, -yoffset); } static void resize_callback(GLFWwindow *window, s32 width, s32 height) { - struct skh_window_glfw *glfw = glfwGetWindowUserPointer(window); + struct stl_window_glfw *glfw = glfwGetWindowUserPointer(window); glfw->w.width = width; glfw->w.height = height; - skh_window_send_resize_event(&glfw->w, width, height); + stl_window_send_resize_event(&glfw->w, width, height); } -#if defined SEKIHI_POLL_INLINE +#if defined STELA_POLL_INLINE static void refresh_callback(GLFWwindow *window) { - struct skh_window_glfw *glfw = glfwGetWindowUserPointer(window); - skh_window_send_refresh_event(&glfw->w); + struct stl_window_glfw *glfw = glfwGetWindowUserPointer(window); + stl_window_send_refresh_event(&glfw->w); } #endif static void close_callback(GLFWwindow *window) { - struct skh_window_glfw *glfw = glfwGetWindowUserPointer(window); - skh_window_send_should_close_event(&glfw->w); + struct stl_window_glfw *glfw = glfwGetWindowUserPointer(window); + stl_window_send_should_close_event(&glfw->w); } -static bool window_glfw_create_window(struct skh_window *window, s32 width, s32 height, +static bool window_glfw_create_window(struct stl_window *window, s32 width, s32 height, const char *monitor, const char *name, s32 flags) { - struct skh_window_glfw *glfw = (struct skh_window_glfw *)window; + struct stl_window_glfw *glfw = (struct stl_window_glfw *)window; (void)monitor; if (!glfwInit()) { @@ -91,16 +91,16 @@ static bool window_glfw_create_window(struct skh_window *window, s32 width, s32 return false; } -#if defined SEKIHI_API_VULKAN || defined SEKIHI_API_DX11 +#if defined STELA_API_VULKAN || defined STELA_API_DX11 glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); -#elif defined SEKIHI_API_OPENGL +#elif defined STELA_API_OPENGL glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_NATIVE_CONTEXT_API); - for (u32 i = 0; i < AL_ARRAY_SIZE(skh_gl_vers); i++) { - glfwWindowHint(GLFW_CLIENT_API, skh_gl_vers[i].api); - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, skh_gl_vers[i].major); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, skh_gl_vers[i].minor); - if (skh_gl_vers[i].api == SEKIHI_GL_API) { - glfwWindowHint(GLFW_OPENGL_PROFILE, skh_gl_vers[i].profile); + for (u32 i = 0; i < AL_ARRAY_SIZE(stl_gl_vers); i++) { + glfwWindowHint(GLFW_CLIENT_API, stl_gl_vers[i].api); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, stl_gl_vers[i].major); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, stl_gl_vers[i].minor); + if (stl_gl_vers[i].api == STELA_GL_API) { + glfwWindowHint(GLFW_OPENGL_PROFILE, stl_gl_vers[i].profile); } #ifdef __APPLE__ if (gl_vers[i].profile == GLFW_OPENGL_CORE_PROFILE) { @@ -108,11 +108,11 @@ static bool window_glfw_create_window(struct skh_window *window, s32 width, s32 } #endif al_log_info("glfw", "Trying to make a %s context of version %i.%i (GLSL %i).", - skh_gl_vers[i].api == SEKIHI_GL_API ? "GL" : "GLES", - skh_gl_vers[i].major, skh_gl_vers[i].minor, skh_gl_vers[i].glsl_ver); + 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, NULL); -#if defined SEKIHI_API_OPENGL +#if defined STELA_API_OPENGL if (glfw->window) { al_log_info("glfw", "Context successfully created."); break; @@ -127,11 +127,11 @@ static bool window_glfw_create_window(struct skh_window *window, s32 width, s32 } glfwMakeContextCurrent(glfw->window); - glfwSwapInterval((flags & SEKIHI_WINDOW_VSYNC) ? 1 : 0); + glfwSwapInterval((flags & STELA_WINDOW_VSYNC) ? 1 : 0); glfwMakeContextCurrent(NULL); glfwGetFramebufferSize(glfw->window, &glfw->w.width, &glfw->w.height); - glfwSetWindowSizeLimits(glfw->window, SEKIHI_MIN_WIDTH, SEKIHI_MIN_HEIGHT, GLFW_DONT_CARE, GLFW_DONT_CARE); + glfwSetWindowSizeLimits(glfw->window, STELA_MIN_WIDTH, STELA_MIN_HEIGHT, GLFW_DONT_CARE, GLFW_DONT_CARE); glfwSetWindowUserPointer(glfw->window, glfw); @@ -140,7 +140,7 @@ static bool window_glfw_create_window(struct skh_window *window, s32 width, s32 glfwSetMouseButtonCallback(glfw->window, mouse_button_callback); glfwSetScrollCallback(glfw->window, scroll_callback); glfwSetFramebufferSizeCallback(glfw->window, resize_callback); -#if defined SEKIHI_POLL_INLINE +#if defined STELA_POLL_INLINE glfwSetWindowRefreshCallback(glfw->window, refresh_callback); #endif glfwSetWindowCloseCallback(glfw->window, close_callback); @@ -148,9 +148,9 @@ static bool window_glfw_create_window(struct skh_window *window, s32 width, s32 return true; } -static void window_glfw_resize(struct skh_window *window, s32 width, s32 height) +static void window_glfw_resize(struct stl_window *window, s32 width, s32 height) { - struct skh_window_glfw *glfw = (struct skh_window_glfw *)window; + struct stl_window_glfw *glfw = (struct stl_window_glfw *)window; glfwSetWindowAspectRatio(glfw->window, width, height); glfwSetWindowSize(glfw->window, width, height); } @@ -195,9 +195,9 @@ static GLFWmonitor *get_current_monitor(GLFWwindow *window) return best_monitor; } -static void window_glfw_toggle_fullscreen(struct skh_window *window) +static void window_glfw_toggle_fullscreen(struct stl_window *window) { - struct skh_window_glfw *glfw = (struct skh_window_glfw *)window; + struct stl_window_glfw *glfw = (struct stl_window_glfw *)window; if (!glfw->w.fullscreen) { glfwGetWindowPos(glfw->window, &glfw->prev_state.x, &glfw->prev_state.y); glfw->prev_state.width = glfw->w.width; @@ -214,14 +214,14 @@ static void window_glfw_toggle_fullscreen(struct skh_window *window) glfw->w.fullscreen = !glfw->w.fullscreen; } -#if defined SEKIHI_POLL_FD -static s32 window_glfw_get_poll_fd(struct skh_window *window) +#if defined STELA_POLL_FD +static s32 window_glfw_get_poll_fd(struct stl_window *window) { (void)window; return -1; } -#elif defined SEKIHI_POLL_INLINE -static bool window_glfw_poll(struct skh_window *window, bool block) +#elif defined STELA_POLL_INLINE +static bool window_glfw_poll(struct stl_window *window, bool block) { (void)window; if (block) glfwWaitEvents(); @@ -229,36 +229,36 @@ static bool window_glfw_poll(struct skh_window *window, bool block) return true; } -#if defined SEKIHI_PAUSE -static void window_glfw_wake(struct skh_window *window) +#if defined STELA_PAUSE +static void window_glfw_wake(struct stl_window *window) { - struct skh_window_glfw *glfw = (struct skh_window_glfw *)window; + struct stl_window_glfw *glfw = (struct stl_window_glfw *)window; glfw->w.pending_refresh = true; glfwPostEmptyEvent(); } #endif #endif -static void window_glfw_process_events(struct skh_window *window) +static void window_glfw_process_events(struct stl_window *window) { (void)window; } -#if defined SEKIHI_PAUSE -static bool window_glfw_should_refresh(struct skh_window *window) +#if defined STELA_PAUSE +static bool window_glfw_should_refresh(struct stl_window *window) { - return skh_should_refresh_common(window); + return stl_should_refresh_common(window); } #endif -static void window_glfw_free(struct skh_window **window) +static void window_glfw_free(struct stl_window **window) { - struct skh_window_glfw *glfw = (struct skh_window_glfw *)*window; + struct stl_window_glfw *glfw = (struct stl_window_glfw *)*window; if (glfw->window) { glfwDestroyWindow(glfw->window); glfwTerminate(); } -#if defined SEKIHI_EVENT_BUFFER +#if defined STELA_EVENT_BUFFER al_free(glfw->w.data); #endif al_array_free(glfw->w.monitors); @@ -266,7 +266,7 @@ static void window_glfw_free(struct skh_window **window) *window = NULL; } -#if defined SEKIHI_API_VULKAN +#if defined STELA_API_VULKAN static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL window_glfw_get_vk_proc_address(VkInstance inst, const char *name) { return (PFN_vkVoidFunction)glfwGetInstanceProcAddress(inst, name); @@ -274,7 +274,7 @@ static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL window_glfw_get_vk_proc_address( static VkResult window_glfw_vk_create_surface(void *data, VkInstance inst, VkSurfaceKHR *surface) { - struct skh_window_glfw *glfw = (struct skh_window_glfw *)data; + struct stl_window_glfw *glfw = (struct stl_window_glfw *)data; return glfwCreateWindowSurface(inst, glfw->window, NULL, surface); } @@ -282,11 +282,11 @@ static const char *const *window_glfw_vk_get_extensions(u32 *num) { return glfwGetRequiredInstanceExtensions(num); } -#elif defined SEKIHI_API_OPENGL +#elif defined STELA_API_OPENGL static bool window_glfw_gl_loader_load(void *data) { - struct skh_window_glfw *glfw = (struct skh_window_glfw *)data; - if (!skh_gl_loader_load(glfw->w.get_gl_proc_address)) { + struct stl_window_glfw *glfw = (struct stl_window_glfw *)data; + if (!stl_gl_loader_load(glfw->w.get_gl_proc_address)) { return false; } return true; @@ -294,7 +294,7 @@ static bool window_glfw_gl_loader_load(void *data) static bool window_glfw_gl_make_current(void *data) { - struct skh_window_glfw *glfw = (struct skh_window_glfw *)data; + struct stl_window_glfw *glfw = (struct stl_window_glfw *)data; glfwMakeContextCurrent(glfw->window); return true; } @@ -307,19 +307,19 @@ static void window_glfw_gl_release_current(void *data) static void window_glfw_gl_swap_buffers(void *data) { - struct skh_window_glfw *glfw = (struct skh_window_glfw *)data; + struct stl_window_glfw *glfw = (struct stl_window_glfw *)data; glfwSwapBuffers(glfw->window); } #endif -struct skh_window *skh_window_glfw_create(void) +struct stl_window *stl_window_glfw_create(void) { - struct skh_window_glfw *glfw = al_alloc_object(struct skh_window_glfw); -#if defined SEKIHI_EVENT_BUFFER - glfw->w.data = al_malloc(SEKIHI_EVENTS_SIZE); - al_ring_buffer_init(&glfw->w.events, glfw->w.data, SEKIHI_EVENTS_SIZE); + struct stl_window_glfw *glfw = al_alloc_object(struct stl_window_glfw); +#if defined STELA_EVENT_BUFFER + glfw->w.data = al_malloc(STELA_EVENTS_SIZE); + al_ring_buffer_init(&glfw->w.events, glfw->w.data, STELA_EVENTS_SIZE); #endif -#if defined SEKIHI_PAUSE +#if defined STELA_PAUSE glfw->w.pending_refresh = true; #endif glfw->w.fullscreen = false; @@ -328,30 +328,30 @@ struct skh_window *skh_window_glfw_create(void) glfw->w.create_window = window_glfw_create_window; glfw->w.resize = window_glfw_resize; glfw->w.toggle_fullscreen = window_glfw_toggle_fullscreen; -#if defined SEKIHI_POLL_FD +#if defined STELA_POLL_FD glfw->w.get_poll_fd = window_glfw_get_poll_fd; -#elif defined SEKIHI_POLL_INLINE +#elif defined STELA_POLL_INLINE glfw->w.poll = window_glfw_poll; -#if defined SEKIHI_PAUSE +#if defined STELA_PAUSE glfw->w.wake = window_glfw_wake; #endif #endif glfw->w.process_events = window_glfw_process_events; -#if defined SEKIHI_PAUSE +#if defined STELA_PAUSE glfw->w.should_refresh = window_glfw_should_refresh; #endif glfw->w.free = window_glfw_free; -#if defined SEKIHI_API_VULKAN +#if defined STELA_API_VULKAN glfw->w.get_vk_proc_address = window_glfw_get_vk_proc_address; glfw->w.vk_create_surface = window_glfw_vk_create_surface; glfw->w.vk_get_extensions = window_glfw_vk_get_extensions; -#elif defined SEKIHI_API_OPENGL +#elif defined STELA_API_OPENGL glfw->w.get_gl_proc_address = glfwGetProcAddress; glfw->w.gl_loader_load = window_glfw_gl_loader_load; glfw->w.gl_make_current = window_glfw_gl_make_current; glfw->w.gl_release_current = window_glfw_gl_release_current; glfw->w.gl_swap_buffers = window_glfw_gl_swap_buffers; -#elif defined SEKIHI_API_DX11 +#elif defined STELA_API_DX11 #endif - return (struct skh_window *)glfw; + return (struct stl_window *)glfw; } diff --git a/src/window_glfw.h b/src/window_glfw.h index c352a9b..2810f2c 100644 --- a/src/window_glfw.h +++ b/src/window_glfw.h @@ -1,6 +1,6 @@ #pragma once -#if defined SEKIHI_API_VULKAN +#if defined STELA_API_VULKAN #define GLFW_INCLUDE_VULKAN #else #include "gl_common.h" @@ -13,8 +13,8 @@ #include "window.h" -struct skh_window_glfw { - struct skh_window w; +struct stl_window_glfw { + struct stl_window w; GLFWwindow *window; struct { s32 x; @@ -24,4 +24,4 @@ struct skh_window_glfw { } prev_state; }; -struct skh_window *skh_window_glfw_create(void); +struct stl_window *stl_window_glfw_create(void); diff --git a/src/window_wayland.c b/src/window_wayland.c index 6ee5b7a..fdb072f 100644 --- a/src/window_wayland.c +++ b/src/window_wayland.c @@ -18,7 +18,7 @@ static const struct xdg_wm_base_listener xdg_wm_base_listener = { static void pointer_enter(void *data, struct wl_pointer *pointer, u32 serial, struct wl_surface *surface, wl_fixed_t surface_x, wl_fixed_t surface_y) { - struct skh_window_wayland *wl = (struct skh_window_wayland *)data; + struct stl_window_wayland *wl = (struct stl_window_wayland *)data; (void)pointer; (void)surface; if (wl->cursor_shape_device) { @@ -26,8 +26,8 @@ static void pointer_enter(void *data, struct wl_pointer *pointer, } (void)surface_x; (void)surface_y; - //wl->pointer_x = wl_fixed_to_double(surface_x); - //wl->pointer_y = wl_fixed_to_double(surface_y); + wl->pointer_x = wl_fixed_to_double(surface_x) * wl->w.scale; + wl->pointer_y = wl_fixed_to_double(surface_y) * wl->w.scale; } static void pointer_leave(void *data, struct wl_pointer *pointer, @@ -42,18 +42,17 @@ static void pointer_leave(void *data, struct wl_pointer *pointer, static void pointer_motion(void *data, struct wl_pointer *pointer, u32 time, wl_fixed_t surface_x, wl_fixed_t surface_y) { - struct skh_window_wayland *wl = (struct skh_window_wayland *)data; + struct stl_window_wayland *wl = (struct stl_window_wayland *)data; (void)pointer; (void)time; - skh_window_send_pointer_pos_event(&wl->w, wl_fixed_to_double(surface_x), wl_fixed_to_double(surface_y)); - //wl->pointer_x += wl_fixed_to_double(surface_x); - //wl->pointer_y += wl_fixed_to_double(surface_y); + wl->pointer_x += wl_fixed_to_double(surface_x) * wl->w.scale; + wl->pointer_y += wl_fixed_to_double(surface_y) * wl->w.scale; } static void pointer_button(void *data, struct wl_pointer *pointer, u32 serial, u32 time, u32 button, u32 state) { - struct skh_window_wayland *wl = (struct skh_window_wayland *)data; + struct stl_window_wayland *wl = (struct stl_window_wayland *)data; (void)pointer; (void)time; #define MOUSE1 0x110 @@ -61,25 +60,25 @@ static void pointer_button(void *data, struct wl_pointer *pointer, #define MOUSE3 0x112 if (button == MOUSE1) { if (state == WL_POINTER_BUTTON_STATE_PRESSED) { - skh_window_send_mouse_button_event(&wl->w, SEKIHI_BUTTON_PRESSED, SEKIHI_MOUSE1); + stl_window_send_mouse_button_event(&wl->w, STELA_BUTTON_PRESSED, STELA_MOUSE1); } else if (state == WL_POINTER_BUTTON_STATE_RELEASED) { - skh_window_send_mouse_button_event(&wl->w, SEKIHI_BUTTON_RELEASED, SEKIHI_MOUSE1); + stl_window_send_mouse_button_event(&wl->w, STELA_BUTTON_RELEASED, STELA_MOUSE1); } } else if (button == MOUSE2) { if (wl->xdg_toplevel) { xdg_toplevel_move(wl->xdg_toplevel, wl->seat, serial); } else { if (state == WL_POINTER_BUTTON_STATE_PRESSED) { - skh_window_send_mouse_button_event(&wl->w, SEKIHI_BUTTON_PRESSED, SEKIHI_MOUSE2); + stl_window_send_mouse_button_event(&wl->w, STELA_BUTTON_PRESSED, STELA_MOUSE2); } else if (state == WL_POINTER_BUTTON_STATE_RELEASED) { - skh_window_send_mouse_button_event(&wl->w, SEKIHI_BUTTON_RELEASED, SEKIHI_MOUSE2); + stl_window_send_mouse_button_event(&wl->w, STELA_BUTTON_RELEASED, STELA_MOUSE2); } } } else if (button == MOUSE3) { if (state == WL_POINTER_BUTTON_STATE_PRESSED) { - skh_window_send_mouse_button_event(&wl->w, SEKIHI_BUTTON_PRESSED, SEKIHI_MOUSE3); + stl_window_send_mouse_button_event(&wl->w, STELA_BUTTON_PRESSED, STELA_MOUSE3); } else if (state == WL_POINTER_BUTTON_STATE_RELEASED) { - skh_window_send_mouse_button_event(&wl->w, SEKIHI_BUTTON_RELEASED, SEKIHI_MOUSE3); + stl_window_send_mouse_button_event(&wl->w, STELA_BUTTON_RELEASED, STELA_MOUSE3); } } } @@ -87,36 +86,30 @@ static void pointer_button(void *data, struct wl_pointer *pointer, static void pointer_axis(void *data, struct wl_pointer *pointer, u32 time, u32 axis, wl_fixed_t value) { - struct skh_window_wayland *wl = (struct skh_window_wayland *)data; + struct stl_window_wayland *wl = (struct stl_window_wayland *)data; (void)pointer; (void)time; - // When using a seat version that supports high resolution scrolling (>4), - // there's some kind of unexplained difference in behavior here. if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) { - //wl->scroll_y += wl_fixed_to_double(value); - skh_window_send_scroll_event(&wl->w, wl_fixed_to_double(value)); + wl->scroll_y += wl_fixed_to_double(value); } else if (axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL) { - //wl->scroll_x += wl_fixed_to_double(value); + wl->scroll_x += wl_fixed_to_double(value); } } static void pointer_frame(void *data, struct wl_pointer *pointer) { - struct skh_window_wayland *wl = (struct skh_window_wayland *)data; + struct stl_window_wayland *wl = (struct stl_window_wayland *)data; (void)wl; (void)pointer; - /* if (wl->pointer_x || wl->pointer_y) { - skh_window_send_pointer_pos_event(&wl->w, wl->pointer_x, wl->pointer_y); + stl_window_send_pointer_pos_event(&wl->w, wl->pointer_x, wl->pointer_y); + wl->pointer_x = 0.0; + wl->pointer_y = 0.0; } if (wl->scroll_y) { - skh_window_send_scroll_event(&wl->w, wl->scroll_y); + stl_window_send_scroll_event(&wl->w, wl->scroll_y); + wl->scroll_y = 0.0; } - wl->pointer_x = 0.0; - wl->pointer_y = 0.0; - wl->scroll_x = 0.0; - wl->scroll_y = 0.0; - */ } static void pointer_axis_source(void *data, struct wl_pointer *pointer, @@ -209,14 +202,14 @@ static void keyboard_leave(void *data, struct wl_keyboard *keyboard, static void keyboard_key(void *data, struct wl_keyboard *keyboard, u32 serial, u32 time, u32 key, u32 state) { - struct skh_window_wayland *wl = (struct skh_window_wayland *)data; + struct stl_window_wayland *wl = (struct stl_window_wayland *)data; (void)serial; (void)keyboard; (void)time; if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { - skh_window_send_key_event(&wl->w, SEKIHI_BUTTON_PRESSED, key); + stl_window_send_key_event(&wl->w, STELA_BUTTON_PRESSED, key); } else if (state == WL_KEYBOARD_KEY_STATE_RELEASED) { - skh_window_send_key_event(&wl->w, SEKIHI_BUTTON_RELEASED, key); + stl_window_send_key_event(&wl->w, STELA_BUTTON_RELEASED, key); } } @@ -251,7 +244,7 @@ static const struct wl_keyboard_listener keyboard_listener = { static void seat_capabilities(void *data, struct wl_seat *seat, u32 capabilities) { - struct skh_window_wayland *wl = (struct skh_window_wayland *)data; + struct stl_window_wayland *wl = (struct stl_window_wayland *)data; (void)seat; if (capabilities & WL_SEAT_CAPABILITY_POINTER) { @@ -298,7 +291,7 @@ static void handle_output_geometry(void *data, struct wl_output *output, s32 x, s32 y, s32 width_mm, s32 height_mm, s32 subpixel, const char *make, const char *model, s32 transform) { - struct skh_monitor_wayland *monitor = (struct skh_monitor_wayland *)data; + struct stl_monitor_wayland *monitor = (struct stl_monitor_wayland *)data; (void)output; (void)x; (void)y; @@ -323,7 +316,7 @@ static void handle_output_geometry(void *data, struct wl_output *output, static void handle_output_mode(void *data, struct wl_output *output, u32 flags, s32 width, s32 height, s32 refresh) { - struct skh_monitor_wayland *monitor = (struct skh_monitor_wayland *)data; + struct stl_monitor_wayland *monitor = (struct stl_monitor_wayland *)data; (void)output; (void)flags; (void)refresh; @@ -338,18 +331,18 @@ static void handle_output_mode(void *data, struct wl_output *output, static void handle_output_done(void *data, struct wl_output *output) { - struct skh_monitor_wayland *monitor = (struct skh_monitor_wayland *)data; + struct stl_monitor_wayland *monitor = (struct stl_monitor_wayland *)data; (void)output; + al_log_info("window_wayland", "Output discovered: %s (%ux%u) (vertical: %s).", + monitor->m.name, monitor->m.width, monitor->m.height, AL_BOOLSTR(monitor->m.vertical)); if (monitor->m.window->output_discovered_callback) { - al_log_info("window_wayland", "Output discovered: %s (%ux%u) (vertical: %s).", - monitor->m.name, monitor->m.width, monitor->m.height, monitor->m.vertical ? "true" : "false"); - monitor->m.window->output_discovered_callback(monitor->m.window->userdata, (struct skh_monitor *)monitor); + monitor->m.window->output_discovered_callback(monitor->m.window->userdata, (struct stl_monitor *)monitor); } } static void handle_output_scale(void *data, struct wl_output *output, s32 factor) { - struct skh_monitor_wayland *monitor = (struct skh_monitor_wayland *)data; + struct stl_monitor_wayland *monitor = (struct stl_monitor_wayland *)data; (void)output; monitor->m.scale = factor; } @@ -363,10 +356,10 @@ static void handle_output_description(void *data, struct wl_output *output, cons static void handle_output_name(void *data, struct wl_output *output, const char *name) { - struct skh_monitor_wayland *monitor = (struct skh_monitor_wayland *)data; + struct stl_monitor_wayland *monitor = (struct stl_monitor_wayland *)data; (void)output; size_t len = strlen(name) + 1; - al_memcpy(monitor->m.name, name, AL_MIN(len, SEKIHI_MAX_MONITOR_NAME)); + al_memcpy(monitor->m.name, name, AL_MIN(len, STELA_MAX_MONITOR_NAME)); } static const struct wl_output_listener output_listener = { @@ -381,7 +374,7 @@ static const struct wl_output_listener output_listener = { /* static void handle_xdg_output_logical_position(void *data, struct zxdg_output_v1 *output, s32 x, s32 y) { - struct skh_monitor_wayland *monitor = (struct skh_monitor_wayland *)data; + struct stl_monitor_wayland *monitor = (struct stl_monitor_wayland *)data; (void)output; monitor->m.x = x; monitor->m.y = y; @@ -445,7 +438,7 @@ static const struct zwlr_foreign_toplevel_manager_v1_listener toplevel_manager_l static void presentation_set_clock_id(void *data, struct wp_presentation *presentation, u32 clock_id) { - struct skh_window_wayland *wl = (struct skh_window_wayland *)data; + struct stl_window_wayland *wl = (struct stl_window_wayland *)data; al_assert(clock_id == CLOCK_MONOTONIC); wl->presentation = presentation; } @@ -457,17 +450,16 @@ static const struct wp_presentation_listener presentation_listener = { static void global_add(void *data, struct wl_registry *registry, u32 name, const char *interface, u32 version) { - struct skh_window_wayland *wl = (struct skh_window_wayland *)data; + struct stl_window_wayland *wl = (struct stl_window_wayland *)data; if (strcmp(interface, wl_compositor_interface.name) == 0) { wl->compositor = wl_registry_bind(registry, name, &wl_compositor_interface, AL_MIN(5u, version)); } else if (strcmp(interface, wl_seat_interface.name) == 0) { - wl->seat = wl_registry_bind(registry, name, &wl_seat_interface, AL_MIN(4u, version)); - //wl->seat = wl_registry_bind(registry, name, &wl_seat_interface, AL_MIN(8u, version)); + wl->seat = wl_registry_bind(registry, name, &wl_seat_interface, AL_MIN(8u, version)); wl_seat_add_listener(wl->seat, &seat_listener, wl); } else if (strcmp(interface, wl_output_interface.name) == 0) { - struct skh_monitor_wayland *monitor = al_alloc_object(struct skh_monitor_wayland); - monitor->m.window = (struct skh_window *)wl; - al_array_push(wl->w.monitors, (struct skh_monitor *)monitor); + struct stl_monitor_wayland *monitor = al_alloc_object(struct stl_monitor_wayland); + monitor->m.window = (struct stl_window *)wl; + al_array_push(wl->w.monitors, (struct stl_monitor *)monitor); monitor->output = wl_registry_bind(registry, name, &wl_output_interface, AL_MIN(4u, version)); wl_output_add_listener(monitor->output, &output_listener, monitor); // monitor->xdg_output = zxdg_output_manager_v1_get_xdg_output(wl->zxdg_output_manager, monitor->output); @@ -539,8 +531,10 @@ static const struct wl_surface_listener surface_listener = { .preferred_buffer_transform = preferred_buffer_transform }; -static bool check_and_set_dimensions(struct skh_window_wayland *wl, s32 width, s32 height) +static bool check_and_set_dimensions(struct stl_window_wayland *wl, s32 width, s32 height) { + width *= wl->w.scale; + height *= wl->w.scale; if (!width || !height || (width == wl->w.width && height == wl->w.height)) { return false; } @@ -549,23 +543,23 @@ static bool check_and_set_dimensions(struct skh_window_wayland *wl, s32 width, s return true; } -static void send_resize_internal(struct skh_window_wayland *wl) +static void send_resize_internal(struct stl_window_wayland *wl) { -#if defined SEKIHI_API_OPENGL - if (skh_egl_is_ready(&wl->egl)) { +#if defined STELA_API_OPENGL + if (stl_egl_is_ready(&wl->egl)) { wl_egl_window_resize(wl->egl_window, wl->w.width, wl->w.height, 0, 0); } #endif - skh_window_send_resize_event(&wl->w, wl->w.width, wl->w.height); + stl_window_send_resize_event(&wl->w, wl->w.width, wl->w.height); wl->pending = false; } static void handle_xdg_surface_configure(void *data, struct xdg_surface *surface, u32 serial) { - struct skh_window_wayland *wl = (struct skh_window_wayland *)data; + struct stl_window_wayland *wl = (struct stl_window_wayland *)data; if (wl->pending) { - xdg_surface_set_window_geometry(wl->xdg_surface, 0, 0, wl->w.width, wl->w.height); send_resize_internal(wl); + xdg_surface_set_window_geometry(wl->xdg_surface, 0, 0, wl->w.width, wl->w.height); } xdg_surface_ack_configure(surface, serial); } @@ -577,7 +571,7 @@ static const struct xdg_surface_listener xdg_surface_listener = { static void handle_xdg_toplevel_configure(void *data, struct xdg_toplevel *toplevel, s32 width, s32 height, struct wl_array *states) { - struct skh_window_wayland *wl = (struct skh_window_wayland *)data; + struct stl_window_wayland *wl = (struct stl_window_wayland *)data; (void)toplevel; (void)states; wl->pending = check_and_set_dimensions(wl, width, height); @@ -585,9 +579,9 @@ static void handle_xdg_toplevel_configure(void *data, struct xdg_toplevel *tople static void handle_xdg_toplevel_close(void *data, struct xdg_toplevel *toplevel) { - struct skh_window_wayland *wl = (struct skh_window_wayland *)data; + struct stl_window_wayland *wl = (struct stl_window_wayland *)data; (void)toplevel; - skh_window_send_should_close_event(&wl->w); + stl_window_send_should_close_event(&wl->w); } static void handle_xdg_toplevel_configure_bounds(void *data, struct xdg_toplevel *toplevel, s32 width, s32 height) @@ -616,7 +610,7 @@ static const struct xdg_toplevel_listener xdg_toplevel_listener = { static void handle_layer_surface_configure(void *data, struct zwlr_layer_surface_v1 *surface, u32 serial, u32 width, u32 height) { - struct skh_window_wayland *wl = (struct skh_window_wayland *)data; + struct stl_window_wayland *wl = (struct stl_window_wayland *)data; if (check_and_set_dimensions(wl, width, height)) { send_resize_internal(wl); } @@ -625,9 +619,9 @@ static void handle_layer_surface_configure(void *data, struct zwlr_layer_surface static void handle_layer_surface_closed(void *data, struct zwlr_layer_surface_v1 *surface) { - struct skh_window_wayland *wl = (struct skh_window_wayland *)data; + struct stl_window_wayland *wl = (struct stl_window_wayland *)data; (void)surface; - skh_window_send_should_close_event(&wl->w); + stl_window_send_should_close_event(&wl->w); } static const struct zwlr_layer_surface_v1_listener layer_surface_listener = { @@ -635,10 +629,10 @@ static const struct zwlr_layer_surface_v1_listener layer_surface_listener = { .closed = handle_layer_surface_closed }; -#if defined SEKIHI_API_OPENGL -static bool wl_egl_init(struct skh_window_wayland *wl) +#if defined STELA_API_OPENGL +static bool wl_egl_init(struct stl_window_wayland *wl) { - if (!skh_maybe_load_egl(&wl->egl)) return false; + if (!stl_maybe_load_egl(&wl->egl)) return false; wl->egl_window = wl_egl_window_create(wl->surface, wl->w.width, wl->w.height); @@ -649,7 +643,7 @@ static bool wl_egl_init(struct skh_window_wayland *wl) } EGLConfig config; - if (!skh_init_egl(&wl->egl, 0, &config)) { + if (!stl_init_egl(&wl->egl, 0, &config)) { return false; } @@ -666,7 +660,7 @@ static bool wl_egl_init(struct skh_window_wayland *wl) } #endif -static bool create_context_internal(struct skh_window_wayland *wl) +static bool create_context_internal(struct stl_window_wayland *wl) { wl->display = wl_display_connect(NULL); if (!wl->display) { @@ -675,7 +669,7 @@ static bool create_context_internal(struct skh_window_wayland *wl) } wl->fds[0].fd = wl_display_get_fd(wl->display); wl->fds[0].events = POLLIN; -#if defined SEKIHI_POLL_INLINE && defined SEKIHI_PAUSE +#if defined STELA_POLL_INLINE && defined STELA_PAUSE wl->fds[1].fd = eventfd(0, 0); wl->fds[1].events = POLLIN; #endif @@ -686,50 +680,50 @@ static bool create_context_internal(struct skh_window_wayland *wl) return true; } -static bool window_wayland_create_context(struct skh_window *window, s32 flags) +static bool window_wayland_create_context(struct stl_window *window, s32 flags) { - struct skh_window_wayland *wl = (struct skh_window_wayland *)window; + struct stl_window_wayland *wl = (struct stl_window_wayland *)window; wl->flags = flags; if (!create_context_internal(wl)) { - wl->w.free((struct skh_window **)&wl); + wl->w.free((struct stl_window **)&wl); return false; } return true; } -static struct skh_monitor_wayland *monitor_from_name(struct skh_window_wayland *wl, const char *name) +static struct stl_monitor_wayland *monitor_from_name(struct stl_window_wayland *wl, const char *name) { if (name) { for (u32 i = 0; i < wl->w.monitors.size; i++) { - struct skh_monitor_wayland *monitor = (struct skh_monitor_wayland *)al_array_at(wl->w.monitors, i); + struct stl_monitor_wayland *monitor = (struct stl_monitor_wayland *)al_array_at(wl->w.monitors, i); if (strcmp(monitor->m.name, name) == 0) return monitor; } } - return (struct skh_monitor_wayland *)al_array_at(wl->w.monitors, 0); + return (struct stl_monitor_wayland *)al_array_at(wl->w.monitors, 0); } //static const struct wl_callback_listener frame_listener; -static bool window_wayland_create_window(struct skh_window *window, s32 width, s32 height, +static bool window_wayland_create_window(struct stl_window *window, s32 width, s32 height, const char *monitor, const char *name, s32 flags) { - struct skh_window_wayland *wl = (struct skh_window_wayland *)window; - + struct stl_window_wayland *wl = (struct stl_window_wayland *)window; wl->flags = flags; - wl->w.width = width; - wl->w.height = height; - wl->pending = true; if (!create_context_internal(wl)) goto err; wl->monitor = monitor_from_name(wl, monitor); + wl->w.scale = wl->monitor ? wl->monitor->m.scale : 1; + wl->w.width = width * wl->w.scale; + wl->w.height = height * wl->w.scale; + wl->pending = true; wl->surface = wl_compositor_create_surface(wl->compositor); if (!wl->surface) goto err; wl_surface_add_listener(wl->surface, &surface_listener, wl); - wl_surface_set_buffer_scale(wl->surface, wl->monitor ? wl->monitor->m.scale : 1); + wl_surface_set_buffer_scale(wl->surface, wl->w.scale); - if (!(flags & SEKIHI_WINDOW_WALLPAPER)) { + if (!(flags & STELA_WINDOW_WALLPAPER)) { wl->xdg_surface = xdg_wm_base_get_xdg_surface(wl->xdg_wm_base, wl->surface); if (!wl->xdg_surface) goto err; xdg_surface_add_listener(wl->xdg_surface, &xdg_surface_listener, wl); @@ -740,7 +734,7 @@ static bool window_wayland_create_window(struct skh_window *window, s32 width, s xdg_toplevel_set_title(wl->xdg_toplevel, name); xdg_toplevel_set_app_id(wl->xdg_toplevel, name); - xdg_toplevel_set_min_size(wl->xdg_toplevel, SEKIHI_MIN_WIDTH, SEKIHI_MIN_HEIGHT); + xdg_toplevel_set_min_size(wl->xdg_toplevel, STELA_MIN_WIDTH, STELA_MIN_HEIGHT); u32 decor = ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE; wl->zxdg_toplevel_decoration = zxdg_decoration_manager_v1_get_toplevel_decoration( @@ -765,17 +759,17 @@ static bool window_wayland_create_window(struct skh_window *window, s32 width, s zwlr_layer_surface_v1_add_listener(wl->layer_surface, &layer_surface_listener, wl); } -#if defined SEKIHI_API_OPENGL +#if defined STELA_API_OPENGL if (!wl_egl_init(wl)) goto err; #endif wl_surface_commit(wl->surface); wl_display_roundtrip(wl->display); -#if defined SEKIHI_API_OPENGL - skh_egl_make_current(&wl->egl); - skh_egl_swap_interval(&wl->egl, (wl->flags & SEKIHI_WINDOW_VSYNC) ? 1 : 0); - skh_egl_release_current(&wl->egl); +#if defined STELA_API_OPENGL + stl_egl_make_current(&wl->egl); + stl_egl_swap_interval(&wl->egl, (wl->flags & STELA_WINDOW_VSYNC) ? 1 : 0); + stl_egl_release_current(&wl->egl); #endif //wl->frame_done = 0; @@ -790,21 +784,21 @@ static bool window_wayland_create_window(struct skh_window *window, s32 width, s return true; err: al_log_error("window_wayland", "Failed to create window."); - wl->w.free((struct skh_window **)&wl); + wl->w.free((struct stl_window **)&wl); return false; } -static void window_wayland_resize(struct skh_window *window, s32 width, s32 height) +static void window_wayland_resize(struct stl_window *window, s32 width, s32 height) { - struct skh_window_wayland *wl = (struct skh_window_wayland *)window; + struct stl_window_wayland *wl = (struct stl_window_wayland *)window; (void)wl; (void)width; (void)height; } -static void window_wayland_toggle_fullscreen(struct skh_window *window) +static void window_wayland_toggle_fullscreen(struct stl_window *window) { - struct skh_window_wayland *wl = (struct skh_window_wayland *)window; + struct stl_window_wayland *wl = (struct stl_window_wayland *)window; if (!wl->w.fullscreen) { xdg_toplevel_set_fullscreen(wl->xdg_toplevel, NULL); } else { @@ -813,7 +807,7 @@ static void window_wayland_toggle_fullscreen(struct skh_window *window) wl->w.fullscreen = !wl->w.fullscreen; } -static void prepare_read_internal(struct skh_window_wayland *wl) +static void prepare_read_internal(struct stl_window_wayland *wl) { while (wl_display_prepare_read(wl->display) != 0) { wl_display_dispatch_pending(wl->display); @@ -821,39 +815,39 @@ static void prepare_read_internal(struct skh_window_wayland *wl) wl_display_flush(wl->display); } -static void window_wayland_prepare_read(struct skh_window *window) +static void window_wayland_prepare_read(struct stl_window *window) { - struct skh_window_wayland *wl = (struct skh_window_wayland *)window; + struct stl_window_wayland *wl = (struct stl_window_wayland *)window; prepare_read_internal(wl); } -#if defined SEKIHI_POLL_FD -static s32 window_wayland_get_poll_fd(struct skh_window *window) +#if defined STELA_POLL_FD +static s32 window_wayland_get_poll_fd(struct stl_window *window) { - struct skh_window_wayland *wl = (struct skh_window_wayland *)window; + struct stl_window_wayland *wl = (struct stl_window_wayland *)window; return wl->fds[0].fd; } -#elif defined SEKIHI_POLL_INLINE -static bool window_wayland_poll(struct skh_window *window, bool block) +#elif defined STELA_POLL_INLINE +static bool window_wayland_poll(struct stl_window *window, bool block) { - struct skh_window_wayland *wl = (struct skh_window_wayland *)window; + struct stl_window_wayland *wl = (struct stl_window_wayland *)window; prepare_read_internal(wl); - return skh_poll_common(wl->fds, block); + return stl_poll_common(wl->fds, block); } -#if defined SEKIHI_PAUSE -static void window_wayland_wake(struct skh_window *window) +#if defined STELA_PAUSE +static void window_wayland_wake(struct stl_window *window) { - struct skh_window_wayland *wl = (struct skh_window_wayland *)window; - skh_wake_common(&wl->w, wl->fds); + struct stl_window_wayland *wl = (struct stl_window_wayland *)window; + stl_wake_common(&wl->w, wl->fds); } #endif #endif -static void window_wayland_process_events(struct skh_window *window) +static void window_wayland_process_events(struct stl_window *window) { - struct skh_window_wayland *wl = (struct skh_window_wayland *)window; - if (skh_process_events_common(wl->fds)) { + struct stl_window_wayland *wl = (struct stl_window_wayland *)window; + if (stl_process_events_common(wl->fds)) { wl_display_read_events(wl->display); wl_display_dispatch_pending(wl->display); } else { @@ -861,14 +855,14 @@ static void window_wayland_process_events(struct skh_window *window) } } -#if defined SEKIHI_PAUSE -static bool window_wayland_should_refresh(struct skh_window *window) +#if defined STELA_PAUSE +static bool window_wayland_should_refresh(struct stl_window *window) { - return skh_should_refresh_common(window); + return stl_should_refresh_common(window); } #endif -static void destroy_surface_internal(struct skh_window_wayland *wl) +static void destroy_surface_internal(struct stl_window_wayland *wl) { if (wl->xdg_surface) { xdg_surface_destroy(wl->xdg_surface); @@ -877,18 +871,18 @@ static void destroy_surface_internal(struct skh_window_wayland *wl) } else if (wl->layer_surface) { zwlr_layer_surface_v1_destroy(wl->layer_surface); } -#if defined SEKIHI_API_OPENGL +#if defined STELA_API_OPENGL if (wl->egl_window) { - skh_egl_destroy_surface(&wl->egl); + stl_egl_destroy_surface(&wl->egl); wl_egl_window_destroy(wl->egl_window); } #endif if (wl->surface) wl_surface_destroy(wl->surface); } -void window_wayland_free(struct skh_window **window) +void window_wayland_free(struct stl_window **window) { - struct skh_window_wayland *wl = (struct skh_window_wayland *)*window; + struct stl_window_wayland *wl = (struct stl_window_wayland *)*window; if (!wl->display) return; if (wl->registry) wl_registry_destroy(wl->registry); if (wl->seat) wl_seat_destroy(wl->seat); @@ -898,7 +892,7 @@ void window_wayland_free(struct skh_window **window) if (wl->keyboard) wl_keyboard_destroy(wl->keyboard); if (wl->compositor) wl_compositor_destroy(wl->compositor); for (u32 i = 0; i < wl->w.monitors.size; i++) { - struct skh_monitor_wayland *monitor = (struct skh_monitor_wayland *)al_array_at(wl->w.monitors, i); + struct stl_monitor_wayland *monitor = (struct stl_monitor_wayland *)al_array_at(wl->w.monitors, i); if (monitor->output) wl_output_destroy(monitor->output); al_free(monitor); } @@ -908,14 +902,14 @@ void window_wayland_free(struct skh_window **window) if (wl->layer_shell) zwlr_layer_shell_v1_destroy(wl->layer_shell); if (wl->presentation) wp_presentation_destroy(wl->presentation); destroy_surface_internal(wl); -#if defined SEKIHI_API_OPENGL - if (skh_egl_is_ready(&wl->egl)) { - skh_egl_destroy_context(&wl->egl); - skh_egl_terminate(&wl->egl); +#if defined STELA_API_OPENGL + if (stl_egl_is_ready(&wl->egl)) { + stl_egl_destroy_context(&wl->egl); + stl_egl_terminate(&wl->egl); } #endif wl_display_disconnect(wl->display); -#if defined SEKIHI_EVENT_BUFFER +#if defined STELA_EVENT_BUFFER al_free(wl->w.data); #endif al_free(wl); @@ -935,7 +929,7 @@ static void feedback_presented(void *data, struct wp_presentation_feedback *feed u32 tv_sec_hi, u32 tv_sec_lo, u32 tv_nsec, u32 refresh_nsec, u32 seq_hi, u32 seq_lo, u32 flags) { - struct skh_window_wayland *wl = (struct skh_window_wayland *)data; + struct stl_window_wayland *wl = (struct stl_window_wayland *)data; (void)refresh_nsec; (void)seq_hi; (void)seq_lo; @@ -948,7 +942,7 @@ static void feedback_presented(void *data, struct wp_presentation_feedback *feed static void feedback_discarded(void *data, struct wp_presentation_feedback *feedback) { - struct skh_window_wayland *wl = (struct skh_window_wayland *)data; + struct stl_window_wayland *wl = (struct stl_window_wayland *)data; wp_presentation_feedback_destroy(feedback); wl->presentation_time = 0.0; } @@ -961,7 +955,7 @@ static const struct wp_presentation_feedback_listener feedback_listener = { static void frame_callback(void *data, struct wl_callback *callback, u32 time) { - struct skh_window_wayland *wl = (struct skh_window_wayland *)data; + struct stl_window_wayland *wl = (struct stl_window_wayland *)data; (void)time; if (callback) wl_callback_destroy(callback); @@ -980,11 +974,11 @@ static const struct wl_callback_listener frame_listener = { }; */ -#if defined SEKIHI_API_OPENGL +#if defined STELA_API_OPENGL static bool window_wayland_gl_loader_load(void *data) { - struct skh_window_wayland *wl = (struct skh_window_wayland *)data; - if (!skh_gl_loader_load(wl->w.get_gl_proc_address)) { + struct stl_window_wayland *wl = (struct stl_window_wayland *)data; + if (!stl_gl_loader_load(wl->w.get_gl_proc_address)) { return false; } return true; @@ -992,27 +986,27 @@ static bool window_wayland_gl_loader_load(void *data) static bool window_wayland_gl_make_current(void *data) { - struct skh_window_wayland *wl = (struct skh_window_wayland *)data; - skh_egl_make_current(&wl->egl); + struct stl_window_wayland *wl = (struct stl_window_wayland *)data; + stl_egl_make_current(&wl->egl); return true; } static void window_wayland_gl_release_current(void *data) { - struct skh_window_wayland *wl = (struct skh_window_wayland *)data; - skh_egl_release_current(&wl->egl); + struct stl_window_wayland *wl = (struct stl_window_wayland *)data; + stl_egl_release_current(&wl->egl); } static void window_wayland_gl_swap_buffers(void *data) { - struct skh_window_wayland *wl = (struct skh_window_wayland *)data; + struct stl_window_wayland *wl = (struct stl_window_wayland *)data; //wl->frame_done = 0; - skh_egl_swap_buffers(&wl->egl); + stl_egl_swap_buffers(&wl->egl); /* // This is not correct and cannot be expected to work anything like vsync or // it will introduce massive input lag. while (!wl->frame_done) { -#if defined SEKIHI_POLL_INLINE +#if defined STELA_POLL_INLINE wl->w.poll(&wl->w, true); #endif } @@ -1020,14 +1014,14 @@ static void window_wayland_gl_swap_buffers(void *data) } #endif -struct skh_window *skh_window_wayland_create(void) +struct stl_window *stl_window_wayland_create(void) { - struct skh_window_wayland *wl = al_alloc_object(struct skh_window_wayland); -#if defined SEKIHI_EVENT_BUFFER - wl->w.data = al_malloc(SEKIHI_EVENTS_SIZE); - al_ring_buffer_init(&wl->w.events, wl->w.data, SEKIHI_EVENTS_SIZE); + struct stl_window_wayland *wl = al_alloc_object(struct stl_window_wayland); +#if defined STELA_EVENT_BUFFER + wl->w.data = al_malloc(STELA_EVENTS_SIZE); + al_ring_buffer_init(&wl->w.events, wl->w.data, STELA_EVENTS_SIZE); #endif -#if defined SEKIHI_PAUSE +#if defined STELA_PAUSE wl->w.pending_refresh = true; #endif wl->w.fullscreen = false; @@ -1037,26 +1031,26 @@ struct skh_window *skh_window_wayland_create(void) wl->w.resize = window_wayland_resize; wl->w.toggle_fullscreen = window_wayland_toggle_fullscreen; wl->w.prepare_read = window_wayland_prepare_read; -#if defined SEKIHI_POLL_FD +#if defined STELA_POLL_FD wl->w.get_poll_fd = window_wayland_get_poll_fd; -#elif defined SEKIHI_POLL_INLINE +#elif defined STELA_POLL_INLINE wl->w.poll = window_wayland_poll; -#if defined SEKIHI_PAUSE +#if defined STELA_PAUSE wl->w.wake = window_wayland_wake; #endif #endif wl->w.process_events = window_wayland_process_events; -#if defined SEKIHI_PAUSE +#if defined STELA_PAUSE wl->w.should_refresh = window_wayland_should_refresh; #endif wl->w.free = window_wayland_free; -#if defined SEKIHI_API_VULKAN -#elif defined SEKIHI_API_OPENGL +#if defined STELA_API_VULKAN +#elif defined STELA_API_OPENGL wl->w.get_gl_proc_address = NULL; wl->w.gl_loader_load = window_wayland_gl_loader_load; wl->w.gl_make_current = window_wayland_gl_make_current; wl->w.gl_release_current = window_wayland_gl_release_current; wl->w.gl_swap_buffers = window_wayland_gl_swap_buffers; #endif - return (struct skh_window *)wl; + return (struct stl_window *)wl; } diff --git a/src/window_wayland.h b/src/window_wayland.h index 12d7763..07a12b6 100644 --- a/src/window_wayland.h +++ b/src/window_wayland.h @@ -18,14 +18,14 @@ #include "window.h" #include "egl_common.h" -struct skh_monitor_wayland { - struct skh_monitor m; +struct stl_monitor_wayland { + struct stl_monitor m; struct wl_output *output; struct zxdg_output_v1 *xdg_output; }; -struct skh_window_wayland { - struct skh_window w; +struct stl_window_wayland { + struct stl_window w; s32 flags; struct wl_display *display; struct wl_registry *registry; @@ -45,15 +45,15 @@ struct skh_window_wayland { struct wp_cursor_shape_device_v1 *cursor_shape_device; struct zxdg_toplevel_decoration_v1 *zxdg_toplevel_decoration; struct zwlr_layer_shell_v1 *layer_shell; - struct skh_monitor_wayland *monitor; + struct stl_monitor_wayland *monitor; struct zwlr_layer_surface_v1 *layer_surface; struct wl_callback *frame_callback; s32 frame_done; struct wp_presentation *presentation; f64 presentation_time; - struct skh_egl egl; + struct stl_egl egl; struct wl_egl_window *egl_window; -#if defined SEKIHI_POLL_INLINE && defined SEKIHI_PAUSE +#if defined STELA_POLL_INLINE && defined STELA_PAUSE struct aki_pollfd fds[2]; #else struct aki_pollfd fds[1]; @@ -66,4 +66,4 @@ struct skh_window_wayland { f64 scroll_y; }; -struct skh_window *skh_window_wayland_create(void); +struct stl_window *stl_window_wayland_create(void); diff --git a/src/window_x11.c b/src/window_x11.c index 6e7d480..eb64982 100644 --- a/src/window_x11.c +++ b/src/window_x11.c @@ -11,9 +11,9 @@ static Atom ATOM_WM_DELETE_WINDOW; #define _NET_WM_STATE_ADD 1 #define _NET_WM_STATE_TOGGLE 2 -static bool x11_egl_init(struct skh_window_x11 *xw) +static bool x11_egl_init(struct stl_window_x11 *xw) { - if (!skh_maybe_load_egl(&xw->egl)) return false; + if (!stl_maybe_load_egl(&xw->egl)) return false; xw->egl.display = eglGetDisplay((EGLNativeDisplayType)xw->x11_d); if (!xw->egl.display) { @@ -21,11 +21,11 @@ static bool x11_egl_init(struct skh_window_x11 *xw) } EGLConfig config; - if (!skh_init_egl(&xw->egl, 0, &config)) { + if (!stl_init_egl(&xw->egl, 0, &config)) { return false; } -#if defined SEKIHI_API_OPENGL +#if defined STELA_API_OPENGL xw->w.get_gl_proc_address = eglGetProcAddress; #endif @@ -39,10 +39,10 @@ static bool x11_egl_init(struct skh_window_x11 *xw) return true; } -static bool window_x11_create_window(struct skh_window *window, s32 width, s32 height, +static bool window_x11_create_window(struct stl_window *window, s32 width, s32 height, const char *monitor, const char *name, s32 flags) { - struct skh_window_x11 *xw = (struct skh_window_x11 *)window; + struct stl_window_x11 *xw = (struct stl_window_x11 *)window; (void)monitor; xw->x11_d = XOpenDisplay(NULL); @@ -79,7 +79,7 @@ static bool window_x11_create_window(struct skh_window *window, s32 width, s32 h xw->w.width = gwa.width; xw->w.height = gwa.height; - if (flags & SEKIHI_WINDOW_WALLPAPER) + if (flags & STELA_WINDOW_WALLPAPER) { /* Atom desktop = XInternAtom(xw->x11_d, "_NET_WM_DESKTOP", False); @@ -119,14 +119,14 @@ static bool window_x11_create_window(struct skh_window *window, s32 width, s32 h if (!x11_egl_init(xw)) return false; - skh_egl_make_current(&xw->egl); - skh_egl_swap_interval(&xw->egl, (flags & SEKIHI_WINDOW_VSYNC) ? 1 : 0); - skh_egl_release_current(&xw->egl); + stl_egl_make_current(&xw->egl); + stl_egl_swap_interval(&xw->egl, (flags & STELA_WINDOW_VSYNC) ? 1 : 0); + stl_egl_release_current(&xw->egl); xw->fds[0].fd = ConnectionNumber(xw->x11_d); xw->fds[0].events = POLLIN; -#if defined SEKIHI_POLL_INLINE && defined SEKIHI_PAUSE +#if defined STELA_POLL_INLINE && defined STELA_PAUSE xw->fds[1].fd = eventfd(0, 0); xw->fds[1].events = POLLIN; #endif @@ -134,96 +134,96 @@ static bool window_x11_create_window(struct skh_window *window, s32 width, s32 h return true; } -static void window_x11_resize(struct skh_window *window, s32 width, s32 height) +static void window_x11_resize(struct stl_window *window, s32 width, s32 height) { - struct skh_window_x11 *xw = (struct skh_window_x11 *)window; + struct stl_window_x11 *xw = (struct stl_window_x11 *)window; (void)xw; (void)width; (void)height; } -static void window_x11_toggle_fullscreen(struct skh_window *window) +static void window_x11_toggle_fullscreen(struct stl_window *window) { - struct skh_window_x11 *xw = (struct skh_window_x11 *)window; + struct stl_window_x11 *xw = (struct stl_window_x11 *)window; if (!xw->w.fullscreen) { } else { } xw->w.fullscreen = !xw->w.fullscreen; } -#if defined SEKIHI_POLL_FD -static s32 window_x11_get_poll_fd(struct skh_window *window) +#if defined STELA_POLL_FD +static s32 window_x11_get_poll_fd(struct stl_window *window) { - struct skh_window_x11 *xw = (struct skh_window_x11 *)window; + struct stl_window_x11 *xw = (struct stl_window_x11 *)window; return xw->fds[0].fd; } -#elif defined SEKIHI_POLL_INLINE -static bool window_x11_poll(struct skh_window *window, bool block) +#elif defined STELA_POLL_INLINE +static bool window_x11_poll(struct stl_window *window, bool block) { - struct skh_window_x11 *xw = (struct skh_window_x11 *)window; - return skh_poll_common(xw->fds, block); + struct stl_window_x11 *xw = (struct stl_window_x11 *)window; + return stl_poll_common(xw->fds, block); } -#if defined SEKIHI_PAUSE -static void window_x11_wake(struct skh_window *window) +#if defined STELA_PAUSE +static void window_x11_wake(struct stl_window *window) { - struct skh_window_x11 *xw = (struct skh_window_x11 *)window; - skh_wake_common(&xw->w, xw->fds); + struct stl_window_x11 *xw = (struct stl_window_x11 *)window; + stl_wake_common(&xw->w, xw->fds); } #endif #endif -static void handle_next_xevent(struct skh_window_x11 *xw) +static void handle_next_xevent(struct stl_window_x11 *xw) { XEvent xev; XNextEvent(xw->x11_d, &xev); switch (xev.type) { case ClientMessage: if ((Atom)xev.xclient.data.l[0] == ATOM_WM_DELETE_WINDOW) { - skh_window_send_should_close_event(&xw->w); + stl_window_send_should_close_event(&xw->w); } break; case ConfigureNotify: xw->w.width = xev.xconfigure.width; xw->w.height = xev.xconfigure.height; - skh_window_send_resize_event(&xw->w, xw->w.width, xw->w.height); + stl_window_send_resize_event(&xw->w, xw->w.width, xw->w.height); break; case KeyPress: - skh_window_send_key_event(&xw->w, SEKIHI_BUTTON_PRESSED, xev.xkey.keycode); + stl_window_send_key_event(&xw->w, STELA_BUTTON_PRESSED, xev.xkey.keycode); break; case KeyRelease: - skh_window_send_key_event(&xw->w, SEKIHI_BUTTON_RELEASED, xev.xkey.keycode); + stl_window_send_key_event(&xw->w, STELA_BUTTON_RELEASED, xev.xkey.keycode); break; case ButtonPress: if (xev.xbutton.button == Button1) { - skh_window_send_mouse_button_event(&xw->w, SEKIHI_BUTTON_PRESSED, SEKIHI_MOUSE1); + stl_window_send_mouse_button_event(&xw->w, STELA_BUTTON_PRESSED, STELA_MOUSE1); } else if (xev.xbutton.button == Button2) { - skh_window_send_mouse_button_event(&xw->w, SEKIHI_BUTTON_PRESSED, SEKIHI_MOUSE2); + stl_window_send_mouse_button_event(&xw->w, STELA_BUTTON_PRESSED, STELA_MOUSE2); } else if (xev.xbutton.button == Button4) { - skh_window_send_scroll_event(&xw->w, -1.f); + stl_window_send_scroll_event(&xw->w, -1.f); } else if (xev.xbutton.button == Button5) { - skh_window_send_scroll_event(&xw->w, 1.f); + stl_window_send_scroll_event(&xw->w, 1.f); } break; case ButtonRelease: if (xev.xbutton.button == Button1) { - skh_window_send_mouse_button_event(&xw->w, SEKIHI_BUTTON_RELEASED, SEKIHI_MOUSE1); + stl_window_send_mouse_button_event(&xw->w, STELA_BUTTON_RELEASED, STELA_MOUSE1); } else if (xev.xbutton.button == Button2) { - skh_window_send_mouse_button_event(&xw->w, SEKIHI_BUTTON_RELEASED, SEKIHI_MOUSE2); + stl_window_send_mouse_button_event(&xw->w, STELA_BUTTON_RELEASED, STELA_MOUSE2); } break; case MotionNotify: - skh_window_send_pointer_pos_event(&xw->w, (f64)xev.xmotion.x, (f64)xev.xmotion.y); + stl_window_send_pointer_pos_event(&xw->w, (f64)xev.xmotion.x, (f64)xev.xmotion.y); break; case MapNotify: break; } } -static void window_x11_process_events(struct skh_window *window) +static void window_x11_process_events(struct stl_window *window) { - struct skh_window_x11 *xw = (struct skh_window_x11 *)window; - skh_process_events_common(xw->fds); + struct stl_window_x11 *xw = (struct stl_window_x11 *)window; + stl_process_events_common(xw->fds); // It seems for some reason POLLIN doesn't get set even // when there's events. XPending(xw->x11_d); @@ -232,18 +232,18 @@ static void window_x11_process_events(struct skh_window *window) } } -#if defined SEKIHI_PAUSE -static bool window_x11_should_refresh(struct skh_window *window) +#if defined STELA_PAUSE +static bool window_x11_should_refresh(struct stl_window *window) { - return skh_should_refresh_common(window); + return stl_should_refresh_common(window); } #endif -static void window_x11_free(struct skh_window **window) +static void window_x11_free(struct stl_window **window) { - struct skh_window_x11 *xw = (struct skh_window_x11 *)*window; + struct stl_window_x11 *xw = (struct stl_window_x11 *)*window; // TODO: Cleanup x11 stuff. -#if defined SEKIHI_EVENT_BUFFER +#if defined STELA_EVENT_BUFFER al_free(xw->w.data); #endif al_array_free(xw->w.monitors); @@ -251,7 +251,7 @@ static void window_x11_free(struct skh_window **window) *window = NULL; } -#if defined SEKIHI_API_VULKAN +#if defined STELA_API_VULKAN static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL window_x11_get_vk_proc_address(VkInstance inst, const char *name) { return NULL; @@ -259,7 +259,7 @@ static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL window_x11_get_vk_proc_address(V static VkResult window_x11_vk_create_surface(void *data, VkInstance inst, VkSurfaceKHR *surface) { - struct skh_window_x11 *xw = (struct skh_window_x11 *)data; + struct stl_window_x11 *xw = (struct stl_window_x11 *)data; return VK_SUCCESS; } @@ -267,11 +267,11 @@ static const char *const *window_x11_vk_get_extensions(u32 *num) { return NULL; } -#elif defined SEKIHI_API_OPENGL +#elif defined STELA_API_OPENGL static bool window_x11_gl_loader_load(void *data) { - struct skh_window_x11 *xw = (struct skh_window_x11 *)data; - if (!skh_gl_loader_load(xw->w.get_gl_proc_address)) { + struct stl_window_x11 *xw = (struct stl_window_x11 *)data; + if (!stl_gl_loader_load(xw->w.get_gl_proc_address)) { return false; } return true; @@ -279,32 +279,32 @@ static bool window_x11_gl_loader_load(void *data) static bool window_x11_gl_make_current(void *data) { - struct skh_window_x11 *xw = (struct skh_window_x11 *)data; - skh_egl_make_current(&xw->egl); + struct stl_window_x11 *xw = (struct stl_window_x11 *)data; + stl_egl_make_current(&xw->egl); return true; } static void window_x11_gl_release_current(void *data) { - struct skh_window_x11 *xw = (struct skh_window_x11 *)data; - skh_egl_release_current(&xw->egl); + struct stl_window_x11 *xw = (struct stl_window_x11 *)data; + stl_egl_release_current(&xw->egl); } static void window_x11_gl_swap_buffers(void *data) { - struct skh_window_x11 *xw = (struct skh_window_x11 *)data; - skh_egl_swap_buffers(&xw->egl); + struct stl_window_x11 *xw = (struct stl_window_x11 *)data; + stl_egl_swap_buffers(&xw->egl); } #endif -struct skh_window *skh_window_x11_create(void) +struct stl_window *stl_window_x11_create(void) { - struct skh_window_x11 *xw = al_alloc_object(struct skh_window_x11); -#if defined SEKIHI_EVENT_BUFFER - xw->w.data = al_malloc(SEKIHI_EVENTS_SIZE); - al_ring_buffer_init(&xw->w.events, xw->w.data, SEKIHI_EVENTS_SIZE); + struct stl_window_x11 *xw = al_alloc_object(struct stl_window_x11); +#if defined STELA_EVENT_BUFFER + xw->w.data = al_malloc(STELA_EVENTS_SIZE); + al_ring_buffer_init(&xw->w.events, xw->w.data, STELA_EVENTS_SIZE); #endif -#if defined SEKIHI_PAUSE +#if defined STELA_PAUSE xw->w.pending_refresh = true; #endif xw->w.fullscreen = false; @@ -313,30 +313,30 @@ struct skh_window *skh_window_x11_create(void) xw->w.create_window = window_x11_create_window; xw->w.resize = window_x11_resize; xw->w.toggle_fullscreen = window_x11_toggle_fullscreen; -#if defined SEKIHI_POLL_FD +#if defined STELA_POLL_FD xw->w.get_poll_fd = window_x11_get_poll_fd; -#elif defined SEKIHI_POLL_INLINE +#elif defined STELA_POLL_INLINE xw->w.poll = window_x11_poll; -#if defined SEKIHI_PAUSE +#if defined STELA_PAUSE xw->w.wake = window_x11_wake; #endif #endif xw->w.process_events = window_x11_process_events; -#if defined SEKIHI_PAUSE +#if defined STELA_PAUSE xw->w.should_refresh = window_x11_should_refresh; #endif xw->w.free = window_x11_free; -#if defined SEKIHI_API_VULKAN +#if defined STELA_API_VULKAN xw->w.get_vk_proc_address = window_x11_get_vk_proc_address; xw->w.vk_create_surface = window_x11_vk_create_surface; xw->w.vk_get_extensions = window_x11_vk_get_extensions; -#elif defined SEKIHI_API_OPENGL +#elif defined STELA_API_OPENGL xw->w.get_gl_proc_address = NULL; xw->w.gl_loader_load = window_x11_gl_loader_load; xw->w.gl_make_current = window_x11_gl_make_current; xw->w.gl_release_current = window_x11_gl_release_current; xw->w.gl_swap_buffers = window_x11_gl_swap_buffers; -#elif defined SEKIHI_API_DX11 +#elif defined STELA_API_DX11 #endif - return (struct skh_window *)xw; + return (struct stl_window *)xw; } diff --git a/src/window_x11.h b/src/window_x11.h index 452a650..c365d91 100644 --- a/src/window_x11.h +++ b/src/window_x11.h @@ -8,16 +8,16 @@ #include "window.h" #include "egl_common.h" -struct skh_window_x11 { - struct skh_window w; +struct stl_window_x11 { + struct stl_window w; Display *x11_d; Window window; - struct skh_egl egl; -#if defined SEKIHI_PAUSE + struct stl_egl egl; +#if defined STELA_PAUSE struct aki_pollfd fds[2]; #else struct aki_pollfd fds[1]; #endif }; -struct skh_window *skh_window_x11_create(void); +struct stl_window *stl_window_x11_create(void); |