mac: report modifier keys on precise scrolling

modifier keys weren't reported when using the trackpad to scroll.

Fixes #11195
This commit is contained in:
der richter 2023-11-29 01:18:53 +01:00
parent aaff9edf57
commit f551a9da34
2 changed files with 24 additions and 3 deletions

View File

@ -67,8 +67,8 @@ class MPVHelper {
mp_input_set_mouse_pos(input, Int32(pos.x), Int32(pos.y))
}
func putAxis(_ mpkey: Int32, delta: Double) {
mp_input_put_wheel(input, mpkey, delta)
func putAxis(_ mpkey: Int32, modifiers: NSEvent.ModifierFlags, delta: Double) {
mp_input_put_wheel(input, mpkey | mapModifier(modifiers), delta)
}
func nextChangedOption(property: inout UnsafeMutableRawPointer?) -> Bool {
@ -111,6 +111,27 @@ class MPVHelper {
free(UnsafeMutablePointer(mutating: cCmd))
}
func mapModifier(_ modifiers: NSEvent.ModifierFlags) -> Int32 {
var mask: UInt32 = 0;
if modifiers.contains(.shift) {
mask |= MP_KEY_MODIFIER_SHIFT
}
if modifiers.contains(.control) {
mask |= MP_KEY_MODIFIER_CTRL
}
if modifiers.contains(.command) {
mask |= MP_KEY_MODIFIER_META
}
if modifiers.rawValue & UInt(NX_DEVICELALTKEYMASK) != 0 ||
modifiers.rawValue & UInt(NX_DEVICERALTKEYMASK) != 0 && !mp_input_use_alt_gr(input)
{
mask |= MP_KEY_MODIFIER_ALT
}
return Int32(mask)
}
// (__bridge void*)
class func bridge<T: AnyObject>(obj: T) -> UnsafeMutableRawPointer {
return UnsafeMutableRawPointer(Unmanaged.passUnretained(obj).toOpaque())

View File

@ -227,7 +227,7 @@ class View: NSView {
cmd = delta > 0 ? SWIFT_WHEEL_LEFT : SWIFT_WHEEL_RIGHT
}
mpv?.putAxis(cmd, delta: abs(delta))
mpv?.putAxis(cmd, modifiers: event.modifierFlags, delta: abs(delta))
}
override func scrollWheel(with event: NSEvent) {