Skip to content

Commit

Permalink
Merge pull request #494 from youknowone/iokit
Browse files Browse the repository at this point in the history
IOKit 처리를 InputMethodServer에서 분리
  • Loading branch information
youknowone committed Jan 12, 2019
2 parents 17409d5 + b3d9447 commit 422e929
Show file tree
Hide file tree
Showing 17 changed files with 108 additions and 95 deletions.
2 changes: 1 addition & 1 deletion CommonInputMethod/CIMApplicationDelegate.swift
Expand Up @@ -3,7 +3,7 @@
// Gureum
//
// Created by KMLee on 2018. 9. 6..
// Copyright © 2018년 youknowone.org. All rights reserved.
// Copyright © 2018 youknowone.org. All rights reserved.
//

import Cocoa
Expand Down
2 changes: 1 addition & 1 deletion CommonInputMethod/CIMBaseComposer.swift
Expand Up @@ -3,7 +3,7 @@
// Gureum
//
// Created by 김민주 on 2018. 9. 1..
// Copyright © 2018년 youknowone.org. All rights reserved.
// Copyright © 2018 youknowone.org. All rights reserved.
//

import Foundation
Expand Down
4 changes: 3 additions & 1 deletion CommonInputMethod/CIMComposer.swift
Expand Up @@ -72,7 +72,9 @@ class CIMComposer: NSObject, CIMComposerDelegate {

var delegate: CIMComposerDelegate!
var inputMode: String = ""
var manager: CIMInputManager!
var server: InputMethodServer {
return InputMethodServer.shared
}

var composedString: String {
return delegate.composedString
Expand Down
2 changes: 1 addition & 1 deletion CommonInputMethod/CIMInputController.h
Expand Up @@ -17,7 +17,7 @@
이 클래스는 @link IMKServer @/link 에 의존하는 입력과 클라이언트에서의 결과 반영을 담당한다.
IMKInputController가 내부 구현으로 의도하지 않은 동작을 하는 것을 방어하고 명시적으로 동작을 덮어쓰기 위해 IMKInputController를 직접 상속하고 모든 기능은 CIMInputReceiver로 위임한다.
@coclass CIMInputManager CIMInputReceiver
@coclass InputMethodServer CIMInputReceiver
@warning 이 클래스에는 IMKServer, 클라이언트와 독립적인 코드는 **절대로** 쓰지 않는다. IMKInputController의 내부 구현과 섞이면 디버그하기 어렵다.
*/

Expand Down
9 changes: 3 additions & 6 deletions CommonInputMethod/CIMInputController.swift
Expand Up @@ -3,7 +3,7 @@
// Gureum
//
// Created by KMLee on 2018. 9. 12..
// Copyright © 2018년 youknowone.org. All rights reserved.
// Copyright © 2018 youknowone.org. All rights reserved.
//

import Foundation
Expand Down Expand Up @@ -64,7 +64,7 @@ extension CIMInputController { // IMKServerInputHandleEvent
// Receiving Events Directly from the Text Services Manager

override func handle(_ event: NSEvent, client sender: Any) -> Bool {
let imkCandidtes = composer.manager.candidates
let imkCandidtes = composer.server.candidates
let keys = imkCandidtes.selectionKeys() as! [NSNumber]
if imkCandidtes.isVisible(), keys.contains(NSNumber(value: event.keyCode)) {
imkCandidtes.interpretKeyEvents([event])
Expand All @@ -78,11 +78,8 @@ extension CIMInputController { // IMKServerInputHandleEvent
return processed
} else if event.type == .flagsChanged {
var modifierFlags = event.modifierFlags
if composer.manager.capsLockPressed {
if composer.server.io.testAndClearCapsLockState() {
dlog(DEBUG_IOKIT_EVENT, "controller detected capslock")
composer.manager.capsLockPressed = false
composer.manager.ioConnect.capsLockState = false
dlog(DEBUG_IOKIT_EVENT, "state after resetting: \(composer.manager.ioConnect.capsLockState)")
modifierFlags.formUnion(.capsLock)

dlog(DEBUG_IOKIT_EVENT, "modifierFlags by IOKit: %lx", modifierFlags.rawValue)
Expand Down
15 changes: 7 additions & 8 deletions CommonInputMethod/CIMInputReceiver.swift
Expand Up @@ -19,7 +19,6 @@ import Foundation
init(server: IMKServer, delegate: Any!, client: Any!, controller: CIMInputController) {
dlog(DEBUG_INPUTCONTROLLER, "**** NEW INPUT CONTROLLER INIT **** WITH SERVER: %@ / DELEGATE: %@ / CLIENT: %@", server, (delegate as? NSObject) ?? "(nil)", (client as? NSObject) ?? "(nil)")
composer = GureumComposer()
composer.manager = CIMInputManager.shared
inputClient = client
self.controller = controller
}
Expand All @@ -29,9 +28,9 @@ import Foundation
dlog(DEBUG_LOGGING, "LOGGING::KEY::(%@)(%ld)(%lu)", string?.replacingOccurrences(of: "\n", with: "\\n") ?? "(nil)", keyCode, flags.rawValue)

let hadComposedString = !_internalComposedString.isEmpty
let handled = composer.manager.input(controller: controller, inputText: string, key: keyCode, modifiers: flags, client: sender)
let handled = composer.server.input(controller: controller, inputText: string, key: keyCode, modifiers: flags, client: sender)

composer.manager.inputting = true
composer.server.inputting = true

switch handled {
case .notProcessed:
Expand All @@ -57,7 +56,7 @@ import Foundation
updateComposition(controller) // 조합 중인 문자 반영
}

composer.manager.inputting = false
composer.server.inputting = false

dlog(DEBUG_INPUTCONTROLLER, "*** End of Input handling ***")
return handled
Expand Down Expand Up @@ -86,7 +85,7 @@ extension CIMInputReceiver { // IMKServerInput
// 조합을 중단하고 현재까지 조합된 글자를 커밋한다.
func commitCompositionEvent(_ sender: Any!, controller: CIMInputController) -> Bool {
dlog(DEBUG_LOGGING, "LOGGING::EVENT::COMMIT")
if !composer.manager.inputting {
if !composer.server.inputting {
// 입력기 외부에서 들어오는 커밋 요청에 대해서는 편집 중인 글자도 커밋한다.
dlog(DEBUG_INPUTCONTROLLER, "-- CANCEL composition because of external commit request from %@", sender as! NSObject)
dlog(DEBUG_LOGGING, "LOGGING::EVENT::CANCEL-INTERNAL")
Expand All @@ -110,7 +109,7 @@ extension CIMInputReceiver { // IMKServerInput
controller.client().insertText(commitString, replacementRange: NSRange(location: NSNotFound, length: NSNotFound))
}

composer.manager.controllerDidCommit(controller)
composer.server.controllerDidCommit(controller)

return true
}
Expand Down Expand Up @@ -152,10 +151,10 @@ extension CIMInputReceiver { // IMKServerInput

func candidateSelected(_ candidateString: NSAttributedString, controller: CIMInputController) {
dlog(DEBUG_LOGGING, "LOGGING::CHECK::CANDIDATESELECTED::%@", candidateString)
composer.manager.inputting = true
composer.server.inputting = true
composer.candidateSelected(candidateString)
commitComposition(inputClient, controller: controller)
composer.manager.inputting = false
composer.server.inputting = false
}

func candidateSelectionChanged(_ candidateString: NSAttributedString, controller: CIMInputController) {
Expand Down
8 changes: 4 additions & 4 deletions Gureum.xcodeproj/project.pbxproj
Expand Up @@ -91,7 +91,7 @@
80383E6F2161F0D300FC5FB6 /* hangul-combination-3p.xml in Copy Keyboards Files */ = {isa = PBXBuildFile; fileRef = 80383E6C2161F0D300FC5FB6 /* hangul-combination-3p.xml */; };
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 */; };
878898012160AA6E00BF5770 /* CIMInputManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 871B807B2153DDFA0013EE69 /* CIMInputManager.swift */; };
878898012160AA6E00BF5770 /* InputMethodServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 871B807B2153DDFA0013EE69 /* InputMethodServer.swift */; };
8FB2D1F50746B5A15A5617BE /* libPods-OSXTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E73EDD6DBCA6CA17A1708BE5 /* libPods-OSXTests.a */; };
A34E20012168B21B00B12476 /* GureumTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3BAAE062160C6970076C66D /* GureumTests.swift */; };
A34E2025216ADBEC00B12476 /* emoji.txt in Copy Hanja Files */ = {isa = PBXBuildFile; fileRef = A34E2024216ADBEC00B12476 /* emoji.txt */; };
Expand Down Expand Up @@ -338,7 +338,7 @@
80383E6C2161F0D300FC5FB6 /* hangul-combination-3p.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = "hangul-combination-3p.xml"; sourceTree = "<group>"; };
80A02B22217E1AA90018E658 /* hangul-keyboard-2y-full.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = "hangul-keyboard-2y-full.xml"; sourceTree = "<group>"; };
80A02B23217E1AA90018E658 /* hangul-keyboard-2-full.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = "hangul-keyboard-2-full.xml"; sourceTree = "<group>"; };
871B807B2153DDFA0013EE69 /* CIMInputManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CIMInputManager.swift; sourceTree = "<group>"; };
871B807B2153DDFA0013EE69 /* InputMethodServer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InputMethodServer.swift; sourceTree = "<group>"; };
9B1EC9A5CFCEEBC9368AE9A9 /* Pods-PreferencesApp.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PreferencesApp.debug.xcconfig"; path = "Pods/Target Support Files/Pods-PreferencesApp/Pods-PreferencesApp.debug.xcconfig"; sourceTree = "<group>"; };
A34E2024216ADBEC00B12476 /* emoji.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = emoji.txt; sourceTree = "<group>"; };
A36A4358216F86780052BE12 /* emoji_ko.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = emoji_ko.txt; sourceTree = "<group>"; };
Expand Down Expand Up @@ -420,6 +420,7 @@
38FA220114233FD900444D67 /* Hangul.xcodeproj */,
388FD02A175EDB5500469B76 /* Version.xcconfig */,
381DB19A21678B74005A37B9 /* Debug.swift */,
871B807B2153DDFA0013EE69 /* InputMethodServer.swift */,
38C2AE4C208795E700FE211A /* GureumConfiguration.swift */,
381B32731DA826B100EA1975 /* Bridge.h */,
E5ED2DE3213030B700BD9B13 /* CIMInputControllerGureum.swift */,
Expand Down Expand Up @@ -550,7 +551,6 @@
387DFFFE1421F1E000DAE6F4 /* Common Input Method */ = {
isa = PBXGroup;
children = (
871B807B2153DDFA0013EE69 /* CIMInputManager.swift */,
E5D234EE2141260E00595FA0 /* CIMApplicationDelegate.swift */,
38AC8D49217C4EDA00E4B332 /* CIMInputReceiver.swift */,
38863C95140E669000A8ED76 /* CIMInputController.h */,
Expand Down Expand Up @@ -1112,7 +1112,7 @@
E5A0EA0A2139098800D4AD69 /* GureumAppDelegate.swift in Sources */,
E54B8382214299EB00527218 /* GureumComposer.swift in Sources */,
38D3E42B21213E9700751191 /* HangulComposer.swift in Sources */,
878898012160AA6E00BF5770 /* CIMInputManager.swift in Sources */,
878898012160AA6E00BF5770 /* InputMethodServer.swift in Sources */,
38F85961215BD27000CD80AE /* main.swift in Sources */,
381DB19B21678B74005A37B9 /* Debug.swift in Sources */,
3831983C21DB744900E20D78 /* UpdateManager.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion OSX/CIMInputControllerGureum.swift
Expand Up @@ -3,7 +3,7 @@
// Gureum
//
// Created by KMLee on 2018. 8. 24..
// Copyright © 2018년 youknowone.org. All rights reserved.
// Copyright © 2018 youknowone.org. All rights reserved.
//

import Cocoa
Expand Down
4 changes: 2 additions & 2 deletions OSX/GureumAppDelegate.swift
Expand Up @@ -3,7 +3,7 @@
// Gureum
//
// Created by 혜원 on 2018. 8. 27..
// Copyright © 2018년 youknowone.org. All rights reserved.
// Copyright © 2018 youknowone.org. All rights reserved.
//

import Crashlytics
Expand Down Expand Up @@ -58,6 +58,6 @@ class NotificationCenterDelegate: NSObject, NSUserNotificationCenterDelegate {

HGKeyboard.initialize()
// IMKServer를 띄워야만 입력기가 동작한다
_ = CIMInputManager.shared
_ = InputMethodServer.shared
}
}
2 changes: 1 addition & 1 deletion OSX/GureumComposer.swift
Expand Up @@ -3,7 +3,7 @@
// Gureum
//
// Created by Hyewon on 2018. 9. 7..
// Copyright © 2018년 youknowone.org. All rights reserved.
// Copyright © 2018 youknowone.org. All rights reserved.
//
/*!
@brief 구름 입력기의 합성기
Expand Down
2 changes: 1 addition & 1 deletion OSX/HangulComposer.swift
Expand Up @@ -3,7 +3,7 @@
// Gureum
//
// Created by Jeong YunWon on 2018. 8. 13..
// Copyright © 2018년 youknowone.org. All rights reserved.
// Copyright © 2018 youknowone.org. All rights reserved.
//

import Foundation
Expand Down
2 changes: 1 addition & 1 deletion OSX/IOKitUtility.swift
Expand Up @@ -3,7 +3,7 @@
// Gureum
//
// Created by Jeong YunWon on 2018. 9. 1..
// Copyright © 2018년 youknowone.org. All rights reserved.
// Copyright © 2018 youknowone.org. All rights reserved.
//

import Foundation
Expand Down

0 comments on commit 422e929

Please sign in to comment.