Permalink
Browse files

swiftformat

  • Loading branch information...
youknowone committed Jan 12, 2019
1 parent 776b745 commit e59589fc38087785bc4e56d1cf63385a781b13ed
@@ -9,7 +9,6 @@
import Foundation

class CIMBaseComposer {

func composedString() -> NSString {
return ""
}
@@ -21,22 +20,22 @@ class CIMBaseComposer {
func commitString() -> NSString {
return ""
}

func dequeueCommitString() -> NSString {
return ""
}

func cancelComposition() -> Void { }

func clearContext() -> Void { }

func cancelComposition() {}

func clearContext() {}

func hasCandidates() -> Bool { return false }

func candidates() -> NSArray? {
return nil
}
public func input(controller: CIMInputController!, command string: String!, key keyCode: Int, modifier flags: NSEvent.ModifierFlags, client sender: Any) -> CIMInputTextProcessResult {

func input(controller _: CIMInputController!, command _: String!, key _: Int, modifier _: NSEvent.ModifierFlags, client _: Any) -> CIMInputTextProcessResult {
return CIMInputTextProcessResult.notProcessed
}
}
@@ -14,27 +14,25 @@ import Foundation
@discussion TextData형식으로 @ref IMKServerInput 을 처리할 클래스의 공통 인터페이스. CharmIM에서 입력 값을 보고 처리하는 모든 클래스는 이 프로토콜을 구현한다.
*/
protocol CIMInputTextDelegate {
/*!
@method
@param controller 서버에서 입력을 받은 컨트롤러
@param string 문자열로 표현된 입력 값
@param keyCode 입력된 raw key code
@param flags 입력된 modifier flag
@param sender 입력 값을 전달한 외부 오브젝트
@return 입력 처리 여부. YES를 반환하면 이미 처리된 입력으로 보고 NO를 반환하면 외부에서 입력을 다시 처리한다.
@see IMKServerInput
*/
/*!
@method
@param controller 서버에서 입력을 받은 컨트롤러
@param string 문자열로 표현된 입력 값
@param keyCode 입력된 raw key code
@param flags 입력된 modifier flag
@param sender 입력 값을 전달한 외부 오브젝트
@return 입력 처리 여부. YES를 반환하면 이미 처리된 입력으로 보고 NO를 반환하면 외부에서 입력을 다시 처리한다.
@see IMKServerInput
*/
func input(controller: CIMInputController, inputText: String?, key: Int, modifiers: NSEvent.ModifierFlags, client: Any) -> CIMInputTextProcessResult
}


/*!
@brief 실제로 문자를 합성하는 합성기의 프로토콜
@discussion 입력기 전체의 상태에 영향을 끼치는 처리를 마친 후 출력할 글자를 조합하기 위해 CIMComposer로 입력을 전달한다. 기본적으로 자판마다 하나씩 구현하게 된다.
*/

protocol CIMComposerDelegate: CIMInputTextDelegate {

//! @brief 입력기가 선택 됨
func composerSelected(_ sender: Any!)

@@ -62,69 +60,65 @@ protocol CIMComposerDelegate: CIMInputTextDelegate {
func candidateSelectionChanged(_ candidateString: NSAttributedString)

func input(controller: CIMInputController, command string: String?, key keyCode: Int, modifiers flags: NSEvent.ModifierFlags, client: Any) -> CIMInputTextProcessResult

}


/*!
@brief 일반적인 합성기 구조
@warning 이 자체로는 동작하지 않는다. 상속하여 동작을 구현하거나 @ref CIMBaseComposer 를 사용한다.
*/
class CIMComposer: NSObject, CIMComposerDelegate {

public func composerSelected(_ sender: Any!) { }

public var delegate: CIMComposerDelegate! = nil
public var inputMode: String = ""
public var manager: CIMInputManager! = nil

public var composedString: String {
func composerSelected(_: Any!) {}

var delegate: CIMComposerDelegate!
var inputMode: String = ""
var manager: CIMInputManager!

var composedString: String {
return delegate.composedString
}
public var originalString: String {

var originalString: String {
return delegate.originalString
}
public var commitString: String {

var commitString: String {
return delegate.commitString
}
public func dequeueCommitString() -> String {

func dequeueCommitString() -> String {
return delegate.dequeueCommitString()
}

public func cancelComposition() {
func cancelComposition() {
delegate.cancelComposition()
}
public func clearContext() {

func clearContext() {
delegate.clearContext()
}
public var hasCandidates: Bool {

var hasCandidates: Bool {
return delegate.hasCandidates
}
public var candidates: [NSAttributedString]? {

var candidates: [NSAttributedString]? {
return delegate.candidates ?? nil
}
public func candidateSelected(_ candidateString: NSAttributedString) {

func candidateSelected(_ candidateString: NSAttributedString) {
return delegate.candidateSelected(candidateString)
}
public func candidateSelectionChanged(_ candidateString: NSAttributedString) {

func candidateSelectionChanged(_ candidateString: NSAttributedString) {
return delegate.candidateSelectionChanged(candidateString)
}

public func input(controller: CIMInputController, inputText string: String?, key keyCode: Int, modifiers flags: NSEvent.ModifierFlags, client sender: Any) -> CIMInputTextProcessResult {
func input(controller: CIMInputController, inputText string: String?, key keyCode: Int, modifiers flags: NSEvent.ModifierFlags, client sender: Any) -> CIMInputTextProcessResult {
return delegate.input(controller: controller, inputText: string, key: keyCode, modifiers: flags, client: sender)
}
public func input(controller: CIMInputController, command string: String?, key keyCode: Int, modifiers flags: NSEvent.ModifierFlags, client sender: Any) -> CIMInputTextProcessResult {

func input(controller: CIMInputController, command string: String?, key keyCode: Int, modifiers flags: NSEvent.ModifierFlags, client sender: Any) -> CIMInputTextProcessResult {
return delegate.input(controller: controller, command: string, key: keyCode, modifiers: flags, client: sender)
}
}

@@ -79,13 +79,13 @@ extension CIMInputController { // IMKServerInputHandleEvent
} else if event.type == .flagsChanged {
var modifierFlags = event.modifierFlags
if composer.manager.capsLockPressed {
dlog(true, "controller detected capslock")
dlog(DEBUG_IOKIT_EVENT, "controller detected capslock")
composer.manager.capsLockPressed = false
composer.manager.ioConnect.capsLockState = false
dlog(true, "state after resetting: \(composer.manager.ioConnect.capsLockState)")
dlog(DEBUG_IOKIT_EVENT, "state after resetting: \(composer.manager.ioConnect.capsLockState)")
modifierFlags.formUnion(.capsLock)

dlog(true, "modifierFlags by IOKit: %lx", modifierFlags.rawValue)
dlog(DEBUG_IOKIT_EVENT, "modifierFlags by IOKit: %lx", modifierFlags.rawValue)
// dlog(DEBUG_INPUTCONTROLLER, @"** CIMInputController FLAGCHANGED -handleEvent:client: with event: %@ / key: %d / modifier: %lu / chars: %@ / chars ignoreMod: %@ / client: %@", event, -1, modifierFlags, nil, nil, [[self client] bundleIdentifier])
_ = receiver.input(controller: self, inputText: nil, key: CIMInputControllerSpecialKeyCode.capsLockPressed.rawValue, modifiers: modifierFlags, client: sender)
return false
@@ -8,7 +8,8 @@
import Foundation

let DEBUG_INPUTHANDLER = false
let DEBUG_INPUT_SERVER = false
let DEBUG_INPUT_HANDLER = false
let DEBUG_IOKIT_EVENT = false

let CIMKeyMapLower = [
@@ -81,16 +82,16 @@ class CIMInputManager: NSObject, CIMInputTextDelegate {
}

init(name: String) {
dlog(true, "** CIMInputManager Init")
dlog(DEBUG_INPUT_SERVER, "** CIMInputManager Init")

server = IMKServer(name: name, bundleIdentifier: Bundle.main.bundleIdentifier)
candidates = IMKCandidates(server: server, panelType: kIMKSingleColumnScrollingCandidatePanel)
candidates.setSelectionKeysKeylayout(TISInputSource.currentLayout().ref)

super.init()
ref = self
ref = self // iokit callback
dlog(true, "\t%@", description)
dlog(DEBUG_INPUT_SERVER, "\t%@", description)

guard let ioService = try? IOService(name: kIOHIDSystemClass) else {
return
@@ -109,7 +110,7 @@ class CIMInputManager: NSObject, CIMInputTextDelegate {
IOHIDManagerRegisterInputValueCallback(ioHidManager, {
inContext, _, _, value in
guard let inContext = inContext else {
dlog(true, "IOKit callback inContext is nil")
dlog(DEBUG_IOKIT_EVENT, "IOKit callback inContext is nil")
return
}
let intValue = value.integerValue
@@ -160,11 +161,11 @@ class CIMInputManager: NSObject, CIMInputTextDelegate {
var string = string
if flags.contains(.option) {
let configuration = GureumConfiguration.shared
dlog(DEBUG_INPUTHANDLER, "option key: %ld", configuration.optionKeyBehavior)
dlog(DEBUG_INPUT_HANDLER, "option key: %ld", configuration.optionKeyBehavior)
switch configuration.optionKeyBehavior {
case 0:
// default
dlog(DEBUG_INPUTHANDLER, " ** ESCAPE from option-key default behavior")
dlog(DEBUG_INPUT_HANDLER, " ** ESCAPE from option-key default behavior")
return .notProcessedAndNeedsCommit
case 1:
// ignore
@@ -190,7 +191,7 @@ class CIMInputManager: NSObject, CIMInputTextDelegate {

// 특정 애플리케이션에서 커맨드/옵션/컨트롤 키 입력을 선점하지 못하는 문제를 회피한다
if flags.contains(.command) || flags.contains(.option) || flags.contains(.control) {
dlog(true, "-- CIMInputHandler -inputText: Command/Option key input / returned NO")
dlog(DEBUG_INPUT_HANDLER, "-- CIMInputHandler -inputText: Command/Option key input / returned NO")
return .notProcessedAndNeedsCommit
}

Oops, something went wrong.

0 comments on commit e59589f

Please sign in to comment.