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
|
@ -90,52 +90,43 @@ extension RangeReplaceableCollection where Element: Hashable {
|
|||
basisKeyboardLayoutButton.menu?.addItem(menuItem_vChewingDachen)
|
||||
|
||||
let basisKeyboardLayoutID = Preferences.basisKeyboardLayout
|
||||
|
||||
|
||||
for source in list {
|
||||
|
||||
func getString(_ key: CFString) -> String? {
|
||||
if let ptr = TISGetInputSourceProperty(source, key) {
|
||||
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) {
|
||||
if let categoryPtr = TISGetInputSourceProperty(source, kTISPropertyInputSourceCategory) {
|
||||
let category = Unmanaged<CFString>.fromOpaque(categoryPtr).takeUnretainedValue()
|
||||
if category != kTISCategoryKeyboardInputSource {
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
|
||||
if let asciiCapable = getBool(kTISPropertyInputSourceIsASCIICapable) {
|
||||
if !asciiCapable {
|
||||
if let asciiCapablePtr = TISGetInputSourceProperty(source, kTISPropertyInputSourceIsASCIICapable) {
|
||||
let asciiCapable = Unmanaged<CFBoolean>.fromOpaque(asciiCapablePtr).takeUnretainedValue()
|
||||
if asciiCapable != kCFBooleanTrue {
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
|
||||
if let sourceType = getString(kTISPropertyInputSourceType) {
|
||||
if sourceType != String(kTISTypeKeyboardLayout) {
|
||||
if let sourceTypePtr = TISGetInputSourceProperty(source, kTISPropertyInputSourceType) {
|
||||
let sourceType = Unmanaged<CFString>.fromOpaque(sourceTypePtr).takeUnretainedValue()
|
||||
if sourceType != kTISTypeKeyboardLayout {
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
|
||||
guard let sourceID = getString(kTISPropertyInputSourceID),
|
||||
let localizedName = getString(kTISPropertyLocalizedName) else {
|
||||
guard let sourceIDPtr = TISGetInputSourceProperty(source, kTISPropertyInputSourceID),
|
||||
let localizedNamePtr = TISGetInputSourceProperty(source, kTISPropertyLocalizedName) else {
|
||||
continue
|
||||
}
|
||||
|
||||
let sourceID = String(Unmanaged<CFString>.fromOpaque(sourceIDPtr).takeUnretainedValue())
|
||||
let localizedName = String(Unmanaged<CFString>.fromOpaque(localizedNamePtr).takeUnretainedValue())
|
||||
|
||||
let menuItem = NSMenuItem()
|
||||
menuItem.title = localizedName
|
||||
menuItem.representedObject = sourceID
|
||||
|
|
Loading…
Reference in New Issue