aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-10-27 04:01:56 +0200
committerSven Gothel <[email protected]>2012-10-27 04:01:56 +0200
commit70d58b030bdbac98ba592a3a14a84cc0e4941c51 (patch)
tree326485c2123f347eec63f253539d36197d9ad537
parent2f9c77a347b76bebdadd4bec1ac92aa7ab72365f (diff)
NEWT KeyEvent (Windows, OSX): Check whether keyCode is tracked before using bitfield, use more IntBitfield.put(..) return value for efficiency.
-rwxr-xr-xmake/scripts/tests-x64.bat4
-rwxr-xr-xmake/scripts/tests.sh4
-rw-r--r--src/newt/classes/jogamp/newt/WindowImpl.java3
-rw-r--r--src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java23
-rw-r--r--src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java26
5 files changed, 31 insertions, 29 deletions
diff --git a/make/scripts/tests-x64.bat b/make/scripts/tests-x64.bat
index 21e303dc2..72ee5f666 100755
--- a/make/scripts/tests-x64.bat
+++ b/make/scripts/tests-x64.bat
@@ -32,9 +32,9 @@ REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.glsl.TestGLSLSi
REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.newt.TestParenting01AWT
REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.newt.TestListenerCom01AWT
-scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.newt.TestKeyEventOrderNEWT %*
+REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.newt.TestKeyEventOrderNEWT %*
REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.newt.TestKeyEventAutoRepeatNEWT %*
-REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.newt.TestKeyPressReleaseUnmaskRepeatNEWT %*
+scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.newt.TestKeyPressReleaseUnmaskRepeatNEWT %*
REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.newt.parenting.TestParenting01NEWT %*
REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.newt.parenting.TestParenting02NEWT %*
REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.newt.parenting.TestParenting01bAWT %*
diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh
index 734fa671f..8594bfe2e 100755
--- a/make/scripts/tests.sh
+++ b/make/scripts/tests.sh
@@ -375,9 +375,9 @@ function testawtswt() {
#testawt com.jogamp.opengl.test.junit.newt.TestEventSourceNotAWTBug
#testawt com.jogamp.opengl.test.junit.newt.TestFocus01SwingAWTRobot $*
#testawt com.jogamp.opengl.test.junit.newt.TestFocus02SwingAWTRobot $*
-testawt com.jogamp.opengl.test.junit.newt.TestKeyEventOrderNEWT $*
+#testawt com.jogamp.opengl.test.junit.newt.TestKeyEventOrderNEWT $*
#testawt com.jogamp.opengl.test.junit.newt.TestKeyEventAutoRepeatNEWT $*
-#testawt com.jogamp.opengl.test.junit.newt.TestKeyPressReleaseUnmaskRepeatNEWT $*
+testawt com.jogamp.opengl.test.junit.newt.TestKeyPressReleaseUnmaskRepeatNEWT $*
#testawt com.jogamp.opengl.test.junit.newt.TestListenerCom01AWT
#testawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting01aAWT $*
#testawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting01bAWT $*
diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java
index 311ed0bbb..4f8eb3d3a 100644
--- a/src/newt/classes/jogamp/newt/WindowImpl.java
+++ b/src/newt/classes/jogamp/newt/WindowImpl.java
@@ -2193,6 +2193,9 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
return -1;
}
+ protected final boolean isKeyCodeTracked(int keyCode) {
+ return 0 <= keyCode && keyCode < keyRepeatState.capacity();
+ }
public void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) {
consumeKeyEvent(new KeyEvent(eventType, this, System.currentTimeMillis(), modifiers, keyCode, keyChar) );
diff --git a/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java
index bcdd6b9df..e0ea8ea76 100644
--- a/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java
@@ -324,24 +324,21 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
// Auto-Repeat: OSX delivers only PRESSED, inject auto-repeat RELEASE and TYPED keys _before_ PRESSED
switch(eventType) {
case KeyEvent.EVENT_KEY_RELEASED:
- if( 1 == isKeyInAutoRepeat(keyCode) ) {
- // AR out
- keyRepeatState.put(keyCode, false);
+ if( isKeyCodeTracked(keyCode) ) {
+ keyRepeatState.put(keyCode, false); // prev == true -> AR out
+ keyPressedState.put(keyCode, false);
}
- keyPressedState.put(keyCode, false);
keyChar = (char)-1;
break;
case KeyEvent.EVENT_KEY_PRESSED:
- if( 1 == isKeyPressed(keyCode) ) {
- if( 0 == isKeyInAutoRepeat(keyCode) ) {
- // AR in
- keyRepeatState.put(keyCode, true);
+ if( isKeyCodeTracked(keyCode) ) {
+ if( keyPressedState.put(keyCode, true) ) {
+ // key was already pressed
+ keyRepeatState.put(keyCode, true); // prev == false -> AR in
+ modifiers |= InputEvent.AUTOREPEAT_MASK;
+ emitKeyEvent(send, wait, KeyEvent.EVENT_KEY_RELEASED, modifiers, keyCode, (char)-1); // RELEASED
+ emitKeyEvent(send, wait, KeyEvent.EVENT_KEY_TYPED, modifiers, keyCode, keyChar); // TYPED
}
- modifiers |= InputEvent.AUTOREPEAT_MASK;
- emitKeyEvent(send, wait, KeyEvent.EVENT_KEY_RELEASED, modifiers, keyCode, (char)-1); // RELEASED
- emitKeyEvent(send, wait, KeyEvent.EVENT_KEY_TYPED, modifiers, keyCode, keyChar); // TYPED
- } else {
- keyPressedState.put(keyCode, true);
}
keyChar = (char)-1;
break;
diff --git a/src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java
index be9f6603e..8b57a241d 100644
--- a/src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java
@@ -281,12 +281,13 @@ public class WindowDriver extends WindowImpl {
// Auto-Repeat: WINDOWS delivers only PRESSED and TYPED.
switch(eventType) {
case KeyEvent.EVENT_KEY_RELEASED:
- if( 1 == isKeyInAutoRepeat(keyCode) ) {
- // AR out - send out missing PRESSED
- emitKeyEvent(send, wait, KeyEvent.EVENT_KEY_PRESSED, modifiers | InputEvent.AUTOREPEAT_MASK, keyCode, (char)-1);
- keyRepeatState.put(keyCode, false);
+ if( isKeyCodeTracked(keyCode) ) {
+ if( keyRepeatState.put(keyCode, false) ) {
+ // AR out - send out missing PRESSED
+ emitKeyEvent(send, wait, KeyEvent.EVENT_KEY_PRESSED, modifiers | InputEvent.AUTOREPEAT_MASK, keyCode, (char)-1);
+ }
+ keyPressedState.put(keyCode, false);
}
- keyPressedState.put(keyCode, false);
emitKeyEvent(send, wait, eventType, modifiers, keyCode, keyChar);
final char lastTypedKeyChar = (char) typedKeyCode2KeyChar.put(keyCode, 0);
if( 0 < lastTypedKeyChar ) {
@@ -294,16 +295,17 @@ public class WindowDriver extends WindowImpl {
}
break;
case KeyEvent.EVENT_KEY_PRESSED:
- lastPressedKeyCode = keyCode;
- if( 1 == isKeyPressed(keyCode) ) {
- if( 0 == isKeyInAutoRepeat(keyCode) ) {
- // AR in - skip already send PRESSED
- keyRepeatState.put(keyCode, true);
+ lastPressedKeyCode = keyCode;
+ if( isKeyCodeTracked(keyCode) ) {
+ if( keyPressedState.put(keyCode, true) ) {
+ // key was already pressed
+ if( keyRepeatState.put(keyCode, true) ) {
+ emitKeyEvent(send, wait, eventType, modifiers | InputEvent.AUTOREPEAT_MASK, keyCode, (char)-1);
+ } // else AR in - skip already send PRESSED
} else {
- emitKeyEvent(send, wait, eventType, modifiers | InputEvent.AUTOREPEAT_MASK, keyCode, (char)-1);
+ emitKeyEvent(send, wait, eventType, modifiers, keyCode, (char)-1);
}
} else {
- keyPressedState.put(keyCode, true);
emitKeyEvent(send, wait, eventType, modifiers, keyCode, (char)-1);
}
break;