IME // Implement a whitelist towards enumerated keyLayouts.

This commit is contained in:
ShikiSuen 2022-04-10 11:53:55 +08:00
parent d6a1470bb0
commit 1a74d9de14
1 changed files with 24 additions and 3 deletions

View File

@ -230,6 +230,17 @@ import Cocoa
var strName: String = ""
var strValue: String = ""
}
static let arrWhitelistedKeyLayoutsASCII: [String] = [
"com.apple.keylayout.ABC",
"com.apple.keylayout.ABC-AZERTY",
"com.apple.keylayout.ABC-QWERTZ",
"com.apple.keylayout.British",
"com.apple.keylayout.Colemak",
"com.apple.keylayout.Dvorak",
"com.apple.keylayout.Dvorak-Left",
"com.apple.keylayout.DVORAK-QWERTYCMD",
"com.apple.keylayout.Dvorak-Right",
]
static var arrEnumerateSystemKeyboardLayouts: [IME.CarbonKeyboardLayout] {
// macOS
var arrKeyLayouts: [IME.CarbonKeyboardLayout] = []
@ -243,6 +254,7 @@ import Cocoa
]
// ASCII
var arrKeyLayoutsMACV: [IME.CarbonKeyboardLayout] = []
var arrKeyLayoutsASCII: [IME.CarbonKeyboardLayout] = []
let list = TISCreateInputSourceList(nil, true).takeRetainedValue() as! [TISInputSource]
for source in list {
@ -286,10 +298,19 @@ import Cocoa
let localizedName = String(
Unmanaged<CFString>.fromOpaque(localizedNamePtr).takeUnretainedValue())
arrKeyLayoutsASCII += [
IME.CarbonKeyboardLayout.init(strName: localizedName, strValue: sourceID)
]
if sourceID.contains("vChewing") {
arrKeyLayoutsMACV += [
IME.CarbonKeyboardLayout.init(strName: localizedName, strValue: sourceID)
]
}
if IME.arrWhitelistedKeyLayoutsASCII.contains(sourceID) {
arrKeyLayoutsASCII += [
IME.CarbonKeyboardLayout.init(strName: localizedName, strValue: sourceID)
]
}
}
arrKeyLayouts += arrKeyLayoutsMACV
arrKeyLayouts += arrKeyLayoutsASCII
return arrKeyLayouts
}