aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt/native
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-05-16 21:33:25 +0200
committerSven Gothel <[email protected]>2013-05-16 21:33:25 +0200
commit86a5460c5052cdab7b9f6294c46a0b4e30dfa260 (patch)
tree5c029a5d847fe6f7856098e5c734dd621cd31c9d /src/newt/native
parent890dabf77593732bd9833350b441a37c60f74d45 (diff)
Fix Bug 723: Remove VK_KP_<Cursor> numpad key-codes, use general VK_<Cursor> key-codes; Respect numpad printable keys; Use keySym for numpad if possible.
- KeyEvent keyCode/keySym values re-ordered! - Remove VK_KP_<Cursor> numpad key-codes, use general VK_<Cursor> key-codes. Numpad cursor keys are not supported on some platforms (Windows), or not configured on most X11 configurations. - Respect numpad printable keys, i.e. don't treat them as non-printable. - Use keySym for numpad if possible. Numpad keys require modifiers, hence X11 and Windows shall return keySym.
Diffstat (limited to 'src/newt/native')
-rw-r--r--src/newt/native/KeyEvent.h20
-rw-r--r--src/newt/native/WindowsWindow.c42
-rw-r--r--src/newt/native/X11Display.c24
3 files changed, 53 insertions, 33 deletions
diff --git a/src/newt/native/KeyEvent.h b/src/newt/native/KeyEvent.h
index 7a63b19ce..a182db973 100644
--- a/src/newt/native/KeyEvent.h
+++ b/src/newt/native/KeyEvent.h
@@ -161,7 +161,7 @@
// Unicode: Non printable controls: [0x7F - 0x9F]
//
-#define J_VK_DELETE ( 0x7FU )
+#define J_VK_SEPARATOR ( 0x7FU )
#define J_VK_NUMPAD0 ( 0x80U )
#define J_VK_NUMPAD1 ( 0x81U )
#define J_VK_NUMPAD2 ( 0x82U )
@@ -173,16 +173,13 @@
#define J_VK_NUMPAD8 ( 0x88U )
#define J_VK_NUMPAD9 ( 0x89U )
#define J_VK_DECIMAL ( 0x8AU )
-#define J_VK_SEPARATOR ( 0x8BU )
-#define J_VK_ADD ( 0x8CU )
-#define J_VK_SUBTRACT ( 0x8DU )
-#define J_VK_MULTIPLY ( 0x8EU )
-#define J_VK_DIVIDE ( 0x8FU )
-#define J_VK_NUM_LOCK ( 0x90U )
-#define J_VK_KP_LEFT ( 0x91U )
-#define J_VK_KP_UP ( 0x92U )
-#define J_VK_KP_RIGHT ( 0x93U )
-#define J_VK_KP_DOWN ( 0x94U )
+#define J_VK_ADD ( 0x8BU )
+#define J_VK_SUBTRACT ( 0x8CU )
+#define J_VK_MULTIPLY ( 0x8DU )
+#define J_VK_DIVIDE ( 0x8EU )
+
+#define J_VK_DELETE ( 0x93U )
+#define J_VK_NUM_LOCK ( 0x94U )
#define J_VK_LEFT ( 0x95U )
#define J_VK_UP ( 0x96U )
#define J_VK_RIGHT ( 0x97U )
@@ -195,7 +192,6 @@
#define J_VK_BEGIN ( 0x9EU )
#define J_VK_STOP ( 0x9FU )
-
//
// Unicode: Printable [0x00A0 - 0xDFFF]
//
diff --git a/src/newt/native/WindowsWindow.c b/src/newt/native/WindowsWindow.c
index 7ede3a20d..ac0ebf07e 100644
--- a/src/newt/native/WindowsWindow.c
+++ b/src/newt/native/WindowsWindow.c
@@ -219,6 +219,7 @@ static KeyMapEntry keyMapTable[] = {
{J_VK_INSERT, VK_INSERT, 0},
{J_VK_DELETE, VK_DELETE, 0},
{J_VK_HOME, VK_HOME, 0},
+ // {J_VK_BEGIN, VK_BEGIN, 0}, // not mapped
{J_VK_END, VK_END, 0},
{J_VK_PAGE_UP, VK_PRIOR, 0},
{J_VK_PAGE_DOWN, VK_NEXT, 0},
@@ -332,6 +333,8 @@ static KeyMapEntry keyMapTable[] = {
#define MAPVK_VK_TO_VSC_EX 4
#endif
+#define IS_WITHIN(k,a,b) ((a)<=(k)&&(k)<=(b))
+
static HKL kbdLayoutUS = 0;
static const LPCSTR US_LAYOUT_NAME = "00000409";
@@ -398,23 +401,6 @@ static void ParseWmVKeyAndScanCode(USHORT winVKey, BYTE winScanCode, BYTE flags,
kbdState[VK_SPACE] &= ~0x80;
}
- // Assume extended scan code 0xE0 if extended flags is set (no 0xE1 from WM_KEYUP/WM_KEYDOWN)
- USHORT winScanCodeExt = winScanCode;
- if( 0 != ( 0x01 & flags ) ) {
- winScanCodeExt |= 0xE000;
- }
-
- //
- // winVKey, winScanCodeExt -> javaVKeyUS w/ US KeyboardLayout
- //
- for (i = 0; keyMapTable[i].windowsKey != 0; i++) {
- if ( keyMapTable[i].windowsScanCodeUS == winScanCodeExt ) {
- javaVKeyUS = keyMapTable[i].javaKey;
- winVKeyUS = keyMapTable[i].windowsKey;
- break;
- }
- }
-
//
// winVKey -> javaVKeyXX
//
@@ -424,6 +410,28 @@ static void ParseWmVKeyAndScanCode(USHORT winVKey, BYTE winScanCode, BYTE flags,
break;
}
}
+ if( IS_WITHIN( winVKey, VK_NUMPAD0, VK_DIVIDE ) ) {
+ // Use modded keySym for keypad for US and NN
+ winVKeyUS = winVKey;
+ javaVKeyUS = javaVKeyXX;
+ } else {
+ // Assume extended scan code 0xE0 if extended flags is set (no 0xE1 from WM_KEYUP/WM_KEYDOWN)
+ USHORT winScanCodeExt = winScanCode;
+ if( 0 != ( 0x01 & flags ) ) {
+ winScanCodeExt |= 0xE000;
+ }
+
+ //
+ // winVKey, winScanCodeExt -> javaVKeyUS w/ US KeyboardLayout
+ //
+ for (i = 0; keyMapTable[i].windowsKey != 0; i++) {
+ if ( keyMapTable[i].windowsScanCodeUS == winScanCodeExt ) {
+ winVKeyUS = keyMapTable[i].windowsKey;
+ javaVKeyUS = keyMapTable[i].javaKey;
+ break;
+ }
+ }
+ }
*outJavaVKeyUS = javaVKeyUS;
*outJavaVKeyXX = javaVKeyXX;
diff --git a/src/newt/native/X11Display.c b/src/newt/native/X11Display.c
index 56b7251d2..e2392a113 100644
--- a/src/newt/native/X11Display.c
+++ b/src/newt/native/X11Display.c
@@ -58,6 +58,10 @@ static jmethodID requestFocusID = NULL;
#define IS_WITHIN(k,a,b) ((a)<=(k)&&(k)<=(b))
+/**
+ * QT Reference:
+ * <http://qt.gitorious.org/qt/qt/blobs/4.7/src/gui/kernel/qkeymapper_x11.cpp#line879>
+ */
static short X11KeySym2NewtVKey(KeySym keySym) {
if( IS_WITHIN( keySym, XK_a, XK_z ) ) {
return ( keySym - XK_a ) + J_VK_A ;
@@ -84,8 +88,6 @@ static short X11KeySym2NewtVKey(KeySym keySym) {
return J_VK_TAB;
case XK_Cancel:
return J_VK_CANCEL;
- case XK_Clear:
- return J_VK_CLEAR;
case XK_Shift_L:
case XK_Shift_R:
return J_VK_SHIFT;
@@ -95,6 +97,7 @@ static short X11KeySym2NewtVKey(KeySym keySym) {
case XK_Alt_L:
return J_VK_ALT;
case XK_Alt_R:
+ case XK_ISO_Level3_Shift:
return J_VK_ALT_GRAPH;
case XK_Super_L:
case XK_Super_R:
@@ -119,6 +122,10 @@ static short X11KeySym2NewtVKey(KeySym keySym) {
case XK_End:
case XK_KP_End:
return J_VK_END;
+ case XK_Begin:
+ return J_VK_BEGIN;
+ case XK_KP_Begin: // NumPad 5 - equal behavior w/ QT/Windows
+ return J_VK_CLEAR;
case XK_Home:
case XK_KP_Home:
return J_VK_HOME;
@@ -146,6 +153,7 @@ static short X11KeySym2NewtVKey(KeySym keySym) {
return J_VK_DECIMAL;
case XK_KP_Divide:
return J_VK_DIVIDE;
+ case XK_Clear: // equal behavior w/ QT
case XK_Delete:
case XK_KP_Delete:
return J_VK_DELETE;
@@ -450,7 +458,15 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_DisplayDriver_DispatchMessage
keyString = (*env)->NewStringUTF(env, text);
}
- if( 0 == keyChar ) {
+ #ifdef DEBUG_KEYS
+ fprintf(stderr, "NEWT X11 Key.0: keyCode 0x%X keySym 0x%X, (shifted: 0x%X)\n",
+ (int)keyCode, (int)keySym, (int) shiftedKeySym);
+ #endif
+ if( IS_WITHIN( shiftedKeySym, XK_KP_Space, XK_KP_9 ) ) {
+ // Use modded keySym for keypad for US and NN
+ keySym = shiftedKeySym;
+ unShiftedKeySym = shiftedKeySym;
+ } else if( 0 == keyChar ) {
// Use keyCode's keySym for dead-key (aka modifiers, etc)
unShiftedKeySym = keySym;
} else if( 0 == ( evt.xkey.state & ShiftCtrlModMask ) ) {
@@ -467,7 +483,7 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_DisplayDriver_DispatchMessage
modifiers |= X11InputState2NewtModifiers(xkey_state, javaVKeyNN, evt.type == KeyPress) | autoRepeatModifiers;
#ifdef DEBUG_KEYS
- fprintf(stderr, "NEWT X11 Key: keyCode 0x%X keySym 0x%X, (0x%X, shifted: 0x%X), keyChar '%c' 0x%X %d, javaVKey[US 0x%X, NN 0x%X], xstate 0x%X %u, jmods 0x%X\n",
+ fprintf(stderr, "NEWT X11 Key.X: keyCode 0x%X keySym 0x%X, (0x%X, shifted: 0x%X), keyChar '%c' 0x%X %d, javaVKey[US 0x%X, NN 0x%X], xstate 0x%X %u, jmods 0x%X\n",
(int)keyCode, (int)keySym, (int) unShiftedKeySym, (int)shiftedKeySym, keyChar, keyChar, charCount,
(int)javaVKeyUS, (int)javaVKeyNN,
(int)xkey_state, (int)xkey_state, (int)modifiers);