summaryrefslogtreecommitdiffstats
path: root/src/newt
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 /src/newt
parent2f9c77a347b76bebdadd4bec1ac92aa7ab72365f (diff)
NEWT KeyEvent (Windows, OSX): Check whether keyCode is tracked before using bitfield, use more IntBitfield.put(..) return value for efficiency.
Diffstat (limited to 'src/newt')
-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
3 files changed, 27 insertions, 25 deletions
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;