Skip to content

Commit

Permalink
Revert to old method and add license notice
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Dec 4, 2017
1 parent 15a20ef commit e89bd89
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 41 deletions.
3 changes: 3 additions & 0 deletions AUTHORS
@@ -0,0 +1,3 @@
Jinxin She was the original founder, designer and author of fcitx-remote-for-osx.

Jiajie Chen made some improvements and bug fixes.
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -34,9 +34,13 @@ in compilation.
## Install

```bash
brew install fcitx-remote-for-osx
brew install fcitx-remote-for-osx --with-input-method=<method>
```

## System Settings for methods other than general

None.

## System Settings for GENERAL method only

Set your shortcut for `Select next source in input menu` to `Ctrl-Shift-z`.
Expand Down
64 changes: 24 additions & 40 deletions fcitx-remote/main.m
@@ -1,10 +1,20 @@
//
// main.m
// fcitx-remote
//
// Created by codefalling on 15/11/2.
// Copyright (c) 2015 codefalling. All rights reserved.
//
/*
* This file is part of fcitx-remote-for-osx
* Copyright (c) 2015-2017 fcitx-remote-for-osx's authors
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/


#import <Foundation/Foundation.h>
#import <Carbon/Carbon.h>
Expand Down Expand Up @@ -50,7 +60,7 @@ void switch_to(NSString* imId){
// slow but ensure to work
runScript(@"tell application \"System Events\" to keystroke \"z\" using {shift down, control down}");
return;

// faster but not reliable
/*
CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
Expand All @@ -66,8 +76,6 @@ void switch_to(NSString* imId){
*/
}

// slow but ensure to work
// Idea from https://github.com/noraesae/kawa/blob/master/kawa/InputSourceManager.swift#L55
CFArrayRef keyboards = TISCreateInputSourceList(nil, false);
if (keyboards) {
NSArray *array = CFBridgingRelease(keyboards);
Expand All @@ -77,43 +85,19 @@ void switch_to(NSString* imId){
CFBooleanRef selectable = TISGetInputSourceProperty(inputSource, kTISPropertyInputSourceIsSelectCapable);
return CFEqual(category, kTISCategoryKeyboardInputSource) && CFBooleanGetValue(selectable);
}]];
int index = 0,i = 0, us = 0;
int index = 0;
for (id object in filteredArray) {
TISInputSourceRef inputSource = (__bridge TISInputSourceRef)(object);
NSString *name = (__bridge NSString*)TISGetInputSourceProperty(inputSource, kTISPropertyInputSourceID);
NSLog(@"%@", name);
if ([name isEqualTo: imId]) {
index = i;
}
if ([name isEqualTo: US_KEYBOARD_LAYOUT]) {
us = i;
TISInputSourceRef inputSource = (__bridge TISInputSourceRef)filteredArray[index];
NSString *name = (__bridge NSString*)TISGetInputSourceProperty(inputSource, kTISPropertyInputSourceID);
NSLog(@"Changing to %@", name);
TISSelectInputSource((__bridge TISInputSourceRef)filteredArray[index]);
}
i++;
index++;
}

NSString *current = get_current_imname();
if (![current isEqualTo: US_KEYBOARD_LAYOUT]) {
TISInputSourceRef inputSource = (__bridge TISInputSourceRef)filteredArray[us];
NSString *name = (__bridge NSString*)TISGetInputSourceProperty(inputSource, kTISPropertyInputSourceID);
NSLog(@"%d %@", us, name);
TISSelectInputSource((__bridge TISInputSourceRef)filteredArray[index]);

}

int diff = (us - index + i) % i;
for (int j = 0;j < diff;j++) {
CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
CGEventRef down = CGEventCreateKeyboardEvent(source, kVK_Space, true);
CGEventRef up = CGEventCreateKeyboardEvent(source, kVK_Space, false);

int flag = kCGEventFlagMaskAlternate | kCGEventFlagMaskControl;
CGEventSetFlags(down, flag);
CGEventSetFlags(up, flag);
CGEventPost(kCGHIDEventTap, down);
CGEventPost(kCGHIDEventTap, up);

[NSThread sleepForTimeInterval:0.05f];
}
}
}

Expand Down

0 comments on commit e89bd89

Please sign in to comment.