Skip to content

Commit

Permalink
Port of key handling improvements AvaloniaUI#12549 to 0.10
Browse files Browse the repository at this point in the history
  • Loading branch information
MrJul committed Oct 1, 2023
1 parent 6de4179 commit e11a209
Show file tree
Hide file tree
Showing 36 changed files with 3,815 additions and 1,315 deletions.
13 changes: 7 additions & 6 deletions native/Avalonia.Native/src/OSX/AvnView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -396,20 +396,21 @@ - (void)mouseExited:(NSEvent *)event

- (void) keyboardEvent: (NSEvent *) event withType: (AvnRawKeyEventType)type
{
if([self ignoreUserInput: false])
if([self ignoreUserInput: false] || _parent == nullptr)
{
return;
}

auto key = s_KeyMap[[event keyCode]];
auto scanCode = [event keyCode];
auto key = VirtualKeyFromScanCode(scanCode, [event modifierFlags]);
auto physicalKey = PhysicalKeyFromScanCode(scanCode);
auto keySymbol = KeySymbolFromScanCode(scanCode, [event modifierFlags]);
auto keySymbolUtf8 = keySymbol == nullptr ? nullptr : [keySymbol UTF8String];

auto timestamp = static_cast<uint64_t>([event timestamp] * 1000);
auto modifiers = [self getModifiers:[event modifierFlags]];

if(_parent != nullptr)
{
_lastKeyHandled = _parent->BaseEvents->RawKeyEvent(type, timestamp, modifiers, key);
}
_lastKeyHandled = _parent->BaseEvents->RawKeyEvent(type, timestamp, modifiers, key, physicalKey, keySymbolUtf8);
}

- (BOOL)performKeyEquivalent:(NSEvent *)event
Expand Down
11 changes: 6 additions & 5 deletions native/Avalonia.Native/src/OSX/KeyTransform.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#ifndef keytransform_h
#define keytransform_h

#import <cstdint>
#include "common.h"
#include <map>

extern std::map<int, AvnKey> s_KeyMap;
AvnPhysicalKey PhysicalKeyFromScanCode(uint16_t scanCode);

extern std::map<AvnKey, int> s_AvnKeyMap;
AvnKey VirtualKeyFromScanCode(uint16_t scanCode, NSEventModifierFlags modifierFlags);

extern std::map<int, const char*> s_QwertyKeyMap;
NSString* KeySymbolFromScanCode(uint16_t scanCode, NSEventModifierFlags modifierFlags);

extern std::map<AvnKey, int> s_UnicodeKeyMap;
uint16_t MenuCharFromVirtualKey(AvnKey key);

#endif
Loading

0 comments on commit e11a209

Please sign in to comment.