changeset 7078:701abcfabf03

RT-34745 [Lens] Shift is being ignored while caps lock is on Reviewed-by: kselle
author Daniel Blaukopf <daniel.blaukopf@oracle.com>
date Tue, 20 May 2014 11:30:59 +0300
parents 6c7f6d64aac5
children 7a1db976a80b
files modules/graphics/src/main/java/com/sun/glass/ui/monocle/input/KeyInput.java modules/graphics/src/main/java/com/sun/glass/ui/monocle/linux/LinuxKeyProcessor.java modules/graphics/src/main/native-glass/lens/LensInputEvents.c tests/system/src/test/java/com/sun/glass/ui/monocle/input/USKeyboardTest.java
diffstat 4 files changed, 165 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/input/KeyInput.java	Tue May 20 08:44:42 2014 +0200
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/input/KeyInput.java	Tue May 20 11:30:59 2014 +0300
@@ -117,10 +117,11 @@
 
     private char[] getKeyChars(KeyState state, int key) {
         char c = '\000';
-        boolean shifted = state.isShiftPressed() ^ capsLock;
+        boolean shifted = state.isShiftPressed();
         // TODO: implement configurable keyboard mappings.
         // The following is only for US keyboards
         if (key >= KeyEvent.VK_A && key <= KeyEvent.VK_Z) {
+            shifted ^= capsLock;
             if (shifted) {
                 c = (char) (key - KeyEvent.VK_A + 'A');
             } else {
--- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/linux/LinuxKeyProcessor.java	Tue May 20 08:44:42 2014 +0200
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/linux/LinuxKeyProcessor.java	Tue May 20 11:30:59 2014 +0300
@@ -78,7 +78,7 @@
         } else if (linuxKeyCode >= Input.KEY_F13 && linuxKeyCode <= Input.KEY_F24) {
             return linuxKeyCode - Input.KEY_F13 + KeyEvent.VK_F13;
         } else switch (linuxKeyCode) {
-            case Input.KEY_1: return KeyEvent.VK_1;
+            case Input.KEY_0: return KeyEvent.VK_0;
             case Input.KEY_A: return KeyEvent.VK_A;
             case Input.KEY_B: return KeyEvent.VK_B;
             case Input.KEY_C: return KeyEvent.VK_C;
--- a/modules/graphics/src/main/native-glass/lens/LensInputEvents.c	Tue May 20 08:44:42 2014 +0200
+++ b/modules/graphics/src/main/native-glass/lens/LensInputEvents.c	Tue May 20 11:30:59 2014 +0300
@@ -198,12 +198,18 @@
 }
 
 jboolean glass_inputEvents_checkForShift(int keyCode) {
-    if (shiftDown || (capsOn && glass_inputEvents_isAlpha(keyCode))) {
-        GLASS_LOG_FINER("Shift state is true");
-        return JNI_TRUE;
+    jboolean shifted = JNI_FALSE;
+    if (capsOn) {
+        if (glass_inputEvents_isAlpha(keyCode)) {
+            shifted = !shiftDown;
+        } else {
+            shifted = shiftDown;
+        }
+    } else {
+        shifted = shiftDown;
     }
-    GLASS_LOG_FINER("Shift state is false");
-    return JNI_FALSE;
+    GLASS_LOG_FINER("Shift state is %i", (int) shifted);
+    return shifted;
 }
 
 void glass_inputEvents_updateKeyModifiers(int key, int eventType) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/system/src/test/java/com/sun/glass/ui/monocle/input/USKeyboardTest.java	Tue May 20 11:30:59 2014 +0300
@@ -0,0 +1,151 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.glass.ui.monocle.input;
+
+import org.junit.After;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Test;
+
+public class USKeyboardTest {
+
+    private UInput ui;
+
+    @Before
+    public void initDevice() {
+        TestLog.reset();
+        ui = new UInput();
+    }
+
+    @After
+    public void destroyDevice() throws InterruptedException {
+        ui.waitForQuiet();
+        try {
+            ui.processLine("DESTROY");
+        } catch (RuntimeException e) { }
+        ui.processLine("CLOSE");
+        ui.dispose();
+    }
+
+    private void checkShift(String key, char unShifted, char shifted) throws Exception {
+        checkKey(key, unShifted, false);
+        checkKey(key, shifted, true);
+    }
+
+    private void checkKey(String key, char c, boolean shiftPressed) throws Exception {
+        if (shiftPressed) {
+            ui.processLine("EV_KEY KEY_LEFTSHIFT 1");
+            ui.processLine("EV_SYN");
+        }
+        ui.processLine("EV_KEY " + key + " 1");
+        ui.processLine("EV_SYN");
+        ui.processLine("EV_KEY " + key + " 0");
+        ui.processLine("EV_SYN");
+        if (shiftPressed) {
+            ui.processLine("EV_KEY KEY_LEFTSHIFT 0");
+            ui.processLine("EV_SYN");
+        }
+        TestLog.waitForLog("Key typed: %0$c", new Object[] { c });
+    }
+
+    @Test
+    public void testShift() throws Exception {
+        TestApplication.showFullScreenScene();
+        TestApplication.addKeyListeners();
+        ui.processLine("OPEN");
+        ui.processLine("EVBIT EV_KEY");
+        ui.processLine("EVBIT EV_SYN");
+        ui.processLine("KEYBIT KEY_A");
+        ui.processLine("KEYBIT KEY_1");
+        ui.processLine("KEYBIT KEY_2");
+        ui.processLine("KEYBIT KEY_3");
+        ui.processLine("KEYBIT KEY_4");
+        ui.processLine("KEYBIT KEY_5");
+        ui.processLine("KEYBIT KEY_6");
+        ui.processLine("KEYBIT KEY_7");
+        ui.processLine("KEYBIT KEY_8");
+        ui.processLine("KEYBIT KEY_9");
+        ui.processLine("KEYBIT KEY_0");
+        ui.processLine("KEYBIT KEY_LEFTSHIFT");
+        ui.processLine("PROPERTY ID_INPUT_KEYBOARD 1");
+        ui.processLine("CREATE");
+
+        checkShift("KEY_A", 'a', 'A');
+        checkShift("KEY_1", '1', '!');
+        checkShift("KEY_2", '2', '@');
+        checkShift("KEY_3", '3', '#');
+        checkShift("KEY_4", '4', '$');
+        checkShift("KEY_5", '5', '%');
+        checkShift("KEY_6", '6', '^');
+        checkShift("KEY_7", '7', '&');
+        checkShift("KEY_8", '8', '*');
+        checkShift("KEY_9", '9', '(');
+        checkShift("KEY_0", '0', ')');
+    }
+
+    @Test
+    public void testCapsLock() throws Exception {
+        TestApplication.showFullScreenScene();
+        TestApplication.addKeyListeners();
+        ui.processLine("OPEN");
+        ui.processLine("EVBIT EV_KEY");
+        ui.processLine("EVBIT EV_SYN");
+        ui.processLine("KEYBIT KEY_A");
+        ui.processLine("KEYBIT KEY_1");
+        ui.processLine("KEYBIT KEY_2");
+        ui.processLine("KEYBIT KEY_3");
+        ui.processLine("KEYBIT KEY_4");
+        ui.processLine("KEYBIT KEY_5");
+        ui.processLine("KEYBIT KEY_6");
+        ui.processLine("KEYBIT KEY_7");
+        ui.processLine("KEYBIT KEY_8");
+        ui.processLine("KEYBIT KEY_9");
+        ui.processLine("KEYBIT KEY_0");
+        ui.processLine("KEYBIT KEY_LEFTSHIFT");
+        ui.processLine("KEYBIT KEY_CAPSLOCK");
+        ui.processLine("PROPERTY ID_INPUT_KEYBOARD 1");
+        ui.processLine("CREATE");
+
+        ui.processLine("EV_KEY KEY_CAPSLOCK 1");
+        ui.processLine("EV_SYN");
+
+        checkShift("KEY_A", 'A', 'a');
+        checkShift("KEY_1", '1', '!');
+        checkShift("KEY_2", '2', '@');
+        checkShift("KEY_3", '3', '#');
+        checkShift("KEY_4", '4', '$');
+        checkShift("KEY_5", '5', '%');
+        checkShift("KEY_6", '6', '^');
+        checkShift("KEY_7", '7', '&');
+        checkShift("KEY_8", '8', '*');
+        checkShift("KEY_9", '9', '(');
+        checkShift("KEY_0", '0', ')');
+
+        ui.processLine("EV_KEY KEY_CAPSLOCK 0");
+        ui.processLine("EV_SYN");
+    }
+
+}