Fix Cmd+plus zoom handling on non-US layouts (#680)
This commit is contained in:
parent
f73887154d
commit
c3b55e2a9f
3 changed files with 124 additions and 14 deletions
|
|
@ -11,4 +11,36 @@ class KeyboardLayout {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
/// Translate a physical keyCode to the unmodified character under the current keyboard layout.
|
||||
static func character(forKeyCode keyCode: UInt16) -> String? {
|
||||
guard let source = TISCopyCurrentKeyboardInputSource()?.takeRetainedValue(),
|
||||
let layoutDataPointer = TISGetInputSourceProperty(source, kTISPropertyUnicodeKeyLayoutData) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
let layoutData = unsafeBitCast(layoutDataPointer, to: CFData.self)
|
||||
guard let bytes = CFDataGetBytePtr(layoutData) else { return nil }
|
||||
let keyboardLayout = UnsafeRawPointer(bytes).assumingMemoryBound(to: UCKeyboardLayout.self)
|
||||
|
||||
var deadKeyState: UInt32 = 0
|
||||
var chars = [UniChar](repeating: 0, count: 4)
|
||||
var length = 0
|
||||
|
||||
let status = UCKeyTranslate(
|
||||
keyboardLayout,
|
||||
keyCode,
|
||||
UInt16(kUCKeyActionDisplay),
|
||||
0,
|
||||
UInt32(LMGetKbdType()),
|
||||
UInt32(kUCKeyTranslateNoDeadKeysBit),
|
||||
&deadKeyState,
|
||||
chars.count,
|
||||
&length,
|
||||
&chars
|
||||
)
|
||||
|
||||
guard status == noErr, length > 0 else { return nil }
|
||||
return String(utf16CodeUnits: chars, count: length).lowercased()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue