From 0de0b31448789ea8a9252b32a132f0d50cac6c71 Mon Sep 17 00:00:00 2001 From: groverlynn Date: Tue, 16 May 2023 09:36:32 +0200 Subject: [PATCH] Avoid autorelease --- SquirrelInputController.m | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/SquirrelInputController.m b/SquirrelInputController.m index f0b553cef..2c1fb52f7 100644 --- a/SquirrelInputController.m +++ b/SquirrelInputController.m @@ -24,7 +24,6 @@ @implementation SquirrelInputController { NSUInteger _caretPos; NSArray *_candidates; NSUInteger _lastModifier; - NSEventType _lastEventType; uint32_t _lastEventCount; RimeSessionId _session; NSString *_schemaId; @@ -52,9 +51,9 @@ - (BOOL)handleEvent:(NSEvent*)event client:(id)sender // Returning NO means the original key down will be passed on to the client. _currentClient = sender; - - CGEventFlags modifiers = CGEventGetFlags(event.CGEvent); - + NSEventModifierFlags modifiers = event.modifierFlags & NSEventModifierFlagDeviceIndependentFlagsMask; + uint32_t eventCount = CGEventSourceCounterForEventType(kCGEventSourceStateCombinedSessionState, + kCGEventFlagsChanged|kCGEventLeftMouseDown|kCGEventRightMouseDown|kCGEventOtherMouseDown); BOOL handled = NO; @autoreleasepool { @@ -82,10 +81,9 @@ - (BOOL)handleEvent:(NSEvent*)event client:(id)sender int release_mask = 0; NSUInteger changes = _lastModifier ^ modifiers; int rime_modifiers = osx_modifiers_to_rime_modifiers(modifiers); - int64_t keyCode = CGEventGetIntegerValueField(event.CGEvent, kCGKeyboardEventKeycode); - int rime_keycode = osx_keycode_to_rime_keycode((int)keyCode, 0, 0, 0); + CGKeyCode keyCode = CGEventGetIntegerValueField(event.CGEvent, kCGKeyboardEventKeycode); + int rime_keycode = osx_keycode_to_rime_keycode(keyCode, 0, 0, 0); _lastModifier = modifiers; - uint32_t eventCount = CGEventSourceCounterForEventType(kCGEventSourceStateCombinedSessionState, kCGAnyInputEventType); if (changes & OSX_CAPITAL_MASK) { rime_modifiers ^= kLockMask; [self processKey:rime_keycode modifiers:rime_modifiers]; @@ -105,12 +103,10 @@ - (BOOL)handleEvent:(NSEvent*)event client:(id)sender if (changes & OSX_COMMAND_MASK) { release_mask = modifiers & OSX_COMMAND_MASK ? 0 : kReleaseMask | (eventCount - _lastEventCount <= 1 ? 0 : kIgnoredMask); [self processKey:rime_keycode modifiers:(rime_modifiers | release_mask)]; - _lastEventCount = eventCount; // do not update UI when using Command key - break; + goto saveStatus; } [self rimeUpdate]; - _lastEventCount = eventCount; } break; case NSEventTypeKeyDown: { // ignore Command+X hotkeys. @@ -139,10 +135,10 @@ - (BOOL)handleEvent:(NSEvent*)event client:(id)sender break; } } - - _lastModifier = modifiers; - _lastEventType = event.type; - + saveStatus: if (event.type == NSEventTypeFlagsChanged) { + _lastModifier = modifiers; + _lastEventCount = eventCount; + } return handled; }