From 5482eecb8afe686101ce386184cafde00798606e Mon Sep 17 00:00:00 2001 From: der richter Date: Sun, 10 Mar 2024 23:17:54 +0100 Subject: [PATCH] mac/input: define AltGr mask as static NSEvent.ModifierFlags variable this makes it possible to properly test for those modifiers in a proper swift like way. --- osdep/mac/input_helper.swift | 4 ++-- osdep/mac/swift_extensions.swift | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/osdep/mac/input_helper.swift b/osdep/mac/input_helper.swift index 9e1b4811a9..48e289f409 100644 --- a/osdep/mac/input_helper.swift +++ b/osdep/mac/input_helper.swift @@ -85,8 +85,8 @@ class InputHelper: NSObject { 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) + if modifiers.contains(.optionLeft) || + modifiers.contains(.optionRight) && !mp_input_use_alt_gr(input) { mask |= MP_KEY_MODIFIER_ALT } diff --git a/osdep/mac/swift_extensions.swift b/osdep/mac/swift_extensions.swift index c0a7cd95e4..004927766d 100644 --- a/osdep/mac/swift_extensions.swift +++ b/osdep/mac/swift_extensions.swift @@ -16,6 +16,7 @@ */ import Cocoa +import IOKit.hidsystem extension NSDeviceDescriptionKey { static let screenNumber = NSDeviceDescriptionKey("NSScreenNumber") @@ -41,6 +42,11 @@ extension NSColor { } } +extension NSEvent.ModifierFlags { + public static var optionLeft: NSEvent.ModifierFlags = .init(rawValue: UInt(NX_DEVICELALTKEYMASK)) + public static var optionRight: NSEvent.ModifierFlags = .init(rawValue: UInt(NX_DEVICERALTKEYMASK)) +} + extension Bool { init(_ int32: Int32) { self.init(int32 != 0)