Skip to content

Commit

Permalink
Fixes stuck modifier keys on focus lost on macOS (#16788)
Browse files Browse the repository at this point in the history
Co-authored-by: Steven Kirk <[email protected]>
  • Loading branch information
MrJul and grokys authored Sep 12, 2024
1 parent add5ef0 commit a31ff27
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions native/Avalonia.Native/src/OSX/AvnView.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
-(NSEvent* _Nonnull) lastMouseDownEvent;
-(AvnPoint) translateLocalPoint:(AvnPoint)pt;
-(void) onClosed;
-(void) setModifiers:(NSEventModifierFlags)modifierFlags;

-(AvnPlatformResizeReason) getResizeReason;
-(void) setResizeReason:(AvnPlatformResizeReason)reason;
Expand Down
5 changes: 5 additions & 0 deletions native/Avalonia.Native/src/OSX/AvnView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,11 @@ - (void) keyboardEvent: (NSEvent *) event withType: (AvnRawKeyEventType)type
_parent->TopLevelEvents->RawKeyEvent(type, timestamp, modifiers, key, physicalKey, keySymbolUtf8);
}

- (void)setModifiers:(NSEventModifierFlags)modifierFlags
{
_modifierState = [self getModifiers:modifierFlags];
}

- (void)flagsChanged:(NSEvent *)event
{
auto newModifierState = [self getModifiers:[event modifierFlags]];
Expand Down
5 changes: 4 additions & 1 deletion native/Avalonia.Native/src/OSX/AvnWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,10 @@ - (void)windowDidBecomeKey:(NSNotification *_Nonnull)notification
{
if (_parent == nullptr)
return;


if (_parent->View != nullptr)
[_parent->View setModifiers:NSEvent.modifierFlags];

_parent->BringToFront();

dispatch_async(dispatch_get_main_queue(), ^{
Expand Down

0 comments on commit a31ff27

Please sign in to comment.