aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt
diff options
context:
space:
mode:
Diffstat (limited to 'src/newt')
-rw-r--r--src/newt/classes/com/jogamp/newt/event/InputEvent.java2
-rw-r--r--src/newt/classes/com/jogamp/newt/event/KeyEvent.java5
-rw-r--r--src/newt/classes/jogamp/newt/driver/linux/LinuxEventDeviceTracker.java2
-rw-r--r--src/newt/classes/jogamp/newt/driver/macosx/MacKeyUtil.java2
-rw-r--r--src/newt/native/WindowsWindow.c36
-rw-r--r--src/newt/native/X11Display.c32
6 files changed, 51 insertions, 28 deletions
diff --git a/src/newt/classes/com/jogamp/newt/event/InputEvent.java b/src/newt/classes/com/jogamp/newt/event/InputEvent.java
index 4920b59ea..b04ebc1af 100644
--- a/src/newt/classes/com/jogamp/newt/event/InputEvent.java
+++ b/src/newt/classes/com/jogamp/newt/event/InputEvent.java
@@ -133,7 +133,7 @@ public abstract class InputEvent extends NEWTEvent
if(isControlDown()) { if(!isFirst) { sb.append(", "); } isFirst = false; sb.append("ctrl"); }
if(isMetaDown()) { if(!isFirst) { sb.append(", "); } isFirst = false; sb.append("meta"); }
if(isAltDown()) { if(!isFirst) { sb.append(", "); } isFirst = false; sb.append("alt"); }
- if(isAltGraphDown()) { if(!isFirst) { sb.append(", "); } isFirst = false; sb.append("altg"); }
+ if(isAltGraphDown()) { if(!isFirst) { sb.append(", "); } isFirst = false; sb.append("altgr"); }
if(isAutoRepeat()) { if(!isFirst) { sb.append(", "); } isFirst = false; sb.append("repeat"); }
for(int i=1; i<=MouseEvent.BUTTON_NUMBER; i++) {
if(isButtonDown(i)) { if(!isFirst) { sb.append(", "); } isFirst = false; sb.append("button").append(i); }
diff --git a/src/newt/classes/com/jogamp/newt/event/KeyEvent.java b/src/newt/classes/com/jogamp/newt/event/KeyEvent.java
index 5117ffe29..777c9b471 100644
--- a/src/newt/classes/com/jogamp/newt/event/KeyEvent.java
+++ b/src/newt/classes/com/jogamp/newt/event/KeyEvent.java
@@ -325,6 +325,9 @@ public class KeyEvent extends InputEvent
public static final short VK_CLEAR = (short) 0x0C;
public static final short VK_SHIFT = (short) 0x10;
public static final short VK_CONTROL = (short) 0x11;
+ /**
+ * Constant for the ALT function key, i.e. left ALT key.
+ */
public static final short VK_ALT = (short) 0x12;
public static final short VK_PAUSE = (short) 0x13;
public static final short VK_CAPS_LOCK = (short) 0x14;
@@ -862,7 +865,7 @@ public class KeyEvent extends InputEvent
public static final short VK_COMPOSE = (short) 0xFF20;
/**
- * Constant for the AltGraph function key.
+ * Constant for the ALT_GRAPH function key, i.e. right ALT key.
*/
public static final short VK_ALT_GRAPH = (short) 0xFF7E;
diff --git a/src/newt/classes/jogamp/newt/driver/linux/LinuxEventDeviceTracker.java b/src/newt/classes/jogamp/newt/driver/linux/LinuxEventDeviceTracker.java
index 2c0e6d3dd..bc69c2204 100644
--- a/src/newt/classes/jogamp/newt/driver/linux/LinuxEventDeviceTracker.java
+++ b/src/newt/classes/jogamp/newt/driver/linux/LinuxEventDeviceTracker.java
@@ -586,7 +586,7 @@ public class LinuxEventDeviceTracker implements WindowListener {
break; // FIXME
case 100: // right alt
- return KeyEvent.VK_ALT;
+ return KeyEvent.VK_ALT_GRAPH;
case 101: // linefeed
break; // FIXME
case 102: // home
diff --git a/src/newt/classes/jogamp/newt/driver/macosx/MacKeyUtil.java b/src/newt/classes/jogamp/newt/driver/macosx/MacKeyUtil.java
index c07576901..baa94facd 100644
--- a/src/newt/classes/jogamp/newt/driver/macosx/MacKeyUtil.java
+++ b/src/newt/classes/jogamp/newt/driver/macosx/MacKeyUtil.java
@@ -317,7 +317,7 @@ public class MacKeyUtil {
case kVK_Option: return KeyEvent.VK_ALT;
case kVK_Control: return KeyEvent.VK_CONTROL;
case kVK_RightShift: return KeyEvent.VK_SHIFT;
- case kVK_RightOption: return KeyEvent.VK_ALT;
+ case kVK_RightOption: return KeyEvent.VK_ALT_GRAPH;
case kVK_RightControl: return KeyEvent.VK_CONTROL;
// case kVK_Function: return KeyEvent.VK_F;
case kVK_F17: return KeyEvent.VK_F17;
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: