Skip to content

Commit c46c172

Browse files
Martin FoxAndy Goryachev
Martin Fox
authored and
Andy Goryachev
committed
8320773: [macOS] All IME input blocked
Reviewed-by: angorya, kcr, jpereda
1 parent b80ec39 commit c46c172

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

modules/javafx.graphics/src/main/native-glass/mac/GlassApplication.m

+8-2
Original file line numberDiff line numberDiff line change
@@ -799,8 +799,14 @@ + (void)registerKeyEvent:(NSEvent*)event
799799
[keyCodeForCharMap setObject:mapObject forKey:[event characters]];
800800
// getKeyCodeForChar should not just match against a character the user types
801801
// directly but any other character printed on the same key.
802-
[keyCodeForCharMap setObject:mapObject forKey:[event charactersByApplyingModifiers: 0]];
803-
[keyCodeForCharMap setObject:mapObject forKey:[event charactersByApplyingModifiers: NSEventModifierFlagShift]];
802+
NSString* unshifted = GetStringForMacKey(event.keyCode, false);
803+
if (unshifted != nil) {
804+
[keyCodeForCharMap setObject:mapObject forKey:unshifted];
805+
}
806+
NSString* shifted = GetStringForMacKey(event.keyCode, true);
807+
if (shifted != nil) {
808+
[keyCodeForCharMap setObject:mapObject forKey:shifted];
809+
}
804810
// On some European keyboards there are useful symbols which are only
805811
// accessible via the Option key. We don't query for the Option key
806812
// character because on most layouts just about every key has some

modules/javafx.graphics/src/main/native-glass/mac/GlassKey.h

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ jint GetJavaKeyCodeFor(unsigned short keyCode);
3434
jint GetJavaKeyCode(NSEvent *event);
3535
jcharArray GetJavaKeyChars(JNIEnv *env, NSEvent *event);
3636
NSString* GetStringForJavaKey(jchar key);
37+
NSString* GetStringForMacKey(unsigned short keyCode, bool shifted);
3738

3839
// for key event injection
3940
BOOL GetMacKey(jint javaKeyCode, unsigned short *outMacKeyCode);

modules/javafx.graphics/src/main/native-glass/mac/GlassKey.m

+21
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,27 @@ BOOL GetMacKey(jint javaKeyCode, unsigned short *outMacKeyCode)
600600

601601
}
602602

603+
NSString* GetStringForMacKey(unsigned short keyCode, bool shifted)
604+
{
605+
// Restrict to printable characters. UCKeyTranslate can produce
606+
// odd results with keys like Home, Up Arrow, etc.
607+
if (!macKeyCodeIsLayoutSensitive(keyCode)) return nil;
608+
609+
TISInputSourceRef keyboard = TISCopyCurrentKeyboardLayoutInputSource();
610+
if (keyboard == NULL) return nil;
611+
612+
UInt32 modifiers = (shifted ? shiftKey : 0);
613+
UniChar unicode[8];
614+
UniCharCount length = queryKeyboard(keyboard, keyCode, modifiers, unicode, 8);
615+
CFRelease(keyboard);
616+
617+
if (length == 1) {
618+
return [NSString stringWithCharacters: &unicode[0] length: 1];
619+
}
620+
621+
return nil;
622+
}
623+
603624
/*
604625
* Class: com_sun_glass_ui_mac_MacApplication
605626
* Method: _getKeyCodeForChar

modules/javafx.graphics/src/main/native-glass/mac/GlassView3D.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -510,9 +510,9 @@ - (BOOL)performKeyEquivalent:(NSEvent *)theEvent
510510
- (void)keyDown:(NSEvent *)theEvent
511511
{
512512
KEYLOG("keyDown");
513-
[GlassApplication registerKeyEvent:theEvent];
514513

515514
if (![[self inputContext] handleEvent:theEvent] || shouldProcessKeyEvent) {
515+
[GlassApplication registerKeyEvent:theEvent];
516516
[self->_delegate sendJavaKeyEvent:theEvent isDown:YES];
517517
}
518518
shouldProcessKeyEvent = YES;

0 commit comments

Comments
 (0)