ctlPrefWindow // Re-enable previous keyboard layouts menu procesing.
- This is to attempt fixing an issue that the PrefWindow may hang for few secongs when being switched back from other windows / apps.
This commit is contained in:
parent
34f466de03
commit
2d01add28f
|
@ -92,50 +92,41 @@ extension RangeReplaceableCollection where Element: Hashable {
|
||||||
let basisKeyboardLayoutID = Preferences.basisKeyboardLayout
|
let basisKeyboardLayoutID = Preferences.basisKeyboardLayout
|
||||||
|
|
||||||
for source in list {
|
for source in list {
|
||||||
|
if let categoryPtr = TISGetInputSourceProperty(source, kTISPropertyInputSourceCategory) {
|
||||||
func getString(_ key: CFString) -> String? {
|
let category = Unmanaged<CFString>.fromOpaque(categoryPtr).takeUnretainedValue()
|
||||||
if let ptr = TISGetInputSourceProperty(source, key) {
|
if category != kTISCategoryKeyboardInputSource {
|
||||||
return String(Unmanaged<CFString>.fromOpaque(ptr).takeUnretainedValue())
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func getBool(_ key: CFString) -> Bool? {
|
|
||||||
if let ptr = TISGetInputSourceProperty(source, key) {
|
|
||||||
return Unmanaged<CFBoolean>.fromOpaque(ptr).takeUnretainedValue() == kCFBooleanTrue
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if let category = getString(kTISPropertyInputSourceCategory) {
|
|
||||||
if category != String(kTISCategoryKeyboardInputSource) {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if let asciiCapable = getBool(kTISPropertyInputSourceIsASCIICapable) {
|
if let asciiCapablePtr = TISGetInputSourceProperty(source, kTISPropertyInputSourceIsASCIICapable) {
|
||||||
if !asciiCapable {
|
let asciiCapable = Unmanaged<CFBoolean>.fromOpaque(asciiCapablePtr).takeUnretainedValue()
|
||||||
|
if asciiCapable != kCFBooleanTrue {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if let sourceType = getString(kTISPropertyInputSourceType) {
|
if let sourceTypePtr = TISGetInputSourceProperty(source, kTISPropertyInputSourceType) {
|
||||||
if sourceType != String(kTISTypeKeyboardLayout) {
|
let sourceType = Unmanaged<CFString>.fromOpaque(sourceTypePtr).takeUnretainedValue()
|
||||||
|
if sourceType != kTISTypeKeyboardLayout {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let sourceID = getString(kTISPropertyInputSourceID),
|
guard let sourceIDPtr = TISGetInputSourceProperty(source, kTISPropertyInputSourceID),
|
||||||
let localizedName = getString(kTISPropertyLocalizedName) else {
|
let localizedNamePtr = TISGetInputSourceProperty(source, kTISPropertyLocalizedName) else {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let sourceID = String(Unmanaged<CFString>.fromOpaque(sourceIDPtr).takeUnretainedValue())
|
||||||
|
let localizedName = String(Unmanaged<CFString>.fromOpaque(localizedNamePtr).takeUnretainedValue())
|
||||||
|
|
||||||
let menuItem = NSMenuItem()
|
let menuItem = NSMenuItem()
|
||||||
menuItem.title = localizedName
|
menuItem.title = localizedName
|
||||||
menuItem.representedObject = sourceID
|
menuItem.representedObject = sourceID
|
||||||
|
|
Loading…
Reference in New Issue