diff options
| author | 2025-08-05 10:44:49 -0400 | |
|---|---|---|
| committer | 2025-08-05 10:44:49 -0400 | |
| commit | f595bcadb2305d5bbc5ea945935a42bcfbf6bdb1 (patch) | |
| tree | f580d588c0f6911335e56a8d108f080f2383477c /src | |
| parent | 01637283b33d7fe4921e9347ada867e44b29edba (diff) | |
| download | stela-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>
Diffstat (limited to 'src')
| -rw-r--r-- | src/egl_common.c | 4 | ||||
| -rw-r--r-- | src/gl_versions.h | 14 | ||||
| -rw-r--r-- | src/keys.h | 2 | ||||
| -rw-r--r-- | src/window.h | 2 | ||||
| -rw-r--r-- | src/window_glfm.c | 5 | ||||
| -rw-r--r-- | src/window_glfw.c | 7 | ||||
| -rw-r--r-- | src/window_kms.c | 5 | ||||
| -rw-r--r-- | src/window_wayland.c | 35 | ||||
| -rw-r--r-- | src/window_win32.c | 30 | ||||
| -rw-r--r-- | src/window_x11.c | 9 |
10 files changed, 80 insertions, 33 deletions
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 { \ @@ -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: |