From dad6f6cf87a94f5a1e804b2f68afa4ef680540e0 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Fri, 13 Mar 2026 20:19:47 -0700 Subject: Support trackpad scrolling --- src/xplorer.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/xplorer.c b/src/xplorer.c index 6dd1bbf..da66f0d 100644 --- a/src/xplorer.c +++ b/src/xplorer.c @@ -270,11 +270,13 @@ int main( State state = {0}; if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS)) { - return false; + success = false; + goto cleanup; } if (!uiInit()) { - return false; + success = false; + goto cleanup; } if (!Initialize(&state)) { @@ -297,6 +299,12 @@ int main( // Initially true to perform an initial draw before the window is displayed. bool redraw = true; + // Scrolling on a trackpad often results in scroll values in [0,1], but the UI + // library handles integer scroll deltas only. + // Accumulate floating-point deltas and issue them to the UI library when + // the integer part becomes non-zero. + float scroll = 0.f; + while (running) { EVENT_LOOP_PRINT("loop\n"); @@ -366,21 +374,21 @@ int main( }; redraw = uiSendEvent(state.frame, &ev); } else if (event.type == SDL_EVENT_MOUSE_WHEEL) { - int x, y; - MouseCoordsToUiCoords( - state.window, event.wheel.mouse_x, event.wheel.mouse_y, &x, &y); - // TODO: Scrolling on a trackpad results in 0