aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt/native
diff options
context:
space:
mode:
Diffstat (limited to 'src/newt/native')
-rw-r--r--src/newt/native/KeyEvent.h21
-rw-r--r--src/newt/native/WindowsWindow.c42
-rw-r--r--src/newt/native/X11Display.c24
-rw-r--r--src/newt/native/X11Event.c6
-rw-r--r--src/newt/native/X11Window.c6
-rw-r--r--src/newt/native/XCBEvent.c6
6 files changed, 59 insertions, 46 deletions
diff --git a/src/newt/native/KeyEvent.h b/src/newt/native/KeyEvent.h
index 7a63b19ce..59977d565 100644
--- a/src/newt/native/KeyEvent.h
+++ b/src/newt/native/KeyEvent.h
@@ -31,7 +31,6 @@
#define EVENT_KEY_PRESSED 300
#define EVENT_KEY_RELEASED 301
-#define EVENT_KEY_TYPED 302
#define J_VK_UNDEFINED ( 0x0U )
#define J_VK_HOME ( 0x02U )
@@ -161,7 +160,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 +172,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 +191,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);
diff --git a/src/newt/native/X11Event.c b/src/newt/native/X11Event.c
index 770f60e8f..32a55c67c 100644
--- a/src/newt/native/X11Event.c
+++ b/src/newt/native/X11Event.c
@@ -170,15 +170,9 @@ void X11EventPoll(JNIEnv *env, jobject obj, Display *dpy, jlong javaObjectAtom,
#ifdef USE_SENDIO_DIRECT
(*env)->CallVoidMethod(env, jwindow, sendKeyEventID, (jint) EVENT_KEY_RELEASED,
modifiers, keySym, (jchar) -1);
-
- (*env)->CallVoidMethod(env, jwindow, sendKeyEventID, (jint) EVENT_KEY_TYPED,
- modifiers, keySym, (jchar) keyChar);
#else
(*env)->CallVoidMethod(env, jwindow, enqueueKeyEventID, JNI_FALSE, (jint) EVENT_KEY_RELEASED,
modifiers, keySym, (jchar) -1);
-
- (*env)->CallVoidMethod(env, jwindow, enqueueKeyEventID, JNI_FALSE, (jint) EVENT_KEY_TYPED,
- modifiers, keySym, (jchar) keyChar);
#endif
break;
diff --git a/src/newt/native/X11Window.c b/src/newt/native/X11Window.c
index 6c5a127b6..3f50f27a4 100644
--- a/src/newt/native/X11Window.c
+++ b/src/newt/native/X11Window.c
@@ -676,6 +676,7 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_WindowDriver_CloseWindow0
Display * dpy = (Display *) (intptr_t) display;
Window w = (Window)window;
jobject jwindow;
+ XWindowAttributes xwa;
if(dpy==NULL) {
NewtCommon_FatalError(env, "invalid display connection..");
@@ -694,6 +695,8 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_WindowDriver_CloseWindow0
}
XSync(dpy, False);
+ memset(&xwa, 0, sizeof(XWindowAttributes));
+ XGetWindowAttributes(dpy, w, &xwa); // prefetch colormap to be destroyed after window destruction
XSelectInput(dpy, w, 0);
XUnmapWindow(dpy, w);
@@ -701,6 +704,9 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_WindowDriver_CloseWindow0
Java_jogamp_newt_driver_x11_DisplayDriver_DispatchMessages0(env, obj, display, javaObjectAtom, windowDeleteAtom /*, kbdHandle */); // XKB disabled for now
XDestroyWindow(dpy, w);
+ if( None != xwa.colormap ) {
+ XFreeColormap(dpy, xwa.colormap);
+ }
XSync(dpy, True); // discard all events now, no more handler
(*env)->DeleteGlobalRef(env, jwindow);
diff --git a/src/newt/native/XCBEvent.c b/src/newt/native/XCBEvent.c
index f067f4b7a..d02d5a4ba 100644
--- a/src/newt/native/XCBEvent.c
+++ b/src/newt/native/XCBEvent.c
@@ -176,15 +176,9 @@ void XCBEventPoll(JNIEnv *env, jobject obj, Display *dpy, jlong javaObjectAtom,
#ifdef USE_SENDIO_DIRECT
(*env)->CallVoidMethod(env, jwindow, sendKeyEventID, (jint) EVENT_KEY_RELEASED,
modifiers, X11KeySym2NewtVKey(_evt->state), (jchar) keyChar);
-
- (*env)->CallVoidMethod(env, jwindow, sendKeyEventID, (jint) EVENT_KEY_TYPED,
- modifiers, (jint) -1, (jchar) keyChar);
#else
(*env)->CallVoidMethod(env, jwindow, enqueueKeyEventID, JNI_FALSE, (jint) EVENT_KEY_RELEASED,
modifiers, X11KeySym2NewtVKey(_evt->state), (jchar) keyChar);
-
- (*env)->CallVoidMethod(env, jwindow, enqueueKeyEventID, JNI_FALSE, (jint) EVENT_KEY_TYPED,
- modifiers, (jint) -1, (jchar) keyChar);
#endif
} break;