mirror of
https://github.com/coteditor/CotEditor.git
synced 2024-09-11 11:25:57 +03:00
Add the Globe key check
This commit is contained in:
parent
de726ed8f1
commit
7142dc1f4c
@ -2,6 +2,15 @@
|
||||
Change Log
|
||||
==========================
|
||||
|
||||
4.7.0 (unreleased)
|
||||
--------------------------
|
||||
|
||||
### Improvements
|
||||
|
||||
- [rc] Display the Globe symbol instead of “fn” for shortcuts in the Quick Action bar if the user keyboard is supposed to have the Globe key (thanks to Katsumi Kishikawa!).
|
||||
|
||||
|
||||
|
||||
4.7.0-rc (615)
|
||||
--------------------------
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
import Foundation
|
||||
import AppKit.NSEvent
|
||||
import IOKit
|
||||
|
||||
/// Modifier keys for keyboard shortcut.
|
||||
///
|
||||
@ -41,10 +42,6 @@ private enum ModifierKey: CaseIterable {
|
||||
static let validCases: [Self] = Array(Self.allCases[0..<4])
|
||||
|
||||
|
||||
/// It seems there is no easy way to detect the Globe key without private APIs... (2023-12 on macOS 14)
|
||||
private static let supportsGlobeKey = false
|
||||
|
||||
|
||||
/// NSEvent.ModifierFlags representation.
|
||||
var mask: NSEvent.ModifierFlags {
|
||||
|
||||
@ -95,6 +92,18 @@ private enum ModifierKey: CaseIterable {
|
||||
case .function: preconditionFailure("Fn/Globe key cannot be used for custom shortcuts.")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Return `true` if the user keyboard is supposed to have the Globe key.
|
||||
private static let supportsGlobeKey = {
|
||||
|
||||
let entry = IOServiceGetMatchingService(kIOMainPortDefault, IOServiceMatching("AppleHIDKeyboardEventDriverV2"))
|
||||
defer { IOObjectRelease(entry) }
|
||||
|
||||
guard let property = IORegistryEntryCreateCFProperty(entry, "SupportsGlobeKey" as CFString, kCFAllocatorDefault, 0)?.takeRetainedValue() else { return false }
|
||||
|
||||
return (property as? Int) == 1
|
||||
}()
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user