Skip to content

Commit

Permalink
mac: report modifier keys on precise scrolling
Browse files Browse the repository at this point in the history
modifier keys weren't reported when using the trackpad to scroll.

Fixes mpv-player#11195
  • Loading branch information
Akemi committed Dec 2, 2023
1 parent aaff9ed commit f551a9d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
25 changes: 23 additions & 2 deletions osdep/macos/mpv_helper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion video/out/mac/view.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit f551a9d

Please sign in to comment.