Skip to content

Commit

Permalink
IOKit을 manager로 옮기고 InputController swift포트
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowone committed Jan 12, 2019
1 parent 6d37be4 commit ad66966
Show file tree
Hide file tree
Showing 10 changed files with 324 additions and 269 deletions.
2 changes: 1 addition & 1 deletion CommonInputMethod/CIMApplicationDelegate.swift
Original file line number Diff line number Diff line change
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
22 changes: 0 additions & 22 deletions CommonInputMethod/CIMInputController.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,6 @@ static const int CIMKeyMapSize = 0x33;

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
Original file line number Diff line number Diff line change
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 ad66966

Please sign in to comment.