Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 17 additions & 20 deletions im-select.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,26 @@
#import <Carbon/Carbon.h>

int main(int argc, const char * argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

int returnCode = 0;

if (argc > 1) {
NSString *imId = [NSString stringWithUTF8String:argv[1]];
NSDictionary *filter = [NSDictionary dictionaryWithObject:imId forKey:(NSString *)kTISPropertyInputSourceID];
CFArrayRef keyboards = TISCreateInputSourceList((CFDictionaryRef)filter, false);
if (keyboards) {
TISInputSourceRef selected = (TISInputSourceRef)CFArrayGetValueAtIndex(keyboards, 0);
returnCode = TISSelectInputSource(selected);
CFRelease(keyboards);
} else {
returnCode = 1;
}
} else {
@autoreleasepool {
TISInputSourceRef current = TISCopyCurrentKeyboardInputSource();
NSString *sourceId = (NSString *)(TISGetInputSourceProperty(current, kTISPropertyInputSourceID));
NSString *sourceId = (__bridge NSString *)(TISGetInputSourceProperty(current, kTISPropertyInputSourceID));
fprintf(stdout, "%s\n", [sourceId UTF8String]);
CFRelease(current);
if (argc > 1) {
NSString *imId = [NSString stringWithUTF8String:argv[1]];
if (![sourceId isEqualToString:imId]) {
NSDictionary *filter = [NSDictionary dictionaryWithObject:imId forKey:(NSString *)kTISPropertyInputSourceID];
CFArrayRef keyboards = TISCreateInputSourceList((CFDictionaryRef)filter, false);
if (keyboards) {
TISInputSourceRef selected = (TISInputSourceRef)CFArrayGetValueAtIndex(keyboards, 0);
returnCode = TISSelectInputSource(selected);
CFRelease(keyboards);
} else {
returnCode = 1;
}
}
}
}

[pool release];

return returnCode;
}
}
6 changes: 2 additions & 4 deletions plugin/smartim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ call Smartim_start_debug()

function! Smartim_GetInputMethodHandler(channel, msg)
silent let b:saved_im = a:msg
silent call system(s:imselect_path . ' ' .g:smartim_default)
call Smartim_debug_print('b:saved_im = ' . b:saved_im)
call Smartim_debug_print('<<< Smartim_SelectDefault returned ' . v:shell_error)
endfunction
Expand All @@ -68,10 +67,9 @@ function! Smartim_SelectDefault()
endif

if has('job')
call job_start([s:imselect_path], {'callback': 'Smartim_GetInputMethodHandler'})
call job_start([s:imselect_path, g:smartim_default], {'callback': 'Smartim_GetInputMethodHandler'})
else
silent let b:saved_im = system(s:imselect_path)
silent call system(s:imselect_path . ' ' . g:smartim_default)
silent let b:saved_im = system(s:imselect_path . ' ' . g:smartim_default)
call Smartim_debug_print('b:saved_im = ' . b:saved_im)
call Smartim_debug_print('<<< Smartim_SelectDefault returned ' . v:shell_error)
endif
Expand Down