Skip to content
Permalink
Browse files

Add configuration for overriding keyboard layout

  • Loading branch information...
yous committed May 21, 2019
1 parent 9582320 commit 7cdbaf0c96614363923095aed09b9051836291a5
@@ -103,6 +103,7 @@
80383E6D2161F0D300FC5FB6 /* hangul-keyboard-3-2012.xml in Copy Keyboards Files */ = {isa = PBXBuildFile; fileRef = 80383E6A2161F0D300FC5FB6 /* hangul-keyboard-3-2012.xml */; };
80383E6E2161F0D300FC5FB6 /* hangul-keyboard-3-2011.xml in Copy Keyboards Files */ = {isa = PBXBuildFile; fileRef = 80383E6B2161F0D300FC5FB6 /* hangul-keyboard-3-2011.xml */; };
80383E6F2161F0D300FC5FB6 /* hangul-combination-3p.xml in Copy Keyboards Files */ = {isa = PBXBuildFile; fileRef = 80383E6C2161F0D300FC5FB6 /* hangul-combination-3p.xml */; };
8044BCD822940EE7009996E0 /* TISInputSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 388186A721EB34FA004B7FDB /* TISInputSource.swift */; };
80A02B24217E1AA90018E658 /* hangul-keyboard-2y-full.xml in Copy Keyboards Files */ = {isa = PBXBuildFile; fileRef = 80A02B22217E1AA90018E658 /* hangul-keyboard-2y-full.xml */; };
80A02B25217E1AA90018E658 /* hangul-keyboard-2-full.xml in Copy Keyboards Files */ = {isa = PBXBuildFile; fileRef = 80A02B23217E1AA90018E658 /* hangul-keyboard-2-full.xml */; };
A34E20012168B21B00B12476 /* GureumTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3BAAE062160C6970076C66D /* GureumTests.swift */; };
@@ -909,7 +910,7 @@
};
buildConfigurationList = 38863C53140E62D100A8ED76 /* Build configuration list for PBXProject "Gureum" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
@@ -1226,6 +1227,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8044BCD822940EE7009996E0 /* TISInputSource.swift in Sources */,
381CA2EF1FCE16EA00DDB81D /* Preferences.swift in Sources */,
388186AB21EB3E72004B7FDB /* Configuration.swift in Sources */,
);
@@ -19,6 +19,7 @@ enum ConfigurationName: String {
case inputModeEnglishKey = "InputModeEnglishKey"
case inputModeKoreanKey = "InputModeKoreanKey"
case optionKeyBehavior = "OptionKeyBehavior"
case overridingKeyboardName = "OverridingKeyboardName"

case romanModeByEscapeKey = "ExchangeToRomanModeByEscapeKey"
case showsInputForHanjaCandidates = "ShowsInputForHanjaCandidates"
@@ -60,6 +61,7 @@ public class Configuration: UserDefaults {
ConfigurationName.inputModeEmoticonKey.rawValue: Configuration.convertShortcutToConfiguration((0x24, [.shift, .option])),
ConfigurationName.inputModeHanjaKey.rawValue: Configuration.convertShortcutToConfiguration((0x24, .option)),
ConfigurationName.optionKeyBehavior.rawValue: 0,
ConfigurationName.overridingKeyboardName.rawValue: "com.apple.keylayout.US",

ConfigurationName.romanModeByEscapeKey.rawValue: false,
ConfigurationName.showsInputForHanjaCandidates.rawValue: false,
@@ -118,6 +120,15 @@ public class Configuration: UserDefaults {
}
}

var overridingKeyboardName: String {
get {
return string(forKey: ConfigurationName.overridingKeyboardName.rawValue)!
}
set {
`set`(newValue, forKey: ConfigurationName.overridingKeyboardName.rawValue)
}
}

var showsInputForHanjaCandidates: Bool {
get {
return bool(forKey: ConfigurationName.showsInputForHanjaCandidates.rawValue)
@@ -270,7 +270,7 @@ extension InputReceiver { // IMKStateSetting
InputMethodServer.shared.io.capsLockDate = nil
dlog(DEBUG_LOGGING, "LOGGING::EVENT::CHANGE-%lu-%@", tag, value as? String ?? "(nonstring)")
dlog(DEBUG_INPUTCONTROLLER, "** InputController -setValue:forTag:client: with value: %@ / tag: %lx / client: %@", value as? String ?? "(nonstring)", tag, String(describing: controller.client as AnyObject))
sender.overrideKeyboard(withKeyboardNamed: "com.apple.keylayout.US")
sender.overrideKeyboard(withKeyboardNamed: Configuration.shared.overridingKeyboardName)
switch tag {
case kTextServiceInputModePropertyTag:
guard let value = value as? String else {
@@ -9,6 +9,12 @@
import Carbon
import CoreFoundation

class TISProperty {
static let InputSourceIsEnabled = kTISPropertyInputSourceIsEnabled as String
static let InputSourceID = kTISPropertyInputSourceID as String
static let LocalizedName = kTISPropertyLocalizedName as String
}

extension TISInputSource {
class func currentKeyboard() -> TISInputSource? {
guard let unmanaged = TISCopyCurrentKeyboardInputSource() else {
@@ -23,4 +29,30 @@ extension TISInputSource {
}
return unmanaged.takeRetainedValue()
}

class func sources(withProperties properties: NSDictionary, includeAllInstalled: Bool) -> [TISInputSource]? {
guard let unmanaged = TISCreateInputSourceList(properties, includeAllInstalled) else {
return nil
}
return unmanaged.takeRetainedValue() as? [TISInputSource]
}

func property(forKey key: String) -> Any? {
guard let unmanaged = TISGetInputSourceProperty(self, key as CFString) else {
return nil
}
return Unmanaged<AnyObject>.fromOpaque(unmanaged).takeUnretainedValue()
}

var enabled: Bool {
return property(forKey: TISProperty.InputSourceIsEnabled) as! Bool
}

var identifier: String {
return property(forKey: TISProperty.InputSourceID) as! String
}

var localizedName: String {
return property(forKey: TISProperty.LocalizedName) as! String
}
}

0 comments on commit 7cdbaf0

Please sign in to comment.
You can’t perform that action at this time.