8214578: [macos] Problem with backslashes on macOS/JIS keyboard: Java ignores system settings
authorpsadhukhan
Thu, 07 Nov 2019 11:30:22 +0530
changeset 59182 d0bfaae2ff33
parent 59181 a4ecc45541da
child 59183 d0b0b4ee4481
8214578: [macos] Problem with backslashes on macOS/JIS keyboard: Java ignores system settings Reviewed-by: serb, prr
src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.h
src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m
--- a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.h	Wed Nov 06 11:05:28 2019 +0530
+++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.h	Thu Nov 07 11:30:22 2019 +0530
@@ -37,6 +37,9 @@
 
     // TODO: NSMenu *contextualMenu;
 
+    // Keyboard layout
+    NSTextInputSourceIdentifier kbdLayout;
+
     // dnd support (see AppKit/NSDragging.h, NSDraggingSource/Destination):
     CDragSource *_dragSource;
     CDropTarget *_dropTarget;
--- a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m	Wed Nov 06 11:05:28 2019 +0530
+++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m	Thu Nov 07 11:30:22 2019 +0530
@@ -951,8 +951,16 @@
     NSUInteger utf16Length = [useString lengthOfBytesUsingEncoding:NSUTF16StringEncoding];
     NSUInteger utf8Length = [useString lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
     BOOL aStringIsComplex = NO;
+
+    unichar codePoint = [useString characterAtIndex:0];
+
+#ifdef IM_DEBUG
+    NSLog(@"insertText kbdlayout %@ ",(NSString *)kbdLayout);
+#endif // IM_DEBUG
+
     if ((utf16Length > 2) ||
-        ((utf8Length > 1) && [self isCodePointInUnicodeBlockNeedingIMEvent:[useString characterAtIndex:0]])) {
+        ((utf8Length > 1) && [self isCodePointInUnicodeBlockNeedingIMEvent:codePoint]) ||
+        ((codePoint == 0x5c) && ([(NSString *)kbdLayout containsString:@"Kotoeri"]))) {
         aStringIsComplex = YES;
     }
 
@@ -990,6 +998,15 @@
     [self abandonInput];
 }
 
+- (void)keyboardInputSourceChanged:(NSNotification *)notification
+{
+#ifdef IM_DEBUG
+    NSLog(@"keyboardInputSourceChangeNotification received");
+#endif
+    NSTextInputContext *curContxt = [NSTextInputContext currentInputContext];
+    kbdLayout = curContxt.selectedKeyboardInputSource;
+}
+
 - (void) doCommandBySelector:(SEL)aSelector
 {
 #ifdef IM_DEBUG
@@ -1315,6 +1332,13 @@
         fInputMethodLOCKABLE = JNFNewGlobalRef(env, inputMethod);
     else
         fInputMethodLOCKABLE = NULL;
+
+    NSTextInputContext *curContxt = [NSTextInputContext currentInputContext];
+    kbdLayout = curContxt.selectedKeyboardInputSource;
+    [[NSNotificationCenter defaultCenter] addObserver:self
+                                           selector:@selector(keyboardInputSourceChanged:)
+                                               name:NSTextInputContextKeyboardSelectionDidChangeNotification
+                                             object:nil];
 }
 
 - (void)abandonInput