Skip to content

Commit

Permalink
fix issues/102
Browse files Browse the repository at this point in the history
  • Loading branch information
dongyuwei committed Apr 12, 2022
1 parent 82c69b7 commit 7aa67df
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/AnnotationWinController.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ + (id)sharedController {
- (void)awakeFromNib {
sharedController = self;
self.width = 160;
//self.height = 282;
// self.height = 282;

[self.panel orderFront:nil];
[self.panel setLevel:CGShieldingWindowLevel() + 1];
// Make sure panel can float over full screen apps
// self.panel.collectionBehavior = NSWindowCollectionBehaviorCanJoinAllSpaces;
// self.panel.collectionBehavior = NSWindowCollectionBehaviorCanJoinAllSpaces;
[self.panel setStyleMask:NSWindowStyleMaskBorderless];
[self performSelector:@selector(hideWindow) withObject:nil afterDelay:0.01];
// [self showWindow:NSMakePoint(10, self.height + 10)]; //for dev debug
Expand Down
9 changes: 6 additions & 3 deletions src/InputController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
extern ConversionEngine *engine;

typedef NSInteger KeyCode;
static const KeyCode KEY_RETURN = 36, KEY_SPACE = 49, KEY_DELETE = 51, KEY_ESC = 53, KEY_ARROW_DOWN = 125, KEY_ARROW_UP = 126;
static const KeyCode KEY_RETURN = 36, KEY_SPACE = 49, KEY_DELETE = 51, KEY_ESC = 53, KEY_ARROW_DOWN = 125, KEY_ARROW_UP = 126,
KEY_RIGHT_SHIFT = 60;

@implementation InputController

Expand All @@ -23,12 +24,14 @@ - (BOOL)handleEvent:(NSEvent *)event client:(id)sender {
bool handled = NO;
switch ([event type]) {
case NSEventTypeFlagsChanged:
// NSLog(@"hallelujah event modifierFlags %lu, event keyCode: %@", (unsigned long)[event modifierFlags], [event keyCode]);

if (_lastEventTypes[1] == NSEventTypeFlagsChanged && _lastModifiers[1] == modifiers) {
return YES;
}

if (modifiers == 0 && _lastEventTypes[1] == NSEventTypeFlagsChanged && _lastModifiers[1] == NSEventModifierFlagShift &&
!(_lastModifiers[0] & NSEventModifierFlagShift)) {
[event keyCode] == KEY_RIGHT_SHIFT && !(_lastModifiers[0] & NSEventModifierFlagShift)) {

_defaultEnglishMode = !_defaultEnglishMode;
if (_defaultEnglishMode) {
Expand Down Expand Up @@ -304,7 +307,7 @@ - (void)_updateComposedBuffer:(NSAttributedString *)candidateString {

- (void)activateServer:(id)sender {
[sender overrideKeyboardWithKeyboardNamed:@"com.apple.keylayout.US"];

if (_annotationWin == nil) {
_annotationWin = [AnnotationWinController sharedController];
}
Expand Down

1 comment on commit 7aa67df

@dongyuwei
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/WebKit/webkit/blob/main/Source/WebCore/platform/mac/PlatformEventFactoryMac.mm#L485

String keyIdentifierForKeyEvent(NSEvent* event)
{
    if ([event type] == NSEventTypeFlagsChanged) {
        switch ([event keyCode]) {
        case 54: // Right Command
        case 55: // Left Command
            return "Meta"_str;

        case 57: // Capslock
            return "CapsLock"_str;

        case 56: // Left Shift
        case 60: // Right Shift
            return "Shift"_str;

        case 58: // Left Alt
        case 61: // Right Alt
            return "Alt"_str;

        case 59: // Left Ctrl
        case 62: // Right Ctrl
            return "Control"_str;

        default:
            ASSERT_NOT_REACHED();
            return emptyString();
        }
    }
    
    NSString *s = [event charactersIgnoringModifiers];
    if ([s length] != 1) {
        LOG(Events, "received an unexpected number of characters in key event: %u", [s length]);
        return "Unidentified"_s;
    }
    return keyIdentifierForCharCode([s characterAtIndex:0]);
}

Please sign in to comment.