From f551a9da3471fcb2568e9c4d031e2ffb867e35a8 Mon Sep 17 00:00:00 2001 From: der richter Date: Wed, 29 Nov 2023 01:18:53 +0100 Subject: [PATCH] mac: report modifier keys on precise scrolling modifier keys weren't reported when using the trackpad to scroll. Fixes #11195 --- osdep/macos/mpv_helper.swift | 25 +++++++++++++++++++++++-- video/out/mac/view.swift | 2 +- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/osdep/macos/mpv_helper.swift b/osdep/macos/mpv_helper.swift index 6e5a80dc89..532a5f723c 100644 --- a/osdep/macos/mpv_helper.swift +++ b/osdep/macos/mpv_helper.swift @@ -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(obj: T) -> UnsafeMutableRawPointer { return UnsafeMutableRawPointer(Unmanaged.passUnretained(obj).toOpaque()) diff --git a/video/out/mac/view.swift b/video/out/mac/view.swift index c4776c3fba..0ac90f5a54 100644 --- a/video/out/mac/view.swift +++ b/video/out/mac/view.swift @@ -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) {