macos: build scroll mods value

This commit is contained in:
Mitchell Hashimoto
2023-06-29 11:06:34 -07:00
parent 68631a1ccd
commit 9a40dc4630
2 changed files with 28 additions and 2 deletions

View File

@ -291,14 +291,40 @@ extension Ghostty {
override func scrollWheel(with event: NSEvent) {
guard let surface = self.surface else { return }
// Builds up the "input.ScrollMods" bitmask
var mods: Int32 = 0
var x = event.scrollingDeltaX
var y = event.scrollingDeltaY
if event.hasPreciseScrollingDeltas {
mods = 1
x *= 0.1
y *= 0.1
}
ghostty_surface_mouse_scroll(surface, x, y, 0)
// Determine our momentum value
var momentum: ghostty_input_mouse_momentum_e = GHOSTTY_MOUSE_MOMENTUM_NONE
switch (event.momentumPhase) {
case .began:
momentum = GHOSTTY_MOUSE_MOMENTUM_BEGAN
case .stationary:
momentum = GHOSTTY_MOUSE_MOMENTUM_STATIONARY
case .changed:
momentum = GHOSTTY_MOUSE_MOMENTUM_CHANGED
case .ended:
momentum = GHOSTTY_MOUSE_MOMENTUM_ENDED
case .cancelled:
momentum = GHOSTTY_MOUSE_MOMENTUM_CANCELLED
case .mayBegin:
momentum = GHOSTTY_MOUSE_MOMENTUM_MAY_BEGIN
default:
break
}
// Pack our momentum value into the mods bitmask
mods |= Int32(momentum.rawValue) << 1
ghostty_surface_mouse_scroll(surface, x, y, mods)
}
override func keyDown(with event: NSEvent) {

View File

@ -1290,7 +1290,7 @@ pub fn scrollCallback(
} else |_| {}
}
// log.info("SCROLL: {} {}", .{ xoff, yoff });
// log.info("SCROLL: xoff={} yoff={} mods={}", .{ xoff, yoff, scroll_mods });
// Positive is up
const y_sign: isize = if (yoff > 0) -1 else 1;