macos: slow down inspector trackpad (precision) scrolling

This commit is contained in:
Mitchell Hashimoto
2026-01-27 08:34:31 -08:00
parent 7feb30a836
commit 32f5677a94
2 changed files with 9 additions and 12 deletions

View File

@@ -269,16 +269,10 @@ extension Ghostty {
// Builds up the "input.ScrollMods" bitmask
var mods: Int32 = 0
var x = event.scrollingDeltaX
var y = event.scrollingDeltaY
let x = event.scrollingDeltaX
let y = event.scrollingDeltaY
if event.hasPreciseScrollingDeltas {
mods = 1
// We do a 2x speed multiplier. This is subjective, it "feels" better to me.
x *= 2;
y *= 2;
// TODO(mitchellh): do we have to scale the x/y here by window scale factor?
}
// Determine our momentum value

View File

@@ -1133,15 +1133,18 @@ pub const Inspector = struct {
yoff: f64,
mods: input.ScrollMods,
) void {
_ = mods;
self.queueRender();
cimgui.c.ImGui_SetCurrentContext(self.ig_ctx);
const io: *cimgui.c.ImGuiIO = cimgui.c.ImGui_GetIO();
// For precision scrolling (trackpads), the values are in pixels which
// scroll way too fast. Scale them down to approximate discrete wheel
// notches. imgui expects 1.0 to scroll ~5 lines of text.
const scale: f64 = if (mods.precision) 0.1 else 1.0;
cimgui.c.ImGuiIO_AddMouseWheelEvent(
io,
@floatCast(xoff),
@floatCast(yoff),
@floatCast(xoff * scale),
@floatCast(yoff * scale),
);
}