Skip to content

Commit

Permalink
Merge pull request #492 from youknowone/iokit
Browse files Browse the repository at this point in the history
 IOKit을 manager로 옮기고 InputController swift포트
  • Loading branch information
youknowone committed Jan 12, 2019
2 parents 2d7d73f + ad66966 commit 776b745
Show file tree
Hide file tree
Showing 13 changed files with 371 additions and 318 deletions.
2 changes: 1 addition & 1 deletion CommonInputMethod/CIMApplicationDelegate.swift
Expand Up @@ -6,8 +6,8 @@
// Copyright © 2018년 youknowone.org. All rights reserved.
//

import Foundation
import Cocoa
import Foundation

@objc protocol CIMApplicationDelegate: NSObjectProtocol {
//! @brief 언어 설정에 추가될 메뉴
Expand Down
6 changes: 3 additions & 3 deletions CommonInputMethod/CIMComposer.swift
Expand Up @@ -13,7 +13,7 @@ import Foundation
@brief 입력을 처리하는 클래스의 관한 공통 형식
@discussion TextData형식으로 @ref IMKServerInput 을 처리할 클래스의 공통 인터페이스. CharmIM에서 입력 값을 보고 처리하는 모든 클래스는 이 프로토콜을 구현한다.
*/
public protocol CIMInputTextDelegate {
protocol CIMInputTextDelegate {
/*!
@method
@param controller 서버에서 입력을 받은 컨트롤러
Expand All @@ -33,7 +33,7 @@ public protocol CIMInputTextDelegate {
@discussion 입력기 전체의 상태에 영향을 끼치는 처리를 마친 후 출력할 글자를 조합하기 위해 CIMComposer로 입력을 전달한다. 기본적으로 자판마다 하나씩 구현하게 된다.
*/

public protocol CIMComposerDelegate: CIMInputTextDelegate {
protocol CIMComposerDelegate: CIMInputTextDelegate {

//! @brief 입력기가 선택 됨
func composerSelected(_ sender: Any!)
Expand Down Expand Up @@ -71,7 +71,7 @@ public protocol CIMComposerDelegate: CIMInputTextDelegate {
@warning 이 자체로는 동작하지 않는다. 상속하여 동작을 구현하거나 @ref CIMBaseComposer 를 사용한다.
*/
public class CIMComposer: NSObject, CIMComposerDelegate {
class CIMComposer: NSObject, CIMComposerDelegate {

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

Expand Down
34 changes: 0 additions & 34 deletions CommonInputMethod/CIMInputController.h
Expand Up @@ -28,42 +28,8 @@ static const int CIMKeyMapSize = 0x33;

@class CIMInputController;

/*!
@enum
@brief 최종적으로 CIMInputController가 처리할 결과
*/
typedef NS_ENUM(int, CIMInputTextProcessResult) {
CIMInputTextProcessResultNotProcessedAndNeedsCommit = -2,
CIMInputTextProcessResultNotProcessedAndNeedsCancel = -1,
CIMInputTextProcessResultNotProcessed = 0,
CIMInputTextProcessResultProcessed = 1,
};


NS_ASSUME_NONNULL_BEGIN

@class CIMInputReceiver;
@class IOConnect;

typedef NS_ENUM(NSInteger, CIMInputControllerSpecialKeyCode) {
CIMInputControllerSpecialKeyCodeCapsLockPressed = -1,
CIMInputControllerSpecialKeyCodeCapsLockFlagsChanged = -2,
};

@interface CIMInputController : IMKInputController {
CIMInputReceiver *_receiver;
IOConnect *_ioConnect;
IOHIDManagerRef _hidManager;
BOOL _capsLockPressed;
}

@property(readonly) CIMInputReceiver *receiver; // temp bridge
@property(readonly) IOConnect *ioConnect; // temp bridge
@property(assign) BOOL capsLockPressed; // temp bridge

@end


#if DEBUG

// no impleentation for this class here
Expand Down
56 changes: 0 additions & 56 deletions CommonInputMethod/CIMInputController.m
Expand Up @@ -30,66 +30,10 @@
return source;
}


@implementation CIMInputController

@synthesize receiver=_receiver, ioConnect=_ioConnect, capsLockPressed=_capsLockPressed;

- (instancetype)initWithServer:(nullable IMKServer *)server delegate:(nullable id)delegate client:(nullable id)inputClient {
self = [super initWithServer:server delegate:delegate client:inputClient];
if (self != nil) {
dlog(DEBUG_INPUTCONTROLLER, @"**** NEW INPUT CONTROLLER INIT **** WITH SERVER: %@ / DELEGATE: %@ / CLIENT: %@", server, delegate, inputClient);
self->_receiver = [[CIMInputReceiver alloc] initWithServer:server delegate:delegate client:inputClient controller:self];

IOService* service = [[IOService alloc] initWithName:@(kIOHIDSystemClass) error:NULL];
self->_ioConnect = [service openWithOwningTask:mach_task_self_ type:kIOHIDParamConnectType];
dlog(DEBUG_INPUTCONTROLLER, @"io_connect: %@", self->_ioConnect);

self->_hidManager = [IOHIDManagerBridge capsLockManager];
CFRetain(self->_hidManager);

// Set input value callback
IOHIDManagerRegisterInputValueCallback(self->_hidManager, handleInputValueCallback, (__bridge void *)(self));
IOHIDManagerScheduleWithRunLoop(self->_hidManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
IOReturn ioReturn = IOHIDManagerOpen(self->_hidManager, kIOHIDOptionsTypeNone);
if (ioReturn) {
dlog(DEBUG_INPUTCONTROLLER, @"IOHIDManagerOpen failed");
}

self->_capsLockPressed = NO;
}
return self;
}

- (void)dealloc {
IOHIDManagerUnscheduleFromRunLoop(self->_hidManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
IOHIDManagerRegisterInputValueCallback(self->_hidManager, nil, nil);
IOHIDManagerClose(self->_hidManager, kIOHIDOptionsTypeNone);
CFRelease(self->_hidManager);
}


static void handleInputValueCallback(void *inContext, IOReturn inResult, void *inSender, IOHIDValueRef inIOHIDValueRef) {
CIMInputController *inputController = (__bridge CIMInputController *)(inContext);
CFIndex intValue = IOHIDValueGetIntegerValue(inIOHIDValueRef);

dlog(DEBUG_INPUTCONTROLLER, @"context: %@, caps lock pressed: %lx", inputController, intValue);
if (intValue == 1) {
inputController->_capsLockPressed = YES;
}
}

@end


#if DEBUG

@implementation CIMMockInputController (IMKServerInputTextData)

- (id<IMKTextInput,NSObject>)client {
return self._receiver.inputClient;
}

- (void)updateComposition {
[self._receiver updateCompositionEvent:(id)self];
{ // super
Expand Down

0 comments on commit 776b745

Please sign in to comment.