Permalink
Browse files

항상 입력 소스를 US로 고정

issue #128
  • Loading branch information...
1 parent c2a31f8 commit 9390d1a64dcde4185dec8137bf86d29c1e8abad9 @youknowone youknowone committed Oct 28, 2014
@@ -7,6 +7,7 @@
//
#import <AppKit/AppKit.h>
+#import <Carbon/Carbon.h>
#import "CIMCommon.h"
#import "CIMApplicationDelegate.h"
@@ -17,12 +18,26 @@
#import "CIMInputController.h"
#import "CIMConfiguration.h"
+#import "TISInputSource.h"
+
#define DEBUG_INPUTCONTROLLER FALSE
#define DEBUG_LOGGING FALSE
#define CIMSharedInputManager CIMAppDelegate.sharedInputManager
+TISInputSource *_USSource() {
+ static NSString *mainSourceID = @"com.apple.keylayout.US";
+ static TISInputSource *source = nil;
+ if (source == nil) {
+ NSArray *mainSources = [TISInputSource sourcesWithProperties:@{(NSString *)kTISPropertyInputSourceID: mainSourceID} includeAllInstalled:YES];
+ dlog(1, @"main sources: %@", mainSources);
+ source = [mainSources[0] retain];
+ }
+ return source;
+}
+
+
@interface CIMInputReceiver(IMKServerInput)
- (BOOL)commitComposition:(id)sender controller:(CIMInputController *)controller;
@@ -239,6 +254,39 @@ - (void)setValue:(id)value forTag:(long)tag client:(id)sender controller:(CIMInp
dlog(DEBUG_INPUTCONTROLLER, @"**** UNKNOWN TAG %ld !!! ****", tag);
break;
}
+
+ dlog(1, @"==== source");
+
+ TISInputSource *mainSource = _USSource();
+ NSString *mainSourceID = mainSource.identifier;
+ TISInputSource *currentSource = [TISInputSource currentSource];
+ dlog(1, @"current source: %@", currentSource);
+
+ [TISInputSource setInputMethodKeyboardLayoutOverride:mainSource];
+
+ TISInputSource *override = [TISInputSource inputMethodKeyboardLayoutOverride];
+ if (override == nil) {
+ dlog(1, @"override fail");
+ TISInputSource *currentASCIISource = [TISInputSource currentASCIICapableLayoutSource];
+ dlog(1, @"ascii: %@", currentASCIISource);
+ id ASCIISourceID = currentASCIISource.identifier;
+ if (![ASCIISourceID isEqualToString:mainSourceID]) {
+ dlog(1, @"id: %@ != %@", ASCIISourceID, mainSourceID);
+ BOOL mainSourceIsEnabled = mainSource.enabled;
+ //if (!mainSourceIsEnabled) {
+ // [mainSource enable];
+ //}
+ if (mainSourceIsEnabled) {
+ [mainSource select];
+ [currentSource select];
+ }
+ //if (!mainSourceIsEnabled) {
+ // [mainSource disable];
+ //}
+ }
+ } else {
+ dlog(1, @"overrided");
+ }
}
@end
@@ -0,0 +1,76 @@
+//
+// TISInputSource.h
+// Gureum
+//
+// Created by Jeong YunWon on 2014. 10. 29..
+// Copyright (c) 2014년 youknowone.org. All rights reserved.
+//
+
+#import <Carbon/Carbon.h>
+
+#define TISPropertyInputSourceCategory (NSString *)kTISPropertyInputSourceCategory
+#define TISPropertyInputSourceType (NSString *)kTISPropertyInputSourceType
+#define TISPropertyInputSourceIsASCIICapable (NSString *)kTISPropertyInputSourceIsASCIICapable
+#define TISPropertyInputSourceIsEnableCapable (NSString *)kTISPropertyInputSourceIsEnableCapable
+#define TISPropertyInputSourceIsSelectCapable (NSString *)kTISPropertyInputSourceIsSelectCapable
+#define TISPropertyInputSourceIsEnabled (NSString *)kTISPropertyInputSourceIsEnabled
+#define TISPropertyInputSourceIsSelected (NSString *)kTISPropertyInputSourceIsSelected
+#define TISPropertyInputSourceID (NSString *)kTISPropertyInputSourceID
+#define TISPropertyBundleID (NSString *)kTISPropertyBundleID
+#define TISPropertyInputModeID (NSString *)kTISPropertyInputModeID
+#define TISPropertyLocalizedName (NSString *)kTISPropertyLocalizedName
+
+#define TISPropertyInputSourceLanguages (NSString *)kTISPropertyInputSourceLanguages
+#define TISPropertyUnicodeKeyLayoutData (NSString *)kTISPropertyUnicodeKeyLayoutData
+#define TISPropertyIconRef (NSString *)kTISPropertyIconRef
+#define TISPropertyIconImageURL (NSString *)kTISPropertyIconImageURL
+
+#define TISCategoryKeyboardInputSource (NSString *)kTISCategoryKeyboardInputSource
+#define TISCategoryPaletteInputSource (NSString *)kTISCategoryPaletteInputSource
+#define TISCategoryInkInputSource (NSString *)kTISCategoryInkInputSource
+
+#define TISTypeKeyboardLayout (NSString *)kTISTypeKeyboardLayout
+#define TISTypeKeyboardInputMethodWithoutModes (NSString *)kTISTypeKeyboardInputMethodWithoutModes
+#define TISTypeKeyboardInputMethodModeEnabled (NSString *)kTISTypeKeyboardInputMethodModeEnabled
+#define TISTypeKeyboardInputMode (NSString *)kTISTypeKeyboardInputMode
+#define TISTypeCharacterPalette (NSString *)kTISTypeCharacterPalette
+#define TISTypeKeyboardViewer (NSString *)kTISTypeKeyboardViewer
+#define TISTypeInk (NSString *)kTISTypeInk
+
+#define TISNotifySelectedKeyboardInputSourceChanged (NSString *)kTISNotifySelectedKeyboardInputSourceChanged
+#define TISNotifyEnabledKeyboardInputSourcesChanged (NSString *)kTISNotifyEnabledKeyboardInputSourcesChanged
+
+
+@interface TISInputSource : NSObject {
+ TISInputSourceRef _ref;
+}
+
+- (id)propertyForKey:(NSString *)key;
+
+@property(nonatomic,readonly) NSString *category, *type;
+@property(nonatomic,readonly) BOOL ASCIICapable, enableCapable, selectCapable;
+@property(nonatomic,readonly) BOOL enabled, selected;
+@property(nonatomic,readonly) NSString *identifier, *bundleIdentifier, *inputModeIdentifier;
+@property(nonatomic,readonly) NSString *localizedName;
+@property(nonatomic,readonly) NSArray *languages;
+@property(nonatomic,readonly) NSData *layoutData;
+@property(nonatomic,readonly) NSURL *iconImageURL;
+
+- (void)select;
+- (void)deselect;
+- (void)enable;
+- (void)disable;
+
++ (CFTypeID)typeID;
++ (NSArray *)sourcesWithProperties:(NSDictionary *)properties includeAllInstalled:(BOOL)includeAllInstalled;
++ (instancetype)currentSource;
++ (instancetype)currentLayoutSource;
++ (instancetype)currentASCIICapableSource;
++ (instancetype)currentASCIICapableLayoutSource;
++ (NSArray *)sourcesForLanguage:(NSString *)language;
++ (NSArray *)ASCIICapableSources;
++ (void)setInputMethodKeyboardLayoutOverride:(TISInputSource *)source;
++ (TISInputSource *)inputMethodKeyboardLayoutOverride;
++ (void)register:(NSURL *)location;
+
+@end
@@ -0,0 +1,229 @@
+//
+// TISInputSource.m
+// Gureum
+//
+// Created by Jeong YunWon on 2014. 10. 29..
+// Copyright (c) 2014년 youknowone.org. All rights reserved.
+//
+
+#import "TISInputSource.h"
+
+@interface TISInputSourceError : NSError
+
+- (instancetype)initWithCode:(OSStatus)err;
++ (instancetype)errorWithCode:(OSStatus)err;
+
+@end
+
+@implementation TISInputSourceError
+
+- (instancetype)initWithCode:(OSStatus)err {
+ return [super initWithDomain:@"TISInputSource" code:err userInfo:@{}];
+}
+
++ (instancetype)errorWithCode:(OSStatus)err {
+ return [[[self alloc] initWithCode:err] autorelease];
+}
+
+@end
+
+
+@interface TISInputSource ()
+
+- (instancetype)initWithRef:(TISInputSourceRef)ref;
+
+@end
+
+
+@implementation TISInputSource
+
+- (instancetype)init {
+ [self release];
+ return nil;
+}
+
+- (instancetype)initWithRef:(TISInputSourceRef)ref {
+ self = [super init];
+ if (self != nil) {
+ self->_ref = ref;
+ }
+ return self;
+}
+
+- (void)dealloc {
+ if (self->_ref) {
+ CFRelease(self->_ref);
+ }
+ [super dealloc];
+}
+
+- (NSString *)description {
+ return [@"<%@(%@)>" format:self.class.name, self.identifier];
+}
+
+- (id)propertyForKey:(NSString *)key {
+ return (id)TISGetInputSourceProperty(self->_ref, (CFStringRef)key);
+}
+
+- (NSString *)category {
+ return [self propertyForKey:TISPropertyInputSourceCategory];
+}
+
+- (NSString *)type {
+ return [self propertyForKey:TISPropertyInputSourceType];
+}
+
+- (BOOL)ASCIICapable {
+ return CFBooleanGetValue((CFBooleanRef)[self propertyForKey:TISPropertyInputSourceIsASCIICapable]);
+}
+
+- (BOOL)enableCapable {
+ return CFBooleanGetValue((CFBooleanRef)[self propertyForKey:TISPropertyInputSourceIsEnableCapable]);
+}
+
+- (BOOL)selectCapable {
+ return CFBooleanGetValue((CFBooleanRef)[self propertyForKey:TISPropertyInputSourceIsSelectCapable]);
+}
+
+- (BOOL)enabled {
+ return CFBooleanGetValue((CFBooleanRef)[self propertyForKey:TISPropertyInputSourceIsEnabled]);
+}
+
+- (BOOL)selected {
+ return CFBooleanGetValue((CFBooleanRef)[self propertyForKey:TISPropertyInputSourceIsSelected]);
+}
+
+- (NSString *)identifier {
+ return [self propertyForKey:TISPropertyInputSourceID];
+}
+
+- (NSString *)bundleIdentifier {
+ return [self propertyForKey:TISPropertyBundleID];
+}
+
+- (NSString *)inputModeIdentifier {
+ return [self propertyForKey:TISPropertyInputModeID];
+}
+
+- (NSString *)localizedName {
+ return [self propertyForKey:TISPropertyLocalizedName];
+}
+
+- (NSArray *)languages {
+ return [self propertyForKey:TISPropertyInputSourceLanguages];
+}
+
+- (NSData *)layoutData {
+ return [self propertyForKey:TISPropertyUnicodeKeyLayoutData];
+}
+
+- (NSURL *)iconImageURL {
+ return [self propertyForKey:TISPropertyIconImageURL];
+}
+
++ (CFTypeID)typeID {
+ return TISInputSourceGetTypeID();
+}
+
+NSArray *_TISSourceInputRefToObject(NSArray *refs) {
+ return [refs arrayByMappingOperator:^id(id obj) {
+ TISInputSourceRef ref = (TISInputSourceRef)obj;
+ CFRetain(ref);
+ id source = [[[TISInputSource alloc] initWithRef:ref] autorelease];
+ dassert(source);
+ return source;
+ }];
+}
+
++ (NSArray *)sourcesWithProperties:(NSDictionary *)properties includeAllInstalled:(BOOL)includeAllInstalled {
+ NSArray *refs = (NSArray *)TISCreateInputSourceList((CFDictionaryRef)properties, includeAllInstalled);
+ NSArray *sources = _TISSourceInputRefToObject(refs);
+ [refs release];
+ return sources;
+}
+
++ (instancetype)currentSource {
+ TISInputSourceRef ref = TISCopyCurrentKeyboardInputSource();
+ return [[self alloc] initWithRef:ref];
+}
+
++ (instancetype)currentLayoutSource {
+ TISInputSourceRef ref = TISCopyCurrentKeyboardLayoutInputSource();
+ return [[self alloc] initWithRef:ref];
+}
+
++ (instancetype)currentASCIICapableSource {
+ TISInputSourceRef ref = TISCopyCurrentASCIICapableKeyboardInputSource();
+ return [[self alloc] initWithRef:ref];
+}
+
++ (instancetype)currentASCIICapableLayoutSource {
+ TISInputSourceRef ref = TISCopyCurrentASCIICapableKeyboardLayoutInputSource();
+ return [[self alloc] initWithRef:ref];
+}
+
++ (NSArray *)sourcesForLanguage:(NSString *)language {
+ NSArray *refs = (NSArray *)TISCopyInputSourceForLanguage((CFStringRef)language);
+ NSArray *sources = _TISSourceInputRefToObject(refs);
+ [refs release];
+ return sources;
+}
+
++ (NSArray *)ASCIICapableSources {
+ NSArray *refs = (NSArray *)TISCreateASCIICapableInputSourceList();
+ NSArray *sources = _TISSourceInputRefToObject(refs);
+ [refs release];
+ return sources;
+}
+
+- (void)select {
+ OSStatus err = TISSelectInputSource(self->_ref);
+ if (err != 0) {
+ @throw [TISInputSourceError errorWithCode:err];
+ }
+}
+
+- (void)deselect {
+ OSStatus err = TISDeselectInputSource(self->_ref);
+ if (err != 0) {
+ @throw [TISInputSourceError errorWithCode:err];
+ }
+}
+
+- (void)enable {
+ OSStatus err = TISEnableInputSource(self->_ref);
+ if (err != 0) {
+ @throw [TISInputSourceError errorWithCode:err];
+ }
+}
+
+- (void)disable {
+ OSStatus err = TISDisableInputSource(self->_ref);
+ if (err != 0) {
+ @throw [TISInputSourceError errorWithCode:err];
+ }
+}
+
++ (void)setInputMethodKeyboardLayoutOverride:(TISInputSource *)source {
+ OSStatus err = TISSetInputMethodKeyboardLayoutOverride(source->_ref);
+ if (err != 0) {
+ @throw [TISInputSourceError errorWithCode:err];
+ }
+}
+
++ (TISInputSource *)inputMethodKeyboardLayoutOverride {
+ TISInputSourceRef ref = TISCopyInputMethodKeyboardLayoutOverride();
+ if (ref == nil) {
+ return nil;
+ }
+ return [[self alloc] initWithRef:ref];
+}
+
++ (void)register:(NSURL *)location {
+ OSStatus err = TISRegisterInputSource((CFURLRef)location);
+ if (err != 0) {
+ @throw [TISInputSourceError errorWithCode:err];
+ }
+}
+
+@end
Oops, something went wrong.

0 comments on commit 9390d1a

Please sign in to comment.