Permalink
Browse files

Experimental Dvorak Composer

  • Loading branch information...
youknowone committed Aug 27, 2017
1 parent 2b92df6 commit 37b0076ae0ea586b8a64d316111e861005c6700c
@@ -47,6 +47,6 @@ typedef enum {
@return 입력 처리 여부. YES를 반환하면 이미 처리된 입력으로 보고 NO를 반환하면 외부에서 입력을 다시 처리한다.
@see IMKServerInput
*/
- (CIMInputTextProcessResult)inputController:(CIMInputController *)controller inputText:(NSString *)string key:(NSInteger)keyCode modifiers:(NSUInteger)flags client:(id)sender;
- (CIMInputTextProcessResult)inputController:(CIMInputController *)controller inputText:(NSString *)string key:(NSInteger)keyCode modifiers:(NSEventModifierFlags)flags client:(id)sender;
@end
@@ -38,14 +38,14 @@
@optional
//! @brief 변환 후보 문자열 리스트
@property(nonatomic, readonly) NSArray *candidates;
@property(nonatomic, readonly) NSArray<NSString *> *candidates;
//! @brief 변환 후보 문자열 선택
- (void)candidateSelected:(NSAttributedString *)candidateString;
//! @brief 변환 후보 문자열 변경
- (void)candidateSelectionChanged:(NSAttributedString *)candidateString;
@required
- (CIMInputTextProcessResult)inputController:(CIMInputController *)controller commandString:(NSString *)string key:(NSInteger)keyCode modifiers:(NSUInteger)flags client:(id)sender;
- (CIMInputTextProcessResult)inputController:(CIMInputController *)controller commandString:(NSString *)string key:(NSInteger)keyCode modifiers:(NSEventModifierFlags)flags client:(id)sender;
@end
@@ -60,11 +60,11 @@ - (void)candidateSelectionChanged:(NSAttributedString *)candidateString {
[_delegate candidateSelectionChanged:candidateString];
}
- (CIMInputTextProcessResult)inputController:(CIMInputController *)controller commandString:(NSString *)string key:(NSInteger)keyCode modifiers:(NSUInteger)flags client:(id)sender {
- (CIMInputTextProcessResult)inputController:(CIMInputController *)controller commandString:(NSString *)string key:(NSInteger)keyCode modifiers:(NSEventModifierFlags)flags client:(id)sender {
return [_delegate inputController:controller commandString:string key:keyCode modifiers:flags client:sender];
}
- (CIMInputTextProcessResult)inputController:(CIMInputController *)controller inputText:(NSString *)string key:(NSInteger)keyCode modifiers:(NSUInteger)flags client:(id)sender {
- (CIMInputTextProcessResult)inputController:(CIMInputController *)controller inputText:(NSString *)string key:(NSInteger)keyCode modifiers:(NSEventModifierFlags)flags client:(id)sender {
return [_delegate inputController:controller inputText:string key:keyCode modifiers:flags client:sender];
}
@@ -98,8 +98,8 @@ - (NSArray *)candidates { return nil; }
#pragma -
- (CIMInputTextProcessResult)inputController:(CIMInputController *)controller inputText:(NSString *)string key:(NSInteger)keyCode modifiers:(NSUInteger)flags client:(id)sender {
- (CIMInputTextProcessResult)inputController:(CIMInputController *)controller inputText:(NSString *)string key:(NSInteger)keyCode modifiers:(NSEventModifierFlags)flags client:(id)sender {
return CIMInputTextProcessResultNotProcessed;
}
@end
@end
@@ -84,7 +84,7 @@ - (void)dealloc {
}
// IMKServerInput 프로토콜에 대한 공용 핸들러
- (CIMInputTextProcessResult)inputController:(CIMInputController *)controller inputText:(NSString *)string key:(NSInteger)keyCode modifiers:(NSUInteger)flags client:(id)sender {
- (CIMInputTextProcessResult)inputController:(CIMInputController *)controller inputText:(NSString *)string key:(NSInteger)keyCode modifiers:(NSEventModifierFlags)flags client:(id)sender {
dlog(DEBUG_LOGGING, @"LOGGING::KEY::(%@)(%ld)(%lu)", [string stringByReplacingOccurrencesOfString:@"\n" withString:@"\\n"], keyCode, flags);
BOOL hadComposedString = self._internalComposedString.length > 0;
@@ -321,7 +321,7 @@ - (CIMComposer *)composer {
/*
@implementation CIMInputController (IMKServerInputTextData)
- (BOOL)inputText:(NSString *)string key:(NSInteger)keyCode modifiers:(NSUInteger)flags client:(id)sender {
- (BOOL)inputText:(NSString *)string key:(NSInteger)keyCode modifiers:(NSEventModifierFlags)flags client:(id)sender {
dlog(DEBUG_INPUTCONTROLLER, @"** CIMInputController -inputText:key:modifiers:client with string: %@ / keyCode: %ld / modifier flags: %lu / client: %@(%@)", string, keyCode, flags, [[self client] bundleIdentifier], [[self client] class]);
BOOL processed = [self->_receiver inputController:self inputText:string key:keyCode modifiers:flags client:sender] > CIMInputTextProcessResultNotProcessed;
@@ -513,7 +513,7 @@ - (NSRange)selectionRange {
@implementation CIMMockInputController (IMKServerInputTextData)
- (BOOL)inputText:(NSString *)string key:(NSInteger)keyCode modifiers:(NSUInteger)flags client:(id)sender {
- (BOOL)inputText:(NSString *)string key:(NSInteger)keyCode modifiers:(NSEventModifierFlags)flags client:(id)sender {
dlog(DEBUG_INPUTCONTROLLER, @"** CIMInputController -inputText:key:modifiers:client with string: %@ / keyCode: %ld / modifier flags: %lu / client: %@(%@)", string, keyCode, flags, [[self client] bundleIdentifier], [[self client] class]);
BOOL processed = [self->_receiver inputController:(id)self inputText:string key:keyCode modifiers:flags client:sender] > CIMInputTextProcessResultNotProcessed;
@@ -33,7 +33,7 @@ - (void)setManager:(CIMInputManager *)aManager {
#pragma - IMKServerInputTextData
- (CIMInputTextProcessResult)inputController:(CIMInputController *)controller inputText:(NSString *)string key:(NSInteger)keyCode modifiers:(NSUInteger)flags client:(id)sender {
- (CIMInputTextProcessResult)inputController:(CIMInputController *)controller inputText:(NSString *)string key:(NSInteger)keyCode modifiers:(NSEventModifierFlags)flags client:(id)sender {
// 입력기용 특수 커맨드 처리
CIMInputTextProcessResult result = [controller.composer inputController:controller commandString:string key:keyCode modifiers:flags client:sender];
if (result == CIMInputTextProcessResultNotProcessedAndNeedsCommit) {
@@ -52,7 +52,7 @@ - (NSString *)description {
#pragma - IMKServerInputTextData
// 일단 받은 입력은 모두 핸들러로 넘겨준다.
- (CIMInputTextProcessResult)inputController:(CIMInputController *)controller inputText:(NSString *)string key:(NSInteger)keyCode modifiers:(NSUInteger)flags client:(id)sender {
- (CIMInputTextProcessResult)inputController:(CIMInputController *)controller inputText:(NSString *)string key:(NSInteger)keyCode modifiers:(NSEventModifierFlags)flags client:(id)sender {
assert([[controller className] hasSuffix:@"InputController"]);
self.needsFakeComposedString = NO;
CIMInputTextProcessResult handled = [self->handler inputController:controller inputText:string key:keyCode modifiers:flags client:sender];
@@ -62,7 +62,6 @@
38FA21D71422DBBF00444D67 /* CIMInputManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 387D00051421FB6E00DAE6F4 /* CIMInputManager.m */; };
38FA21DA14230E1000444D67 /* GureumComposer.m in Sources */ = {isa = PBXBuildFile; fileRef = 38FA21D914230E1000444D67 /* GureumComposer.m */; };
38FA21DD14230E2E00444D67 /* CIMInputController.m in Sources */ = {isa = PBXBuildFile; fileRef = 38863C96140E669000A8ED76 /* CIMInputController.m */; };
38FDDEE019F547170055731D /* RomanComposer.m in Sources */ = {isa = PBXBuildFile; fileRef = 38FDDEDF19F547170055731D /* RomanComposer.m */; };
4566647A80A740283CE070C9 /* libPods-OSX.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B994C498AB6F1C414B12608 /* libPods-OSX.a */; };
/* End PBXBuildFile section */
@@ -223,7 +222,6 @@
38FA21D814230E1000444D67 /* GureumComposer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GureumComposer.h; sourceTree = "<group>"; };
38FA21D914230E1000444D67 /* GureumComposer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GureumComposer.m; sourceTree = "<group>"; };
38FA220114233FD900444D67 /* Hangul.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Hangul.xcodeproj; path = "../libhangul-objc/Hangul.xcodeproj"; sourceTree = "<group>"; };
38FDDEDF19F547170055731D /* RomanComposer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RomanComposer.m; sourceTree = "<group>"; };
3B994C498AB6F1C414B12608 /* libPods-OSX.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-OSX.a"; sourceTree = BUILT_PRODUCTS_DIR; };
4CAB632CA8BB927B15D0FF2A /* Pods-OSX.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OSX.debug.xcconfig"; path = "Pods/Target Support Files/Pods-OSX/Pods-OSX.debug.xcconfig"; sourceTree = "<group>"; };
60EF36B9B3B06EE1D160329E /* Pods-OSX.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OSX.release.xcconfig"; path = "Pods/Target Support Files/Pods-OSX/Pods-OSX.release.xcconfig"; sourceTree = "<group>"; };
@@ -468,7 +466,6 @@
children = (
38FA21D814230E1000444D67 /* GureumComposer.h */,
38FA21D914230E1000444D67 /* GureumComposer.m */,
38FDDEDF19F547170055731D /* RomanComposer.m */,
38162D7A140F64B70077AA2D /* HangulComposer.h */,
38162D7B140F64B70077AA2D /* HangulComposer.m */,
38C75C8B1F153A74004BE02A /* RomanComposer.swift */,
@@ -788,7 +785,6 @@
38699DC21F36191500FD093E /* RomanComposer.swift in Sources */,
38162E1514126ACE0077AA2D /* CIMComposer.m in Sources */,
3802E4661413AA0000256B54 /* CIMConfiguration.m in Sources */,
38FDDEE019F547170055731D /* RomanComposer.m in Sources */,
38FA21D71422DBBF00444D67 /* CIMInputManager.m in Sources */,
38FA21DA14230E1000444D67 /* GureumComposer.m in Sources */,
38FA21DD14230E2E00444D67 /* CIMInputController.m in Sources */,
@@ -21,7 +21,7 @@
@property(nonatomic,strong) CIMInputController *controller;
@property(nonatomic,strong) CIMMockClient *client;
- (BOOL)inputText:(NSString *)text key:(NSUInteger)keyCode modifiers:(NSUInteger)flags;
- (BOOL)inputText:(NSString *)text key:(NSUInteger)keyCode modifiers:(NSEventModifierFlags)flags;
@end
@@ -52,7 +52,7 @@ - (id)init {
return self;
}
- (BOOL)inputText:(NSString *)text key:(NSUInteger)keyCode modifiers:(NSUInteger)flags {
- (BOOL)inputText:(NSString *)text key:(NSUInteger)keyCode modifiers:(NSEventModifierFlags)flags {
CIMInputController *controller = self.controller;
CIMMockClient *client = self.client;
BOOL processed = [controller inputText:text key:keyCode modifiers:flags client:client];
@@ -65,7 +65,7 @@ - (BOOL)inputText:(NSString *)text key:(NSUInteger)keyCode modifiers:(NSUInteger
@implementation ModerateApp
- (BOOL)inputText:(NSString *)text key:(NSUInteger)keyCode modifiers:(NSUInteger)flags {
- (BOOL)inputText:(NSString *)text key:(NSUInteger)keyCode modifiers:(NSEventModifierFlags)flags {
BOOL processed = [super inputText:text key:keyCode modifiers:flags];
if (!processed) {
[self.client insertText:text replacementRange:self.client.markedRange];
@@ -78,7 +78,7 @@ - (BOOL)inputText:(NSString *)text key:(NSUInteger)keyCode modifiers:(NSUInteger
@implementation TerminalApp
- (BOOL)inputText:(NSString *)text key:(NSUInteger)keyCode modifiers:(NSUInteger)flags {
- (BOOL)inputText:(NSString *)text key:(NSUInteger)keyCode modifiers:(NSEventModifierFlags)flags {
BOOL processed = NO;
if (self.client.hasMarkedText) {
processed = [super inputText:text key:keyCode modifiers:flags];
@@ -105,7 +105,7 @@ - (BOOL)inputText:(NSString *)text key:(NSUInteger)keyCode modifiers:(NSUInteger
@implementation GreedyApp
- (BOOL)inputText:(NSString *)text key:(NSUInteger)keyCode modifiers:(NSUInteger)flags {
- (BOOL)inputText:(NSString *)text key:(NSUInteger)keyCode modifiers:(NSEventModifierFlags)flags {
BOOL processed = NO;
if (self.client.hasMarkedText) {
processed = [super inputText:text key:keyCode modifiers:flags];
View
@@ -1,6 +1,9 @@
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//
#import <Foundation/Foundation.h>
#import <InputMethodKit/InputMethodKit.h>
#import "CIMCommon.h"
#import "CIMInputController.h"
#import "GureumComposer.h"
View
@@ -108,7 +108,7 @@ - (void)setInputMode:(NSString *)newInputMode {
[super setInputMode:newInputMode];
}
- (CIMInputTextProcessResult)inputController:(CIMInputController *)controller commandString:(NSString *)string key:(NSInteger)keyCode modifiers:(NSUInteger)flags client:(id)sender {
- (CIMInputTextProcessResult)inputController:(CIMInputController *)controller commandString:(NSString *)string key:(NSInteger)keyCode modifiers:(NSEventModifierFlags)flags client:(id)sender {
NSInteger inputModifier = flags & NSDeviceIndependentModifierFlagsMask & ~NSAlphaShiftKeyMask;
BOOL need_exchange = NO;
BOOL need_hanjamode = NO;
View
@@ -73,7 +73,7 @@ - (void)setKeyboardWithIdentifier:(NSString *)identifier {
#pragma - IMKInputServerTextData
- (CIMInputTextProcessResult)inputController:(CIMInputController *)inputController inputText:(NSString *)string key:(NSInteger)keyCode modifiers:(NSUInteger)flags client:(id)sender {
- (CIMInputTextProcessResult)inputController:(CIMInputController *)inputController inputText:(NSString *)string key:(NSInteger)keyCode modifiers:(NSEventModifierFlags)flags client:(id)sender {
// libhangul은 backspace를 키로 받지 않고 별도로 처리한다.
if (keyCode == kVK_Delete) {
return [self->_inputContext backspace] ? CIMInputTextProcessResultProcessed : CIMInputTextProcessResultNotProcessed;
@@ -99,7 +99,7 @@ - (CIMInputTextProcessResult)inputController:(CIMInputController *)inputControll
return handled ? CIMInputTextProcessResultProcessed : CIMInputTextProcessResultNotProcessedAndNeedsCancel;
}
- (CIMInputTextProcessResult)inputController:(CIMInputController *)controller commandString:(NSString *)string key:(NSInteger)keyCode modifiers:(NSUInteger)flags client:(id)sender {
- (CIMInputTextProcessResult)inputController:(CIMInputController *)controller commandString:(NSString *)string key:(NSInteger)keyCode modifiers:(NSEventModifierFlags)flags client:(id)sender {
dassert(NO); // 한글입력 상태로 념겨져서 처리하는 명령은 없다
return CIMInputTextProcessResultNotProcessed;
}
@@ -151,6 +151,7 @@ - (void)candidateSelectionChanged:(NSAttributedString *)candidateString {
@end
@implementation HanjaComposer
@synthesize mode=_mode;
@@ -364,7 +365,7 @@ - (HGHanjaTable *)emoticonReversedTable {
return sharedHanjaTable;
}
- (CIMInputTextProcessResult)inputController:(CIMInputController *)controller inputText:(NSString *)string key:(NSInteger)keyCode modifiers:(NSUInteger)flags client:(id)sender {
- (CIMInputTextProcessResult)inputController:(CIMInputController *)controller inputText:(NSString *)string key:(NSInteger)keyCode modifiers:(NSEventModifierFlags)flags client:(id)sender {
CIMInputTextProcessResult result = [self.delegate inputController:controller inputText:string key:keyCode modifiers:flags client:sender];
switch (keyCode) {
// backspace
View

This file was deleted.

Oops, something went wrong.
View
@@ -1,5 +1,5 @@
//
// DvorakComposer.swift
// RomanComposer.swift
// Gureum
//
// Created by Jeong YunWon on 2017. 7. 12..
@@ -50,27 +50,97 @@ class RomanComposer: CIMComposer {
}
}
override var candidates: [Any]! {
override var candidates: [String]! {
return nil
}
/*
#pragma -
override func inputController(_ controller: CIMInputController!, inputText string: String!, key keyCode: Int, modifiers flags: NSEventModifierFlags, client sender: Any!) -> CIMInputTextProcessResult {
- (CIMInputTextProcessResult)inputController:(CIMInputController *)controller inputText:(NSString *)string key:(NSInteger)keyCode modifiers:(NSUInteger)flags client:(id)sender {
if (string.length > 0 && keyCode < 0x33 && !(flags & NSAlternateKeyMask)) {
unichar chr = [string characterAtIndex:0];
if (flags & NSAlphaShiftKeyMask && 'a' <= chr && chr <= 'z') {
chr -= 0x20;
string = [NSString stringWithCharacters:&chr length:1];
if !string.isEmpty && keyCode < 0x33 && !flags.contains(NSAlternateKeyMask) {
var newString = string
let chr = string.characters.first!
if flags.contains(NSAlphaShiftKeyMask) && "a" <= chr && chr <= "z" {
let newChr = Character(UnicodeScalar(String(chr).unicodeScalars.first!.value - 0x20)!)
newString = String(newChr)
}
self._commitString = newString
return CIMInputTextProcessResultProcessed
} else {
self._commitString = nil
return CIMInputTextProcessResultNotProcessed
}
}
}
class DvorakComposer: CIMComposer {
var _commitString: String? = nil
override var composedString: String! {
get {
return "";
}
}
override var originalString: String! {
get {
return self._commitString ?? "";
}
}
override var commitString: String! {
get {
return self._commitString ?? "";
}
}
self._commitString = string;
return CIMInputTextProcessResultProcessed;
} else {
self._commitString = nil;
return CIMInputTextProcessResultNotProcessed;
override func dequeueCommitString() -> String! {
let dequeued = self._commitString
self._commitString = nil
return dequeued ?? ""
}
override func cancelComposition() {
}
override func clearContext() {
self._commitString = nil
}
override var hasCandidates: Bool {
get {
return false
}
}
override var candidates: [String]! {
return nil
}
override func inputController(_ controller: CIMInputController!, inputText string: String!, key keyCode: Int, modifiers flags: NSEventModifierFlags, client sender: Any!) -> CIMInputTextProcessResult {
let qwerty = "`1234567890-=\\qwertyuiop[]asdfghjkl;'zxcvbnm,./~!@#$%^&*()_+|QWERTYUIOP{}ASDFGHJKL:\"ZXCVBNM<>?"
let dvorak = "`1234567890[]\\',.pyfgcrl/=aoeuidhtns-;qjkxbmwvz~!@#$%^&*(){}|\"<>PYFGCRL?+AOEUIDHTNS_:QJKXBMWVZ"
var map: [Character: Character] = [:]
zip(qwerty.characters, dvorak.characters).forEach {
map[$0] = $1
}
if !string.isEmpty && keyCode < 0x33 && !flags.contains(NSAlternateKeyMask) {
let newChr: Character
let chr = string.characters.first!
if flags.contains(NSAlphaShiftKeyMask) && "a" <= chr && chr <= "z" {
newChr = Character(UnicodeScalar(String(chr).unicodeScalars.first!.value - 0x20)!)
} else {
newChr = chr
}
self._commitString = String(map[newChr]!)
return CIMInputTextProcessResultProcessed
} else {
self._commitString = nil
return CIMInputTextProcessResultNotProcessed
}
}
*/
}

0 comments on commit 37b0076

Please sign in to comment.