summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2025-08-05 10:44:49 -0400
committerAndrew Opalach <andrew@akon.city> 2025-08-05 10:44:49 -0400
commitf595bcadb2305d5bbc5ea945935a42bcfbf6bdb1 (patch)
treef580d588c0f6911335e56a8d108f080f2383477c
parent01637283b33d7fe4921e9347ada867e44b29edba (diff)
downloadstela-f595bcadb2305d5bbc5ea945935a42bcfbf6bdb1.tar.gz
stela-f595bcadb2305d5bbc5ea945935a42bcfbf6bdb1.tar.bz2
stela-f595bcadb2305d5bbc5ea945935a42bcfbf6bdb1.zip
Interface for scaling scroll values at time of use
- Add MOVE cursor. - Build fixes. Signed-off-by: Andrew Opalach <andrew@akon.city>
-rw-r--r--.gitignore1
-rw-r--r--meson.build2
-rw-r--r--src/egl_common.c4
-rw-r--r--src/gl_versions.h14
-rw-r--r--src/keys.h2
-rw-r--r--src/window.h2
-rw-r--r--src/window_glfm.c5
-rw-r--r--src/window_glfw.c7
-rw-r--r--src/window_kms.c5
-rw-r--r--src/window_wayland.c35
-rw-r--r--src/window_win32.c30
-rw-r--r--src/window_x11.c9
-rw-r--r--subprojects/libalabaster.wrap2
-rw-r--r--subprojects/libnaunet.wrap2
-rw-r--r--tests/window.c12
15 files changed, 86 insertions, 46 deletions
diff --git a/.gitignore b/.gitignore
index 2c664dc..e05b367 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,3 +14,4 @@ subprojects/libnaunet
subprojects/libnaunet/
subprojects/wayland-protocols-*/
subprojects/wlr-protocols-*/
+tags
diff --git a/meson.build b/meson.build
index 146c7e6..1ba5efe 100644
--- a/meson.build
+++ b/meson.build
@@ -218,6 +218,6 @@ if not meson.is_subproject()
stela_lib = shared_library('stela', dependencies: stela, install: false)
endif
-if get_option('tests').auto() and not meson.is_subproject()
+if get_option('tests').allowed() and not meson.is_subproject()
subdir('tests')
endif
diff --git a/src/egl_common.c b/src/egl_common.c
index 606cc67..e3531c2 100644
--- a/src/egl_common.c
+++ b/src/egl_common.c
@@ -151,9 +151,7 @@ bool stl_init_egl_context(struct stl_egl *egl, struct stl_egl_global *global, EG
continue;
}
- log_debug("Attempting to create a %s context of version %d.%d (GLSL %d).",
- 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);
+ STELA_LOG_GL_CONTEXT_CREATION(stl_gl_vers[i]);
egl->context = eglCreateContext(egl->display, *config, EGL_NO_CONTEXT, context_attr);
diff --git a/src/gl_versions.h b/src/gl_versions.h
index 0182317..eb53794 100644
--- a/src/gl_versions.h
+++ b/src/gl_versions.h
@@ -1,17 +1,19 @@
#pragma once
-#ifdef NAUNET_WIN32_COMPAT_MODE
-#ifndef STELA_FORCE_COMPATABILITY
-#define STELA_FORCE_COMPATABILITY
-#endif
-#endif
-
// This is likely ill-defined overall. For example, WGL has confusing behavior defined here.
// https://registry.khronos.org/OpenGL/extensions/ARB/WGL_ARB_create_context.txt
// Under "Additions to the WGL specification".
// This also seems to behave different under Wine vs Native Windows. Requesting GL 3.0 Compatibility
// on Wine still forces a Core context but works according to the specification on Windows.
+#ifdef NAUNET_WIN32_COMPAT_MODE
+#define STELA_FORCE_COMPATABILITY
+#endif
+
+#define STELA_LOG_GL_CONTEXT_CREATION(ver) \
+ log_debug("Attempting to create a %s context of version %d.%d (GLSL %d).", \
+ (ver).api == STELA_GL_API ? "GL" : "GLES", (ver).major, (ver).minor, (ver).glsl_ver)
+
// https://github.com/haasn/libplacebo/blob/795600a44b03fcd52c055981a403ad60ee5d027a/demos/window_glfw.c#L194
#ifdef STELA_USE_GLES
#define PASTE_GL_VERSIONS() static struct { \
diff --git a/src/keys.h b/src/keys.h
index a5691a5..a055c1d 100644
--- a/src/keys.h
+++ b/src/keys.h
@@ -31,7 +31,7 @@ static u32 stl_all_modifiers[] = {
AL_IGNORE_WARNING_END
// https://github.com/glfw/glfw/blob/e7ea71be039836da3a98cea55ae5569cb5eb885c/include/GLFW/glfw3.h#L395C1-L519C50
-// See window_glfw.c:key_callback() for ommited keys.
+// See window_glfw.c:key_callback() for omitted keys.
#define STELA_KEY_NONE 0
diff --git a/src/window.h b/src/window.h
index b1b2425..35aa5f0 100644
--- a/src/window.h
+++ b/src/window.h
@@ -49,6 +49,7 @@ enum {
enum {
STELA_CURSOR_NORMAL = 0,
+ STELA_CURSOR_MOVE,
STELA_CURSOR_CROSSHAIR,
STELA_CURSOR_HIDDEN
};
@@ -169,6 +170,7 @@ enum {
extern s32 stl_platform_main(u32 argc, str *argv);
+f64 stl_scale_scroll(f64 v, f64 factor);
void stl_set_output_discovered_callback(void (*output_discovered)(void *, struct stl_monitor *), void *userdata);
bool stl_global_init(bool skip_graphics);
diff --git a/src/window_glfm.c b/src/window_glfm.c
index 39de449..202a55f 100644
--- a/src/window_glfm.c
+++ b/src/window_glfm.c
@@ -5,6 +5,11 @@
#include "window_glfm.h"
#include "common.h"
+f64 stl_scale_scroll(f64 v, f64 factor)
+{
+ return v / factor;
+}
+
static struct stl_glfm_global global = { 0 };
void stl_set_output_discovered_callback(void (*output_discovered)(void *, struct stl_monitor *), void *userdata)
diff --git a/src/window_glfw.c b/src/window_glfw.c
index 0669bd4..14a3d73 100644
--- a/src/window_glfw.c
+++ b/src/window_glfw.c
@@ -24,6 +24,11 @@
PASTE_GL_VERSIONS()
#endif
+f64 stl_scale_scroll(f64 v, f64 factor)
+{
+ return v / (1.5 * factor);
+}
+
static struct stl_glfw_global global = { 0 };
void stl_set_output_discovered_callback(void (*output_discovered)(void *, struct stl_monitor *), void *userdata)
@@ -121,7 +126,7 @@ static void scroll_callback(GLFWwindow *window, f64 xoffset, f64 yoffset)
{
struct stl_window_glfw *glfw = glfwGetWindowUserPointer(window);
(void)xoffset;
- stl_window_send_scroll_event(&glfw->w, -yoffset);
+ stl_window_send_scroll_event(&glfw->w, yoffset);
}
static void mouse_button_callback(GLFWwindow *window, s32 button, s32 action, s32 mods)
diff --git a/src/window_kms.c b/src/window_kms.c
index 15d1532..900ac59 100644
--- a/src/window_kms.c
+++ b/src/window_kms.c
@@ -1,6 +1,11 @@
#include "window_kms.h"
#include "common.h"
+f64 stl_scale_scroll(f64 v, f64 factor)
+{
+ return v / factor;
+}
+
void stl_set_output_discovered_callback(void (*output_discovered)(void *, struct stl_monitor *), void *userdata)
{
(void)output_discovered;
diff --git a/src/window_wayland.c b/src/window_wayland.c
index ccf911c..1c707f8 100644
--- a/src/window_wayland.c
+++ b/src/window_wayland.c
@@ -12,6 +12,11 @@
#define FRAME_NO_VALUE -DBL_MAX
+f64 stl_scale_scroll(f64 v, f64 factor)
+{
+ return v / (15.0 * factor);
+}
+
static struct stl_wayland_global global = { 0 };
static void handle_output_geometry(void *data, struct wl_output *output,
@@ -365,6 +370,12 @@ static void set_cursor_internal(struct stl_window_wayland *wl, u8 shape)
wl->cursor.serial, WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DEFAULT);
}
break;
+ case STELA_CURSOR_MOVE:
+ if (wl->cursor_shape_device) {
+ wp_cursor_shape_device_v1_set_shape(wl->cursor_shape_device,
+ wl->cursor.serial, WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_MOVE);
+ }
+ break;
case STELA_CURSOR_CROSSHAIR:
if (wl->cursor_shape_device) {
wp_cursor_shape_device_v1_set_shape(wl->cursor_shape_device,
@@ -430,14 +441,13 @@ static void pointer_button(void *data, struct wl_pointer *pointer,
}
break;
case MOUSE2:
- if (wl->xdg_toplevel) {
+ if (wl->xdg_toplevel && !wl->w.fullscreen) {
xdg_toplevel_move(wl->xdg_toplevel, wl->seat, serial);
- } else {
- if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
- stl_window_send_mouse_button_event(&wl->w, STELA_BUTTON_PRESSED, STELA_MOUSE2);
- } else if (state == WL_POINTER_BUTTON_STATE_RELEASED) {
- stl_window_send_mouse_button_event(&wl->w, STELA_BUTTON_RELEASED, STELA_MOUSE2);
- }
+ }
+ if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
+ stl_window_send_mouse_button_event(&wl->w, STELA_BUTTON_PRESSED, STELA_MOUSE2);
+ } else if (state == WL_POINTER_BUTTON_STATE_RELEASED) {
+ stl_window_send_mouse_button_event(&wl->w, STELA_BUTTON_RELEASED, STELA_MOUSE2);
}
break;
case MOUSE3:
@@ -458,10 +468,10 @@ static void pointer_axis(void *data, struct wl_pointer *pointer,
(void)time;
if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) {
if (wl->frame.scroll_y == FRAME_NO_VALUE) wl->frame.scroll_y = 0.0;
- wl->frame.scroll_y += wl_fixed_to_double(value);
+ wl->frame.scroll_y -= wl_fixed_to_double(value);
} else if (axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL) {
if (wl->frame.scroll_x == FRAME_NO_VALUE) wl->frame.scroll_x = 0.0;
- wl->frame.scroll_x += wl_fixed_to_double(value);
+ wl->frame.scroll_x -= wl_fixed_to_double(value);
}
}
@@ -1014,7 +1024,7 @@ static bool window_wayland_create_window(struct stl_window *window, u32 width, u
goto err;
}
stl_egl_make_current(&wl->egl);
- stl_egl_swap_interval(&wl->egl, flags & STELA_WINDOW_VSYNC ? 1 : 0);
+ stl_egl_swap_interval(&wl->egl, (flags & STELA_WINDOW_VSYNC) ? 1 : 0);
stl_egl_release_current(&wl->egl);
#endif
@@ -1170,6 +1180,7 @@ void window_wayland_free(struct stl_window **window)
#if defined STELA_API_VULKAN
static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL get_vk_proc_address(VkInstance inst, const char *name)
{
+ /*
const char *vk_lib = "libvulkan.so.1";
void *vk_module = dlopen(vk_lib, RTLD_LAZY | RTLD_LOCAL);
if (!vk_module) {
@@ -1177,7 +1188,9 @@ static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL get_vk_proc_address(VkInstance i
return NULL;
}
PFN_vkGetInstanceProcAddr vk_get_proc_addr = (PFN_vkGetInstanceProcAddr)dlsym(vk_module, "vkGetInstanceProcAddr");
- dlclose(vk_module);
+ */
+ PFN_vkGetInstanceProcAddr vk_get_proc_addr = vkGetInstanceProcAddr;
+ //dlclose(vk_module);
if (!vk_get_proc_addr) return NULL;
return (PFN_vkVoidFunction)vk_get_proc_addr(inst, name);
}
diff --git a/src/window_win32.c b/src/window_win32.c
index 6bb4945..6e47db6 100644
--- a/src/window_win32.c
+++ b/src/window_win32.c
@@ -33,7 +33,12 @@
PASTE_GL_VERSIONS()
#endif
-static LPCWSTR DangerousClass = L"Dangerous Class";
+f64 stl_scale_scroll(f64 v, f64 factor)
+{
+ SHORT Value = 0;
+ al_memcpy(&Value, &v, sizeof(SHORT));
+ return Value / (WHEEL_DELTA * factor);
+}
void stl_set_output_discovered_callback(void (*output_discovered)(void *, struct stl_monitor *), void *userdata)
{
@@ -43,6 +48,8 @@ void stl_set_output_discovered_callback(void (*output_discovered)(void *, struct
// https://github.com/cmuratori/dtc
+static LPCWSTR DangerousClass = L"Dangerous Class";
+
struct the_baby {
DWORD dwExStyle;
LPCWSTR lpClassName;
@@ -61,10 +68,10 @@ struct the_baby {
// Service messages.
#define CREATE_DANGEROUS_WINDOW (WM_USER + 0x1337)
#define DESTROY_DANGEROUS_WINDOW (WM_USER + 0x1338)
-#define WAKE_WINDOW (WM_USER + 0x1339)
-#define EXIT_PROCESS (WM_USER + 0x133a)
+#define EXIT_PROCESS (WM_USER + 0x1339)
// Window messages.
+#define WAKE_WINDOW (WM_USER + 0x133a)
#define SET_CURSOR (WM_USER + 0x133b)
static DWORD MainThreadID;
@@ -698,7 +705,7 @@ static LRESULT CALLBACK DisplayWndProc(HWND Window, UINT Message, WPARAM WParam,
// https://stackoverflow.com/a/35522584, incredible...
// https://gitlab.winehq.org/agusev/wine/-/blob/wine-971221/windows/nonclient.c#L1773
// This works on Wine but not Windows. Everything works the same except on Windows
- // there must be a special case for LBUTTON.
+ // it seems there is a special case for LBUTTON.
SendMessageW(w32->Window, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, LParam);
}
break;
@@ -858,6 +865,7 @@ static bool CreateWGLContext(struct stl_window_win32 *w32)
mask |= stl_gl_vers[i].profile == STELA_GL_CORE_PROFILE_BIT ?
WGL_CONTEXT_CORE_PROFILE_BIT_ARB : WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
}
+
s32 attribs[] = {
WGL_CONTEXT_FLAGS_ARB, flags,
WGL_CONTEXT_PROFILE_MASK_ARB, mask,
@@ -866,9 +874,7 @@ static bool CreateWGLContext(struct stl_window_win32 *w32)
0, 0
};
- log_info("Attempting to create a %s context of version %d.%d (GLSL %d).",
- 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);
+ STELA_LOG_GL_CONTEXT_CREATION(stl_gl_vers[i]);
w32->GLContext = CreateContextAttribsARB(w32->DeviceContext, NULL, attribs);
if (w32->GLContext) break;
@@ -1129,9 +1135,13 @@ static void win32_handle_message(struct stl_window_win32 *w32, MSG *Message)
stl_window_send_pointer_pos_event(&w32->w, (f64)Pos.x, (f64)Pos.y);
break;
}
- case WM_MOUSEWHEEL:
- stl_window_send_scroll_event(&w32->w, -(f64)GET_WHEEL_DELTA_WPARAM(Message->wParam));
+ case WM_MOUSEWHEEL: {
+ SHORT Value = (SHORT)HIWORD(Message->wParam);
+ f64 Bits = 0.0;
+ al_memcpy(&Bits, &Value, sizeof(SHORT));
+ stl_window_send_scroll_event(&w32->w, Bits);
break;
+ }
case WM_ACTIVATE: {
switch (LOWORD(Message->wParam)) {
case WA_ACTIVE:
@@ -1164,7 +1174,9 @@ static void win32_handle_message(struct stl_window_win32 *w32, MSG *Message)
stl_window_send_resize_event(&w32->w, w32->w.width, w32->w.height);
break;
case WAKE_WINDOW:
+#ifdef STELA_PAUSE
w32->w.pending_refresh = true;
+#endif
break;
default:
break;
diff --git a/src/window_x11.c b/src/window_x11.c
index 2566fda..a1c56e9 100644
--- a/src/window_x11.c
+++ b/src/window_x11.c
@@ -13,6 +13,11 @@ static Atom ATOM_WM_DELETE_WINDOW;
#define _NET_WM_STATE_ADD 1
#define _NET_WM_STATE_TOGGLE 2
+f64 stl_scale_scroll(f64 v, f64 factor)
+{
+ return v / factor;
+}
+
static struct stl_x11_global global = { 0 };
void stl_set_output_discovered_callback(void (*output_discovered)(void *, struct stl_monitor *), void *userdata)
@@ -329,9 +334,9 @@ static void handle_next_xevent(struct stl_window_x11 *xw)
} else if (xev.xbutton.button == Button2) {
stl_window_send_mouse_button_event(&xw->w, STELA_BUTTON_PRESSED, STELA_MOUSE2);
} else if (xev.xbutton.button == Button4) {
- stl_window_send_scroll_event(&xw->w, -1.f);
- } else if (xev.xbutton.button == Button5) {
stl_window_send_scroll_event(&xw->w, 1.f);
+ } else if (xev.xbutton.button == Button5) {
+ stl_window_send_scroll_event(&xw->w, -1.f);
}
break;
case ButtonRelease:
diff --git a/subprojects/libalabaster.wrap b/subprojects/libalabaster.wrap
index 9a9cfc1..425ed78 100644
--- a/subprojects/libalabaster.wrap
+++ b/subprojects/libalabaster.wrap
@@ -1,4 +1,4 @@
[wrap-git]
url = https://git.akon.city/libalabaster
-revision = 0470ca3416388e7e58b64f63bfe505d454f150b9
+revision = 1aa0177d1eb3767f1a7840115c3afeb93e8c858e
depth = 1
diff --git a/subprojects/libnaunet.wrap b/subprojects/libnaunet.wrap
index 15dd478..a069af9 100644
--- a/subprojects/libnaunet.wrap
+++ b/subprojects/libnaunet.wrap
@@ -1,4 +1,4 @@
[wrap-git]
url = https://git.akon.city/libnaunet
-revision = 3ea974dd51b1f01483bad6a4d115189928bbf4db
+revision = eaf84a7850f2af70b16fb417cd002f5e39df5db2
depth = 1
diff --git a/tests/window.c b/tests/window.c
index e13f1fa..e1c5de1 100644
--- a/tests/window.c
+++ b/tests/window.c
@@ -3,11 +3,10 @@
#include <al/types.h>
#include <al/array.h>
#include <al/str.h>
+#include <al/math.h>
#include <stl/window.h>
#include <stl/gl.h>
#include <nnwt/common.h>
-#define _USE_MATH_DEFINES
-#include <math.h>
#define DEFAULT_WIDTH 720
#define DEFAULT_HEIGHT 480
@@ -23,13 +22,6 @@ static const GLfloat init_rotation[] = { -25.f, 35.f, 0.f };
static GLfloat rotation[] = { init_rotation[0], init_rotation[1], init_rotation[2] };
static GLfloat zoom = 0.5f;
-AL_IGNORE_WARNING("-Wunused-function")
-static inline GLfloat degrees_to_radians(GLfloat degrees)
-{
- return degrees * M_PI / 180.f;
-}
-AL_IGNORE_WARNING_END
-
static bool pointer_pos_callback(void *userdata, f64 x, f64 y)
{
(void)userdata;
@@ -60,7 +52,7 @@ static bool pointer_pos_callback(void *userdata, f64 x, f64 y)
static bool scroll_callback(void *userdata, f64 y)
{
(void)userdata;
- zoom += y / -2500.f;
+ zoom += (f32)stl_scale_scroll(y, 50.0);
if (zoom < 0.1f) zoom = 0.1f;
return true;
}