Skip to content

Commit 0b0a33e

Browse files
committed
8214578: [macos] Problem with backslashes on macOS/JIS keyboard: Java ignores system settings
Reviewed-by: serb, prr
1 parent 007a0fb commit 0b0a33e

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737

3838
// TODO: NSMenu *contextualMenu;
3939

40+
// Keyboard layout
41+
NSTextInputSourceIdentifier kbdLayout;
42+
4043
// dnd support (see AppKit/NSDragging.h, NSDraggingSource/Destination):
4144
CDragSource *_dragSource;
4245
CDropTarget *_dropTarget;

src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,8 +951,16 @@ - (void) insertText:(id)aString replacementRange:(NSRange)replacementRange
951951
NSUInteger utf16Length = [useString lengthOfBytesUsingEncoding:NSUTF16StringEncoding];
952952
NSUInteger utf8Length = [useString lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
953953
BOOL aStringIsComplex = NO;
954+
955+
unichar codePoint = [useString characterAtIndex:0];
956+
957+
#ifdef IM_DEBUG
958+
NSLog(@"insertText kbdlayout %@ ",(NSString *)kbdLayout);
959+
#endif // IM_DEBUG
960+
954961
if ((utf16Length > 2) ||
955-
((utf8Length > 1) && [self isCodePointInUnicodeBlockNeedingIMEvent:[useString characterAtIndex:0]])) {
962+
((utf8Length > 1) && [self isCodePointInUnicodeBlockNeedingIMEvent:codePoint]) ||
963+
((codePoint == 0x5c) && ([(NSString *)kbdLayout containsString:@"Kotoeri"]))) {
956964
aStringIsComplex = YES;
957965
}
958966

@@ -990,6 +998,15 @@ - (void) insertText:(id)aString replacementRange:(NSRange)replacementRange
990998
[self abandonInput];
991999
}
9921000

1001+
- (void)keyboardInputSourceChanged:(NSNotification *)notification
1002+
{
1003+
#ifdef IM_DEBUG
1004+
NSLog(@"keyboardInputSourceChangeNotification received");
1005+
#endif
1006+
NSTextInputContext *curContxt = [NSTextInputContext currentInputContext];
1007+
kbdLayout = curContxt.selectedKeyboardInputSource;
1008+
}
1009+
9931010
- (void) doCommandBySelector:(SEL)aSelector
9941011
{
9951012
#ifdef IM_DEBUG
@@ -1315,6 +1332,13 @@ - (void)setInputMethod:(jobject)inputMethod
13151332
fInputMethodLOCKABLE = JNFNewGlobalRef(env, inputMethod);
13161333
else
13171334
fInputMethodLOCKABLE = NULL;
1335+
1336+
NSTextInputContext *curContxt = [NSTextInputContext currentInputContext];
1337+
kbdLayout = curContxt.selectedKeyboardInputSource;
1338+
[[NSNotificationCenter defaultCenter] addObserver:self
1339+
selector:@selector(keyboardInputSourceChanged:)
1340+
name:NSTextInputContextKeyboardSelectionDidChangeNotification
1341+
object:nil];
13181342
}
13191343

13201344
- (void)abandonInput

0 commit comments

Comments
 (0)