diff options
author | Sven Gothel <[email protected]> | 2013-04-06 04:47:34 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-04-06 04:47:34 +0200 |
commit | 4898f582d9303caa7fd1b44438808e86b51c2a3b (patch) | |
tree | 6dbc1fe716e922828709aec69ab3f20ac0e299d7 /src/newt/native | |
parent | 9cf72802f4559efa77baa14ae5d501bc341bf86a (diff) |
Bug 678: Differentiate ALT (left) and ALT_GRAPH (right) on X11, EventDev, Windows and OSX
- X11: Memorize pressed Alt_R to decide which 'alt' has to be used for non key modifier fetching
- Windows: Only use GetKeyState(..) and compare the US vkey, since int. kbd layout use reduced scancode
Diffstat (limited to 'src/newt/native')
-rw-r--r-- | src/newt/native/WindowsWindow.c | 36 | ||||
-rw-r--r-- | src/newt/native/X11Display.c | 32 |
2 files changed, 44 insertions, 24 deletions
diff --git a/src/newt/native/WindowsWindow.c b/src/newt/native/WindowsWindow.c index aeb860bbc..7426e5dfe 100644 --- a/src/newt/native/WindowsWindow.c +++ b/src/newt/native/WindowsWindow.c @@ -161,7 +161,7 @@ static KeyMapEntry keyMapTable[] = { {J_VK_CONTROL, VK_RCONTROL, 0}, {J_VK_ALT, VK_MENU, 0}, {J_VK_ALT, VK_LMENU, 0}, - {J_VK_ALT, VK_RMENU, 0}, + {J_VK_ALT_GRAPH, VK_RMENU, 0}, {J_VK_NUM_LOCK, VK_NUMLOCK, 0}, // Miscellaneous Windows keys @@ -431,7 +431,7 @@ static void ParseWmVKeyAndScanCode(USHORT winVKey, BYTE winScanCode, BYTE flags, #endif } -static jint GetModifiers(BOOL altKeyFlagged, USHORT jkey) { +static jint GetModifiers(USHORT jkey) { jint modifiers = 0; // have to do &0xFFFF to avoid runtime assert caused by compiling with // /RTCcsu @@ -441,9 +441,12 @@ static jint GetModifiers(BOOL altKeyFlagged, USHORT jkey) { if ( HIBYTE((GetKeyState(VK_SHIFT) & 0xFFFF)) != 0 || J_VK_SHIFT == jkey ) { modifiers |= EVENT_SHIFT_MASK; } - if ( altKeyFlagged || HIBYTE((GetKeyState(VK_MENU) & 0xFFFF)) != 0 || J_VK_ALT == jkey ) { + if ( HIBYTE((GetKeyState(VK_LMENU) & 0xFFFF)) != 0 || J_VK_ALT == jkey ) { modifiers |= EVENT_ALT_MASK; } + if ( HIBYTE((GetKeyState(VK_RMENU) & 0xFFFF)) != 0 || (USHORT)J_VK_ALT_GRAPH == jkey ) { + modifiers |= EVENT_ALT_GRAPH_MASK; + } if ( HIBYTE((GetKeyState(VK_LBUTTON) & 0xFFFF)) != 0 ) { modifiers |= EVENT_BUTTON1_MASK; } @@ -457,11 +460,12 @@ static jint GetModifiers(BOOL altKeyFlagged, USHORT jkey) { return modifiers; } +/** static BOOL IsAltKeyDown(BYTE flags, BOOL system) { // The Alt modifier is reported in the 29th bit of the lParam, // i.e., it is the 5th bit of `flags' (which is HIBYTE(HIWORD(lParam))). return system && ( flags & (1<<5) ) != 0; -} +} */ static int WmKeyDown(JNIEnv *env, jobject window, USHORT wkey, WORD repCnt, BYTE scanCode, BYTE flags, BOOL system) { UINT modifiers = 0; @@ -472,7 +476,7 @@ static int WmKeyDown(JNIEnv *env, jobject window, USHORT wkey, WORD repCnt, BYTE ParseWmVKeyAndScanCode(wkey, scanCode, flags, &javaVKeyUS, &javaVKeyXX, &utf16Char); - modifiers = GetModifiers( IsAltKeyDown(flags, system), javaVKeyXX ); + modifiers = GetModifiers( javaVKeyUS ); (*env)->CallVoidMethod(env, window, sendKeyEventID, (jshort) EVENT_KEY_PRESSED, @@ -490,7 +494,7 @@ static int WmKeyUp(JNIEnv *env, jobject window, USHORT wkey, WORD repCnt, BYTE s ParseWmVKeyAndScanCode(wkey, scanCode, flags, &javaVKeyUS, &javaVKeyXX, &utf16Char); - modifiers = GetModifiers( IsAltKeyDown(flags, system), javaVKeyXX ); + modifiers = GetModifiers( javaVKeyUS ); (*env)->CallVoidMethod(env, window, sendKeyEventID, (jshort) EVENT_KEY_RELEASED, @@ -859,7 +863,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message, WPARAM wParam, LPARAM lP (*env)->CallVoidMethod(env, window, requestFocusID, JNI_FALSE); (*env)->CallVoidMethod(env, window, sendMouseEventID, (jshort) EVENT_MOUSE_PRESSED, - GetModifiers( FALSE, 0 ), + GetModifiers( 0 ), (jint) GET_X_LPARAM(lParam), (jint) GET_Y_LPARAM(lParam), (jshort) 1, (jfloat) 0.0f); useDefWindowProc = 1; @@ -868,7 +872,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message, WPARAM wParam, LPARAM lP case WM_LBUTTONUP: (*env)->CallVoidMethod(env, window, sendMouseEventID, (jshort) EVENT_MOUSE_RELEASED, - GetModifiers( FALSE, 0 ), + GetModifiers( 0 ), (jint) GET_X_LPARAM(lParam), (jint) GET_Y_LPARAM(lParam), (jshort) 1, (jfloat) 0.0f); useDefWindowProc = 1; @@ -879,7 +883,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message, WPARAM wParam, LPARAM lP (*env)->CallVoidMethod(env, window, requestFocusID, JNI_FALSE); (*env)->CallVoidMethod(env, window, sendMouseEventID, (jshort) EVENT_MOUSE_PRESSED, - GetModifiers( FALSE, 0 ), + GetModifiers( 0 ), (jint) GET_X_LPARAM(lParam), (jint) GET_Y_LPARAM(lParam), (jshort) 2, (jfloat) 0.0f); useDefWindowProc = 1; @@ -888,7 +892,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message, WPARAM wParam, LPARAM lP case WM_MBUTTONUP: (*env)->CallVoidMethod(env, window, sendMouseEventID, (jshort) EVENT_MOUSE_RELEASED, - GetModifiers( FALSE, 0 ), + GetModifiers( 0 ), (jint) GET_X_LPARAM(lParam), (jint) GET_Y_LPARAM(lParam), (jshort) 2, (jfloat) 0.0f); useDefWindowProc = 1; @@ -899,7 +903,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message, WPARAM wParam, LPARAM lP (*env)->CallVoidMethod(env, window, requestFocusID, JNI_FALSE); (*env)->CallVoidMethod(env, window, sendMouseEventID, (jshort) EVENT_MOUSE_PRESSED, - GetModifiers( FALSE, 0 ), + GetModifiers( 0 ), (jint) GET_X_LPARAM(lParam), (jint) GET_Y_LPARAM(lParam), (jshort) 3, (jfloat) 0.0f); useDefWindowProc = 1; @@ -908,17 +912,17 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message, WPARAM wParam, LPARAM lP case WM_RBUTTONUP: (*env)->CallVoidMethod(env, window, sendMouseEventID, (jshort) EVENT_MOUSE_RELEASED, - GetModifiers( FALSE, 0 ), + GetModifiers( 0 ), (jint) GET_X_LPARAM(lParam), (jint) GET_Y_LPARAM(lParam), (jshort) 3, (jfloat) 0.0f); useDefWindowProc = 1; break; case WM_MOUSEMOVE: - DBG_PRINT("*** WindowsWindow: WM_MOUSEMOVE %d/%d\n", (jint) GET_X_LPARAM(lParam), (jint) GET_Y_LPARAM(lParam)); + // DBG_PRINT("*** WindowsWindow: WM_MOUSEMOVE %d/%d\n", (jint) GET_X_LPARAM(lParam), (jint) GET_Y_LPARAM(lParam)); (*env)->CallVoidMethod(env, window, sendMouseEventID, (jshort) EVENT_MOUSE_MOVED, - GetModifiers( FALSE, 0 ), + GetModifiers( 0 ), (jint) GET_X_LPARAM(lParam), (jint) GET_Y_LPARAM(lParam), (jshort) 0, (jfloat) 0.0f); useDefWindowProc = 1; @@ -936,7 +940,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message, WPARAM wParam, LPARAM lP case WM_HSCROLL: { // Only delivered if windows has WS_HSCROLL, hence dead code! int sb = LOWORD(wParam); - int modifiers = GetModifiers( FALSE, 0 ) | EVENT_SHIFT_MASK; + int modifiers = GetModifiers( 0 ) | EVENT_SHIFT_MASK; float rotation; switch(sb) { case SB_LINELEFT: @@ -966,7 +970,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message, WPARAM wParam, LPARAM lP // need to convert the coordinates to component-relative int x = GET_X_LPARAM(lParam); int y = GET_Y_LPARAM(lParam); - int modifiers = GetModifiers( FALSE, 0 ); + int modifiers = GetModifiers( 0 ); float rotationOrTilt = (float)(GET_WHEEL_DELTA_WPARAM(wParam))/WHEEL_DELTAf; int vKeys = GET_KEYSTATE_WPARAM(wParam); POINT eventPt; diff --git a/src/newt/native/X11Display.c b/src/newt/native/X11Display.c index 9b11ff0dd..d927b8069 100644 --- a/src/newt/native/X11Display.c +++ b/src/newt/native/X11Display.c @@ -52,9 +52,11 @@ static jmethodID requestFocusID = NULL; * Keycode */ +// #define DEBUG_KEYS 1 + #define IS_WITHIN(k,a,b) ((a)<=(k)&&(k)<=(b)) -static jint X11KeySym2NewtVKey(KeySym keySym) { +static short X11KeySym2NewtVKey(KeySym keySym) { if( IS_WITHIN( keySym, XK_a, XK_z ) ) { return ( keySym - XK_a ) + J_VK_A ; } @@ -89,8 +91,9 @@ static jint X11KeySym2NewtVKey(KeySym keySym) { case XK_Control_R: return J_VK_CONTROL; case XK_Alt_L: - case XK_Alt_R: return J_VK_ALT; + case XK_Alt_R: + return J_VK_ALT_GRAPH; case XK_Pause: return J_VK_PAUSE; case XK_Caps_Lock: @@ -158,7 +161,9 @@ static jint X11KeySym2NewtVKey(KeySym keySym) { return keySym; } -static jint X11InputState2NewtModifiers(unsigned int xstate, int javaVKey) { +static jboolean altGraphDown = JNI_FALSE; + +static jint X11InputState2NewtModifiers(unsigned int xstate, jshort javaVKey, jboolean keyDown) { jint modifiers = 0; if ( (ControlMask & xstate) != 0 || J_VK_CONTROL == javaVKey ) { modifiers |= EVENT_CTRL_MASK; @@ -166,8 +171,15 @@ static jint X11InputState2NewtModifiers(unsigned int xstate, int javaVKey) { if ( (ShiftMask & xstate) != 0 || J_VK_SHIFT == javaVKey ) { modifiers |= EVENT_SHIFT_MASK; } - if ( (Mod1Mask & xstate) != 0 || J_VK_ALT == javaVKey ) { + if ( J_VK_ALT == javaVKey ) { + altGraphDown = JNI_FALSE; modifiers |= EVENT_ALT_MASK; + } else if ( (short)J_VK_ALT_GRAPH == javaVKey ) { + altGraphDown = keyDown; + modifiers |= EVENT_ALT_GRAPH_MASK; + } else if ( (Mod1Mask & xstate) != 0 ) { + // XK_Alt_L or XK_Alt_R + modifiers |= altGraphDown ? EVENT_ALT_GRAPH_MASK : EVENT_ALT_MASK; } if ( (Button1Mask & xstate) != 0 ) { modifiers |= EVENT_BUTTON1_MASK; @@ -401,17 +413,21 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_DisplayDriver_DispatchMessage javaVKeyNN = X11KeySym2NewtVKey(keySym); javaVKeyUS = javaVKeyNN; // FIXME! - modifiers |= X11InputState2NewtModifiers(evt.xkey.state, javaVKeyNN) | autoRepeatModifiers; + modifiers |= X11InputState2NewtModifiers(evt.xkey.state, javaVKeyNN, evt.type == KeyPress) | autoRepeatModifiers; - fprintf(stderr, "NEWT X11 Key: keyCode 0x%X keySym 0x%X (shifted: 0x%X), keyChar '%c', javaVKey[US 0x%X, NN 0x%X]\n", - (int)keyCode, (int)keySym, (int)shiftedKeySym, (int)keyChar, (int)javaVKeyUS, (int)javaVKeyNN); + #ifdef DEBUG_KEYS + fprintf(stderr, "NEWT X11 Key: keyCode 0x%X keySym 0x%X (shifted: 0x%X), keyChar '%c', javaVKey[US 0x%X, NN 0x%X], xstate 0x%X %u, jmods 0x%X\n", + (int)keyCode, (int)keySym, (int)shiftedKeySym, keyChar, + (int)javaVKeyUS, (int)javaVKeyNN, + (int)evt.xkey.state, (int)evt.xkey.state, (int)modifiers); + #endif } break; case ButtonPress: case ButtonRelease: case MotionNotify: - modifiers |= X11InputState2NewtModifiers(evt.xbutton.state, 0); + modifiers |= X11InputState2NewtModifiers(evt.xbutton.state, 0, JNI_FALSE); break; default: |