aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt/classes/jogamp
diff options
context:
space:
mode:
Diffstat (limited to 'src/newt/classes/jogamp')
-rw-r--r--src/newt/classes/jogamp/newt/DisplayImpl.java26
-rw-r--r--src/newt/classes/jogamp/newt/WindowImpl.java250
-rw-r--r--src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java110
-rw-r--r--src/newt/classes/jogamp/newt/awt/event/AWTParentWindowAdapter.java6
-rw-r--r--src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java100
-rw-r--r--src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventTranslator.java8
-rw-r--r--src/newt/classes/jogamp/newt/driver/awt/WindowDriver.java5
-rw-r--r--src/newt/classes/jogamp/newt/driver/linux/LinuxEventDeviceTracker.java33
-rw-r--r--src/newt/classes/jogamp/newt/driver/linux/LinuxMouseTracker.java14
-rw-r--r--src/newt/classes/jogamp/newt/driver/macosx/MacKeyUtil.java262
-rw-r--r--src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java207
-rw-r--r--src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java89
-rw-r--r--src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java33
-rw-r--r--src/newt/classes/jogamp/newt/swt/event/SWTNewtEventFactory.java52
14 files changed, 699 insertions, 496 deletions
diff --git a/src/newt/classes/jogamp/newt/DisplayImpl.java b/src/newt/classes/jogamp/newt/DisplayImpl.java
index 20b915cae..d4842ba2f 100644
--- a/src/newt/classes/jogamp/newt/DisplayImpl.java
+++ b/src/newt/classes/jogamp/newt/DisplayImpl.java
@@ -370,15 +370,8 @@ public abstract class DisplayImpl extends Display {
DisplayImpl.this.dispatchMessages();
} };
- final void dispatchMessage(final NEWTEventTask eventTask) {
- final NEWTEvent event = eventTask.get();
+ final void dispatchMessage(final NEWTEvent event) {
try {
- if(null == event) {
- // Ooops ?
- System.err.println("Warning: event of eventTask is NULL");
- Thread.dumpStack();
- return;
- }
final Object source = event.getSource();
if(source instanceof NEWTEventConsumer) {
final NEWTEventConsumer consumer = (NEWTEventConsumer) source ;
@@ -396,6 +389,21 @@ public abstract class DisplayImpl extends Display {
} else {
re = new RuntimeException(t);
}
+ throw re;
+ }
+ }
+
+ final void dispatchMessage(final NEWTEventTask eventTask) {
+ final NEWTEvent event = eventTask.get();
+ try {
+ if(null == event) {
+ // Ooops ?
+ System.err.println("Warning: event of eventTask is NULL");
+ Thread.dumpStack();
+ return;
+ }
+ dispatchMessage(event);
+ } catch (RuntimeException re) {
if( eventTask.isCallerWaiting() ) {
// propagate exception to caller
eventTask.setException(re);
@@ -451,7 +459,7 @@ public abstract class DisplayImpl extends Display {
// can't wait if we are on EDT or NEDT -> consume right away
if(wait && edtUtil.isCurrentThreadEDTorNEDT() ) {
- dispatchMessage(new NEWTEventTask(e, null));
+ dispatchMessage(e);
return;
}
diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java
index cb43fae32..66ca3e07d 100644
--- a/src/newt/classes/jogamp/newt/WindowImpl.java
+++ b/src/newt/classes/jogamp/newt/WindowImpl.java
@@ -110,7 +110,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
private boolean pointerConfined = false;
private LifecycleHook lifecycleHook = null;
- private boolean handleDestroyNotify = true;
+ private Runnable windowDestroyNotifyAction = null;
private FocusRunnable focusAction = null;
private KeyListener keyboardFocusHandler = null;
@@ -121,10 +121,10 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
private ArrayList<NativeWindow> childWindows = new ArrayList<NativeWindow>();
private ArrayList<MouseListener> mouseListeners = new ArrayList<MouseListener>();
- private int mouseButtonPressed = 0; // current pressed mouse button number
- private int mouseButtonModMask = 0; // current pressed mouse button modifier mask
+ private short mouseButtonPressed = (short)0; // current pressed mouse button number
+ private int mouseButtonModMask = 0; // current pressed mouse button modifier mask
private long lastMousePressed = 0; // last time when a mouse button was pressed
- private int lastMouseClickCount = 0; // last mouse button click count
+ private short lastMouseClickCount = (short)0; // last mouse button click count
private boolean mouseInWindow = false;// mouse entered window - is inside the window (may be synthetic)
private Point lastMousePosition = new Point();
@@ -527,9 +527,15 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
protected void setTitleImpl(String title) {}
/**
- * Return screen coordinates of the given coordinates
- * or null, in which case a NativeWindow traversal shall being used
+ * Translates the given window client-area coordinates with top-left origin
+ * to screen coordinates.
+ * <p>
+ * Since the position reflects the client area, it does not include the insets.
+ * </p>
+ * <p>
+ * May return <code>null</code>, in which case the caller shall traverse through the NativeWindow tree
* as demonstrated in {@link #getLocationOnScreen(javax.media.nativewindow.util.Point)}.
+ * </p>
*
* @return if not null, the screen location of the given coordinates
*/
@@ -644,14 +650,17 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
// public final void destroy() - see below
+ @Override
public final NativeWindow getParent() {
return parentWindow;
}
+ @Override
public final long getWindowHandle() {
return windowHandle;
}
+ @Override
public Point getLocationOnScreen(Point storage) {
if(isNativeValid()) {
Point d;
@@ -688,14 +697,16 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
// Window
//
+ @Override
public final boolean isNativeValid() {
return 0 != windowHandle ;
}
+ @Override
public final Screen getScreen() {
return screen;
}
-
+
protected final void setVisibleImpl(boolean visible, int x, int y, int width, int height) {
reconfigureWindowImpl(x, y, width, height, getReconfigureFlags(FLAG_CHANGE_VISIBILITY, visible));
}
@@ -778,7 +789,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
runOnEDTIfAvail(wait, new VisibleAction(visible));
}
-
+
+ @Override
public void setVisible(boolean visible) {
setVisible(true, visible);
}
@@ -830,9 +842,11 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
}
+ @Override
public void setSize(int width, int height) {
runOnEDTIfAvail(true, new SetSizeAction(width, height));
}
+ @Override
public void setTopLevelSize(int width, int height) {
setSize(width - getInsets().getTotalWidth(), height - getInsets().getTotalHeight());
}
@@ -850,8 +864,12 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
_lock.lock();
try {
if(DEBUG_IMPLEMENTATION) {
- System.err.println("Window DestroyAction() "+getThreadName());
+ System.err.println("Window DestroyAction() hasScreen "+(null != screen)+", isNativeValid "+isNativeValid()+" - "+getThreadName());
}
+
+ // send synced destroy-notify notification
+ sendWindowEvent(WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY);
+
// Childs first ..
synchronized(childWindowsLock) {
if(childWindows.size()>0) {
@@ -861,8 +879,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
while( clonedChildWindows.size() > 0 ) {
NativeWindow nw = clonedChildWindows.remove(0);
if(nw instanceof WindowImpl) {
- ((WindowImpl)nw).sendWindowEvent(WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY);
- ((WindowImpl)nw).destroy();
+ ((WindowImpl)nw).windowDestroyNotify(true);
} else {
nw.destroy();
}
@@ -932,6 +949,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
private final DestroyAction destroyAction = new DestroyAction();
+ @Override
public void destroy() {
visible = false; // Immediately mark synchronized visibility flag, avoiding possible recreation
runOnEDTIfAvail(true, destroyAction);
@@ -1253,6 +1271,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
private final ReparentActionRecreate reparentActionRecreate = new ReparentActionRecreate();
+ @Override
public final ReparentOperation reparentWindow(NativeWindow newParent) {
return reparentWindow(newParent, false);
}
@@ -1263,16 +1282,19 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
return reparentAction.getOp();
}
+ @Override
public CapabilitiesChooser setCapabilitiesChooser(CapabilitiesChooser chooser) {
CapabilitiesChooser old = this.capabilitiesChooser;
this.capabilitiesChooser = chooser;
return old;
}
+ @Override
public final CapabilitiesImmutable getChosenCapabilities() {
return getGraphicsConfiguration().getChosenCapabilities();
}
+ @Override
public final CapabilitiesImmutable getRequestedCapabilities() {
return capsRequested;
}
@@ -1312,10 +1334,12 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
}
+ @Override
public void setUndecorated(boolean value) {
runOnEDTIfAvail(true, new DecorationAction(value));
}
+ @Override
public final boolean isUndecorated() {
return 0 != parentWindowHandle || undecorated || fullscreen ;
}
@@ -1355,17 +1379,21 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
}
+ @Override
public final void setAlwaysOnTop(boolean value) {
runOnEDTIfAvail(true, new AlwaysOnTopAction(value));
}
+ @Override
public final boolean isAlwaysOnTop() {
return alwaysOnTop;
}
+ @Override
public String getTitle() {
return title;
}
+ @Override
public void setTitle(String title) {
if (title == null) {
title = "";
@@ -1376,9 +1404,11 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
}
+ @Override
public boolean isPointerVisible() {
return pointerVisible;
}
+ @Override
public void setPointerVisible(boolean pointerVisible) {
if(this.pointerVisible != pointerVisible) {
boolean setVal = 0 == getWindowHandle();
@@ -1390,10 +1420,12 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
}
}
+ @Override
public boolean isPointerConfined() {
return pointerConfined;
}
+ @Override
public void confinePointer(boolean confine) {
if(this.pointerConfined != confine) {
boolean setVal = 0 == getWindowHandle();
@@ -1417,12 +1449,14 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
}
+ @Override
public void warpPointer(int x, int y) {
if(0 != getWindowHandle()) {
warpPointerImpl(x, y);
}
}
+ @Override
public final InsetsImmutable getInsets() {
if(isUndecorated()) {
return Insets.getZero();
@@ -1431,18 +1465,22 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
return insets;
}
+ @Override
public final int getWidth() {
return width;
}
+ @Override
public final int getHeight() {
return height;
}
+ @Override
public final int getX() {
return x;
}
+ @Override
public final int getY() {
return y;
}
@@ -1468,10 +1506,12 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
this.width = width; this.height = height;
}
+ @Override
public final boolean isVisible() {
return visible;
}
+ @Override
public final boolean isFullscreen() {
return fullscreen;
}
@@ -1480,6 +1520,15 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
// Window
//
+ @Override
+ public final Window getDelegatedWindow() {
+ return this;
+ }
+
+ //----------------------------------------------------------------------
+ // WindowImpl
+ //
+
/**
* If the implementation is capable of detecting a device change
* return true and clear the status/reason of the change.
@@ -1503,23 +1552,11 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
public Object getWrappedWindow() {
return null;
}
-
- public final Window getDelegatedWindow() {
- return this;
- }
-
- /**
- * If set to true, the default value, this NEWT Window implementation will
- * handle the destruction (ie {@link #destroy()} call) within {@link #windowDestroyNotify(boolean)} implementation.<br>
- * If set to false, it's up to the caller/owner to handle destruction within {@link #windowDestroyNotify(boolean)}.
- */
- public void setHandleDestroyNotify(boolean b) {
- handleDestroyNotify = b;
- }
- //----------------------------------------------------------------------
- // WindowImpl
- //
+ @Override
+ public void setWindowDestroyNotifyAction(Runnable r) {
+ windowDestroyNotifyAction = r;
+ }
/**
* Returns the non delegated {@link AbstractGraphicsConfiguration},
@@ -1976,17 +2013,17 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
//
// MouseListener/Event Support
//
- public void sendMouseEvent(int eventType, int modifiers,
- int x, int y, int button, float rotation) {
+ public void sendMouseEvent(short eventType, int modifiers,
+ int x, int y, short button, float rotation) {
doMouseEvent(false, false, eventType, modifiers, x, y, button, rotation);
}
- public void enqueueMouseEvent(boolean wait, int eventType, int modifiers,
- int x, int y, int button, float rotation) {
+ public void enqueueMouseEvent(boolean wait, short eventType, int modifiers,
+ int x, int y, short button, float rotation) {
doMouseEvent(true, wait, eventType, modifiers, x, y, button, rotation);
}
- protected void doMouseEvent(boolean enqueue, boolean wait, int eventType, int modifiers,
- int x, int y, int button, float rotation) {
+ protected void doMouseEvent(boolean enqueue, boolean wait, short eventType, int modifiers,
+ int x, int y, short button, float rotation) {
if( eventType == MouseEvent.EVENT_MOUSE_ENTERED || eventType == MouseEvent.EVENT_MOUSE_EXITED ) {
if( eventType == MouseEvent.EVENT_MOUSE_EXITED && x==-1 && y==-1 ) {
x = lastMousePosition.getX();
@@ -1996,9 +2033,11 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
x = Math.min(Math.max(x, 0), getWidth()-1);
y = Math.min(Math.max(y, 0), getHeight()-1);
mouseInWindow = eventType == MouseEvent.EVENT_MOUSE_ENTERED;
- lastMousePressed = 0; // clear state
- mouseButtonPressed = 0; // clear state
- mouseButtonModMask = 0; // clear state
+ // clear states
+ lastMousePressed = 0;
+ lastMouseClickCount = (short)0;
+ mouseButtonPressed = 0;
+ mouseButtonModMask = 0;
}
if( x < 0 || y < 0 || x >= getWidth() || y >= getHeight() ) {
return; // .. invalid ..
@@ -2013,10 +2052,12 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
if(!mouseInWindow) {
mouseInWindow = true;
eEntered = new MouseEvent(MouseEvent.EVENT_MOUSE_ENTERED, this, when,
- modifiers, x, y, lastMouseClickCount, button, 0);
- lastMousePressed = 0; // clear state
- mouseButtonPressed = 0; // clear state
- mouseButtonModMask = 0; // clear state
+ modifiers, x, y, (short)0, (short)0, (short)0);
+ // clear states
+ lastMousePressed = 0;
+ lastMouseClickCount = (short)0;
+ mouseButtonPressed = 0;
+ mouseButtonModMask = 0;
} else if( lastMousePosition.getX() == x && lastMousePosition.getY()==y ) {
if(DEBUG_MOUSE_EVENT) {
System.err.println("doMouseEvent: skip EVENT_MOUSE_MOVED w/ same position: "+lastMousePosition);
@@ -2046,7 +2087,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
if( when - lastMousePressed < MouseEvent.getClickTimeout() ) {
lastMouseClickCount++;
} else {
- lastMouseClickCount=1;
+ lastMouseClickCount=(short)1;
}
lastMousePressed = when;
mouseButtonPressed = button;
@@ -2060,7 +2101,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
eClicked = new MouseEvent(MouseEvent.EVENT_MOUSE_CLICKED, this, when,
modifiers, x, y, lastMouseClickCount, button, 0);
} else {
- lastMouseClickCount = 0;
+ lastMouseClickCount = (short)0;
lastMousePressed = 0;
}
mouseButtonPressed = 0;
@@ -2068,15 +2109,15 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
} else if( MouseEvent.EVENT_MOUSE_MOVED == eventType ) {
if ( mouseButtonPressed > 0 ) {
e = new MouseEvent(MouseEvent.EVENT_MOUSE_DRAGGED, this, when,
- modifiers, x, y, 1, mouseButtonPressed, 0);
+ modifiers, x, y, (short)1, mouseButtonPressed, 0);
} else {
e = new MouseEvent(eventType, this, when,
- modifiers, x, y, 0, button, 0);
+ modifiers, x, y, (short)0, button, (short)0);
}
} else if( MouseEvent.EVENT_MOUSE_WHEEL_MOVED == eventType ) {
- e = new MouseEvent(eventType, this, when, modifiers, x, y, 0, button, rotation);
+ e = new MouseEvent(eventType, this, when, modifiers, x, y, (short)0, button, rotation);
} else {
- e = new MouseEvent(eventType, this, when, modifiers, x, y, 0, button, 0);
+ e = new MouseEvent(eventType, this, when, modifiers, x, y, (short)0, button, 0);
}
if( null != eEntered ) {
if(DEBUG_MOUSE_EVENT) {
@@ -2169,7 +2210,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
default:
throw new NativeWindowException("Unexpected mouse event type " + e.getEventType());
}
- consumed = InputEvent.consumedTag == e.getAttachment();
+ consumed = NEWTEvent.consumedTag == e.getAttachment();
}
}
@@ -2203,23 +2244,16 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
return 0 <= keyCode && keyCode < keyRepeatState.capacity();
}
- public void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) {
- doKeyEvent(false, false, eventType, modifiers, keyCode, keyChar);
+ public void sendKeyEvent(short eventType, int modifiers, short keyCode, short keySym, char keyChar) {
+ // Always add currently pressed mouse buttons to modifier mask
+ consumeKeyEvent(new KeyEvent(eventType, this, System.currentTimeMillis(), modifiers | mouseButtonModMask, keyCode, keySym, keyChar) );
}
- public void enqueueKeyEvent(boolean wait, int eventType, int modifiers, int keyCode, char keyChar) {
- doKeyEvent(true, wait, eventType, modifiers, keyCode, keyChar);
+ public void enqueueKeyEvent(boolean wait, short eventType, int modifiers, short keyCode, short keySym, char keyChar) {
+ // Always add currently pressed mouse buttons to modifier mask
+ enqueueEvent(wait, new KeyEvent(eventType, this, System.currentTimeMillis(), modifiers | mouseButtonModMask, keyCode, keySym, keyChar) );
}
- protected void doKeyEvent(boolean enqueue, boolean wait, int eventType, int modifiers, int keyCode, char keyChar) {
- modifiers |= mouseButtonModMask; // Always add currently pressed mouse buttons to modifier mask
- if( enqueue ) {
- enqueueEvent(wait, new KeyEvent(eventType, this, System.currentTimeMillis(), modifiers, keyCode, keyChar) );
- } else {
- consumeKeyEvent(new KeyEvent(eventType, this, System.currentTimeMillis(), modifiers, keyCode, keyChar) );
- }
- }
-
public void addKeyListener(KeyListener l) {
addKeyListener(-1, l);
}
@@ -2290,6 +2324,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
return keyListeners.toArray(new KeyListener[keyListeners.size()]);
}
+ @SuppressWarnings("deprecation")
private final boolean propagateKeyEvent(KeyEvent e, KeyListener l) {
switch(e.getEventType()) {
case KeyEvent.EVENT_KEY_PRESSED:
@@ -2304,24 +2339,52 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
default:
throw new NativeWindowException("Unexpected key event type " + e.getEventType());
}
- return InputEvent.consumedTag == e.getAttachment();
+ return NEWTEvent.consumedTag == e.getAttachment();
}
+ @SuppressWarnings("deprecation")
protected void consumeKeyEvent(KeyEvent e) {
- boolean consumed;
+ boolean consumedE = false, consumedTyped = false;
+ if( KeyEvent.EVENT_KEY_TYPED == e.getEventType() ) {
+ throw new InternalError("Deprecated KeyEvent.EVENT_KEY_TYPED is synthesized - don't send/enqueue it!");
+ }
+
+ // Synthesize deprecated event KeyEvent.EVENT_KEY_TYPED
+ final KeyEvent eTyped;
+ if( KeyEvent.EVENT_KEY_RELEASED == e.getEventType() && e.isPrintableKey() && !e.isAutoRepeat() ) {
+ eTyped = new KeyEvent(KeyEvent.EVENT_KEY_TYPED, e.getSource(), e.getWhen(), e.getModifiers(), e.getKeyCode(), e.getKeySymbol(), e.getKeyChar());
+ } else {
+ eTyped = null;
+ }
if(null != keyboardFocusHandler) {
- consumed = propagateKeyEvent(e, keyboardFocusHandler);
+ consumedE = propagateKeyEvent(e, keyboardFocusHandler);
if(DEBUG_KEY_EVENT) {
- System.err.println("consumeKeyEvent: "+e+", keyboardFocusHandler consumed: "+consumed);
+ System.err.println("consumeKeyEvent: "+e+", keyboardFocusHandler consumed: "+consumedE);
}
- } else {
- consumed = false;
- if(DEBUG_KEY_EVENT) {
+ if( null != eTyped ) {
+ consumedTyped = propagateKeyEvent(eTyped, keyboardFocusHandler);
+ if(DEBUG_KEY_EVENT) {
+ System.err.println("consumeKeyEvent: "+eTyped+", keyboardFocusHandler consumed: "+consumedTyped);
+ }
+ }
+ }
+ if(DEBUG_KEY_EVENT) {
+ if( !consumedE ) {
System.err.println("consumeKeyEvent: "+e);
}
}
- for(int i = 0; !consumed && i < keyListeners.size(); i++ ) {
- consumed = propagateKeyEvent(e, keyListeners.get(i));
+ for(int i = 0; !consumedE && i < keyListeners.size(); i++ ) {
+ consumedE = propagateKeyEvent(e, keyListeners.get(i));
+ }
+ if( null != eTyped ) {
+ if(DEBUG_KEY_EVENT) {
+ if( !consumedTyped ) {
+ System.err.println("consumeKeyEvent: "+eTyped);
+ }
+ }
+ for(int i = 0; !consumedTyped && i < keyListeners.size(); i++ ) {
+ consumedTyped = propagateKeyEvent(eTyped, keyListeners.get(i));
+ }
}
}
@@ -2329,11 +2392,11 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
// WindowListener/Event Support
//
public void sendWindowEvent(int eventType) {
- consumeWindowEvent( new WindowEvent(eventType, this, System.currentTimeMillis()) );
+ consumeWindowEvent( new WindowEvent((short)eventType, this, System.currentTimeMillis()) ); // FIXME
}
public void enqueueWindowEvent(boolean wait, int eventType) {
- enqueueEvent( wait, new WindowEvent(eventType, this, System.currentTimeMillis()) );
+ enqueueEvent( wait, new WindowEvent((short)eventType, this, System.currentTimeMillis()) ); // FIXME
}
public void addWindowListener(WindowListener l) {
@@ -2382,7 +2445,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
if(DEBUG_IMPLEMENTATION) {
System.err.println("consumeWindowEvent: "+e+", visible "+isVisible()+" "+getX()+"/"+getY()+" "+getWidth()+"x"+getHeight());
}
- for(int i = 0; i < windowListeners.size(); i++ ) {
+ boolean consumed = false;
+ for(int i = 0; !consumed && i < windowListeners.size(); i++ ) {
WindowListener l = windowListeners.get(i);
switch(e.getEventType()) {
case WindowEvent.EVENT_WINDOW_RESIZED:
@@ -2411,6 +2475,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
new NativeWindowException("Unexpected window event type "
+ e.getEventType());
}
+ consumed = NEWTEvent.consumedTag == e.getAttachment();
}
}
@@ -2551,32 +2616,45 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
/**
- * Triggered by implementation's WM events or programmatically
+ * Triggered by implementation's WM events or programmatic while respecting {@link #getDefaultCloseOperation()}.
*
* @param force if true, overrides {@link #setDefaultCloseOperation(WindowClosingMode)} with {@link WindowClosingProtocol#DISPOSE_ON_CLOSE}
* and hence force destruction. Otherwise is follows the user settings.
* @return true if this window is no more valid and hence has been destroyed, otherwise false.
*/
- protected boolean windowDestroyNotify(boolean force) {
+ public boolean windowDestroyNotify(boolean force) {
+ final WindowClosingMode defMode = getDefaultCloseOperation();
+ final WindowClosingMode mode = force ? WindowClosingMode.DISPOSE_ON_CLOSE : defMode;
if(DEBUG_IMPLEMENTATION) {
- System.err.println("Window.windowDestroyNotify(force: "+force+") START "+getThreadName()+": "+this);
+ System.err.println("Window.windowDestroyNotify(force: "+force+", mode "+defMode+" -> "+mode+") "+getThreadName()+": "+this);
}
- if(force) {
- setDefaultCloseOperation(WindowClosingMode.DISPOSE_ON_CLOSE);
- }
-
- // send synced destroy notifications
- enqueueWindowEvent(true, WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY);
-
- if(handleDestroyNotify && WindowClosingMode.DISPOSE_ON_CLOSE == getDefaultCloseOperation()) {
- destroy();
+
+ if( WindowClosingMode.DISPOSE_ON_CLOSE == mode ) {
+ if(force) {
+ setDefaultCloseOperation(mode);
+ }
+ try {
+ if( null == windowDestroyNotifyAction ) {
+ destroy();
+ } else {
+ windowDestroyNotifyAction.run();
+ }
+ } finally {
+ if(force) {
+ setDefaultCloseOperation(defMode);
+ }
+ }
+ } else {
+ // send synced destroy notifications
+ sendWindowEvent(WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY);
}
final boolean destroyed = !isNativeValid();
if(DEBUG_IMPLEMENTATION) {
- System.err.println("Window.windowDestroyNotify(force: "+force+") END "+getThreadName()+": destroyed "+destroyed+", "+this);
- }
+ System.err.println("Window.windowDestroyNotify(force: "+force+", mode "+mode+") END "+getThreadName()+": destroyed "+destroyed+", "+this);
+ }
+
return destroyed;
}
diff --git a/src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java b/src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java
index e11d79ddc..b90c2106e 100644
--- a/src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java
+++ b/src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java
@@ -28,8 +28,6 @@
package jogamp.newt.awt.event;
-import com.jogamp.common.util.IntIntHashMap;
-
/**
*
* <a name="AWTEventModifierMapping"><h5>AWT Event Modifier Mapping</h5></a>
@@ -76,47 +74,10 @@ import com.jogamp.common.util.IntIntHashMap;
*/
public class AWTNewtEventFactory {
- protected static final IntIntHashMap eventTypeAWT2NEWT;
-
/** zero-based AWT button mask array filled by {@link #getAWTButtonDownMask(int)}, allowing fast lookup. */
private static int awtButtonDownMasks[] ;
static {
- IntIntHashMap map = new IntIntHashMap();
- map.setKeyNotFoundValue(0xFFFFFFFF);
- // n/a map.put(java.awt.event.WindowEvent.WINDOW_OPENED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_OPENED);
- map.put(java.awt.event.WindowEvent.WINDOW_CLOSING, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY);
- map.put(java.awt.event.WindowEvent.WINDOW_CLOSED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_DESTROYED);
- // n/a map.put(java.awt.event.WindowEvent.WINDOW_ICONIFIED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_ICONIFIED);
- // n/a map.put(java.awt.event.WindowEvent.WINDOW_DEICONIFIED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_DEICONIFIED);
- map.put(java.awt.event.WindowEvent.WINDOW_ACTIVATED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_GAINED_FOCUS);
- map.put(java.awt.event.WindowEvent.WINDOW_GAINED_FOCUS, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_GAINED_FOCUS);
- map.put(java.awt.event.FocusEvent.FOCUS_GAINED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_GAINED_FOCUS);
- map.put(java.awt.event.WindowEvent.WINDOW_DEACTIVATED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_LOST_FOCUS);
- map.put(java.awt.event.WindowEvent.WINDOW_LOST_FOCUS, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_LOST_FOCUS);
- map.put(java.awt.event.FocusEvent.FOCUS_LOST, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_LOST_FOCUS);
- // n/a map.put(java.awt.event.WindowEvent.WINDOW_STATE_CHANGED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_STATE_CHANGED);
-
- map.put(java.awt.event.ComponentEvent.COMPONENT_MOVED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_MOVED);
- map.put(java.awt.event.ComponentEvent.COMPONENT_RESIZED, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_RESIZED);
- // n/a map.put(java.awt.event.ComponentEvent.COMPONENT_SHOWN, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_SHOWN);
- // n/a map.put(java.awt.event.ComponentEvent.COMPONENT_HIDDEN, com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_HIDDEN);
-
- map.put(java.awt.event.MouseEvent.MOUSE_CLICKED, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_CLICKED);
- map.put(java.awt.event.MouseEvent.MOUSE_PRESSED, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_PRESSED);
- map.put(java.awt.event.MouseEvent.MOUSE_RELEASED, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_RELEASED);
- map.put(java.awt.event.MouseEvent.MOUSE_MOVED, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_MOVED);
- map.put(java.awt.event.MouseEvent.MOUSE_ENTERED, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_ENTERED);
- map.put(java.awt.event.MouseEvent.MOUSE_EXITED, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_EXITED);
- map.put(java.awt.event.MouseEvent.MOUSE_DRAGGED, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_DRAGGED);
- map.put(java.awt.event.MouseEvent.MOUSE_WHEEL, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_WHEEL_MOVED);
-
- map.put(java.awt.event.KeyEvent.KEY_PRESSED, com.jogamp.newt.event.KeyEvent.EVENT_KEY_PRESSED);
- map.put(java.awt.event.KeyEvent.KEY_RELEASED, com.jogamp.newt.event.KeyEvent.EVENT_KEY_RELEASED);
- map.put(java.awt.event.KeyEvent.KEY_TYPED, com.jogamp.newt.event.KeyEvent.EVENT_KEY_TYPED);
-
- eventTypeAWT2NEWT = map;
-
// There is an assumption in awtModifiers2Newt(int,int,boolean)
// that the awtButtonMasks and newtButtonMasks are peers, i.e.
// a given index refers to the same button in each array.
@@ -135,6 +96,41 @@ public class AWTNewtEventFactory {
}
}
+ public static final short eventTypeAWT2NEWT(int awtType) {
+ switch( awtType ) {
+ // n/a case java.awt.event.WindowEvent.WINDOW_OPENED: return com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_OPENED;
+ case java.awt.event.WindowEvent.WINDOW_CLOSING: return com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY;
+ case java.awt.event.WindowEvent.WINDOW_CLOSED: return com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_DESTROYED;
+ // n/a case java.awt.event.WindowEvent.WINDOW_ICONIFIED: return com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_ICONIFIED;
+ // n/a case java.awt.event.WindowEvent.WINDOW_DEICONIFIED: return com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_DEICONIFIED;
+ case java.awt.event.WindowEvent.WINDOW_ACTIVATED: return com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_GAINED_FOCUS;
+ case java.awt.event.WindowEvent.WINDOW_GAINED_FOCUS: return com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_GAINED_FOCUS;
+ case java.awt.event.FocusEvent.FOCUS_GAINED: return com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_GAINED_FOCUS;
+ case java.awt.event.WindowEvent.WINDOW_DEACTIVATED: return com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_LOST_FOCUS;
+ case java.awt.event.WindowEvent.WINDOW_LOST_FOCUS: return com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_LOST_FOCUS;
+ case java.awt.event.FocusEvent.FOCUS_LOST: return com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_LOST_FOCUS;
+ // n/a case java.awt.event.WindowEvent.WINDOW_STATE_CHANGED: return com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_STATE_CHANGED;
+
+ case java.awt.event.ComponentEvent.COMPONENT_MOVED: return com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_MOVED;
+ case java.awt.event.ComponentEvent.COMPONENT_RESIZED: return com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_RESIZED;
+ // n/a case java.awt.event.ComponentEvent.COMPONENT_SHOWN: return com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_SHOWN;
+ // n/a case java.awt.event.ComponentEvent.COMPONENT_HIDDEN: return com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_HIDDEN;
+
+ case java.awt.event.MouseEvent.MOUSE_CLICKED: return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_CLICKED;
+ case java.awt.event.MouseEvent.MOUSE_PRESSED: return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_PRESSED;
+ case java.awt.event.MouseEvent.MOUSE_RELEASED: return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_RELEASED;
+ case java.awt.event.MouseEvent.MOUSE_MOVED: return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_MOVED;
+ case java.awt.event.MouseEvent.MOUSE_ENTERED: return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_ENTERED;
+ case java.awt.event.MouseEvent.MOUSE_EXITED: return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_EXITED;
+ case java.awt.event.MouseEvent.MOUSE_DRAGGED: return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_DRAGGED;
+ case java.awt.event.MouseEvent.MOUSE_WHEEL: return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_WHEEL_MOVED;
+
+ case java.awt.event.KeyEvent.KEY_PRESSED: return com.jogamp.newt.event.KeyEvent.EVENT_KEY_PRESSED;
+ case java.awt.event.KeyEvent.KEY_RELEASED: return com.jogamp.newt.event.KeyEvent.EVENT_KEY_RELEASED;
+ }
+ return (short)0;
+ }
+
private static int getAWTButtonDownMaskImpl(int button) {
/**
* java.awt.event.InputEvent.getMaskForButton(button);
@@ -227,48 +223,48 @@ public class AWTNewtEventFactory {
return newtMods;
}
- public static final int awtButton2Newt(int awtButton) {
+ public static final short awtButton2Newt(int awtButton) {
if( 0 < awtButton && awtButton <= com.jogamp.newt.event.MouseEvent.BUTTON_NUMBER ) {
- return awtButton;
+ return (short)awtButton;
} else {
- return 0;
+ return (short)0;
}
}
public static final com.jogamp.newt.event.WindowEvent createWindowEvent(java.awt.event.WindowEvent event, com.jogamp.newt.Window newtSource) {
- final int newtType = eventTypeAWT2NEWT.get(event.getID());
- if(0xFFFFFFFF != newtType) {
+ final short newtType = eventTypeAWT2NEWT(event.getID());
+ if( (short)0 != newtType ) {
return new com.jogamp.newt.event.WindowEvent(newtType, ((null==newtSource)?(Object)event.getComponent():(Object)newtSource), System.currentTimeMillis());
}
return null; // no mapping ..
}
public static final com.jogamp.newt.event.WindowEvent createWindowEvent(java.awt.event.ComponentEvent event, com.jogamp.newt.Window newtSource) {
- final int newtType = eventTypeAWT2NEWT.get(event.getID());
- if(0xFFFFFFFF != newtType) {
+ final short newtType = eventTypeAWT2NEWT(event.getID());
+ if( (short)0 != newtType ) {
return new com.jogamp.newt.event.WindowEvent(newtType, (null==newtSource)?(Object)event.getComponent():(Object)newtSource, System.currentTimeMillis());
}
return null; // no mapping ..
}
public static final com.jogamp.newt.event.WindowEvent createWindowEvent(java.awt.event.FocusEvent event, com.jogamp.newt.Window newtSource) {
- final int newtType = eventTypeAWT2NEWT.get(event.getID());
- if(0xFFFFFFFF != newtType) {
+ final short newtType = eventTypeAWT2NEWT(event.getID());
+ if( (short)0 != newtType ) {
return new com.jogamp.newt.event.WindowEvent(newtType, (null==newtSource)?(Object)event.getComponent():(Object)newtSource, System.currentTimeMillis());
}
return null; // no mapping ..
}
public static final com.jogamp.newt.event.MouseEvent createMouseEvent(java.awt.event.MouseEvent event, com.jogamp.newt.Window newtSource) {
- final int newtType = eventTypeAWT2NEWT.get(event.getID());
- if(0xFFFFFFFF != newtType) {
+ final short newtType = eventTypeAWT2NEWT(event.getID());
+ if( (short)0 != newtType ) {
float rotation = 0;
if (event instanceof java.awt.event.MouseWheelEvent) {
// AWT/NEWT rotation is reversed - AWT +1 is down, NEWT +1 is up.
rotation = -1f * ((java.awt.event.MouseWheelEvent)event).getWheelRotation();
}
- final int newtButton = awtButton2Newt(event.getButton());
+ final short newtButton = awtButton2Newt(event.getButton());
int mods = awtModifiers2Newt(event.getModifiers(), event.getModifiersEx());
mods |= com.jogamp.newt.event.InputEvent.getButtonMask(newtButton); // always include NEWT BUTTON_MASK
if(null!=newtSource) {
@@ -281,25 +277,25 @@ public class AWTNewtEventFactory {
}
return new com.jogamp.newt.event.MouseEvent(
newtType, (null==newtSource)?(Object)event.getComponent():(Object)newtSource, event.getWhen(),
- mods, event.getX(), event.getY(), event.getClickCount(),
+ mods, event.getX(), event.getY(), (short)event.getClickCount(),
newtButton, rotation);
}
return null; // no mapping ..
}
public static final com.jogamp.newt.event.KeyEvent createKeyEvent(java.awt.event.KeyEvent event, com.jogamp.newt.Window newtSource) {
- return createKeyEvent(eventTypeAWT2NEWT.get(event.getID()), event, newtSource);
+ return createKeyEvent(eventTypeAWT2NEWT(event.getID()), event, newtSource);
}
- public static final com.jogamp.newt.event.KeyEvent createKeyEvent(int newtType, java.awt.event.KeyEvent event, com.jogamp.newt.Window newtSource) {
- if(0xFFFFFFFF != newtType) {
+ public static final com.jogamp.newt.event.KeyEvent createKeyEvent(short newtType, java.awt.event.KeyEvent event, com.jogamp.newt.Window newtSource) {
+ if( (short)0 != newtType ) {
+ final short keyCode = (short)event.getKeyCode();
return new com.jogamp.newt.event.KeyEvent(
newtType, (null==newtSource)?(Object)event.getComponent():(Object)newtSource, event.getWhen(),
awtModifiers2Newt(event.getModifiers(), event.getModifiersEx()),
- event.getKeyCode(), event.getKeyChar());
+ keyCode, keyCode, event.getKeyChar());
}
return null; // no mapping ..
}
}
-
diff --git a/src/newt/classes/jogamp/newt/awt/event/AWTParentWindowAdapter.java b/src/newt/classes/jogamp/newt/awt/event/AWTParentWindowAdapter.java
index 747e2368e..b348220d6 100644
--- a/src/newt/classes/jogamp/newt/awt/event/AWTParentWindowAdapter.java
+++ b/src/newt/classes/jogamp/newt/awt/event/AWTParentWindowAdapter.java
@@ -42,9 +42,7 @@ import com.jogamp.newt.event.awt.AWTWindowAdapter;
* Specialized parent/client adapter,
* where the NEWT child window really gets resized,
* and the parent move window event gets discarded. */
-public class AWTParentWindowAdapter
- extends AWTWindowAdapter
- implements java.awt.event.HierarchyListener
+public class AWTParentWindowAdapter extends AWTWindowAdapter implements java.awt.event.HierarchyListener
{
NativeWindow downstreamParent;
@@ -98,7 +96,7 @@ public class AWTParentWindowAdapter
public void run() {
int cw = comp.getWidth();
int ch = comp.getHeight();
- if( 0 < cw * ch ) {
+ if( 0 < cw && 0 < ch ) {
if( newtWindow.getWidth() != cw || newtWindow.getHeight() != ch ) {
newtWindow.setSize(cw, ch);
if(comp.isVisible() != newtWindow.isVisible()) {
diff --git a/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java b/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java
index 55fbbe603..4f19e9c4d 100644
--- a/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java
+++ b/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java
@@ -42,78 +42,62 @@ public class AndroidNewtEventFactory {
/** API Level 12: {@link android.view.MotionEvent#ACTION_SCROLL} = {@value} */
private static final int ACTION_SCROLL = 8;
- private static final int aMotionEventType2Newt(int aType) {
- final int nType;
+ private static final short aMotionEventType2Newt(int aType) {
switch( aType ) {
case android.view.MotionEvent.ACTION_DOWN:
- nType = com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_PRESSED;
- break;
+ return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_PRESSED;
case android.view.MotionEvent.ACTION_UP:
- nType = com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_RELEASED;
- break;
+ return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_RELEASED;
case android.view.MotionEvent.ACTION_MOVE:
- nType = com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_DRAGGED;
- break;
+ return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_DRAGGED;
case android.view.MotionEvent.ACTION_CANCEL:
- nType = com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_RELEASED;
- break;
+ return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_RELEASED;
case android.view.MotionEvent.ACTION_OUTSIDE:
- nType = com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_MOVED;
- break;
- //
+ return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_MOVED;
case android.view.MotionEvent.ACTION_POINTER_DOWN:
- nType = com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_PRESSED;
- break;
+ return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_PRESSED;
case android.view.MotionEvent.ACTION_POINTER_UP:
- nType = com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_RELEASED;
- break;
+ return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_RELEASED;
// case ACTION_HOVER_MOVE
case ACTION_SCROLL: // API Level 12 !
- nType = com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_WHEEL_MOVED;
- break;
+ return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_WHEEL_MOVED;
// case ACTION_HOVER_ENTER
// case ACTION_HOVER_EXIT
- default:
- nType = 0xFFFFFFFF;
}
- return nType;
+ return (short)0;
}
- private static final int aAccessibilityEventType2Newt(int aType) {
- final int nType;
+ private static final short aAccessibilityEventType2Newt(int aType) {
switch( aType ) {
case android.view.accessibility.AccessibilityEvent.TYPE_VIEW_FOCUSED:
- nType = com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_GAINED_FOCUS; break;
- default:
- nType = 0xFFFFFFFF;
+ return com.jogamp.newt.event.WindowEvent.EVENT_WINDOW_GAINED_FOCUS;
}
- return nType;
+ return (short)0;
}
- private static final int aKeyEventType2NewtEventType(int androidKeyAction) {
+ private static final short aKeyEventType2NewtEventType(int androidKeyAction) {
switch(androidKeyAction) {
case android.view.KeyEvent.ACTION_DOWN:
case android.view.KeyEvent.ACTION_MULTIPLE:
return com.jogamp.newt.event.KeyEvent.EVENT_KEY_PRESSED;
case android.view.KeyEvent.ACTION_UP:
return com.jogamp.newt.event.KeyEvent.EVENT_KEY_RELEASED;
- default:
- return 0;
}
+ return (short)0;
}
- private static final int aKeyCode2NewtKeyCode(int androidKeyCode) {
+ private static final short aKeyCode2NewtKeyCode(int androidKeyCode) {
if(android.view.KeyEvent.KEYCODE_0 <= androidKeyCode && androidKeyCode <= android.view.KeyEvent.KEYCODE_9) {
- return com.jogamp.newt.event.KeyEvent.VK_0 + ( androidKeyCode - android.view.KeyEvent.KEYCODE_0 ) ;
+ return (short) ( com.jogamp.newt.event.KeyEvent.VK_0 + ( androidKeyCode - android.view.KeyEvent.KEYCODE_0 ) );
}
if(android.view.KeyEvent.KEYCODE_A <= androidKeyCode && androidKeyCode <= android.view.KeyEvent.KEYCODE_Z) {
- return com.jogamp.newt.event.KeyEvent.VK_A + ( androidKeyCode - android.view.KeyEvent.KEYCODE_A ) ;
+ return (short) ( com.jogamp.newt.event.KeyEvent.VK_A + ( androidKeyCode - android.view.KeyEvent.KEYCODE_A ) );
}
if(android.view.KeyEvent.KEYCODE_F1 <= androidKeyCode && androidKeyCode <= android.view.KeyEvent.KEYCODE_F12) {
- return com.jogamp.newt.event.KeyEvent.VK_F1 + ( androidKeyCode - android.view.KeyEvent.KEYCODE_F1 ) ;
+ return (short) ( com.jogamp.newt.event.KeyEvent.VK_F1 + ( androidKeyCode - android.view.KeyEvent.KEYCODE_F1 ) );
}
if(android.view.KeyEvent.KEYCODE_NUMPAD_0 <= androidKeyCode && androidKeyCode <= android.view.KeyEvent.KEYCODE_NUMPAD_9) {
- return com.jogamp.newt.event.KeyEvent.VK_NUMPAD0 + ( androidKeyCode - android.view.KeyEvent.KEYCODE_NUMPAD_0 ) ;
+ return (short) ( com.jogamp.newt.event.KeyEvent.VK_NUMPAD0 + ( androidKeyCode - android.view.KeyEvent.KEYCODE_NUMPAD_0 ) );
}
switch(androidKeyCode) {
case android.view.KeyEvent.KEYCODE_COMMA: return com.jogamp.newt.event.KeyEvent.VK_COMMA;
@@ -144,7 +128,7 @@ public class AndroidNewtEventFactory {
case android.view.KeyEvent.KEYCODE_CTRL_LEFT: return com.jogamp.newt.event.KeyEvent.VK_CONTROL;
case android.view.KeyEvent.KEYCODE_CTRL_RIGHT: return com.jogamp.newt.event.KeyEvent.VK_CONTROL; // ??
}
- return 0;
+ return (short)0;
}
private static final int aKeyModifiers2Newt(int androidMods) {
@@ -170,38 +154,29 @@ public class AndroidNewtEventFactory {
public com.jogamp.newt.event.WindowEvent createWindowEvent(android.view.accessibility.AccessibilityEvent event, com.jogamp.newt.Window newtSource) {
final int aType = event.getEventType();
- final int nType = aAccessibilityEventType2Newt(aType);
+ final short nType = aAccessibilityEventType2Newt(aType);
- if(0xFFFFFFFF != nType) {
+ if( (short)0 != nType) {
return new com.jogamp.newt.event.WindowEvent(nType, ((null==newtSource)?null:(Object)newtSource), event.getEventTime());
}
return null; // no mapping ..
}
- public com.jogamp.newt.event.KeyEvent[] createKeyEvents(int keyCode, android.view.KeyEvent event, com.jogamp.newt.Window newtSource) {
- final int type = aKeyEventType2NewtEventType(event.getAction());
+ public com.jogamp.newt.event.KeyEvent createKeyEvent(int keyCode, android.view.KeyEvent event, com.jogamp.newt.Window newtSource) {
+ final short type = aKeyEventType2NewtEventType(event.getAction());
if(Window.DEBUG_MOUSE_EVENT) {
System.err.println("createKeyEvent: type 0x"+Integer.toHexString(type)+", keyCode 0x"+Integer.toHexString(keyCode)+", "+event);
}
- if(0xFFFFFFFF != type) {
- final int newtKeyCode = aKeyCode2NewtKeyCode(keyCode);
- if(0 != newtKeyCode) {
+ if( (short)0 != type) {
+ final short newtKeyCode = aKeyCode2NewtKeyCode(keyCode);
+ if( (short)0 != newtKeyCode ) {
final Object src = (null==newtSource)?null:(Object)newtSource;
final long unixTime = System.currentTimeMillis() + ( event.getEventTime() - android.os.SystemClock.uptimeMillis() );
final int newtMods = aKeyModifiers2Newt(event.getMetaState());
- final com.jogamp.newt.event.KeyEvent ke1 = new com.jogamp.newt.event.KeyEvent(
- type, src, unixTime, newtMods, newtKeyCode, (char) event.getUnicodeChar());
-
- if( com.jogamp.newt.event.KeyEvent.EVENT_KEY_RELEASED == type ) {
- return new com.jogamp.newt.event.KeyEvent[] { ke1,
- new com.jogamp.newt.event.KeyEvent(
- com.jogamp.newt.event.KeyEvent.EVENT_KEY_TYPED,
- src, unixTime, newtMods, newtKeyCode, (char) event.getUnicodeChar()) };
- } else {
- return new com.jogamp.newt.event.KeyEvent[] { ke1 };
- }
+ return new com.jogamp.newt.event.KeyEvent(
+ type, src, unixTime, newtMods, newtKeyCode, newtKeyCode, (char) event.getUnicodeChar());
}
}
return null;
@@ -218,7 +193,8 @@ public class AndroidNewtEventFactory {
//
// Prefilter Android Event (Gesture, ..) and determine final type
//
- final int aType, nType;
+ final int aType;
+ final short nType;
float[] rotationXY = null;
int rotationSource = 0; // 1 - Gesture, 2 - ACTION_SCROLL
{
@@ -265,8 +241,8 @@ public class AndroidNewtEventFactory {
}
}
- if(0xFFFFFFFF != nType) {
- final int clickCount = 1;
+ if( (short)0 != nType ) {
+ final short clickCount = 1;
int modifiers = 0;
if( null == rotationXY && AndroidVersion.SDK_INT >= 12 && ACTION_SCROLL == aType ) { // API Level 12
@@ -299,7 +275,7 @@ public class AndroidNewtEventFactory {
//
final int pCount;
final int pIndex;
- final int button;
+ final short button;
switch( aType ) {
case android.view.MotionEvent.ACTION_POINTER_DOWN:
case android.view.MotionEvent.ACTION_POINTER_UP: {
@@ -307,7 +283,7 @@ public class AndroidNewtEventFactory {
pCount = 1;
final int b = event.getPointerId(pIndex) + 1; // FIXME: Assumption that Pointer-ID starts w/ 0 !
if( com.jogamp.newt.event.MouseEvent.BUTTON1 <= b && b <= com.jogamp.newt.event.MouseEvent.BUTTON_NUMBER ) {
- button = b;
+ button = (short)b;
} else {
button = com.jogamp.newt.event.MouseEvent.BUTTON1;
}
@@ -326,7 +302,7 @@ public class AndroidNewtEventFactory {
final int[] x = new int[pCount];
final int[] y = new int[pCount];
final float[] pressure = new float[pCount];
- final int[] pointerIds = new int[pCount];
+ final short[] pointerIds = new short[pCount];
{
if(Window.DEBUG_MOUSE_EVENT) {
System.err.println("createMouseEvent: collect ptr-data ["+pIndex+".."+(pIndex+pCount-1)+", "+pCount+"], aType "+aType+", button "+button+", gestureScrollPointerDown "+gestureScrollPointerDown);
@@ -337,7 +313,7 @@ public class AndroidNewtEventFactory {
x[j] = (int)event.getX(i);
y[j] = (int)event.getY(i);
pressure[j] = event.getPressure(i);
- pointerIds[j] = event.getPointerId(i);
+ pointerIds[j] = (short)event.getPointerId(i);
if(Window.DEBUG_MOUSE_EVENT) {
System.err.println("createMouseEvent: ptr-data["+i+" -> "+j+"] "+x[j]+"/"+y[j]+", pressure "+pressure[j]+", id "+pointerIds[j]);
}
diff --git a/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventTranslator.java b/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventTranslator.java
index ee0c8f8b1..2d972f752 100644
--- a/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventTranslator.java
+++ b/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventTranslator.java
@@ -38,11 +38,9 @@ public class AndroidNewtEventTranslator implements View.OnKeyListener, View.OnTo
@Override
public boolean onKey(View v, int keyCode, android.view.KeyEvent event) {
- final com.jogamp.newt.event.KeyEvent[] newtEvents = factory.createKeyEvents(keyCode, event, newtWindow);
- if(null != newtEvents) {
- for(int i=0; i<newtEvents.length; i++) {
- newtWindow.enqueueEvent(false, newtEvents[i]);
- }
+ final com.jogamp.newt.event.KeyEvent newtEvent = factory.createKeyEvent(keyCode, event, newtWindow);
+ if(null != newtEvent) {
+ newtWindow.enqueueEvent(false, newtEvent);
return true;
}
return false;
diff --git a/src/newt/classes/jogamp/newt/driver/awt/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/awt/WindowDriver.java
index bee43a95e..0172309fb 100644
--- a/src/newt/classes/jogamp/newt/driver/awt/WindowDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/awt/WindowDriver.java
@@ -256,10 +256,7 @@ public class WindowDriver extends WindowImpl {
}
@Override
public void windowDestroyed(WindowEvent e) {
- if(isNativeValid()) {
- WindowDriver.this.windowDestroyNotify(true);
- }
-
+ // Not fwd by AWTWindowAdapter, synthesized by NEWT
}
@Override
public void windowGainedFocus(WindowEvent e) {
diff --git a/src/newt/classes/jogamp/newt/driver/linux/LinuxEventDeviceTracker.java b/src/newt/classes/jogamp/newt/driver/linux/LinuxEventDeviceTracker.java
index 5efce2524..2c0e6d3dd 100644
--- a/src/newt/classes/jogamp/newt/driver/linux/LinuxEventDeviceTracker.java
+++ b/src/newt/classes/jogamp/newt/driver/linux/LinuxEventDeviceTracker.java
@@ -210,9 +210,9 @@ public class LinuxEventDeviceTracker implements WindowListener {
short code;
int value;
- int keyCode=KeyEvent.VK_UNDEFINED;
+ short keyCode=KeyEvent.VK_UNDEFINED;
char keyChar=' ';
- int eventType=0;
+ short eventType=0;
int modifiers=0;
loop:
@@ -263,24 +263,20 @@ public class LinuxEventDeviceTracker implements WindowListener {
case 0:
modifiers=0;
eventType=KeyEvent.EVENT_KEY_RELEASED;
- focusedWindow.sendKeyEvent(eventType, modifiers, keyCode, keyChar);
- //Send syntetic typed
- focusedWindow.sendKeyEvent(KeyEvent.EVENT_KEY_TYPED, modifiers, keyCode, (char) keyChar);
+ focusedWindow.sendKeyEvent(eventType, modifiers, keyCode, keyCode, keyChar);
break;
case 1:
eventType=KeyEvent.EVENT_KEY_PRESSED;
- focusedWindow.sendKeyEvent(eventType, modifiers, keyCode, keyChar);
+ focusedWindow.sendKeyEvent(eventType, modifiers, keyCode, keyCode, keyChar);
break;
case 2:
eventType=KeyEvent.EVENT_KEY_PRESSED;
modifiers=InputEvent.AUTOREPEAT_MASK;
//Send syntetic autorepeat release
- focusedWindow.sendKeyEvent(KeyEvent.EVENT_KEY_RELEASED, modifiers, keyCode, keyChar);
- //Send syntetic typed
- focusedWindow.sendKeyEvent(KeyEvent.EVENT_KEY_TYPED, modifiers, keyCode, keyChar);
+ focusedWindow.sendKeyEvent(KeyEvent.EVENT_KEY_RELEASED, modifiers, keyCode, keyCode, keyChar);
- focusedWindow.sendKeyEvent(eventType, modifiers, keyCode, keyChar);
+ focusedWindow.sendKeyEvent(eventType, modifiers, keyCode, keyCode, keyChar);
break;
}
break;
@@ -314,14 +310,15 @@ public class LinuxEventDeviceTracker implements WindowListener {
stop=true;
}
- private char NewtVKey2Unicode(int VK){
- if(KeyEvent.isPrintableKey(VK)){
+ private char NewtVKey2Unicode(short VK){
+ if( KeyEvent.isPrintableKey(VK) ){
return (char)VK;
}
return 0;
}
- private char LinuxEVKey2Unicode(short EVKey) {
+ @SuppressWarnings("unused")
+ private char LinuxEVKey2Unicode(short EVKey) {
// This is the stuff normally mapped by a system keymap
switch(EVKey){
@@ -377,9 +374,8 @@ public class LinuxEventDeviceTracker implements WindowListener {
return 0;
}
- private int LinuxEVKey2NewtVKey(short EVKey) {
- char vkCode = KeyEvent.VK_UNDEFINED;
-
+ private short LinuxEVKey2NewtVKey(short EVKey) {
+
switch(EVKey) {
case 1: // ESC
return KeyEvent.VK_ESCAPE;
@@ -886,8 +882,9 @@ public class LinuxEventDeviceTracker implements WindowListener {
if(Window.DEBUG_KEY_EVENT) {
System.out.println("LinuxEVKey2NewtVKey: Unmapped EVKey "+EVKey);
- }
- return vkCode;
+ }
+
+ return KeyEvent.VK_UNDEFINED;
}
}
}
diff --git a/src/newt/classes/jogamp/newt/driver/linux/LinuxMouseTracker.java b/src/newt/classes/jogamp/newt/driver/linux/LinuxMouseTracker.java
index b8a326a6c..0d6278bfb 100644
--- a/src/newt/classes/jogamp/newt/driver/linux/LinuxMouseTracker.java
+++ b/src/newt/classes/jogamp/newt/driver/linux/LinuxMouseTracker.java
@@ -65,10 +65,10 @@ public class LinuxMouseTracker implements WindowListener {
private volatile boolean stop = false;
private int x = 0;
private int y = 0;
- private int buttonDown = 0;
+ private short buttonDown = 0;
private int old_x = 0;
private int old_y = 0;
- private int old_buttonDown = 0;
+ private short old_buttonDown = 0;
private WindowImpl focusedWindow = null;
private MouseDevicePoller mouseDevicePoller = new MouseDevicePoller();
@@ -183,19 +183,15 @@ public class LinuxMouseTracker implements WindowListener {
if(old_x != x || old_y != y) {
// mouse moved
- focusedWindow.sendMouseEvent(MouseEvent.EVENT_MOUSE_MOVED, 0, wx, wy, 0, 0 );
+ focusedWindow.sendMouseEvent(MouseEvent.EVENT_MOUSE_MOVED, 0, wx, wy, (short)0, 0 );
}
if(old_buttonDown != buttonDown) {
// press/release
if( 0 != buttonDown ) {
- focusedWindow.sendMouseEvent(
- MouseEvent.EVENT_MOUSE_PRESSED,
- 0, wx, wy, buttonDown, 0 );
+ focusedWindow.sendMouseEvent(MouseEvent.EVENT_MOUSE_PRESSED, 0, wx, wy, buttonDown, 0 );
} else {
- focusedWindow.sendMouseEvent(
- MouseEvent.EVENT_MOUSE_RELEASED,
- 0, wx, wy, old_buttonDown, 0 );
+ focusedWindow.sendMouseEvent(MouseEvent.EVENT_MOUSE_RELEASED, 0, wx, wy, old_buttonDown, 0 );
}
}
} else {
diff --git a/src/newt/classes/jogamp/newt/driver/macosx/MacKeyUtil.java b/src/newt/classes/jogamp/newt/driver/macosx/MacKeyUtil.java
index 5966bd30f..c07576901 100644
--- a/src/newt/classes/jogamp/newt/driver/macosx/MacKeyUtil.java
+++ b/src/newt/classes/jogamp/newt/driver/macosx/MacKeyUtil.java
@@ -31,56 +31,129 @@ import com.jogamp.newt.event.KeyEvent;
public class MacKeyUtil {
- // KeyCodes (independent)
- private static final int kVK_Return = 0x24;
- private static final int kVK_Tab = 0x30;
- private static final int kVK_Space = 0x31;
- private static final int kVK_Delete = 0x33;
- private static final int kVK_Escape = 0x35;
- private static final int kVK_Command = 0x37;
- private static final int kVK_Shift = 0x38;
- private static final int kVK_CapsLock = 0x39;
- private static final int kVK_Option = 0x3A;
- private static final int kVK_Control = 0x3B;
- private static final int kVK_RightShift = 0x3C;
- private static final int kVK_RightOption = 0x3D;
- private static final int kVK_RightControl = 0x3E;
- private static final int kVK_Function = 0x3F;
- private static final int kVK_F17 = 0x40;
- private static final int kVK_VolumeUp = 0x48;
- private static final int kVK_VolumeDown = 0x49;
- private static final int kVK_Mute = 0x4A;
- private static final int kVK_F18 = 0x4F;
- private static final int kVK_F19 = 0x50;
- private static final int kVK_F20 = 0x5A;
- private static final int kVK_F5 = 0x60;
- private static final int kVK_F6 = 0x61;
- private static final int kVK_F7 = 0x62;
- private static final int kVK_F3 = 0x63;
- private static final int kVK_F8 = 0x64;
- private static final int kVK_F9 = 0x65;
- private static final int kVK_F11 = 0x67;
- private static final int kVK_F13 = 0x69;
- private static final int kVK_F16 = 0x6A;
- private static final int kVK_F14 = 0x6B;
- private static final int kVK_F10 = 0x6D;
- private static final int kVK_F12 = 0x6F;
- private static final int kVK_F15 = 0x71;
- private static final int kVK_Help = 0x72;
- private static final int kVK_Home = 0x73;
- private static final int kVK_PageUp = 0x74;
- private static final int kVK_ForwardDelete = 0x75;
- private static final int kVK_F4 = 0x76;
- private static final int kVK_End = 0x77;
- private static final int kVK_F2 = 0x78;
- private static final int kVK_PageDown = 0x79;
- private static final int kVK_F1 = 0x7A;
- private static final int kVK_LeftArrow = 0x7B;
- private static final int kVK_RightArrow = 0x7C;
- private static final int kVK_DownArrow = 0x7D;
- private static final int kVK_UpArrow = 0x7E;
+ //
+ // KeyCodes (Layout Dependent)
+ //
+ private static final short kVK_ANSI_A = 0x00;
+ private static final short kVK_ANSI_S = 0x01;
+ private static final short kVK_ANSI_D = 0x02;
+ private static final short kVK_ANSI_F = 0x03;
+ private static final short kVK_ANSI_H = 0x04;
+ private static final short kVK_ANSI_G = 0x05;
+ private static final short kVK_ANSI_Z = 0x06;
+ private static final short kVK_ANSI_X = 0x07;
+ private static final short kVK_ANSI_C = 0x08;
+ private static final short kVK_ANSI_V = 0x09;
+ private static final short kVK_ANSI_B = 0x0B;
+ private static final short kVK_ANSI_Q = 0x0C;
+ private static final short kVK_ANSI_W = 0x0D;
+ private static final short kVK_ANSI_E = 0x0E;
+ private static final short kVK_ANSI_R = 0x0F;
+ private static final short kVK_ANSI_Y = 0x10;
+ private static final short kVK_ANSI_T = 0x11;
+ private static final short kVK_ANSI_1 = 0x12;
+ private static final short kVK_ANSI_2 = 0x13;
+ private static final short kVK_ANSI_3 = 0x14;
+ private static final short kVK_ANSI_4 = 0x15;
+ private static final short kVK_ANSI_6 = 0x16;
+ private static final short kVK_ANSI_5 = 0x17;
+ private static final short kVK_ANSI_Equal = 0x18;
+ private static final short kVK_ANSI_9 = 0x19;
+ private static final short kVK_ANSI_7 = 0x1A;
+ private static final short kVK_ANSI_Minus = 0x1B;
+ private static final short kVK_ANSI_8 = 0x1C;
+ private static final short kVK_ANSI_0 = 0x1D;
+ private static final short kVK_ANSI_RightBracket = 0x1E;
+ private static final short kVK_ANSI_O = 0x1F;
+ private static final short kVK_ANSI_U = 0x20;
+ private static final short kVK_ANSI_LeftBracket = 0x21;
+ private static final short kVK_ANSI_I = 0x22;
+ private static final short kVK_ANSI_P = 0x23;
+ private static final short kVK_ANSI_L = 0x25;
+ private static final short kVK_ANSI_J = 0x26;
+ private static final short kVK_ANSI_Quote = 0x27;
+ private static final short kVK_ANSI_K = 0x28;
+ private static final short kVK_ANSI_Semicolon = 0x29;
+ private static final short kVK_ANSI_Backslash = 0x2A;
+ private static final short kVK_ANSI_Comma = 0x2B;
+ private static final short kVK_ANSI_Slash = 0x2C;
+ private static final short kVK_ANSI_N = 0x2D;
+ private static final short kVK_ANSI_M = 0x2E;
+ private static final short kVK_ANSI_Period = 0x2F;
+ private static final short kVK_ANSI_Grave = 0x32;
+ private static final short kVK_ANSI_KeypadDecimal = 0x41;
+ private static final short kVK_ANSI_KeypadMultiply = 0x43;
+ private static final short kVK_ANSI_KeypadPlus = 0x45;
+ private static final short kVK_ANSI_KeypadClear = 0x47;
+ private static final short kVK_ANSI_KeypadDivide = 0x4B;
+ private static final short kVK_ANSI_KeypadEnter = 0x4C;
+ private static final short kVK_ANSI_KeypadMinus = 0x4E;
+ private static final short kVK_ANSI_KeypadEquals = 0x51;
+ private static final short kVK_ANSI_Keypad0 = 0x52;
+ private static final short kVK_ANSI_Keypad1 = 0x53;
+ private static final short kVK_ANSI_Keypad2 = 0x54;
+ private static final short kVK_ANSI_Keypad3 = 0x55;
+ private static final short kVK_ANSI_Keypad4 = 0x56;
+ private static final short kVK_ANSI_Keypad5 = 0x57;
+ private static final short kVK_ANSI_Keypad6 = 0x58;
+ private static final short kVK_ANSI_Keypad7 = 0x59;
+ private static final short kVK_ANSI_Keypad8 = 0x5B;
+ private static final short kVK_ANSI_Keypad9 = 0x5C;
+
+ //
+ // KeyCodes (Layout Independent)
+ //
+ private static final short kVK_Return = 0x24;
+ private static final short kVK_Tab = 0x30;
+ private static final short kVK_Space = 0x31;
+ private static final short kVK_Delete = 0x33;
+ private static final short kVK_Escape = 0x35;
+ private static final short kVK_Command = 0x37;
+ private static final short kVK_Shift = 0x38;
+ private static final short kVK_CapsLock = 0x39;
+ private static final short kVK_Option = 0x3A;
+ private static final short kVK_Control = 0x3B;
+ private static final short kVK_RightShift = 0x3C;
+ private static final short kVK_RightOption = 0x3D;
+ private static final short kVK_RightControl = 0x3E;
+ // private static final short kVK_Function = 0x3F;
+ private static final short kVK_F17 = 0x40;
+ // private static final short kVK_VolumeUp = 0x48;
+ // private static final short kVK_VolumeDown = 0x49;
+ // private static final short kVK_Mute = 0x4A;
+ private static final short kVK_F18 = 0x4F;
+ private static final short kVK_F19 = 0x50;
+ private static final short kVK_F20 = 0x5A;
+ private static final short kVK_F5 = 0x60;
+ private static final short kVK_F6 = 0x61;
+ private static final short kVK_F7 = 0x62;
+ private static final short kVK_F3 = 0x63;
+ private static final short kVK_F8 = 0x64;
+ private static final short kVK_F9 = 0x65;
+ private static final short kVK_F11 = 0x67;
+ private static final short kVK_F13 = 0x69;
+ private static final short kVK_F16 = 0x6A;
+ private static final short kVK_F14 = 0x6B;
+ private static final short kVK_F10 = 0x6D;
+ private static final short kVK_F12 = 0x6F;
+ private static final short kVK_F15 = 0x71;
+ private static final short kVK_Help = 0x72;
+ private static final short kVK_Home = 0x73;
+ private static final short kVK_PageUp = 0x74;
+ private static final short kVK_ForwardDelete = 0x75;
+ private static final short kVK_F4 = 0x76;
+ private static final short kVK_End = 0x77;
+ private static final short kVK_F2 = 0x78;
+ private static final short kVK_PageDown = 0x79;
+ private static final short kVK_F1 = 0x7A;
+ private static final short kVK_LeftArrow = 0x7B;
+ private static final short kVK_RightArrow = 0x7C;
+ private static final short kVK_DownArrow = 0x7D;
+ private static final short kVK_UpArrow = 0x7E;
+ //
// Key constants handled differently on Mac OS X than other platforms
+ //
private static final char NSUpArrowFunctionKey = 0xF700;
private static final char NSDownArrowFunctionKey = 0xF701;
private static final char NSLeftArrowFunctionKey = 0xF702;
@@ -109,6 +182,7 @@ public class MacKeyUtil {
private static final char NSF22FunctionKey = 0xF719;
private static final char NSF23FunctionKey = 0xF71A;
private static final char NSF24FunctionKey = 0xF71B;
+ /**
private static final char NSF25FunctionKey = 0xF71C;
private static final char NSF26FunctionKey = 0xF71D;
private static final char NSF27FunctionKey = 0xF71E;
@@ -120,6 +194,7 @@ public class MacKeyUtil {
private static final char NSF33FunctionKey = 0xF724;
private static final char NSF34FunctionKey = 0xF725;
private static final char NSF35FunctionKey = 0xF726;
+ */
private static final char NSInsertFunctionKey = 0xF727;
private static final char NSDeleteFunctionKey = 0xF728;
private static final char NSHomeFunctionKey = 0xF729;
@@ -130,10 +205,11 @@ public class MacKeyUtil {
private static final char NSPrintScreenFunctionKey = 0xF72E;
private static final char NSScrollLockFunctionKey = 0xF72F;
private static final char NSPauseFunctionKey = 0xF730;
- private static final char NSSysReqFunctionKey = 0xF731;
- private static final char NSBreakFunctionKey = 0xF732;
- private static final char NSResetFunctionKey = 0xF733;
+ // private static final char NSSysReqFunctionKey = 0xF731;
+ // private static final char NSBreakFunctionKey = 0xF732;
+ // private static final char NSResetFunctionKey = 0xF733;
private static final char NSStopFunctionKey = 0xF734;
+ /**
private static final char NSMenuFunctionKey = 0xF735;
private static final char NSUserFunctionKey = 0xF736;
private static final char NSSystemFunctionKey = 0xF737;
@@ -153,10 +229,83 @@ public class MacKeyUtil {
private static final char NSFindFunctionKey = 0xF745;
private static final char NSHelpFunctionKey = 0xF746;
private static final char NSModeSwitchFunctionKey = 0xF747;
+ */
- static int validateKeyCode(int keyCode, char keyChar) {
+ static short validateKeyCode(short keyCode, char keyChar) {
// OS X Virtual Keycodes
switch(keyCode) {
+ //
+ // KeyCodes (Layout Dependent)
+ //
+ case kVK_ANSI_A: return KeyEvent.VK_A;
+ case kVK_ANSI_S: return KeyEvent.VK_S;
+ case kVK_ANSI_D: return KeyEvent.VK_D;
+ case kVK_ANSI_F: return KeyEvent.VK_F;
+ case kVK_ANSI_H: return KeyEvent.VK_H;
+ case kVK_ANSI_G: return KeyEvent.VK_G;
+ case kVK_ANSI_Z: return KeyEvent.VK_Z;
+ case kVK_ANSI_X: return KeyEvent.VK_X;
+ case kVK_ANSI_C: return KeyEvent.VK_C;
+ case kVK_ANSI_V: return KeyEvent.VK_V;
+ case kVK_ANSI_B: return KeyEvent.VK_B;
+ case kVK_ANSI_Q: return KeyEvent.VK_Q;
+ case kVK_ANSI_W: return KeyEvent.VK_W;
+ case kVK_ANSI_E: return KeyEvent.VK_E;
+ case kVK_ANSI_R: return KeyEvent.VK_R;
+ case kVK_ANSI_Y: return KeyEvent.VK_Y;
+ case kVK_ANSI_T: return KeyEvent.VK_T;
+ case kVK_ANSI_1: return KeyEvent.VK_1;
+ case kVK_ANSI_2: return KeyEvent.VK_2;
+ case kVK_ANSI_3: return KeyEvent.VK_3;
+ case kVK_ANSI_4: return KeyEvent.VK_4;
+ case kVK_ANSI_6: return KeyEvent.VK_6;
+ case kVK_ANSI_5: return KeyEvent.VK_5;
+ case kVK_ANSI_Equal: return KeyEvent.VK_EQUALS;
+ case kVK_ANSI_9: return KeyEvent.VK_9;
+ case kVK_ANSI_7: return KeyEvent.VK_7;
+ case kVK_ANSI_Minus: return KeyEvent.VK_MINUS;
+ case kVK_ANSI_8: return KeyEvent.VK_8;
+ case kVK_ANSI_0: return KeyEvent.VK_0;
+ case kVK_ANSI_RightBracket: return KeyEvent.VK_CLOSE_BRACKET;
+ case kVK_ANSI_O: return KeyEvent.VK_O;
+ case kVK_ANSI_U: return KeyEvent.VK_U;
+ case kVK_ANSI_LeftBracket: return KeyEvent.VK_OPEN_BRACKET;
+ case kVK_ANSI_I: return KeyEvent.VK_I;
+ case kVK_ANSI_P: return KeyEvent.VK_P;
+ case kVK_ANSI_L: return KeyEvent.VK_L;
+ case kVK_ANSI_J: return KeyEvent.VK_J;
+ case kVK_ANSI_Quote: return KeyEvent.VK_QUOTE;
+ case kVK_ANSI_K: return KeyEvent.VK_K;
+ case kVK_ANSI_Semicolon: return KeyEvent.VK_SEMICOLON;
+ case kVK_ANSI_Backslash: return KeyEvent.VK_BACK_SLASH;
+ case kVK_ANSI_Comma: return KeyEvent.VK_COMMA;
+ case kVK_ANSI_Slash: return KeyEvent.VK_SLASH;
+ case kVK_ANSI_N: return KeyEvent.VK_N;
+ case kVK_ANSI_M: return KeyEvent.VK_M;
+ case kVK_ANSI_Period: return KeyEvent.VK_PERIOD;
+ case kVK_ANSI_Grave: return KeyEvent.VK_BACK_QUOTE; // KeyEvent.VK_DEAD_GRAVE
+ case kVK_ANSI_KeypadDecimal: return KeyEvent.VK_DECIMAL;
+ case kVK_ANSI_KeypadMultiply: return KeyEvent.VK_MULTIPLY;
+ case kVK_ANSI_KeypadPlus: return KeyEvent.VK_PLUS;
+ case kVK_ANSI_KeypadClear: return KeyEvent.VK_CLEAR;
+ case kVK_ANSI_KeypadDivide: return KeyEvent.VK_DIVIDE;
+ case kVK_ANSI_KeypadEnter: return KeyEvent.VK_ENTER;
+ case kVK_ANSI_KeypadMinus: return KeyEvent.VK_MINUS;
+ case kVK_ANSI_KeypadEquals: return KeyEvent.VK_EQUALS;
+ case kVK_ANSI_Keypad0: return KeyEvent.VK_0;
+ case kVK_ANSI_Keypad1: return KeyEvent.VK_1;
+ case kVK_ANSI_Keypad2: return KeyEvent.VK_2;
+ case kVK_ANSI_Keypad3: return KeyEvent.VK_3;
+ case kVK_ANSI_Keypad4: return KeyEvent.VK_4;
+ case kVK_ANSI_Keypad5: return KeyEvent.VK_5;
+ case kVK_ANSI_Keypad6: return KeyEvent.VK_6;
+ case kVK_ANSI_Keypad7: return KeyEvent.VK_7;
+ case kVK_ANSI_Keypad8: return KeyEvent.VK_8;
+ case kVK_ANSI_Keypad9: return KeyEvent.VK_9;
+
+ //
+ // KeyCodes (Layout Independent)
+ //
case kVK_Return: return KeyEvent.VK_ENTER;
case kVK_Tab: return KeyEvent.VK_TAB;
case kVK_Space: return KeyEvent.VK_SPACE;
@@ -270,15 +419,8 @@ public class MacKeyUtil {
// NSFindFunctionKey
// NSHelpFunctionKey
// NSModeSwitchFunctionKey
- case 0x60: return KeyEvent.VK_BACK_QUOTE; // `
- case 0x27: return KeyEvent.VK_QUOTE; // '
- case '\r': return KeyEvent.VK_ENTER;
- }
-
- if ('a' <= keyChar && keyChar <= 'z') {
- return KeyEvent.VK_A + ( keyChar - 'a' ) ;
}
- return (int) keyChar; // let's hope for the best (compatibility of keyChar/keyCode's)
+ return (short) keyChar; // let's hope for the best (compatibility of keyChar/keyCode's)
}
}
diff --git a/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java
index 5755bdf11..6e9335f08 100644
--- a/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java
@@ -41,7 +41,6 @@ import javax.media.nativewindow.NativeWindowException;
import javax.media.nativewindow.MutableSurface;
import javax.media.nativewindow.VisualIDHolder;
import javax.media.nativewindow.util.Insets;
-import javax.media.nativewindow.util.InsetsImmutable;
import javax.media.nativewindow.util.Point;
import javax.media.nativewindow.util.PointImmutable;
@@ -50,6 +49,7 @@ import jogamp.newt.WindowImpl;
import jogamp.newt.driver.DriverClearFocus;
import jogamp.newt.driver.DriverUpdatePosition;
+import com.jogamp.common.util.Function;
import com.jogamp.newt.event.InputEvent;
import com.jogamp.newt.event.KeyEvent;
@@ -86,7 +86,10 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
sscSurfaceHandle = 0;
isOffscreenInstance = false;
if (0 != handle) {
- close0(handle);
+ OSXUtil.RunOnMainThread(true, new Runnable() {
+ public void run() {
+ close0( handle );
+ } } );
}
} catch (Throwable t) {
if(DEBUG_IMPLEMENTATION) {
@@ -140,6 +143,7 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
setTitle0(getWindowHandle(), title);
}
+ @Override
protected void requestFocusImpl(boolean force) {
if(!isOffscreenInstance) {
requestFocus0(getWindowHandle(), force);
@@ -148,6 +152,7 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
}
}
+ @Override
public final void clearFocus() {
if(DEBUG_IMPLEMENTATION) {
System.err.println("MacWindow: clearFocus(), isOffscreenInstance "+isOffscreenInstance);
@@ -159,29 +164,59 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
}
}
+ @Override
public void updatePosition() {
- final Point pS = getTopLevelLocationOnScreen(getX(), getY());
- if(DEBUG_IMPLEMENTATION) {
- System.err.println("MacWindow: updatePosition() - isOffscreenInstance "+isOffscreenInstance+", new abs pos: pS "+pS);
+ final long handle = getWindowHandle();
+ if( 0 != handle && !isOffscreenInstance ) {
+ final Point pS = getLocationOnScreenImpl(0, 0);
+ if(DEBUG_IMPLEMENTATION) {
+ System.err.println("MacWindow: updatePosition() -> abs child-client-pos: "+pS);
+ }
+ setWindowClientTopLeftPoint0(handle, pS.getX(), pS.getY());
+ // no native event (fullscreen, some reparenting)
+ positionChanged(true, pS.getX(), pS.getY());
}
- if( !isOffscreenInstance ) {
- setFrameTopLeftPoint0(getParentWindowHandle(), getWindowHandle(), pS.getX(), pS.getY());
- } // else no offscreen position
- // no native event (fullscreen, some reparenting)
- super.positionChanged(true, getX(), getY());
- }
-
+ }
+ @Override
+ protected void sizeChanged(boolean defer, int newWidth, int newHeight, boolean force) {
+ final long handle = getWindowHandle();
+ if( 0 != handle && !isOffscreenInstance ) {
+ final NativeWindow parent = getParent();
+ final boolean useParent = null != parent && 0 != parent.getWindowHandle() ;
+ if( useParent && ( getWidth() != newWidth || getHeight() != newHeight ) ) {
+ final Point p0S = getLocationOnScreenImpl(0, 0);
+ if(DEBUG_IMPLEMENTATION) {
+ System.err.println("MacWindow: sizeChanged() "+newWidth+"x"+newHeight+" -> abs child-client-pos "+p0S);
+ }
+ setWindowClientTopLeftPoint0(getWindowHandle(), p0S.getX(), p0S.getY());
+ }
+ }
+ super.sizeChanged(defer, newWidth, newHeight, force);
+ }
+
+ @Override
protected boolean reconfigureWindowImpl(int x, int y, int width, int height, int flags) {
final boolean _isOffscreenInstance = isOffscreenInstance(this, this.getParent());
isOffscreenInstance = 0 != sscSurfaceHandle || _isOffscreenInstance;
- final PointImmutable pS = isOffscreenInstance ? new Point(0, 0) : getTopLevelLocationOnScreen(x, y);
+ final PointImmutable pClientLevelOnSreen;
+ if( isOffscreenInstance ) {
+ pClientLevelOnSreen = new Point(0, 0);
+ } else {
+ final NativeWindow parent = getParent();
+ final boolean useParent = null != parent && 0 != parent.getWindowHandle() ;
+ if( useParent ) {
+ pClientLevelOnSreen = getLocationOnScreenImpl(x, y);
+ } else {
+ pClientLevelOnSreen = new Point(x, y);
+ }
+ }
if(DEBUG_IMPLEMENTATION) {
final AbstractGraphicsConfiguration cWinCfg = this.getGraphicsConfiguration();
final NativeWindow pWin = getParent();
final AbstractGraphicsConfiguration pWinCfg = null != pWin ? pWin.getGraphicsConfiguration() : null;
- System.err.println("MacWindow reconfig: "+x+"/"+y+" -> "+pS+" - "+width+"x"+height+
+ System.err.println("MacWindow reconfig.0: "+x+"/"+y+" -> clientPos "+pClientLevelOnSreen+" - "+width+"x"+height+
",\n\t parent type "+(null != pWin ? pWin.getClass().getName() : null)+
",\n\t this-chosenCaps "+(null != cWinCfg ? cWinCfg.getChosenCapabilities() : null)+
",\n\t parent-chosenCaps "+(null != pWinCfg ? pWinCfg.getChosenCapabilities() : null)+
@@ -189,6 +224,7 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
", ioi: "+_isOffscreenInstance+
") -> "+isOffscreenInstance+
"\n\t, "+getReconfigureFlagsAsString(null, flags));
+ Thread.dumpStack();
}
if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) && 0 == ( FLAG_IS_VISIBLE & flags) ) {
@@ -203,25 +239,20 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
0 != ( FLAG_CHANGE_PARENTING & flags) ||
0 != ( FLAG_CHANGE_FULLSCREEN & flags) ) {
if(isOffscreenInstance) {
- createWindow(true, 0 != getWindowHandle(), pS, 64, 64, false);
+ createWindow(true, 0 != getWindowHandle(), pClientLevelOnSreen, 64, 64, false);
} else {
- createWindow(false, 0 != getWindowHandle(), pS, width, height, 0 != ( FLAG_IS_FULLSCREEN & flags));
+ createWindow(false, 0 != getWindowHandle(), pClientLevelOnSreen, width, height, 0 != ( FLAG_IS_FULLSCREEN & flags));
}
if(isVisible()) { flags |= FLAG_CHANGE_VISIBILITY; }
}
- if(x>=0 && y>=0) {
- if( !isOffscreenInstance ) {
- setFrameTopLeftPoint0(getParentWindowHandle(), getWindowHandle(), pS.getX(), pS.getY());
- } // else no offscreen position
- // no native event (fullscreen, some reparenting)
- super.positionChanged(true, x, y);
- }
- if(width>0 && height>0) {
+ if( width>0 && height>0 && x>=0 && y>=0 ) {
if( !isOffscreenInstance ) {
- setContentSize0(getWindowHandle(), width, height);
+ // setContentSize0(getWindowHandle(), width, height);
+ setWindowClientTopLeftPointAndSize0(getWindowHandle(), pClientLevelOnSreen.getX(), pClientLevelOnSreen.getY(), width, height);
} // else offscreen size is realized via recreation
// no native event (fullscreen, some reparenting)
- sizeChanged(true, width, height, false); // incl. validation (incl. repositioning)
+ positionChanged(true, x, y);
+ sizeChanged(true, width, height, false);
}
if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) && 0 != ( FLAG_IS_VISIBLE & flags) ) {
if( !isOffscreenInstance ) {
@@ -233,9 +264,13 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
if( !isOffscreenInstance ) {
setAlwaysOnTop0(getWindowHandle(), 0 != ( FLAG_IS_ALWAYSONTOP & flags));
}
+ if(DEBUG_IMPLEMENTATION) {
+ System.err.println("MacWindow reconfig.X: clientPos "+pClientLevelOnSreen+", "+width+"x"+height+" -> clientPos "+getLocationOnScreenImpl(0, 0)+", insets: "+getInsets());
+ }
return true;
}
+ @Override
protected Point getLocationOnScreenImpl(int x, int y) {
final NativeWindow parent = getParent();
final boolean useParent = null != parent && 0 != parent.getWindowHandle() ;
@@ -253,39 +288,28 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
}
return p;
}
-
- private Point getTopLevelLocationOnScreen(int x, int y) {
- final InsetsImmutable _insets = getInsets(); // zero if undecorated
- // client position -> top-level window position
- x -= _insets.getLeftWidth() ;
- y -= _insets.getTopHeight() ;
- return getLocationOnScreenImpl(x, y);
- }
-
+
+ @Override
protected void updateInsetsImpl(Insets insets) {
// nop - using event driven insetsChange(..)
}
- @Override
- protected void sizeChanged(boolean defer, int newWidth, int newHeight, boolean force) {
- if(getWidth() != newWidth || getHeight() != newHeight) {
- final Point p0S = getTopLevelLocationOnScreen(getX(), getY());
- setFrameTopLeftPoint0(getParentWindowHandle(), getWindowHandle(), p0S.getX(), p0S.getY());
- }
- super.sizeChanged(defer, newWidth, newHeight, force);
- }
-
- @Override
- protected void positionChanged(boolean defer, int newX, int newY) {
+ /** Callback for native screen position change event of the client area. */
+ protected void screenPositionChanged(boolean defer, int newX, int newY) {
// passed coordinates are in screen position of the client area
- if(getWindowHandle()!=0) {
- // screen position -> window position
- Point absPos = new Point(newX, newY);
+ if(DEBUG_IMPLEMENTATION) {
+ System.err.println("MacWindow.positionChanged (Screen Pos): ("+getThreadName()+"): (defer: "+defer+") "+getX()+"/"+getY()+" -> "+newX+"/"+newY);
+ }
+ if(getWindowHandle()!=0) {
final NativeWindow parent = getParent();
- if(null != parent) {
+ if(null == parent) {
+ positionChanged(defer, newX, newY);
+ } else {
+ // screen position -> rel child window position
+ Point absPos = new Point(newX, newY);
absPos.translate( parent.getLocationOnScreen(null).scale(-1, -1) );
+ positionChanged(defer, absPos.getX(), absPos.getY());
}
- super.positionChanged(defer, absPos.getX(), absPos.getY());
}
}
@@ -312,20 +336,21 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
} // else may need offscreen solution ? FIXME
}
- private final void emitKeyEvent(boolean send, boolean wait, int eventType, int modifiers, int keyCode, char keyChar) {
- if( send ) {
- super.sendKeyEvent(eventType, modifiers, keyCode, keyChar);
- } else {
- super.enqueueKeyEvent(wait, eventType, modifiers, keyCode, keyChar);
- }
+ @Override
+ public final void sendKeyEvent(short eventType, int modifiers, short keyCode, short keySym, char keyChar) {
+ throw new InternalError("XXX: Adapt Java Code to Native Code Changes");
}
-
- private final void handleKeyEvent(boolean send, boolean wait, int eventType, int modifiers, int _keyCode, char keyChar) {
+
+ @Override
+ public final void enqueueKeyEvent(boolean wait, short eventType, int modifiers, short _keyCode, short keySym, char keyChar) {
// Note that we send the key char for the key code on this
// platform -- we do not get any useful key codes out of the system
- final int keyCode = MacKeyUtil.validateKeyCode(_keyCode, keyChar);
- // final boolean isModifierKeyCode = KeyEvent.isModifierKey(keyCode);
- // System.err.println("*** handleKeyEvent: event "+KeyEvent.getEventTypeString(eventType)+", key 0x"+Integer.toHexString(_keyCode)+" -> 0x"+Integer.toHexString(keyCode)+", mods "+toHexString(modifiers)+", was: pressed "+isKeyPressed(keyCode)+", repeat "+isKeyInAutoRepeat(keyCode)+", isModifierKeyCode "+isModifierKeyCode);
+ final short keyCode = MacKeyUtil.validateKeyCode(_keyCode, keyChar);
+ /* {
+ final boolean isModifierKeyCode = KeyEvent.isModifierKey(keyCode);
+ System.err.println("*** handleKeyEvent: event "+KeyEvent.getEventTypeString(eventType)+", key 0x"+Integer.toHexString(_keyCode)+" -> 0x"+Integer.toHexString(keyCode)+", mods "+toHexString(modifiers)+
+ ", was: pressed "+isKeyPressed(keyCode)+", repeat "+isKeyInAutoRepeat(keyCode)+", isModifierKeyCode "+isModifierKeyCode);
+ } */
// 1:1 Order: OSX and NEWT delivery order is PRESSED, RELEASED and TYPED
// Auto-Repeat: OSX delivers only PRESSED, inject auto-repeat RELEASE and TYPED keys _before_ PRESSED
@@ -342,25 +367,12 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
// 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, keyChar); // RELEASED
- emitKeyEvent(send, wait, KeyEvent.EVENT_KEY_TYPED, modifiers, keyCode, keyChar); // TYPED
+ super.enqueueKeyEvent(wait, KeyEvent.EVENT_KEY_RELEASED, modifiers, keyCode, keyCode, keyChar); // RELEASED
}
}
break;
- case KeyEvent.EVENT_KEY_TYPED:
- break;
}
- emitKeyEvent(send, wait, eventType, modifiers, keyCode, keyChar);
- }
-
- @Override
- public void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) {
- handleKeyEvent(true, false, eventType, modifiers, keyCode, keyChar);
- }
-
- @Override
- public void enqueueKeyEvent(boolean wait, int eventType, int modifiers, int keyCode, char keyChar) {
- handleKeyEvent(false, wait, eventType, modifiers, keyCode, keyChar);
+ super.enqueueKeyEvent(wait, eventType, modifiers, keyCode, keyCode, keyChar);
}
//----------------------------------------------------------------------
@@ -378,24 +390,36 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
try {
if(0!=getWindowHandle()) {
// save the view .. close the window
- surfaceHandle = changeContentView0(getParentWindowHandle(), getWindowHandle(), 0);
+ surfaceHandle = OSXUtil.RunOnMainThread(true, new Function<Long, Object>() {
+ public Long eval(Object... args) {
+ return Long.valueOf(
+ changeContentView0(getParentWindowHandle(), getWindowHandle(), 0) );
+ } } ).longValue();
if(recreate && 0==surfaceHandle) {
throw new NativeWindowException("Internal Error - recreate, window but no view");
}
- close0(getWindowHandle());
+ OSXUtil.RunOnMainThread(true, new Runnable() {
+ public void run() {
+ close0( getWindowHandle() );
+ } } );
setWindowHandle(0);
} else {
surfaceHandle = 0;
}
- setWindowHandle(createWindow0(getParentWindowHandle(),
- pS.getX(), pS.getY(), width, height,
- (getGraphicsConfiguration().getChosenCapabilities().isBackgroundOpaque() && !offscreenInstance),
- fullscreen,
- ((isUndecorated() || offscreenInstance) ?
- NSBorderlessWindowMask :
- NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask),
- NSBackingStoreBuffered,
- getScreen().getIndex(), surfaceHandle));
+
+ setWindowHandle( OSXUtil.RunOnMainThread(true, new Function<Long, Object>() {
+ public Long eval(Object... args) {
+ return Long.valueOf(
+ createWindow0( getParentWindowHandle(),
+ pS.getX(), pS.getY(), width, height,
+ (getGraphicsConfiguration().getChosenCapabilities().isBackgroundOpaque() && !offscreenInstance),
+ fullscreen,
+ ( (isUndecorated() || offscreenInstance) ? NSBorderlessWindowMask :
+ NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask ),
+ NSBackingStoreBuffered,
+ getScreen().getIndex(), surfaceHandle) );
+ } } ).longValue() );
+
if (getWindowHandle() == 0) {
throw new NativeWindowException("Could create native window "+Thread.currentThread().getName()+" "+this);
}
@@ -411,6 +435,7 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
}
protected static native boolean initIDs0();
+ /** Must be called on Main-Thread */
private native long createWindow0(long parentWindowHandle, int x, int y, int w, int h,
boolean opaque, boolean fullscreen, int windowStyle,
int backingStoreType,
@@ -422,12 +447,14 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
/** in case of a child window, it actually only issues orderBack(..) */
private native void orderOut0(long window);
private native void orderFront0(long window);
+ /** Must be called on Main-Thread */
private native void close0(long window);
private native void setTitle0(long window, String title);
private native long contentView0(long window);
+ /** Must be called on Main-Thread */
private native long changeContentView0(long parentWindowOrViewHandle, long window, long view);
- private native void setContentSize0(long window, int w, int h);
- private native void setFrameTopLeftPoint0(long parentWindowHandle, long window, int x, int y);
+ private native void setWindowClientTopLeftPointAndSize0(long window, int x, int y, int w, int h);
+ private native void setWindowClientTopLeftPoint0(long window, int x, int y);
private native void setAlwaysOnTop0(long window, boolean atop);
private static native Object getLocationOnScreen0(long windowHandle, int src_x, int src_y);
private static native boolean setPointerVisible0(long windowHandle, boolean hasFocus, boolean visible);
diff --git a/src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java
index 650958f25..475687eb4 100644
--- a/src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java
@@ -46,7 +46,6 @@ import javax.media.nativewindow.util.Insets;
import javax.media.nativewindow.util.InsetsImmutable;
import javax.media.nativewindow.util.Point;
-import com.jogamp.common.util.IntIntHashMap;
import com.jogamp.newt.event.InputEvent;
import com.jogamp.newt.event.KeyEvent;
import com.jogamp.newt.event.MouseAdapter;
@@ -261,87 +260,55 @@ public class WindowDriver extends WindowImpl {
// nop - using event driven insetsChange(..)
}
- private final void emitKeyEvent(boolean send, boolean wait, int eventType, int modifiers, int keyCode, char keyChar) {
- if( send ) {
- super.sendKeyEvent(eventType, modifiers, keyCode, keyChar);
- } else {
- super.enqueueKeyEvent(wait, eventType, modifiers, keyCode, keyChar);
- }
+ private final boolean handlePressTypedAutoRepeat(boolean isModifierKey, int modifiers, short keyCode, short keySym, char keyChar) {
+ if( isKeyCodeTracked(keyCode) && keyPressedState.put(keyCode, true) ) {
+ final boolean preKeyRepeatState = keyRepeatState.put(keyCode, true);
+ if( !isModifierKey ) {
+ // AR: Key was already pressed: Either [enter | within] AR mode
+ modifiers |= InputEvent.AUTOREPEAT_MASK;
+ if( preKeyRepeatState ) {
+ // AR: Within AR mode
+ super.sendKeyEvent(KeyEvent.EVENT_KEY_PRESSED, modifiers, keyCode, keySym, keyChar);
+ } // else { AR: Enter AR mode - skip already send PRESSED ; or ALT }
+ super.sendKeyEvent(KeyEvent.EVENT_KEY_RELEASED, modifiers, keyCode, keySym, keyChar);
+ }
+ return true;
+ }
+ return false;
}
- /** FIXME: We have to store the keyChar for typed events, since keyChar from pressed/released may be wrong (Uppercase: SHIFT-1, etc ..). */
- private IntIntHashMap typedKeyCode2KeyChar = new IntIntHashMap(KeyEvent.VK_CONTEXT_MENU+1);
-
- private final void handleKeyEvent(boolean send, boolean wait, int eventType, int modifiers, int keyCode, char keyChar) {
- final boolean isPrintableKey = KeyEvent.isPrintableKey(keyCode);
- final boolean isModifierKey = KeyEvent.isModifierKey(keyCode);
- // System.err.println("*** handleKeyEvent: event "+KeyEvent.getEventTypeString(eventType)+", keyCode "+toHexString(keyCode)+", keyChar <"+keyChar+">, mods "+toHexString(modifiers)+", was: pressed "+isKeyPressed(keyCode)+", repeat "+isKeyInAutoRepeat(keyCode)+", printableKey "+isPrintableKey+" [modifierKey "+isModifierKey+"] - "+System.currentTimeMillis());
+ @Override
+ public final void sendKeyEvent(short eventType, int modifiers, short keyCode, short keySym, char keyChar) {
+ final boolean isModifierKey = KeyEvent.isModifierKey(keySym);
+ // System.err.println("*** sendKeyEvent: event "+KeyEvent.getEventTypeString(eventType)+", keyCode "+toHexString(keyCode)+", keyChar <"+keyChar+">, mods "+toHexString(modifiers)+
+ // ", isKeyCodeTracked "+isKeyCodeTracked(keyCode)+", was: pressed "+isKeyPressed(keyCode)+", repeat "+isKeyInAutoRepeat(keyCode)+", printableKey "+KeyEvent.isPrintableKey(keyCode)+" [modifierKey "+isModifierKey+"] - "+System.currentTimeMillis());
// Reorder: WINDOWS delivery order is PRESSED (t0), TYPED (t0) and RELEASED (t1) -> NEWT order: PRESSED (t0), RELEASED (t1) and TYPED (t1)
// Auto-Repeat: WINDOWS delivers only PRESSED (t0) and TYPED (t0).
switch(eventType) {
case KeyEvent.EVENT_KEY_RELEASED:
- final int keyCharTyped = typedKeyCode2KeyChar.put(keyCode, 0);
- if( 0 != keyCharTyped ) {
- keyChar = (char)keyCharTyped;
- }
if( isKeyCodeTracked(keyCode) ) {
if( keyRepeatState.put(keyCode, false) && !isModifierKey ) {
// AR out - send out missing PRESSED
- emitKeyEvent(send, wait, KeyEvent.EVENT_KEY_PRESSED, modifiers | InputEvent.AUTOREPEAT_MASK, keyCode, keyChar);
+ super.sendKeyEvent(KeyEvent.EVENT_KEY_PRESSED, modifiers | InputEvent.AUTOREPEAT_MASK, keyCode, keySym, keyChar);
}
keyPressedState.put(keyCode, false);
}
- emitKeyEvent(send, wait, eventType, modifiers, keyCode, keyChar);
- emitKeyEvent(send, wait, KeyEvent.EVENT_KEY_TYPED, modifiers, keyCode, keyChar);
+ super.sendKeyEvent(KeyEvent.EVENT_KEY_RELEASED, modifiers, keyCode, keySym, keyChar);
break;
case KeyEvent.EVENT_KEY_PRESSED:
- // TYPED is delivered right after PRESSED for printable keys and contains the key-char information,
- // hence we only deliver non printable keys (action and modifier keys) here.
- // Modifier keys shall not AR.
- if( !isPrintableKey ) {
- if( !handlePressTypedAutoRepeat(isModifierKey, send, wait, modifiers, keyCode, keyChar) ) {
- emitKeyEvent(send, wait, KeyEvent.EVENT_KEY_PRESSED, modifiers, keyCode, keyChar);
- }
- }
- break;
- case KeyEvent.EVENT_KEY_TYPED:
- if( isPrintableKey ) {
- typedKeyCode2KeyChar.put(keyCode, keyChar);
- if( !handlePressTypedAutoRepeat(isModifierKey, send, wait, modifiers, keyCode, keyChar) ) {
- emitKeyEvent(send, wait, KeyEvent.EVENT_KEY_PRESSED, modifiers, keyCode, keyChar);
- }
+ if( !handlePressTypedAutoRepeat(isModifierKey, modifiers, keyCode, keySym, keyChar) ) {
+ super.sendKeyEvent(KeyEvent.EVENT_KEY_PRESSED, modifiers, keyCode, keySym, keyChar);
}
break;
+ // case KeyEvent.EVENT_KEY_TYPED:
+ // break;
}
}
- private final boolean handlePressTypedAutoRepeat(boolean isModifierKey, boolean send, boolean wait, int modifiers, int keyCode, char keyChar) {
- if( isKeyCodeTracked(keyCode) && keyPressedState.put(keyCode, true) ) {
- final boolean preKeyRepeatState = keyRepeatState.put(keyCode, true);
- if( !isModifierKey ) {
- // AR: Key was already pressed: Either [enter | within] AR mode
- modifiers |= InputEvent.AUTOREPEAT_MASK;
- if( preKeyRepeatState ) {
- // AR: Within AR mode
- emitKeyEvent(send, wait, KeyEvent.EVENT_KEY_PRESSED, modifiers, keyCode, keyChar);
- } // else { AR: Enter AR mode - skip already send PRESSED ; or ALT }
- emitKeyEvent(send, wait, KeyEvent.EVENT_KEY_RELEASED, modifiers, keyCode, keyChar);
- emitKeyEvent(send, wait, KeyEvent.EVENT_KEY_TYPED, modifiers, keyCode, keyChar);
- }
- return true;
- }
- return false;
- }
-
- @Override
- public void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) {
- handleKeyEvent(true, false, eventType, modifiers, keyCode, keyChar);
- }
-
@Override
- public void enqueueKeyEvent(boolean wait, int eventType, int modifiers, int keyCode, char keyChar) {
- handleKeyEvent(false, wait, eventType, modifiers, keyCode, keyChar);
+ public final void enqueueKeyEvent(boolean wait, short eventType, int modifiers, short keyCode, short keySym, char keyChar) {
+ throw new InternalError("XXX: Adapt Java Code to Native Code Changes");
}
//----------------------------------------------------------------------
diff --git a/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java
index c55fddd07..8d33d4d73 100644
--- a/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java
@@ -48,6 +48,7 @@ import javax.media.nativewindow.util.Point;
import com.jogamp.nativewindow.x11.X11GraphicsDevice;
import com.jogamp.nativewindow.x11.X11GraphicsScreen;
import com.jogamp.newt.event.InputEvent;
+import com.jogamp.newt.event.KeyEvent;
import com.jogamp.newt.event.MouseEvent;
public class WindowDriver extends WindowImpl {
@@ -227,8 +228,8 @@ public class WindowDriver extends WindowImpl {
}
@Override
- protected void doMouseEvent(boolean enqueue, boolean wait, int eventType, int modifiers,
- int x, int y, int button, float rotation) {
+ protected final void doMouseEvent(boolean enqueue, boolean wait, short eventType, int modifiers,
+ int x, int y, short button, float rotation) {
switch(eventType) {
case MouseEvent.EVENT_MOUSE_PRESSED:
switch(button) {
@@ -270,6 +271,34 @@ public class WindowDriver extends WindowImpl {
super.doMouseEvent(enqueue, wait, eventType, modifiers, x, y, button, rotation);
}
+ @Override
+ public final void sendKeyEvent(short eventType, int modifiers, short keyCode, short keySym, char keyChar) {
+ // handleKeyEvent(true, false, eventType, modifiers, keyCode, keyChar);
+ final boolean isModifierKey = KeyEvent.isModifierKey(keyCode);
+ final boolean isAutoRepeat = 0 != ( KeyEvent.AUTOREPEAT_MASK & modifiers );
+ // System.err.println("*** sendKeyEvent: event "+KeyEvent.getEventTypeString(eventType)+", keyCode "+toHexString(keyCode)+", keyChar <"+keyChar+">, mods "+toHexString(modifiers)+
+ // ", isKeyCodeTracked "+isKeyCodeTracked(keyCode)+", was: pressed "+isKeyPressed(keyCode)+", repeat "+isAutoRepeat+", [modifierKey "+isModifierKey+"] - "+System.currentTimeMillis());
+
+ if( !isAutoRepeat || !isModifierKey ) { // ! ( isModifierKey && isAutoRepeat )
+ switch(eventType) {
+ case KeyEvent.EVENT_KEY_PRESSED:
+ super.sendKeyEvent(KeyEvent.EVENT_KEY_PRESSED, modifiers, keyCode, keySym, keyChar);
+ break;
+
+ case KeyEvent.EVENT_KEY_RELEASED:
+ super.sendKeyEvent(KeyEvent.EVENT_KEY_RELEASED, modifiers, keyCode, keySym, keyChar);
+ break;
+
+ // case KeyEvent.EVENT_KEY_TYPED:
+ // break;
+ }
+ }
+ }
+
+ @Override
+ public final void enqueueKeyEvent(boolean wait, short eventType, int modifiers, short keyCode, short keySym, char keyChar) {
+ throw new InternalError("XXX: Adapt Java Code to Native Code Changes");
+ }
//----------------------------------------------------------------------
// Internals only
diff --git a/src/newt/classes/jogamp/newt/swt/event/SWTNewtEventFactory.java b/src/newt/classes/jogamp/newt/swt/event/SWTNewtEventFactory.java
index 0fc487e91..1ebb714fa 100644
--- a/src/newt/classes/jogamp/newt/swt/event/SWTNewtEventFactory.java
+++ b/src/newt/classes/jogamp/newt/swt/event/SWTNewtEventFactory.java
@@ -32,7 +32,6 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
-import com.jogamp.common.util.IntIntHashMap;
import com.jogamp.newt.event.InputEvent;
/**
@@ -43,26 +42,22 @@ import com.jogamp.newt.event.InputEvent;
*/
public class SWTNewtEventFactory {
- protected static final IntIntHashMap eventTypeSWT2NEWT;
+ public static final short eventTypeSWT2NEWT(int swtType) {
+ switch( swtType ) {
+ // case SWT.MouseXXX: return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_CLICKED;
+ case SWT.MouseDown: return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_PRESSED;
+ case SWT.MouseUp: return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_RELEASED;
+ case SWT.MouseMove: return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_MOVED;
+ case SWT.MouseEnter: return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_ENTERED;
+ case SWT.MouseExit: return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_EXITED;
+ // case SWT.MouseXXX: return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_DRAGGED;
+ case SWT.MouseVerticalWheel: return com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_WHEEL_MOVED;
- static {
- IntIntHashMap map = new IntIntHashMap();
- map.setKeyNotFoundValue(0xFFFFFFFF);
-
- // map.put(SWT.MouseXXX, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_CLICKED);
- map.put(SWT.MouseDown, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_PRESSED);
- map.put(SWT.MouseUp, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_RELEASED);
- map.put(SWT.MouseMove, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_MOVED);
- map.put(SWT.MouseEnter, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_ENTERED);
- map.put(SWT.MouseExit, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_EXITED);
- // map.put(SWT.MouseXXX, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_DRAGGED);
- map.put(SWT.MouseVerticalWheel, com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_WHEEL_MOVED);
-
- map.put(SWT.KeyDown, com.jogamp.newt.event.KeyEvent.EVENT_KEY_PRESSED);
- map.put(SWT.KeyUp, com.jogamp.newt.event.KeyEvent.EVENT_KEY_RELEASED);
- // map.put(SWT.KeyXXX, com.jogamp.newt.event.KeyEvent.EVENT_KEY_TYPED);
-
- eventTypeSWT2NEWT = map;
+ case SWT.KeyDown: return com.jogamp.newt.event.KeyEvent.EVENT_KEY_PRESSED;
+ case SWT.KeyUp: return com.jogamp.newt.event.KeyEvent.EVENT_KEY_RELEASED;
+ // case SWT.KeyXXX: return com.jogamp.newt.event.KeyEvent.EVENT_KEY_TYPED;
+ }
+ return (short)0;
}
public static final int swtModifiers2Newt(int awtMods, boolean mouseHint) {
@@ -93,8 +88,8 @@ public class SWTNewtEventFactory {
default:
return null;
}
- int type = eventTypeSWT2NEWT.get(event.type);
- if(0xFFFFFFFF != type) {
+ final short type = eventTypeSWT2NEWT(event.type);
+ if( (short)0 != type ) {
float rotation = 0;
if (SWT.MouseVerticalWheel == event.type) {
// SWT/NEWT rotation is reversed - AWT +1 is down, NEWT +1 is up.
@@ -116,7 +111,7 @@ public class SWTNewtEventFactory {
return new com.jogamp.newt.event.MouseEvent(
type, (null==source)?(Object)event.data:source, (0xFFFFFFFFL & (long)event.time),
- mods, event.x, event.y, event.count, event.button, rotation);
+ mods, event.x, event.y, (short)event.count, (short)event.button, rotation);
}
return null; // no mapping ..
}
@@ -129,12 +124,12 @@ public class SWTNewtEventFactory {
default:
return null;
}
- int type = eventTypeSWT2NEWT.get(event.type);
- if(0xFFFFFFFF != type) {
+ final short type = eventTypeSWT2NEWT(event.type);
+ if( (short)0 != type ) {
return new com.jogamp.newt.event.KeyEvent(
type, (null==source)?(Object)event.data:source, (0xFFFFFFFFL & (long)event.time),
swtModifiers2Newt(event.stateMask, false),
- event.keyCode, event.character);
+ (short)event.keyCode, (short)event.keyCode, event.character);
}
return null; // no mapping ..
}
@@ -143,7 +138,7 @@ public class SWTNewtEventFactory {
//
//
- int dragButtonDown = 0;
+ short dragButtonDown = 0;
public SWTNewtEventFactory() {
resetButtonsDown();
@@ -159,7 +154,7 @@ public class SWTNewtEventFactory {
if(null != l) {
switch(event.type) {
case SWT.MouseDown:
- dragButtonDown = event.button;
+ dragButtonDown = (short) event.button;
l.mousePressed(res); break;
case SWT.MouseUp:
dragButtonDown = 0;
@@ -214,7 +209,6 @@ public class SWTNewtEventFactory {
break;
case SWT.KeyUp:
l.keyReleased(res);
- l.keyTyped(res);
break;
}
}