ctlIME // Fix IME-windows hang when regaining focus.

- Certain IMK functions could result in infinite loops when an IME-domestic Window is being focused regardless whether the current IME is switched to something else).
This commit is contained in:
ShikiSuen 2022-04-10 19:40:42 +08:00
parent f0d6ade3c7
commit 27af2f569d
1 changed files with 18 additions and 9 deletions

View File

@ -65,8 +65,9 @@ class ctlInputMethod: IMKInputController {
// MARK: - Keyboard Layout Specifier
@objc func setKeyLayout() {
let client = client().self as IMKTextInput
client.overrideKeyboard(withKeyboardNamed: mgrPrefs.basicKeyboardLayout)
if let client = currentClient {
(client as? IMKTextInput)?.overrideKeyboard(withKeyboardNamed: mgrPrefs.basicKeyboardLayout)
}
}
// MARK: - IMKInputController methods
@ -90,14 +91,18 @@ class ctlInputMethod: IMKInputController {
override func activateServer(_ client: Any!) {
UserDefaults.standard.synchronize()
// Override the keyboard layout to the basic one.
setKeyLayout()
// reset the state
currentClient = client
keyHandler.clear()
keyHandler.syncWithPreferences()
if let bundleCheckID = (client as? IMKTextInput)?.bundleIdentifier() {
if bundleCheckID != Bundle.main.bundleIdentifier {
// Override the keyboard layout to the basic one.
setKeyLayout()
self.handle(state: .Empty(), client: client)
}
}
(NSApp.delegate as? AppDelegate)?.checkForUpdate()
}
@ -120,15 +125,19 @@ class ctlInputMethod: IMKInputController {
}
mgrLangModel.loadDataModel(newInputMode)
// Remember to override the keyboard layout again -- treat this as an activate event.
setKeyLayout()
if keyHandler.inputMode != newInputMode {
UserDefaults.standard.synchronize()
keyHandler.clear()
keyHandler.inputMode = newInputMode
if let bundleCheckID = (client as? IMKTextInput)?.bundleIdentifier() {
if bundleCheckID != Bundle.main.bundleIdentifier {
// Remember to override the keyboard layout again -- treat this as an activate event.
setKeyLayout()
self.handle(state: .Empty(), client: client)
}
}
}
//
ctlInputMethod.currentKeyHandler.inputMode = keyHandler.inputMode