summaryrefslogtreecommitdiffstats
path: root/src/newt
diff options
context:
space:
mode:
Diffstat (limited to 'src/newt')
-rw-r--r--[-rwxr-xr-x]src/newt/classes/com/jogamp/newt/Display.java31
-rw-r--r--[-rwxr-xr-x]src/newt/classes/com/jogamp/newt/NewtFactory.java0
-rw-r--r--src/newt/classes/com/jogamp/newt/OffscreenWindow.java3
-rw-r--r--[-rwxr-xr-x]src/newt/classes/com/jogamp/newt/Screen.java0
-rw-r--r--[-rwxr-xr-x]src/newt/classes/com/jogamp/newt/Window.java605
-rw-r--r--src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java107
-rw-r--r--src/newt/classes/com/jogamp/newt/event/NEWTEvent.java8
-rw-r--r--[-rwxr-xr-x]src/newt/classes/com/jogamp/newt/event/NEWTEventConsumer.java (renamed from src/newt/classes/com/jogamp/newt/event/PaintListener.java)33
-rw-r--r--src/newt/classes/com/jogamp/newt/event/TraceWindowAdapter.java4
-rw-r--r--src/newt/classes/com/jogamp/newt/event/WindowAdapter.java2
-rw-r--r--src/newt/classes/com/jogamp/newt/event/WindowEvent.java4
-rw-r--r--src/newt/classes/com/jogamp/newt/event/WindowListener.java1
-rw-r--r--[-rwxr-xr-x]src/newt/classes/com/jogamp/newt/event/WindowUpdateEvent.java (renamed from src/newt/classes/com/jogamp/newt/event/PaintEvent.java)55
-rw-r--r--src/newt/classes/com/jogamp/newt/event/awt/AWTAdapter.java10
-rw-r--r--src/newt/classes/com/jogamp/newt/event/awt/AWTKeyAdapter.java6
-rw-r--r--src/newt/classes/com/jogamp/newt/event/awt/AWTMouseAdapter.java14
-rw-r--r--src/newt/classes/com/jogamp/newt/event/awt/AWTNewtEventFactory.java10
-rw-r--r--src/newt/classes/com/jogamp/newt/event/awt/AWTParentWindowAdapter.java12
-rw-r--r--src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java30
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/awt/AWTWindow.java20
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/intel/gdl/Window.java3
-rw-r--r--[-rwxr-xr-x]src/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java6
-rw-r--r--[-rwxr-xr-x]src/newt/classes/com/jogamp/newt/impl/macosx/MacScreen.java0
-rw-r--r--[-rwxr-xr-x]src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java58
-rw-r--r--[-rwxr-xr-x]src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Screen.java0
-rw-r--r--[-rwxr-xr-x]src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Window.java3
-rw-r--r--[-rwxr-xr-x]src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDDisplay.java0
-rw-r--r--[-rwxr-xr-x]src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDScreen.java0
-rw-r--r--[-rwxr-xr-x]src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDWindow.java14
-rw-r--r--[-rwxr-xr-x]src/newt/classes/com/jogamp/newt/impl/windows/WindowsDisplay.java0
-rw-r--r--[-rwxr-xr-x]src/newt/classes/com/jogamp/newt/impl/windows/WindowsScreen.java0
-rw-r--r--[-rwxr-xr-x]src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java46
-rw-r--r--[-rwxr-xr-x]src/newt/classes/com/jogamp/newt/impl/x11/X11Display.java0
-rw-r--r--[-rwxr-xr-x]src/newt/classes/com/jogamp/newt/impl/x11/X11Screen.java0
-rw-r--r--[-rwxr-xr-x]src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java53
-rw-r--r--src/newt/classes/com/jogamp/newt/opengl/GLWindow.java150
-rw-r--r--src/newt/classes/com/jogamp/newt/util/Insets.java (renamed from src/newt/classes/com/jogamp/newt/Insets.java)2
-rw-r--r--[-rwxr-xr-x]src/newt/native/BroadcomEGL.c0
-rw-r--r--[-rwxr-xr-x]src/newt/native/KDWindow.c0
-rw-r--r--[-rwxr-xr-x]src/newt/native/NewtMacWindow.m0
-rw-r--r--[-rwxr-xr-x]src/newt/native/WindowsWindow.c186
-rw-r--r--[-rwxr-xr-x]src/newt/native/X11Window.c158
42 files changed, 866 insertions, 768 deletions
diff --git a/src/newt/classes/com/jogamp/newt/Display.java b/src/newt/classes/com/jogamp/newt/Display.java
index 193bb26dc..deb4c7abe 100755..100644
--- a/src/newt/classes/com/jogamp/newt/Display.java
+++ b/src/newt/classes/com/jogamp/newt/Display.java
@@ -182,10 +182,9 @@ public abstract class Display {
return true;
}
public EDTUtil getEDTUtil() {
- if( !edtQueried ) {
+ if( null == edtUtil ) {
synchronized (this) {
- if( !edtQueried ) {
- edtQueried = true;
+ if( null == edtUtil ) {
if(NewtFactory.useEDT()) {
final Display f_dpy = this;
Thread current = Thread.currentThread();
@@ -203,12 +202,11 @@ public abstract class Display {
}
return edtUtil;
}
- volatile boolean edtQueried = false;
public void runOnEDTIfAvail(boolean wait, final Runnable task) {
- EDTUtil edtUtil = getEDTUtil();
- if(runCreateAndDestroyOnEDT() && null!=edtUtil) {
- edtUtil.invoke(wait, task);
+ EDTUtil _edtUtil = getEDTUtil();
+ if(runCreateAndDestroyOnEDT() && null!=_edtUtil) {
+ _edtUtil.invoke(wait, task);
} else {
task.run();
}
@@ -238,6 +236,7 @@ public abstract class Display {
if(null!=edtUtil) {
edtUtil.waitUntilStopped();
edtUtil=null;
+ edt=null;
}
aDevice = null;
} else {
@@ -318,11 +317,12 @@ public abstract class Display {
private LinkedList/*<NEWTEvent>*/ events = new LinkedList();
protected void dispatchMessages() {
- if(0==refCount) return; // we should not exist ..
+ if(0==refCount) return; // in destruction ..
+
+ LinkedList/*<NEWTEvent>*/ _events = null;
if(!events.isEmpty()) {
// swap events list to free ASAP
- LinkedList/*<NEWTEvent>*/ _events = null;
synchronized(eventsLock) {
if(!events.isEmpty()) {
_events = events;
@@ -335,10 +335,13 @@ public abstract class Display {
NEWTEventTask eventTask = (NEWTEventTask) iter.next();
NEWTEvent event = eventTask.get();
Object source = event.getSource();
- if(source instanceof Window) {
- ((Window)source).sendEvent(event);
+ if(source instanceof NEWTEventConsumer) {
+ NEWTEventConsumer consumer = (NEWTEventConsumer) source ;
+ if(!consumer.consumeEvent(event)) {
+ enqueueEvent(false, event);
+ }
} else {
- throw new RuntimeException("Event source not a NEWT Window: "+source.getClass().getName()+", "+source);
+ throw new RuntimeException("Event source not a NEWT one: "+source.getClass().getName()+", "+source);
}
eventTask.notifyIssuer();
}
@@ -353,10 +356,6 @@ public abstract class Display {
}
}
- public void enqueueEvent(NEWTEvent e) {
- enqueueEvent(false, e);
- }
-
public void enqueueEvent(boolean wait, NEWTEvent e) {
Object lock = new Object();
NEWTEventTask eTask = new NEWTEventTask(e, wait?lock:null);
diff --git a/src/newt/classes/com/jogamp/newt/NewtFactory.java b/src/newt/classes/com/jogamp/newt/NewtFactory.java
index 3959c6a8d..3959c6a8d 100755..100644
--- a/src/newt/classes/com/jogamp/newt/NewtFactory.java
+++ b/src/newt/classes/com/jogamp/newt/NewtFactory.java
diff --git a/src/newt/classes/com/jogamp/newt/OffscreenWindow.java b/src/newt/classes/com/jogamp/newt/OffscreenWindow.java
index 0f75fbfa9..e85714d4f 100644
--- a/src/newt/classes/com/jogamp/newt/OffscreenWindow.java
+++ b/src/newt/classes/com/jogamp/newt/OffscreenWindow.java
@@ -107,9 +107,8 @@ public class OffscreenWindow extends Window implements SurfaceChangeable {
// nop
return false;
}
- protected boolean setFullscreenImpl(boolean fullscreen, int x, int y, int w, int h) {
+ protected void setFullscreenImpl(boolean fullscreen, int x, int y, int w, int h) {
shouldNotCallThis();
- return false;
}
}
diff --git a/src/newt/classes/com/jogamp/newt/Screen.java b/src/newt/classes/com/jogamp/newt/Screen.java
index 26342519e..26342519e 100755..100644
--- a/src/newt/classes/com/jogamp/newt/Screen.java
+++ b/src/newt/classes/com/jogamp/newt/Screen.java
diff --git a/src/newt/classes/com/jogamp/newt/Window.java b/src/newt/classes/com/jogamp/newt/Window.java
index e9289f5dc..9c724314e 100755..100644
--- a/src/newt/classes/com/jogamp/newt/Window.java
+++ b/src/newt/classes/com/jogamp/newt/Window.java
@@ -34,11 +34,12 @@
package com.jogamp.newt;
import com.jogamp.newt.event.*;
+import com.jogamp.newt.util.*;
import com.jogamp.newt.impl.Debug;
-import com.jogamp.newt.util.EDTUtil;
import com.jogamp.common.util.*;
import javax.media.nativewindow.*;
+import com.jogamp.nativewindow.util.Rectangle;
import com.jogamp.nativewindow.impl.RecursiveToolkitLock;
import java.util.ArrayList;
@@ -46,7 +47,7 @@ import java.util.List;
import java.util.Iterator;
import java.lang.reflect.Method;
-public abstract class Window implements NativeWindow
+public abstract class Window implements NativeWindow, NEWTEventConsumer
{
public static final boolean DEBUG_MOUSE_EVENT = Debug.debug("Window.MouseEvent");
public static final boolean DEBUG_KEY_EVENT = Debug.debug("Window.KeyEvent");
@@ -155,7 +156,7 @@ public abstract class Window implements NativeWindow
return 0 != windowHandle ;
}
if(DEBUG_IMPLEMENTATION) {
- System.err.println("Window.createNative() START ("+getThreadName()+", "+this+")");
+ System.out.println("Window.createNative() START ("+getThreadName()+", "+this+")");
}
if(validateParentWindowHandle()) {
Display dpy = getScreen().getDisplay();
@@ -163,7 +164,7 @@ public abstract class Window implements NativeWindow
setVisibleImpl(true);
}
if(DEBUG_IMPLEMENTATION) {
- System.err.println("Window.createNative() END ("+getThreadName()+", "+this+")");
+ System.out.println("Window.createNative() END ("+getThreadName()+", "+this+")");
}
return 0 != windowHandle ;
}
@@ -190,7 +191,7 @@ public abstract class Window implements NativeWindow
}
} catch (NativeWindowException nwe) {
if(DEBUG_IMPLEMENTATION) {
- System.err.println("Window.getNativeWindowHandle: not successful yet: "+nwe);
+ System.out.println("Window.getNativeWindowHandle: not successful yet: "+nwe);
}
} finally {
if(locked) {
@@ -198,7 +199,7 @@ public abstract class Window implements NativeWindow
}
}
if(DEBUG_IMPLEMENTATION) {
- System.err.println("Window.getNativeWindowHandle: locked "+locked+", "+nativeWindow);
+ System.out.println("Window.getNativeWindowHandle: locked "+locked+", "+nativeWindow);
}
}
return handle;
@@ -245,7 +246,8 @@ public abstract class Window implements NativeWindow
"\n, Visible "+isVisible()+
"\n, Undecorated "+undecorated+
"\n, Fullscreen "+fullscreen+
- "\n, WrappedWindow "+getWrappedWindow());
+ "\n, WrappedWindow "+getWrappedWindow()+
+ "\n, ChildWindows "+childWindows.size());
sb.append(", SurfaceUpdatedListeners num "+surfaceUpdatedListeners.size()+" [");
for (Iterator iter = surfaceUpdatedListeners.iterator(); iter.hasNext(); ) {
@@ -301,6 +303,30 @@ public abstract class Window implements NativeWindow
}
protected void requestFocusImpl() {}
+ /**
+ * May set to a {@link FocusRunnable}, {@link FocusRunnable#run()} before Newt requests the native focus.
+ * This allows notifying a covered window toolkit like AWT that the focus is requested,
+ * hence focus traversal can be made transparent.
+ */
+ public void setFocusAction(FocusRunnable focusAction) {
+ this.focusAction = focusAction;
+ }
+ protected boolean focusAction() {
+ if(null!=focusAction) {
+ return focusAction.run();
+ }
+ return false;
+ }
+ protected FocusRunnable focusAction = null;
+
+ public static interface FocusRunnable {
+ /**
+ * @return false if NEWT shall proceed requesting the focus,
+ * true if NEWT shall not request the focus.
+ */
+ public boolean run();
+ }
+
//
// NativeWindow impl
//
@@ -376,41 +402,38 @@ public abstract class Window implements NativeWindow
public void run() {
windowLock();
try {
- if(DEBUG_WINDOW_EVENT) {
- System.err.println("Window.destroy(deep: "+deep+") START "+getThreadName()+", "+this);
+ if(DEBUG_IMPLEMENTATION) {
+ System.out.println("Window.destroy(deep: "+deep+") START "+getThreadName()+", "+Window.this);
}
// Childs first ..
- ArrayList listeners = null;
- synchronized(childWindows) {
- listeners = childWindows;
- }
- for(Iterator i = listeners.iterator(); i.hasNext(); ) {
+ synchronized(childWindowsLock) {
+ for(Iterator i = childWindows.iterator(); i.hasNext(); ) {
NativeWindow nw = (NativeWindow) i.next();
+ System.out.println("Window.destroy(deep: "+deep+") CHILD BEGIN");
if(nw instanceof Window) {
- ((Window)nw).destroy(deep);
+ ((Window)nw).sendWindowEvent(WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY);
+ if(deep) {
+ ((Window)nw).destroy(deep);
+ }
} else {
nw.destroy();
}
+ System.out.println("Window.destroy(deep: "+deep+") CHILD END");
+ }
}
// Now us ..
if(deep) {
- synchronized(childWindows) {
+ synchronized(childWindowsLock) {
childWindows = new ArrayList();
}
- synchronized(surfaceUpdatedListeners) {
+ synchronized(surfaceUpdatedListenersLock) {
surfaceUpdatedListeners = new ArrayList();
}
- synchronized(windowListeners) {
- windowListeners = new ArrayList();
- }
- synchronized(mouseListeners) {
- mouseListeners = new ArrayList();
- }
- synchronized(keyListeners) {
- keyListeners = new ArrayList();
- }
+ windowListeners = new ArrayList();
+ mouseListeners = new ArrayList();
+ keyListeners = new ArrayList();
}
Display dpy = null;
Screen scr = null;
@@ -428,8 +451,8 @@ public abstract class Window implements NativeWindow
dpy.destroy();
}
}
- if(DEBUG_WINDOW_EVENT) {
- System.err.println("Window.destroy(deep: "+deep+") END "+getThreadName()+", "+this);
+ if(DEBUG_IMPLEMENTATION) {
+ System.out.println("Window.destroy(deep: "+deep+") END "+getThreadName()+", "+Window.this);
}
} finally {
windowUnlock();
@@ -466,16 +489,16 @@ public abstract class Window implements NativeWindow
try{
if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) {
String msg = new String("!!! Window Invalidate(deep: "+deep+") "+getThreadName());
- System.err.println(msg);
- //Exception e = new Exception(msg);
- //e.printStackTrace();
+ //System.out.println(msg);
+ Exception e = new Exception(msg);
+ e.printStackTrace();
}
windowHandle = 0;
- visible=false;
- fullscreen=false;
+ visible = false;
+ fullscreen = false;
if(deep) {
- screen = null;
+ screen = null;
parentWindowHandle = 0;
parentNativeWindow = null;
caps = null;
@@ -593,43 +616,6 @@ public abstract class Window implements NativeWindow
return false;
}
- /**
- * If set to true, the default value, this NEWT Window implementation will
- * handle the destruction (ie {@link #destroy()} call) within {@link #windowDestroyNotify()} implementation.<br>
- * If set to false, it's up to the caller/owner to handle destruction within {@link #windowDestroyNotify()}.
- */
- public void setHandleDestroyNotify(boolean b) {
- handleDestroyNotify = b;
- }
-
- protected void windowDestroyNotify() {
- if(DEBUG_WINDOW_EVENT) {
- System.err.println("Window.windowDestroyNotify START "+getThreadName());
- }
-
- enqueueWindowEvent(WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY);
-
- if(handleDestroyNotify && !isDestroyed()) {
- destroy();
- }
-
- if(DEBUG_WINDOW_EVENT) {
- System.err.println("Window.windowDestroyeNotify END "+getThreadName());
- }
- }
-
- protected void windowDestroyed() {
- if(DEBUG_WINDOW_EVENT) {
- System.err.println("Window.windowDestroyed "+getThreadName());
- }
- invalidate();
- }
-
- protected boolean reparentWindowImpl() {
- // default implementation, no native reparenting support
- return false;
- }
-
class ReparentAction implements Runnable {
NativeWindow newParent;
Screen newScreen;
@@ -652,7 +638,7 @@ public abstract class Window implements NativeWindow
}
if(DEBUG_IMPLEMENTATION) {
- System.err.println("reparent: START ("+getThreadName()+") windowHandle "+toHexString(windowHandle)+" parentWindowHandle "+toHexString(parentWindowHandle)+" -> "+toHexString(newParentHandle)+", visible "+visible+", parentNativeWindow "+(null!=parentNativeWindow));
+ System.out.println("reparent: START ("+getThreadName()+") windowHandle "+toHexString(windowHandle)+" parentWindowHandle "+toHexString(parentWindowHandle)+" -> "+toHexString(newParentHandle)+", visible "+visible+", parentNativeWindow "+(null!=parentNativeWindow));
}
if(null!=parentNativeWindow && parentNativeWindow instanceof Window) {
@@ -671,8 +657,16 @@ public abstract class Window implements NativeWindow
x = 0;
y = 0;
}
+ getScreen().getDisplay().dispatchMessages(); // status up2date
+ boolean wasVisible = isVisible();
+ if(wasVisible) {
+ Window.this.visible = false;
+ setVisibleImpl(false);
+ getScreen().getDisplay().dispatchMessages(); // status up2date
+ }
boolean reparentRes = false;
reparentRes = reparentWindowImpl();
+ getScreen().getDisplay().dispatchMessages(); // status up2date
if(!reparentRes) {
parentWindowHandle = 0;
@@ -680,11 +674,17 @@ public abstract class Window implements NativeWindow
if( 0 != windowHandle ) {
destroy(false);
}
+ } else {
+ if(wasVisible) {
+ Window.this.visible = true;
+ setVisibleImpl(true);
+ getScreen().getDisplay().dispatchMessages(); // status up2date
+ }
}
}
if(DEBUG_IMPLEMENTATION) {
- System.err.println("reparentWindow: END ("+getThreadName()+") windowHandle "+toHexString(windowHandle)+", visible: "+visible+", parentWindowHandle "+toHexString(parentWindowHandle)+", parentNativeWindow "+(null!=parentNativeWindow));
+ System.out.println("reparentWindow: END ("+getThreadName()+") windowHandle "+toHexString(windowHandle)+", visible: "+visible+", parentWindowHandle "+toHexString(parentWindowHandle)+", parentNativeWindow "+(null!=parentNativeWindow));
}
} finally {
windowUnlock();
@@ -707,9 +707,10 @@ public abstract class Window implements NativeWindow
public void reparentWindow(NativeWindow newParent, Screen newScreen) {
if(!isDestroyed()) {
runOnEDTIfAvail(true, new ReparentAction(newParent, newScreen));
- // if( isVisible() ) {
- enqueueWindowEvent(true, WindowEvent.EVENT_WINDOW_RESIZED); // trigger a resize/relayout to listener
- // }
+ if( isVisible() ) {
+ sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); // trigger a resize/relayout to listener
+ windowRepaint(0, 0, getWidth(), getHeight());
+ }
}
}
@@ -722,17 +723,15 @@ public abstract class Window implements NativeWindow
windowLock();
try{
if( !isDestroyed() ) {
- ArrayList listeners = null;
- synchronized(childWindows) {
- listeners = childWindows;
- }
- if(!visible && listeners.size()>0) {
- for(Iterator i = listeners.iterator(); i.hasNext(); ) {
+ if(!visible && childWindows.size()>0) {
+ synchronized(childWindowsLock) {
+ for(Iterator i = childWindows.iterator(); i.hasNext(); ) {
NativeWindow nw = (NativeWindow) i.next();
if(nw instanceof Window) {
((Window)nw).setVisible(false);
}
}
+ }
}
if(0==windowHandle && visible) {
Window.this.visible = visible;
@@ -745,18 +744,20 @@ public abstract class Window implements NativeWindow
setVisibleImpl(visible);
}
}
- if(0!=windowHandle && visible && listeners.size()>0) {
- for(Iterator i = listeners.iterator(); i.hasNext(); ) {
+ if(0!=windowHandle && visible && childWindows.size()>0) {
+ synchronized(childWindowsLock) {
+ for(Iterator i = childWindows.iterator(); i.hasNext(); ) {
NativeWindow nw = (NativeWindow) i.next();
if(nw instanceof Window) {
((Window)nw).setVisible(true);
}
}
+ }
}
}
if(DEBUG_IMPLEMENTATION) {
- System.err.println("Window setVisible: END ("+getThreadName()+") "+x+"/"+y+" "+width+"x"+height+", fs "+fullscreen+", windowHandle "+toHexString(windowHandle)+", visible: "+Window.this.visible);
+ System.out.println("Window setVisible: END ("+getThreadName()+") "+x+"/"+y+" "+width+"x"+height+", fs "+fullscreen+", windowHandle "+toHexString(windowHandle)+", visible: "+Window.this.visible);
}
} finally {
windowUnlock();
@@ -792,7 +793,7 @@ public abstract class Window implements NativeWindow
public void setVisible(boolean visible) {
if(DEBUG_IMPLEMENTATION) {
String msg = new String("Window setVisible: START ("+getThreadName()+") "+x+"/"+y+" "+width+"x"+height+", fs "+fullscreen+", windowHandle "+toHexString(windowHandle)+", visible: "+this.visible+" -> "+visible+", parentWindowHandle "+toHexString(parentWindowHandle)+", parentNativeWindow "+(null!=parentNativeWindow));
- //System.err.println(msg);
+ //System.out.println(msg);
Exception ee = new Exception(msg);
ee.printStackTrace();
}
@@ -829,7 +830,7 @@ public abstract class Window implements NativeWindow
try{
if(DEBUG_IMPLEMENTATION) {
String msg = new String("Window setSize: START "+this.width+"x"+this.height+" -> "+width+"x"+height+", fs "+fullscreen+", windowHandle "+toHexString(windowHandle)+", visible "+visible);
- //System.err.println(msg);
+ //System.out.println(msg);
Exception e = new Exception(msg);
e.printStackTrace();
}
@@ -846,7 +847,7 @@ public abstract class Window implements NativeWindow
this.width = width;
this.height = height;
} else if ( 0 != windowHandle ) {
- // this width/height will be set by windowChanged, called by X11
+ // this width/height will be set by windowChanged, called by the native implementation
setSizeImpl(width, height);
} else {
this.width = width;
@@ -855,7 +856,7 @@ public abstract class Window implements NativeWindow
}
}
if(DEBUG_IMPLEMENTATION) {
- System.err.println("Window setSize: END "+this.width+"x"+this.height+", visibleAction "+visibleAction);
+ System.out.println("Window setSize: END "+this.width+"x"+this.height+", visibleAction "+visibleAction);
}
} finally {
windowUnlock();
@@ -880,7 +881,7 @@ public abstract class Window implements NativeWindow
windowLock();
try{
if(DEBUG_IMPLEMENTATION) {
- System.err.println("Window setPosition: "+this.x+"/"+this.y+" -> "+x+"/"+y+", fs "+fullscreen+", windowHandle "+toHexString(windowHandle));
+ System.out.println("Window setPosition: "+this.x+"/"+this.y+" -> "+x+"/"+y+", fs "+fullscreen+", windowHandle "+toHexString(windowHandle));
}
if ( this.x != x || this.y != y ) {
if(!fullscreen) {
@@ -911,34 +912,42 @@ public abstract class Window implements NativeWindow
w = screen.getWidth();
h = screen.getHeight();
} else {
- x = nfs_x;
- y = nfs_y;
+ if(0!=parentWindowHandle) {
+ x=0;
+ y=0;
+ } else {
+ x = nfs_x;
+ y = nfs_y;
+ }
w = nfs_width;
h = nfs_height;
}
if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) {
- System.err.println("X11Window fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h+", "+isUndecorated());
+ System.out.println("X11Window fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h+", "+isUndecorated());
}
- this.fullscreen = setFullscreenImpl(fullscreen, x, y, w, h);
+ this.fullscreen = fullscreen;
+ setFullscreenImpl(fullscreen, x, y, w, h);
}
- return this.fullscreen;
} finally {
windowUnlock();
}
+ if( isVisible() ) {
+ windowRepaint(0, 0, getWidth(), getHeight());
+ }
+ return this.fullscreen;
}
- protected abstract boolean setFullscreenImpl(boolean fullscreen, int x, int y, int widht, int height);
+ protected abstract void setFullscreenImpl(boolean fullscreen, int x, int y, int widht, int height);
//
// Child Window Management
//
private ArrayList childWindows = new ArrayList();
+ private Object childWindowsLock = new Object();
protected void removeChild(NativeWindow win) {
- synchronized(childWindows) {
- ArrayList newChildWindows = (ArrayList) childWindows.clone();
- newChildWindows.remove(win);
- childWindows = newChildWindows;
+ synchronized(childWindowsLock) {
+ childWindows.remove(win);
}
}
@@ -946,34 +955,72 @@ public abstract class Window implements NativeWindow
if (win == null) {
return;
}
- synchronized(childWindows) {
- ArrayList newChildWindows = (ArrayList) childWindows.clone();
- newChildWindows.add(win);
- childWindows = newChildWindows;
+ synchronized(childWindowsLock) {
+ childWindows.add(win);
}
}
//
// Generic Event Support
//
+ private void doEvent(boolean enqueue, boolean wait, com.jogamp.newt.event.NEWTEvent event) {
+ boolean done = false;
+
+ if(!enqueue) {
+ done = consumeEvent(event);
+ wait = done; // don't wait if event can't be consumed now
+ }
- public void sendEvent(NEWTEvent e) {
+ if(!done) {
+ enqueueEvent(wait, event);
+ }
+ }
+
+ public void enqueueEvent(boolean wait, com.jogamp.newt.event.NEWTEvent event) {
+ if(!getInnerWindow().isDestroyed()) {
+ getInnerWindow().getScreen().getDisplay().enqueueEvent(wait, event);
+ }
+ }
+
+ public boolean consumeEvent(NEWTEvent e) {
+ switch(e.getEventType()) {
+ case WindowEvent.EVENT_WINDOW_REPAINT:
+ if( windowIsLocked() ) {
+ if(!repaintQueued) {
+ repaintQueued=true;
+ return false;
+ } else {
+ return true;
+ }
+ } else {
+ if(DEBUG_IMPLEMENTATION) {
+ System.out.println("Window.windowRepaint: "+e);
+ // Exception ee = new Exception("Window.windowRepaint: "+e);
+ // ee.printStackTrace();
+ }
+ repaintQueued=false;
+ }
+ break;
+ default:
+ break;
+ }
if(e instanceof WindowEvent) {
- sendWindowEvent((WindowEvent)e);
+ getInnerWindow().consumeWindowEvent((WindowEvent)e);
} else if(e instanceof KeyEvent) {
- sendKeyEvent((KeyEvent)e);
+ getInnerWindow().consumeKeyEvent((KeyEvent)e);
} else if(e instanceof MouseEvent) {
- sendMouseEvent((MouseEvent)e);
- } else if(e instanceof PaintEvent) {
- sendPaintEvent((PaintEvent)e);
+ getInnerWindow().consumeMouseEvent((MouseEvent)e);
}
+ return true;
}
+ protected boolean repaintQueued = false;
//
// SurfaceUpdatedListener Support
//
private ArrayList surfaceUpdatedListeners = new ArrayList();
+ private Object surfaceUpdatedListenersLock = new Object();
/**
* Appends the given {@link com.jogamp.newt.event.SurfaceUpdatedListener} to the end of
@@ -999,13 +1046,11 @@ public abstract class Window implements NativeWindow
if(l == null) {
return;
}
- synchronized(surfaceUpdatedListeners) {
+ synchronized(surfaceUpdatedListenersLock) {
if(0>index) {
index = surfaceUpdatedListeners.size();
}
- ArrayList newSurfaceUpdatedListeners = (ArrayList) surfaceUpdatedListeners.clone();
- newSurfaceUpdatedListeners.add(index, l);
- surfaceUpdatedListeners = newSurfaceUpdatedListeners;
+ surfaceUpdatedListeners.add(index, l);
}
}
@@ -1013,21 +1058,19 @@ public abstract class Window implements NativeWindow
if (l == null) {
return;
}
- synchronized(surfaceUpdatedListeners) {
- ArrayList newSurfaceUpdatedListeners = (ArrayList) surfaceUpdatedListeners.clone();
- newSurfaceUpdatedListeners.remove(l);
- surfaceUpdatedListeners = newSurfaceUpdatedListeners;
+ synchronized(surfaceUpdatedListenersLock) {
+ surfaceUpdatedListeners.remove(l);
}
}
public void removeAllSurfaceUpdatedListener() {
- synchronized(surfaceUpdatedListeners) {
+ synchronized(surfaceUpdatedListenersLock) {
surfaceUpdatedListeners = new ArrayList();
}
}
public SurfaceUpdatedListener getSurfaceUpdatedListener(int index) {
- synchronized(surfaceUpdatedListeners) {
+ synchronized(surfaceUpdatedListenersLock) {
if(0>index) {
index = surfaceUpdatedListeners.size()-1;
}
@@ -1036,19 +1079,17 @@ public abstract class Window implements NativeWindow
}
public SurfaceUpdatedListener[] getSurfaceUpdatedListeners() {
- synchronized(surfaceUpdatedListeners) {
+ synchronized(surfaceUpdatedListenersLock) {
return (SurfaceUpdatedListener[]) surfaceUpdatedListeners.toArray();
}
}
public void surfaceUpdated(Object updater, NativeWindow window, long when) {
- ArrayList listeners = null;
- synchronized(surfaceUpdatedListeners) {
- listeners = surfaceUpdatedListeners;
- }
- for(Iterator i = listeners.iterator(); i.hasNext(); ) {
+ synchronized(surfaceUpdatedListenersLock) {
+ for(Iterator i = surfaceUpdatedListeners.iterator(); i.hasNext(); ) {
SurfaceUpdatedListener l = (SurfaceUpdatedListener) i.next();
l.surfaceUpdated(updater, window, when);
+ }
}
}
@@ -1061,13 +1102,21 @@ public abstract class Window implements NativeWindow
private int lastMouseClickCount = 0; // last mouse button click count
public static final int ClickTimeout = 300;
- protected void enqueueMouseEvent(int eventType, int modifiers,
+ public void sendMouseEvent(int eventType, int modifiers,
+ int x, int y, int button, int 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, int rotation) {
+ doMouseEvent(true, wait, eventType, modifiers, x, y, button, rotation);
+ }
+ private void doMouseEvent(boolean enqueue, boolean wait, int eventType, int modifiers,
+ int x, int y, int button, int rotation) {
if(x<0||y<0||x>=width||y>=height) {
return; // .. invalid ..
}
if(DEBUG_MOUSE_EVENT) {
- System.err.println("enqueueMouseEvent: "+MouseEvent.getEventTypeString(eventType)+
+ System.out.println("doMouseEvent: enqueue"+enqueue+", wait "+wait+", "+MouseEvent.getEventTypeString(eventType)+
", mod "+modifiers+", pos "+x+"/"+y+", button "+button);
}
if(button<0||button>MouseEvent.BUTTON_NUMBER) {
@@ -1111,12 +1160,12 @@ public abstract class Window implements NativeWindow
} else {
e = new MouseEvent(eventType, this, when, modifiers, x, y, 0, button, 0);
}
- screen.getDisplay().enqueueEvent(e);
+ doEvent(enqueue, wait, e);
if(null!=eClicked) {
if(DEBUG_MOUSE_EVENT) {
- System.err.println("enqueueMouseEvent: synthesized MOUSE_CLICKED event");
+ System.out.println("doMouseEvent: synthesized MOUSE_CLICKED event");
}
- screen.getDisplay().enqueueEvent(eClicked);
+ doEvent(enqueue, wait, eClicked);
}
}
@@ -1143,52 +1192,41 @@ public abstract class Window implements NativeWindow
if(l == null) {
return;
}
- synchronized(mouseListeners) {
- if(0>index) {
- index = mouseListeners.size();
- }
- ArrayList newMouseListeners = (ArrayList) mouseListeners.clone();
- newMouseListeners.add(index, l);
- mouseListeners = newMouseListeners;
+ ArrayList clonedListeners = (ArrayList) mouseListeners.clone();
+ if(0>index) {
+ index = clonedListeners.size();
}
+ clonedListeners.add(index, l);
+ mouseListeners = clonedListeners;
}
public void removeMouseListener(MouseListener l) {
if (l == null) {
return;
}
- synchronized(mouseListeners) {
- ArrayList newMouseListeners = (ArrayList) mouseListeners.clone();
- newMouseListeners.remove(l);
- mouseListeners = newMouseListeners;
- }
+ ArrayList clonedListeners = (ArrayList) mouseListeners.clone();
+ clonedListeners.remove(l);
+ mouseListeners = clonedListeners;
}
public MouseListener getMouseListener(int index) {
- synchronized(mouseListeners) {
- if(0>index) {
- index = mouseListeners.size()-1;
- }
- return (MouseListener) mouseListeners.get(index);
+ ArrayList clonedListeners = (ArrayList) mouseListeners.clone();
+ if(0>index) {
+ index = clonedListeners.size()-1;
}
+ return (MouseListener) clonedListeners.get(index);
}
public MouseListener[] getMouseListeners() {
- synchronized(mouseListeners) {
- return (MouseListener[]) mouseListeners.toArray();
- }
+ return (MouseListener[]) mouseListeners.toArray();
}
- protected void sendMouseEvent(MouseEvent e) {
+ protected void consumeMouseEvent(MouseEvent e) {
if(DEBUG_MOUSE_EVENT) {
- System.err.println("sendMouseEvent: event: "+e);
+ System.out.println("consumeMouseEvent: event: "+e);
}
- ArrayList listeners = null;
- synchronized(mouseListeners) {
- listeners = mouseListeners;
- }
- for(Iterator i = listeners.iterator(); i.hasNext(); ) {
+ for(Iterator i = mouseListeners.iterator(); i.hasNext(); ) {
MouseListener l = (MouseListener) i.next();
switch(e.getEventType()) {
case MouseEvent.EVENT_MOUSE_CLICKED:
@@ -1225,10 +1263,12 @@ public abstract class Window implements NativeWindow
// KeyListener/Event Support
//
- protected void enqueueKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) {
- screen.getDisplay().enqueueEvent(
- new KeyEvent(eventType, this, System.currentTimeMillis(),
- modifiers, keyCode, keyChar) );
+ public void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) {
+ consumeKeyEvent(new KeyEvent(eventType, this, System.currentTimeMillis(), modifiers, keyCode, keyChar) );
+ }
+
+ public void enqueueKeyEvent(boolean wait, int eventType, int modifiers, int keyCode, char keyChar) {
+ enqueueEvent(wait, new KeyEvent(eventType, this, System.currentTimeMillis(), modifiers, keyCode, keyChar) );
}
/**
@@ -1253,53 +1293,42 @@ public abstract class Window implements NativeWindow
if(l == null) {
return;
}
- synchronized(keyListeners) {
- if(0>index) {
- index = keyListeners.size();
- }
- ArrayList newKeyListeners = (ArrayList) keyListeners.clone();
- newKeyListeners.add(index, l);
- keyListeners = newKeyListeners;
+ ArrayList clonedListeners = (ArrayList) keyListeners.clone();
+ if(0>index) {
+ index = clonedListeners.size();
}
+ clonedListeners.add(index, l);
+ keyListeners = clonedListeners;
}
public void removeKeyListener(KeyListener l) {
if (l == null) {
return;
}
- synchronized(keyListeners) {
- ArrayList newKeyListeners = (ArrayList) keyListeners.clone();
- newKeyListeners.remove(l);
- keyListeners = newKeyListeners;
- }
+ ArrayList clonedListeners = (ArrayList) keyListeners.clone();
+ clonedListeners.remove(l);
+ keyListeners = clonedListeners;
}
public KeyListener getKeyListener(int index) {
- synchronized(keyListeners) {
- if(0>index) {
- index = keyListeners.size()-1;
- }
- return (KeyListener) keyListeners.get(index);
+ ArrayList clonedListeners = (ArrayList) keyListeners.clone();
+ if(0>index) {
+ index = clonedListeners.size()-1;
}
+ return (KeyListener) clonedListeners.get(index);
}
public KeyListener[] getKeyListeners() {
- synchronized(keyListeners) {
- return (KeyListener[]) keyListeners.toArray();
- }
+ return (KeyListener[]) keyListeners.toArray();
}
private ArrayList keyListeners = new ArrayList();
- protected void sendKeyEvent(KeyEvent e) {
+ protected void consumeKeyEvent(KeyEvent e) {
if(DEBUG_KEY_EVENT) {
- System.err.println("sendKeyEvent: "+e);
- }
- ArrayList listeners = null;
- synchronized(keyListeners) {
- listeners = keyListeners;
+ System.out.println("consumeKeyEvent: "+e);
}
- for(Iterator i = listeners.iterator(); i.hasNext(); ) {
+ for(Iterator i = keyListeners.iterator(); i.hasNext(); ) {
KeyListener l = (KeyListener) i.next();
switch(e.getEventType()) {
case KeyEvent.EVENT_KEY_PRESSED:
@@ -1320,14 +1349,12 @@ public abstract class Window implements NativeWindow
//
// WindowListener/Event Support
//
- protected void enqueueWindowEvent(int eventType) {
- enqueueWindowEvent(false, eventType);
+ public void sendWindowEvent(int eventType) {
+ consumeWindowEvent( new WindowEvent(eventType, this, System.currentTimeMillis()) );
}
- protected void enqueueWindowEvent(boolean wait, int eventType) {
- WindowEvent event = new WindowEvent(eventType, this, System.currentTimeMillis());
- screen.getDisplay().enqueueEvent( wait, event );
- // sendWindowEvent ( event ); // FIXME: Think about performance/lag .. ?
+ public void enqueueWindowEvent(boolean wait, int eventType) {
+ enqueueEvent( wait, new WindowEvent(eventType, this, System.currentTimeMillis()) );
}
private ArrayList windowListeners = new ArrayList();
@@ -1356,51 +1383,40 @@ public abstract class Window implements NativeWindow
if(l == null) {
return;
}
- synchronized(windowListeners) {
- if(0>index) {
- index = windowListeners.size();
- }
- ArrayList newWindowListeners = (ArrayList) windowListeners.clone();
- newWindowListeners.add(index, l);
- windowListeners = newWindowListeners;
+ ArrayList clonedListeners = (ArrayList) windowListeners.clone();
+ if(0>index) {
+ index = clonedListeners.size();
}
+ clonedListeners.add(index, l);
+ windowListeners = clonedListeners;
}
public void removeWindowListener(WindowListener l) {
if (l == null) {
return;
}
- synchronized(windowListeners) {
- ArrayList newWindowListeners = (ArrayList) windowListeners.clone();
- newWindowListeners.remove(l);
- windowListeners = newWindowListeners;
- }
+ ArrayList clonedListeners = (ArrayList) windowListeners.clone();
+ clonedListeners.remove(l);
+ windowListeners = clonedListeners;
}
public WindowListener getWindowListener(int index) {
- synchronized(windowListeners) {
- if(0>index) {
- index = windowListeners.size()-1;
- }
- return (WindowListener) windowListeners.get(index);
+ ArrayList clonedListeners = (ArrayList) windowListeners.clone();
+ if(0>index) {
+ index = clonedListeners.size()-1;
}
+ return (WindowListener) clonedListeners.get(index);
}
public WindowListener[] getWindowListeners() {
- synchronized(windowListeners) {
- return (WindowListener[]) windowListeners.toArray();
- }
+ return (WindowListener[]) windowListeners.toArray();
}
- protected void sendWindowEvent(WindowEvent e) {
+ protected void consumeWindowEvent(WindowEvent e) {
if(DEBUG_WINDOW_EVENT) {
- System.err.println("sendWindowEvent: "+e);
- }
- ArrayList listeners = null;
- synchronized(windowListeners) {
- listeners = windowListeners;
+ System.out.println("consumeWindowEvent: "+e);
}
- for(Iterator i = listeners.iterator(); i.hasNext(); ) {
+ for(Iterator i = windowListeners.iterator(); i.hasNext(); ) {
WindowListener l = (WindowListener) i.next();
switch(e.getEventType()) {
case WindowEvent.EVENT_WINDOW_RESIZED:
@@ -1418,6 +1434,9 @@ public abstract class Window implements NativeWindow
case WindowEvent.EVENT_WINDOW_LOST_FOCUS:
l.windowLostFocus(e);
break;
+ case WindowEvent.EVENT_WINDOW_REPAINT:
+ l.windowRepaint((WindowUpdateEvent)e);
+ break;
default:
throw
new NativeWindowException("Unexpected window event type "
@@ -1426,78 +1445,116 @@ public abstract class Window implements NativeWindow
}
}
-
- //
- // PaintListener/Event Support
- //
-
- private ArrayList paintListeners = new ArrayList();
-
- /**
- * Appends the given {@link com.jogamp.newt.event.PaintListener} to the end of
- * the list.
+ /**
+ * @param focusGained
*/
- public void addPaintListener(PaintListener l) {
- getInnerWindow().addPaintListener(-1, l);
+ protected void focusChanged(boolean focusGained) {
+ if(DEBUG_IMPLEMENTATION) {
+ System.out.println("Window.focusChanged: "+focusGained);
+ }
+ if (focusGained) {
+ sendWindowEvent(WindowEvent.EVENT_WINDOW_GAINED_FOCUS);
+ } else {
+ sendWindowEvent(WindowEvent.EVENT_WINDOW_LOST_FOCUS);
+ }
}
- /**
- * Inserts the given {@link com.jogamp.newt.event.PaintListener} at the
- * specified position in the list.<br>
+ protected void visibleChanged(boolean visible) {
+ if(DEBUG_IMPLEMENTATION) {
+ System.out.println("Window.visibleChanged: "+this.visible+" -> "+visible);
+ }
+ this.visible = visible ;
+ }
- * @param index Position where the listener will be inserted.
- * Should be within (0 <= index && index <= size()).
- * An index value of -1 is interpreted as the end of the list, size().
- * @param l The listener object to be inserted
- * @throws IndexOutOfBoundsException If the index is not within (0 <= index && index <= size()), or -1
- */
- public void addPaintListener(int index, PaintListener l) {
- if(l == null) {
- return;
+ protected void sizeChanged(int newWidth, int newHeight) {
+ if(DEBUG_IMPLEMENTATION) {
+ System.out.println("Window.sizeChanged: "+width+"x"+height+" -> "+newWidth+"x"+newHeight);
+ }
+ if(width != newWidth || height != newHeight) {
+ width = newWidth;
+ height = newHeight;
+ if(!fullscreen) {
+ nfs_width=width;
+ nfs_height=height;
+ }
+ sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED);
}
- synchronized(paintListeners) {
- if(0>index) {
- index = paintListeners.size();
+ }
+
+ protected void positionChanged(int newX, int newY) {
+ if(DEBUG_IMPLEMENTATION) {
+ System.out.println("Window.positionChanged: "+x+"/"+y+" -> "+newX+"/"+newY);
+ }
+ if( 0==parentWindowHandle && ( x != newX || y != newY ) ) {
+ x = newX;
+ y = newY;
+ if(!fullscreen) {
+ nfs_x=x;
+ nfs_y=y;
}
- ArrayList newPaintListeners = (ArrayList) paintListeners.clone();
- newPaintListeners.add(index, l);
- paintListeners = newPaintListeners;
+ sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED);
}
}
- public void removePaintListener(PaintListener l) {
- if (l == null) {
- return;
+ /**
+ * If set to true, the default value, this NEWT Window implementation will
+ * handle the destruction (ie {@link #destroy()} call) within {@link #windowDestroyNotify()} implementation.<br>
+ * If set to false, it's up to the caller/owner to handle destruction within {@link #windowDestroyNotify()}.
+ */
+ public void setHandleDestroyNotify(boolean b) {
+ handleDestroyNotify = b;
+ }
+
+ protected void windowDestroyNotify() {
+ if(DEBUG_IMPLEMENTATION) {
+ System.out.println("Window.windowDestroyNotify START "+getThreadName());
}
- synchronized(paintListeners) {
- ArrayList newPaintListeners = (ArrayList) paintListeners.clone();
- newPaintListeners.remove(l);
- paintListeners = newPaintListeners;
+
+ enqueueWindowEvent(false, WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY);
+
+ if(handleDestroyNotify && !isDestroyed()) {
+ destroy();
+ }
+
+ if(DEBUG_IMPLEMENTATION) {
+ System.out.println("Window.windowDestroyeNotify END "+getThreadName());
}
}
- public PaintListener getPaintListener(int index) {
- synchronized(paintListeners) {
- if(0>index) {
- index = paintListeners.size()-1;
- }
- return (PaintListener) paintListeners.get(index);
+ protected void windowDestroyed() {
+ if(DEBUG_IMPLEMENTATION) {
+ System.out.println("Window.windowDestroyed "+getThreadName());
}
+ invalidate();
}
- protected void sendPaintEvent(int eventType, int x, int y, int w, int h) {
- sendPaintEvent( new PaintEvent(eventType, this, System.currentTimeMillis(), x, y, w, h) );
+ public boolean getPropagateRepaint() {
+ return propagateRepaint;
+ }
+ public void setPropagateRepaint(boolean v) {
+ propagateRepaint = v;
}
+ protected boolean propagateRepaint = true;
- protected void sendPaintEvent(PaintEvent e) {
- ArrayList listeners = null;
- synchronized(paintListeners) {
- listeners = paintListeners;
+ public void windowRepaint(int x, int y, int width, int height) {
+ if(!propagateRepaint) {
+ return;
}
- for(Iterator i = listeners.iterator(); i.hasNext(); ) {
- PaintListener l = (PaintListener) i.next();
- l.exposed(e);
+ if(0>width) {
+ width=this.width;
}
+ if(0>height) {
+ height=this.height;
+ }
+
+ NEWTEvent e = new WindowUpdateEvent(WindowEvent.EVENT_WINDOW_REPAINT, this, System.currentTimeMillis(),
+ new Rectangle(x, y, width, height));
+ doEvent(false, false, e);
+ }
+
+ protected boolean reparentWindowImpl() {
+ // default implementation, no native reparenting support
+ return false;
}
//
diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
index a84e571e4..6fd924e66 100644
--- a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
+++ b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
@@ -35,13 +35,21 @@ package com.jogamp.newt.awt;
import java.lang.reflect.*;
import java.security.*;
+import java.awt.Button;
import java.awt.Canvas;
+import java.awt.Component;
+import java.awt.EventQueue;
+import java.awt.Frame;
+import java.awt.Graphics;
import javax.media.nativewindow.*;
-// import javax.media.nativewindow.awt.*;
import com.jogamp.newt.event.awt.AWTAdapter;
import com.jogamp.newt.event.awt.AWTParentWindowAdapter;
+import com.jogamp.newt.event.WindowEvent;
+import com.jogamp.newt.event.WindowAdapter;
+import com.jogamp.newt.event.MouseEvent;
+import com.jogamp.newt.event.MouseAdapter;
import com.jogamp.newt.Screen;
import com.jogamp.newt.Window;
import com.jogamp.newt.impl.Debug;
@@ -68,10 +76,38 @@ public class NewtCanvasAWT extends java.awt.Canvas {
setNEWTChild(child);
}
+ class FocusAction implements Window.FocusRunnable {
+ public boolean run() {
+ if ( EventQueue.isDispatchThread() ) {
+ focusActionImpl.run();
+ } else {
+ try {
+ EventQueue.invokeAndWait(focusActionImpl);
+ } catch (Exception e) {
+ throw new NativeWindowException(e);
+ }
+ }
+ return focusActionImpl.result;
+ }
+
+ class FocusActionImpl implements Runnable {
+ public final boolean result = false; // NEWT shall always proceed requesting the native focus
+ public void run() {
+ if(DEBUG_IMPLEMENTATION) {
+ System.out.println("FocusActionImpl.run() "+Window.getThreadName());
+ }
+ NewtCanvasAWT.this.requestFocusAWT();
+ }
+ }
+ FocusActionImpl focusActionImpl = new FocusActionImpl();
+ }
+ FocusAction focusAction = new FocusAction();
+
/** sets a new NEWT child, provoking reparenting on the NEWT level. */
public NewtCanvasAWT setNEWTChild(Window child) {
if(newtChild!=child) {
newtChild = child;
+ newtChild.setFocusAction(focusAction);
if(null!=parent) {
java.awt.Container cont = getContainer(this);
// reparent right away, addNotify has been called already
@@ -101,12 +137,12 @@ public class NewtCanvasAWT extends java.awt.Canvas {
}
static java.awt.Container getContainer(java.awt.Component comp) {
- while( null != comp && !(comp instanceof java.awt.Container) ) {
+ while( null != comp ) {
+ if( comp instanceof java.awt.Container ) {
+ return (java.awt.Container) comp;
+ }
comp = comp.getParent();
}
- if(comp instanceof java.awt.Container) {
- return (java.awt.Container) comp;
- }
return null;
}
@@ -117,7 +153,8 @@ public class NewtCanvasAWT extends java.awt.Canvas {
if(DEBUG_IMPLEMENTATION) {
// if ( isShowing() == false ) -> Container was not visible yet.
// if ( isShowing() == true ) -> Container is already visible.
- System.err.println("NewtCanvasAWT.addNotify: "+newtChild+", "+this+", visible "+isVisible()+", showing "+isShowing()+", displayable "+isDisplayable()+" -> "+cont);
+ System.err.println("NewtCanvasAWT.addNotify: "+newtChild+", "+this+", visible "+isVisible()+", showing "+isShowing()+
+ ", displayable "+isDisplayable()+" -> "+cont);
}
reparentWindow(true, cont);
}
@@ -154,6 +191,8 @@ public class NewtCanvasAWT extends java.awt.Canvas {
newtChild.reparentWindow(parent, screen);
newtChild.setVisible(true);
setWindowAdapter(true);
+ newtChild.sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); // trigger a resize/relayout to listener
+ newtChild.windowRepaint(0, 0, newtChild.getWidth(), newtChild.getHeight());
}
} else {
setWindowAdapter(false);
@@ -161,7 +200,61 @@ public class NewtCanvasAWT extends java.awt.Canvas {
newtChild.setVisible(false);
newtChild.reparentWindow(null, null);
}
- }
+ }
+
+ public void paint(Graphics g) {
+ if(null!=newtChild) {
+ newtChild.windowRepaint(0, 0, getWidth(), getHeight());
+ }
+ }
+ public void update(Graphics g) {
+ if(null!=newtChild) {
+ newtChild.windowRepaint(0, 0, getWidth(), getHeight());
+ }
+ }
+
+ void requestFocusAWT() {
+ super.requestFocus();
+ }
+
+ public void requestFocus() {
+ super.requestFocus();
+ if(null!=newtChild) {
+ newtChild.setFocusAction(null);
+ newtChild.requestFocus();
+ newtChild.setFocusAction(focusAction);
+ }
+ }
+
+ public boolean requestFocus(boolean temporary) {
+ boolean res = super.requestFocus(temporary);
+ if(res && null!=newtChild) {
+ newtChild.setFocusAction(null);
+ newtChild.requestFocus();
+ newtChild.setFocusAction(focusAction);
+ }
+ return res;
+ }
+
+ public boolean requestFocusInWindow() {
+ boolean res = super.requestFocusInWindow();
+ if(res && null!=newtChild) {
+ newtChild.setFocusAction(null);
+ newtChild.requestFocus();
+ newtChild.setFocusAction(focusAction);
+ }
+ return res;
+ }
+
+ public boolean requestFocusInWindow(boolean temporary) {
+ boolean res = super.requestFocusInWindow(temporary);
+ if(res && null!=newtChild) {
+ newtChild.setFocusAction(null);
+ newtChild.requestFocus();
+ newtChild.setFocusAction(focusAction);
+ }
+ return res;
+ }
// Disables the AWT's erasing of this Canvas's background on Windows
// in Java SE 6. This internal API is not available in previous
diff --git a/src/newt/classes/com/jogamp/newt/event/NEWTEvent.java b/src/newt/classes/com/jogamp/newt/event/NEWTEvent.java
index 2cb2c5177..9afcb840c 100644
--- a/src/newt/classes/com/jogamp/newt/event/NEWTEvent.java
+++ b/src/newt/classes/com/jogamp/newt/event/NEWTEvent.java
@@ -57,9 +57,6 @@ public class NEWTEvent extends java.util.EventObject {
// 2: MouseEvent.java
// 3: com.jogamp.newt.Window
// 3: com.jogamp.newt.event.awt.AWTNewtEventFactory
- // 1: PaintEvent.java
- // 2: com.jogamp.newt.Window
- // 2: com.jogamp.newt.event.awt.AWTNewtEventFactory
// 1: WindowEvent.java
// 2: com.jogamp.newt.Window
// 2: com.jogamp.newt.event.awt.AWTNewtEventFactory
@@ -80,8 +77,7 @@ public class NEWTEvent extends java.util.EventObject {
String clazzName = null;
- if( (event instanceof com.jogamp.newt.event.WindowEvent) ||
- (event instanceof com.jogamp.newt.event.PaintEvent) ) {
+ if( event instanceof com.jogamp.newt.event.WindowEvent ) {
if ( stack.length > 2 ) {
clazzName = stack[2].getClassName();
}
@@ -127,7 +123,7 @@ public class NEWTEvent extends java.util.EventObject {
/**
* Attach the passed object to this event.<br>
- * If an object was previously attached, it will replaced.<br>
+ * If an object was previously attached, it will be replaced.<br>
* Attachments to NEWT events allow users to pass on information
* from one custom listener to another, ie custom listener to listener
* communication.
diff --git a/src/newt/classes/com/jogamp/newt/event/PaintListener.java b/src/newt/classes/com/jogamp/newt/event/NEWTEventConsumer.java
index f64ae0069..e37c820a1 100755..100644
--- a/src/newt/classes/com/jogamp/newt/event/PaintListener.java
+++ b/src/newt/classes/com/jogamp/newt/event/NEWTEventConsumer.java
@@ -1,21 +1,21 @@
/*
- * Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved.
- *
+ * Copyright (c) 2010 Sven Gothel. All Rights Reserved.
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
- *
+ *
* - Redistribution of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
- *
+ *
* - Redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
+ *
+ * Neither the name Sven Gothel or the names of
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
- *
+ *
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
@@ -27,18 +27,17 @@
* DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
- * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
+ * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
-
package com.jogamp.newt.event;
-import com.jogamp.newt.*;
+public interface NEWTEventConsumer {
-/**
- *
- * @author tdv
- */
-public interface PaintListener {
- public void exposed(PaintEvent e);
+ /**
+ * Consume the event
+ *
+ * @return true if the event can be consumed now,
+ * otherwise propagate it later.
+ */
+ public boolean consumeEvent(NEWTEvent event);
}
diff --git a/src/newt/classes/com/jogamp/newt/event/TraceWindowAdapter.java b/src/newt/classes/com/jogamp/newt/event/TraceWindowAdapter.java
index 5a93bca36..fb9e1877a 100644
--- a/src/newt/classes/com/jogamp/newt/event/TraceWindowAdapter.java
+++ b/src/newt/classes/com/jogamp/newt/event/TraceWindowAdapter.java
@@ -65,4 +65,8 @@ public class TraceWindowAdapter implements WindowListener {
System.out.println(e);
if(null!=downstream) { downstream.windowLostFocus(e); }
}
+ public void windowRepaint(WindowUpdateEvent e) {
+ System.out.println(e);
+ if(null!=downstream) { downstream.windowRepaint(e); }
+ }
}
diff --git a/src/newt/classes/com/jogamp/newt/event/WindowAdapter.java b/src/newt/classes/com/jogamp/newt/event/WindowAdapter.java
index 51732789e..587622a81 100644
--- a/src/newt/classes/com/jogamp/newt/event/WindowAdapter.java
+++ b/src/newt/classes/com/jogamp/newt/event/WindowAdapter.java
@@ -45,4 +45,6 @@ public abstract class WindowAdapter implements WindowListener
}
public void windowLostFocus(WindowEvent e) {
}
+ public void windowRepaint(WindowUpdateEvent e) {
+ }
}
diff --git a/src/newt/classes/com/jogamp/newt/event/WindowEvent.java b/src/newt/classes/com/jogamp/newt/event/WindowEvent.java
index e542c467f..5221b3664 100644
--- a/src/newt/classes/com/jogamp/newt/event/WindowEvent.java
+++ b/src/newt/classes/com/jogamp/newt/event/WindowEvent.java
@@ -46,7 +46,7 @@ public class WindowEvent extends NEWTEvent {
public static final int EVENT_WINDOW_DESTROY_NOTIFY = 102;
public static final int EVENT_WINDOW_GAINED_FOCUS = 103;
public static final int EVENT_WINDOW_LOST_FOCUS = 104;
- // public static final int EVENT_WINDOW_REPAINT = 105; // TODO
+ public static final int EVENT_WINDOW_REPAINT = 105;
public WindowEvent(int eventType, Object source, long when) {
super(eventType, source, when);
@@ -59,7 +59,7 @@ public class WindowEvent extends NEWTEvent {
case EVENT_WINDOW_DESTROY_NOTIFY: return "EVENT_WINDOW_DESTROY_NOTIFY";
case EVENT_WINDOW_GAINED_FOCUS: return "EVENT_WINDOW_GAINED_FOCUS";
case EVENT_WINDOW_LOST_FOCUS: return "EVENT_WINDOW_LOST_FOCUS";
- // case EVENT_WINDOW_REPAINT: return "EVENT_WINDOW_REPAINT";
+ case EVENT_WINDOW_REPAINT: return "EVENT_WINDOW_REPAINT";
default: return "unknown (" + type + ")";
}
}
diff --git a/src/newt/classes/com/jogamp/newt/event/WindowListener.java b/src/newt/classes/com/jogamp/newt/event/WindowListener.java
index 871f0fe12..1a10131f7 100644
--- a/src/newt/classes/com/jogamp/newt/event/WindowListener.java
+++ b/src/newt/classes/com/jogamp/newt/event/WindowListener.java
@@ -41,4 +41,5 @@ public interface WindowListener extends NEWTEventListener {
public void windowDestroyNotify(WindowEvent e);
public void windowGainedFocus(WindowEvent e);
public void windowLostFocus(WindowEvent e);
+ public void windowRepaint(WindowUpdateEvent e);
}
diff --git a/src/newt/classes/com/jogamp/newt/event/PaintEvent.java b/src/newt/classes/com/jogamp/newt/event/WindowUpdateEvent.java
index e1c667b55..5a11f0f77 100755..100644
--- a/src/newt/classes/com/jogamp/newt/event/PaintEvent.java
+++ b/src/newt/classes/com/jogamp/newt/event/WindowUpdateEvent.java
@@ -1,21 +1,21 @@
/*
- * Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved.
- *
+ * Copyright (c) 2010 Sven Gothel. All Rights Reserved.
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
- *
+ *
* - Redistribution of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
- *
+ *
* - Redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
+ *
+ * Neither the name Sven Gothel or the names of
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
- *
+ *
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
@@ -27,50 +27,27 @@
* DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
- * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
+ * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
-
package com.jogamp.newt.event;
import com.jogamp.newt.*;
+import com.jogamp.nativewindow.util.Rectangle;
-/**
- *
- * @author tdv
- */
-public class PaintEvent extends NEWTEvent {
+public class WindowUpdateEvent extends WindowEvent {
+ Rectangle bounds;
- // bounds of the damage region
- private int x, y, width, height;
- public PaintEvent(int eventType, Object source,
- long when, int x, int y, int w, int h)
+ public WindowUpdateEvent(int eventType, Object source, long when, Rectangle bounds)
{
super(eventType, source, when);
- this.x = x;
- this.y = y;
- this.width = w;
- this.height = h;
+ this.bounds = bounds;
}
- public int getHeight() {
- return height;
- }
-
- public int getWidth() {
- return width;
- }
-
- public int getX() {
- return x;
- }
-
- public int getY() {
- return y;
+ public Rectangle getBounds() {
+ return bounds;
}
public String toString() {
- return "ExposeEvent[modifiers: x="+x+" y="+y+" w="+width+" h="+height +"]";
+ return "WindowUpdateEvent["+super.toString()+", "+bounds+"]";
}
-
}
diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTAdapter.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTAdapter.java
index e8497a741..b9d1f8678 100644
--- a/src/newt/classes/com/jogamp/newt/event/awt/AWTAdapter.java
+++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTAdapter.java
@@ -165,16 +165,8 @@ public abstract class AWTAdapter implements java.util.EventListener
/** @see #addTo(java.awt.Component) */
public abstract AWTAdapter removeFrom(java.awt.Component awtComponent);
- void enqueueEvent(com.jogamp.newt.event.NEWTEvent event) {
- enqueueEvent(false, event);
- }
-
void enqueueEvent(boolean wait, com.jogamp.newt.event.NEWTEvent event) {
- try {
- newtWindow.getScreen().getDisplay().enqueueEvent(wait, event);
- } catch (NullPointerException npe) {
- /* that's ok .. window might be down already */
- }
+ newtWindow.enqueueEvent(wait, event);
}
}
diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTKeyAdapter.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTKeyAdapter.java
index d2b733f98..7e3e5f1b1 100644
--- a/src/newt/classes/com/jogamp/newt/event/awt/AWTKeyAdapter.java
+++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTKeyAdapter.java
@@ -60,7 +60,7 @@ public class AWTKeyAdapter extends AWTAdapter implements java.awt.event.KeyListe
if(null!=newtListener) {
((com.jogamp.newt.event.KeyListener)newtListener).keyPressed(event);
} else {
- enqueueEvent(event);
+ enqueueEvent(false, event);
}
}
@@ -69,7 +69,7 @@ public class AWTKeyAdapter extends AWTAdapter implements java.awt.event.KeyListe
if(null!=newtListener) {
((com.jogamp.newt.event.KeyListener)newtListener).keyReleased(event);
} else {
- enqueueEvent(event);
+ enqueueEvent(false, event);
}
}
@@ -78,7 +78,7 @@ public class AWTKeyAdapter extends AWTAdapter implements java.awt.event.KeyListe
if(null!=newtListener) {
((com.jogamp.newt.event.KeyListener)newtListener).keyTyped(event);
} else {
- enqueueEvent(event);
+ enqueueEvent(false, event);
}
}
}
diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTMouseAdapter.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTMouseAdapter.java
index 058a5f250..3f774f193 100644
--- a/src/newt/classes/com/jogamp/newt/event/awt/AWTMouseAdapter.java
+++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTMouseAdapter.java
@@ -62,7 +62,7 @@ public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseL
if(null!=newtListener) {
((com.jogamp.newt.event.MouseListener)newtListener).mouseClicked(event);
} else {
- enqueueEvent(event);
+ enqueueEvent(false, event);
}
}
@@ -71,7 +71,7 @@ public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseL
if(null!=newtListener) {
((com.jogamp.newt.event.MouseListener)newtListener).mouseEntered(event);
} else {
- enqueueEvent(event);
+ enqueueEvent(false, event);
}
}
@@ -80,7 +80,7 @@ public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseL
if(null!=newtListener) {
((com.jogamp.newt.event.MouseListener)newtListener).mouseExited(event);
} else {
- enqueueEvent(event);
+ enqueueEvent(false, event);
}
}
@@ -89,7 +89,7 @@ public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseL
if(null!=newtListener) {
((com.jogamp.newt.event.MouseListener)newtListener).mousePressed(event);
} else {
- enqueueEvent(event);
+ enqueueEvent(false, event);
}
}
@@ -98,7 +98,7 @@ public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseL
if(null!=newtListener) {
((com.jogamp.newt.event.MouseListener)newtListener).mouseReleased(event);
} else {
- enqueueEvent(event);
+ enqueueEvent(false, event);
}
}
@@ -107,7 +107,7 @@ public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseL
if(null!=newtListener) {
((com.jogamp.newt.event.MouseListener)newtListener).mouseDragged(event);
} else {
- enqueueEvent(event);
+ enqueueEvent(false, event);
}
}
@@ -116,7 +116,7 @@ public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseL
if(null!=newtListener) {
((com.jogamp.newt.event.MouseListener)newtListener).mouseMoved(event);
} else {
- enqueueEvent(event);
+ enqueueEvent(false, event);
}
}
}
diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTNewtEventFactory.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTNewtEventFactory.java
index e4e97946a..076165c73 100644
--- a/src/newt/classes/com/jogamp/newt/event/awt/AWTNewtEventFactory.java
+++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTNewtEventFactory.java
@@ -48,8 +48,10 @@ class AWTNewtEventFactory {
// 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);
@@ -108,6 +110,14 @@ class AWTNewtEventFactory {
return null; // no mapping ..
}
+ static final com.jogamp.newt.event.WindowEvent createWindowEvent(java.awt.event.FocusEvent event, com.jogamp.newt.Window newtSource) {
+ int type = eventTypeAWT2NEWT.get(event.getID());
+ if(-1 < type) {
+ return new com.jogamp.newt.event.WindowEvent(type, (null==newtSource)?(Object)event.getComponent():(Object)newtSource, System.currentTimeMillis());
+ }
+ return null; // no mapping ..
+ }
+
static final com.jogamp.newt.event.MouseEvent createMouseEvent(java.awt.event.MouseEvent event, com.jogamp.newt.Window newtSource) {
int type = eventTypeAWT2NEWT.get(event.getID());
if(-1 < type) {
diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTParentWindowAdapter.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTParentWindowAdapter.java
index 7905a728c..9f0944ea0 100644
--- a/src/newt/classes/com/jogamp/newt/event/awt/AWTParentWindowAdapter.java
+++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTParentWindowAdapter.java
@@ -53,6 +53,18 @@ public class AWTParentWindowAdapter
return super.removeFrom(awtComponent);
}
+ public void focusGained(java.awt.event.FocusEvent e) {
+ if(DEBUG_IMPLEMENTATION) {
+ System.out.println("AWT: focusGained: START "+ e.getComponent());
+ }
+ }
+
+ public void focusLost(java.awt.event.FocusEvent e) {
+ if(DEBUG_IMPLEMENTATION) {
+ System.out.println("AWT: focusLost: "+ e.getComponent());
+ }
+ }
+
public void componentResized(java.awt.event.ComponentEvent e) {
// Need to resize the NEWT child window
// the resized event will be send via the native window feedback.
diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java
index ee7ca97ad..875401544 100644
--- a/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java
+++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java
@@ -33,7 +33,7 @@ package com.jogamp.newt.event.awt;
public class AWTWindowAdapter
extends AWTAdapter
- implements java.awt.event.ComponentListener, java.awt.event.WindowListener
+ implements java.awt.event.ComponentListener, java.awt.event.WindowListener, java.awt.event.FocusListener
{
WindowClosingListener windowClosingListener;
@@ -52,6 +52,7 @@ public class AWTWindowAdapter
public AWTAdapter addTo(java.awt.Component awtComponent) {
java.awt.Window win = getWindow(awtComponent);
awtComponent.addComponentListener(this);
+ awtComponent.addFocusListener(this);
if( null == windowClosingListener ) {
windowClosingListener = new WindowClosingListener();
}
@@ -65,6 +66,7 @@ public class AWTWindowAdapter
}
public AWTAdapter removeFrom(java.awt.Component awtComponent) {
+ awtComponent.removeFocusListener(this);
awtComponent.removeComponentListener(this);
java.awt.Window win = getWindow(awtComponent);
if( null != win && null != windowClosingListener ) {
@@ -86,12 +88,30 @@ public class AWTWindowAdapter
return null;
}
+ public void focusGained(java.awt.event.FocusEvent e) {
+ com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow);
+ if(null!=newtListener) {
+ ((com.jogamp.newt.event.WindowListener)newtListener).windowGainedFocus(event);
+ } else {
+ enqueueEvent(false, event);
+ }
+ }
+
+ public void focusLost(java.awt.event.FocusEvent e) {
+ com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow);
+ if(null!=newtListener) {
+ ((com.jogamp.newt.event.WindowListener)newtListener).windowLostFocus(event);
+ } else {
+ enqueueEvent(false, event);
+ }
+ }
+
public void componentResized(java.awt.event.ComponentEvent e) {
com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow);
if(null!=newtListener) {
((com.jogamp.newt.event.WindowListener)newtListener).windowResized(event);
} else {
- enqueueEvent(event);
+ enqueueEvent(false, event);
}
}
@@ -100,7 +120,7 @@ public class AWTWindowAdapter
if(null!=newtListener) {
((com.jogamp.newt.event.WindowListener)newtListener).windowMoved(event);
} else {
- enqueueEvent(event);
+ enqueueEvent(false, event);
}
}
@@ -143,7 +163,7 @@ public class AWTWindowAdapter
if(null!=newtListener) {
((com.jogamp.newt.event.WindowListener)newtListener).windowGainedFocus(event);
} else {
- enqueueEvent(event);
+ enqueueEvent(false, event);
}
}
@@ -156,7 +176,7 @@ public class AWTWindowAdapter
if(null!=newtListener) {
((com.jogamp.newt.event.WindowListener)newtListener).windowLostFocus(event);
} else {
- enqueueEvent(event);
+ enqueueEvent(false, event);
}
}
diff --git a/src/newt/classes/com/jogamp/newt/impl/awt/AWTWindow.java b/src/newt/classes/com/jogamp/newt/impl/awt/AWTWindow.java
index a06b7160c..56e5a4240 100644
--- a/src/newt/classes/com/jogamp/newt/impl/awt/AWTWindow.java
+++ b/src/newt/classes/com/jogamp/newt/impl/awt/AWTWindow.java
@@ -215,7 +215,7 @@ public class AWTWindow extends Window {
}
}
- public com.jogamp.newt.Insets getInsets() {
+ public com.jogamp.newt.util.Insets getInsets() {
final int insets[] = new int[] { 0, 0, 0, 0 };
runOnEDT(true, new Runnable() {
public void run() {
@@ -226,7 +226,7 @@ public class AWTWindow extends Window {
insets[3] = contInsets.right;
}
});
- return new com.jogamp.newt.
+ return new com.jogamp.newt.util.
Insets(insets[0],insets[1],insets[2],insets[3]);
}
@@ -240,7 +240,7 @@ public class AWTWindow extends Window {
}
}
- protected boolean setFullscreenImpl(final boolean fullscreen, final int x, final int y, final int w, final int h) {
+ protected void setFullscreenImpl(final boolean fullscreen, final int x, final int y, final int w, final int h) {
/** An AWT event on setSize() would bring us in a deadlock situation, hence invokeLater() */
runOnEDT(false, new Runnable() {
public void run() {
@@ -257,26 +257,12 @@ public class AWTWindow extends Window {
container.setSize(w, h);
}
});
- return fullscreen;
}
public Object getWrappedWindow() {
return canvas;
}
- protected void enqueueWindowEvent(int eventType) {
- super.enqueueWindowEvent(eventType);
- }
-
- protected void enqueueKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) {
- super.enqueueKeyEvent(eventType, modifiers, keyCode, keyChar);
- }
-
- protected void enqueueMouseEvent(int eventType, int modifiers,
- int x, int y, int button, int rotation) {
- super.enqueueMouseEvent(eventType, modifiers, x, y, button, rotation);
- }
-
private void runOnEDT(boolean wait, Runnable r) {
EDTUtil edtUtil = screen.getDisplay().getEDTUtil();
if ( ( null != edtUtil && edtUtil.isCurrentThreadEDT() ) || EventQueue.isDispatchThread() ) {
diff --git a/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Window.java b/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Window.java
index 1b8a62a9c..14621807a 100644
--- a/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Window.java
+++ b/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Window.java
@@ -109,11 +109,10 @@ public class Window extends com.jogamp.newt.Window {
}
}
- protected boolean setFullscreenImpl(boolean fullscreen, int x, int y, int w, int h) {
+ protected void setFullscreenImpl(boolean fullscreen, int x, int y, int w, int h) {
if(0!=surfaceHandle) {
SetBounds0(surfaceHandle, screen.getWidth(), screen.getHeight(), x, y, w, h);
}
- return fullscreen;
}
protected void requestFocusImpl() {
diff --git a/src/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java b/src/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java
index 0fde19cd4..699b675dd 100755..100644
--- a/src/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java
+++ b/src/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java
@@ -99,17 +99,15 @@ public class MacDisplay extends Display {
if(wait) {
ReflectionUtil.callStaticMethod(
"java.awt.EventQueue",
- cl,
"invokeAndWait",
new Class[] { java.lang.Runnable.class },
- new Object[] { r } );
+ new Object[] { r }, cl );
} else {
ReflectionUtil.callStaticMethod(
"java.awt.EventQueue",
- cl,
"invokeLater",
new Class[] { java.lang.Runnable.class },
- new Object[] { r } );
+ new Object[] { r }, cl );
}
} catch (Exception e) {
throw new NativeWindowException(e);
diff --git a/src/newt/classes/com/jogamp/newt/impl/macosx/MacScreen.java b/src/newt/classes/com/jogamp/newt/impl/macosx/MacScreen.java
index d7deb13ee..d7deb13ee 100755..100644
--- a/src/newt/classes/com/jogamp/newt/impl/macosx/MacScreen.java
+++ b/src/newt/classes/com/jogamp/newt/impl/macosx/MacScreen.java
diff --git a/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java b/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java
index 8a656a5a8..8f5041253 100755..100644
--- a/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java
+++ b/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java
@@ -39,6 +39,7 @@ import com.jogamp.nativewindow.impl.RecursiveToolkitLock;
import com.jogamp.newt.*;
import com.jogamp.newt.event.*;
import com.jogamp.newt.impl.*;
+import com.jogamp.newt.util.*;
public class MacWindow extends Window {
@@ -279,7 +280,7 @@ public class MacWindow extends Window {
}
}
- protected boolean setFullscreenImpl(final boolean fullscreen, final int x, final int y, final int w, final int h) {
+ protected void setFullscreenImpl(final boolean fullscreen, final int x, final int y, final int w, final int h) {
nsViewLock.lock();
try {
if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) {
@@ -292,27 +293,8 @@ public class MacWindow extends Window {
} finally {
nsViewLock.unlock();
}
- return fullscreen;
}
- private void sizeChanged(int newWidth, int newHeight) {
- if(width != newWidth || height != newHeight) {
- if (DEBUG_IMPLEMENTATION) {
- System.out.println(Thread.currentThread().getName()+" Size changed to " + newWidth + ", " + newHeight);
- }
- width = newWidth;
- height = newHeight;
- if(!fullscreen) {
- nfs_width=width;
- nfs_height=height;
- }
- if (DEBUG_IMPLEMENTATION) {
- System.out.println(" Posted WINDOW_RESIZED event");
- }
- enqueueWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED);
- }
- }
-
private void insetsChanged(int left, int top, int right, int bottom) {
if (DEBUG_IMPLEMENTATION) {
System.out.println(Thread.currentThread().getName()+
@@ -326,32 +308,6 @@ public class MacWindow extends Window {
}
}
- private void positionChanged(int newX, int newY) {
- if( 0==parentWindowHandle && ( x != newX || y != newY ) ) {
- if (DEBUG_IMPLEMENTATION) {
- System.out.println(Thread.currentThread().getName()+" Position changed to " + newX + ", " + newY);
- }
- x = newX;
- y = newY;
- if(!fullscreen) {
- nfs_x=x;
- nfs_y=y;
- }
- if (DEBUG_IMPLEMENTATION) {
- System.out.println(" Posted WINDOW_MOVED event");
- }
- enqueueWindowEvent(WindowEvent.EVENT_WINDOW_MOVED);
- }
- }
-
- private void focusChanged(boolean focusGained) {
- if (focusGained) {
- enqueueWindowEvent(WindowEvent.EVENT_WINDOW_GAINED_FOCUS);
- } else {
- enqueueWindowEvent(WindowEvent.EVENT_WINDOW_LOST_FOCUS);
- }
- }
-
private char convertKeyChar(char keyChar) {
if (keyChar == '\r') {
// Turn these into \n
@@ -435,12 +391,12 @@ public class MacWindow extends Window {
return keyChar;
}
- protected void enqueueKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) {
+ public void enqueueKeyEvent(boolean wait, int eventType, int modifiers, int keyCode, char keyChar) {
int key = convertKeyChar(keyChar);
if(DEBUG_IMPLEMENTATION) System.out.println("MacWindow.enqueueKeyEvent "+Thread.currentThread().getName());
// 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
- super.enqueueKeyEvent(eventType, modifiers, key, keyChar);
+ super.enqueueKeyEvent(wait, eventType, modifiers, key, keyChar);
}
private void createWindow(final boolean recreate, final int x, final int y, final int width, final int height, final boolean fullscreen) {
@@ -482,9 +438,9 @@ public class MacWindow extends Window {
ie.printStackTrace();
}
- enqueueWindowEvent(WindowEvent.EVENT_WINDOW_MOVED);
- enqueueWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED);
- enqueueWindowEvent(WindowEvent.EVENT_WINDOW_GAINED_FOCUS);
+ enqueueWindowEvent(false, WindowEvent.EVENT_WINDOW_MOVED);
+ enqueueWindowEvent(false, WindowEvent.EVENT_WINDOW_RESIZED);
+ enqueueWindowEvent(false, WindowEvent.EVENT_WINDOW_GAINED_FOCUS);
}
protected static native boolean initIDs0();
diff --git a/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Screen.java b/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Screen.java
index e30896468..e30896468 100755..100644
--- a/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Screen.java
+++ b/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Screen.java
diff --git a/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Window.java b/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Window.java
index 7d3a0ac8c..ca06699f5 100755..100644
--- a/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Window.java
+++ b/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Window.java
@@ -87,10 +87,9 @@ public class Window extends com.jogamp.newt.Window {
System.err.println("BCEGL Window.setPositionImpl n/a in BroadcomEGL");
}
- protected boolean setFullscreenImpl(boolean fullscreen, int x, int y, int w, int h) {
+ protected void setFullscreenImpl(boolean fullscreen, int x, int y, int w, int h) {
// n/a in BroadcomEGL
System.err.println("setFullscreen n/a in BroadcomEGL");
- return false;
}
public boolean surfaceSwap() {
diff --git a/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDDisplay.java b/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDDisplay.java
index 2ab30773f..2ab30773f 100755..100644
--- a/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDDisplay.java
+++ b/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDDisplay.java
diff --git a/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDScreen.java b/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDScreen.java
index d570d9f5b..d570d9f5b 100755..100644
--- a/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDScreen.java
+++ b/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDScreen.java
diff --git a/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDWindow.java b/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDWindow.java
index 0d12a4a0a..2f534548b 100755..100644
--- a/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDWindow.java
+++ b/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDWindow.java
@@ -100,14 +100,13 @@ public class KDWindow extends Window {
System.err.println("setPosition n/a in KD");
}
- protected boolean setFullscreenImpl(final boolean fullscreen, final int x, final int y, final int w, final int h) {
+ protected void setFullscreenImpl(final boolean fullscreen, final int x, final int y, final int w, final int h) {
if(0!=eglWindowHandle) {
setFullScreen0(eglWindowHandle, fullscreen);
if(!fullscreen) {
setSize0(eglWindowHandle, w, h);
}
}
- return true;
}
//----------------------------------------------------------------------
@@ -126,16 +125,11 @@ public class KDWindow extends Window {
windowUserData=userData;
}
- private void sizeChanged(int newWidth, int newHeight) {
- width = newWidth;
- height = newHeight;
- if(!fullscreen) {
- nfs_width=width;
- nfs_height=height;
- } else {
+ protected void sizeChanged(int newWidth, int newHeight) {
+ if(fullscreen) {
((KDScreen)screen).setScreenSize(width, height);
}
- enqueueWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED);
+ super.sizeChanged(newWidth, newHeight);
}
private long eglWindowHandle;
diff --git a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsDisplay.java b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsDisplay.java
index ef033d1c8..ef033d1c8 100755..100644
--- a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsDisplay.java
+++ b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsDisplay.java
diff --git a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsScreen.java b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsScreen.java
index 1b4be0d55..1b4be0d55 100755..100644
--- a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsScreen.java
+++ b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsScreen.java
diff --git a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java
index aedb4ed7d..69cd62201 100755..100644
--- a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java
+++ b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java
@@ -36,6 +36,7 @@ package com.jogamp.newt.impl.windows;
import javax.media.nativewindow.*;
import com.jogamp.newt.*;
import com.jogamp.newt.event.*;
+import com.jogamp.newt.util.*;
public class WindowsWindow extends Window {
@@ -161,9 +162,8 @@ public class WindowsWindow extends Window {
setPosition0(parentWindowHandle, windowHandle, x , y /*, width, height*/);
}
- protected boolean setFullscreenImpl(boolean fullscreen, int x, int y, int w, int h) {
+ protected void setFullscreenImpl(boolean fullscreen, int x, int y, int w, int h) {
setFullscreen0(fullscreen?0:parentWindowHandle, windowHandle, x, y, w, h, isUndecorated(fullscreen));
- return fullscreen;
}
protected boolean reparentWindowImpl() {
@@ -175,7 +175,7 @@ public class WindowsWindow extends Window {
protected void requestFocusImpl() {
if (windowHandle != 0L) {
- requestFocus0(fullscreen?0:parentWindowHandle, windowHandle);
+ requestFocus0(windowHandle);
}
}
@@ -206,7 +206,7 @@ public class WindowsWindow extends Window {
private native void setFullscreen0(long parentWindowHandle, long windowHandle, int x, int y, int width, int height, boolean isUndecorated);
private native void reparentWindow0(long parentWindowHandle, long windowHandle, int x, int y, int width, int height, boolean isUndecorated);
private static native void setTitle0(long windowHandle, String title);
- private static native void requestFocus0(long parentWindowHandle, long windowHandle);
+ private native void requestFocus0(long windowHandle);
private void insetsChanged(int left, int top, int right, int bottom) {
if (left != -1 && top != -1 && right != -1 && bottom != -1) {
@@ -216,42 +216,4 @@ public class WindowsWindow extends Window {
insets.bottom = bottom;
}
}
-
- private void sizeChanged(int newWidth, int newHeight) {
- if(width != newWidth || height != newHeight) {
- width = newWidth;
- height = newHeight;
- if(!fullscreen) {
- nfs_width=width;
- nfs_height=height;
- }
- enqueueWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED);
- }
- }
-
- private void positionChanged(int newX, int newY) {
- if( 0==parentWindowHandle && ( x != newX || y != newY ) ) {
- x = newX;
- y = newY;
- if(!fullscreen) {
- nfs_x=x;
- nfs_y=y;
- }
- enqueueWindowEvent(WindowEvent.EVENT_WINDOW_MOVED);
- }
- }
-
- /**
- *
- * @param focusOwner if focusGained is true, focusOwner is the previous
- * focus owner, if focusGained is false, focusOwner is the new focus owner
- * @param focusGained
- */
- private void focusChanged(long focusOwner, boolean focusGained) {
- if (focusGained) {
- enqueueWindowEvent(WindowEvent.EVENT_WINDOW_GAINED_FOCUS);
- } else {
- enqueueWindowEvent(WindowEvent.EVENT_WINDOW_LOST_FOCUS);
- }
- }
}
diff --git a/src/newt/classes/com/jogamp/newt/impl/x11/X11Display.java b/src/newt/classes/com/jogamp/newt/impl/x11/X11Display.java
index 6701d6c8e..6701d6c8e 100755..100644
--- a/src/newt/classes/com/jogamp/newt/impl/x11/X11Display.java
+++ b/src/newt/classes/com/jogamp/newt/impl/x11/X11Display.java
diff --git a/src/newt/classes/com/jogamp/newt/impl/x11/X11Screen.java b/src/newt/classes/com/jogamp/newt/impl/x11/X11Screen.java
index 453d8e5e1..453d8e5e1 100755..100644
--- a/src/newt/classes/com/jogamp/newt/impl/x11/X11Screen.java
+++ b/src/newt/classes/com/jogamp/newt/impl/x11/X11Screen.java
diff --git a/src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java b/src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java
index e7fc96019..7a770f770 100755..100644
--- a/src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java
+++ b/src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java
@@ -71,7 +71,8 @@ public class X11Window extends Window {
if(0!=windowHandleClose && null!=getScreen() ) {
X11Display display = (X11Display) getScreen().getDisplay();
try {
- CloseWindow0(display.getHandle(), windowHandleClose, display.getJavaObjectAtom());
+ CloseWindow0(display.getHandle(), windowHandleClose,
+ display.getJavaObjectAtom(), display.getWindowDeleteAtom());
} catch (Throwable t) {
if(DEBUG_IMPLEMENTATION) {
Exception e = new Exception("closeNative failed - "+Thread.currentThread().getName(), t);
@@ -101,10 +102,9 @@ public class X11Window extends Window {
setPosition0(parentWindowHandle, getDisplayHandle(), windowHandle, x, y);
}
- protected boolean setFullscreenImpl(boolean fullscreen, int x, int y, int w, int h) {
+ protected void setFullscreenImpl(boolean fullscreen, int x, int y, int w, int h) {
setPosSizeDecor0(fullscreen?0:parentWindowHandle, getDisplayHandle(), getScreenIndex(), windowHandle,
x, y, w, h, isUndecorated(fullscreen), isVisible());
- return fullscreen;
}
protected boolean reparentWindowImpl() {
@@ -134,7 +134,7 @@ public class X11Window extends Window {
private native long CreateWindow0(long parentWindowHandle, long display, int screen_index,
long visualID, long javaObjectAtom, long windowDeleteAtom,
int x, int y, int width, int height, boolean undecorated);
- private native void CloseWindow0(long display, long windowHandle, long javaObjectAtom);
+ private native void CloseWindow0(long display, long windowHandle, long javaObjectAtom, long windowDeleteAtom);
private native void setVisible0(long display, long windowHandle, boolean visible);
private native void setSize0(long display, long windowHandle, int width, int height);
private native void setPosSizeDecor0(long parentWindowHandle, long display, int screen_index, long windowHandle,
@@ -145,51 +145,6 @@ public class X11Window extends Window {
private native void reparentWindow0(long parentWindowHandle, long display, int screen_index, long windowHandle,
int x, int y, boolean undecorated, boolean isVisible);
- private void windowChanged(int newX, int newY, int newWidth, int newHeight) {
- if(width != newWidth || height != newHeight) {
- if(DEBUG_IMPLEMENTATION) {
- System.err.println("X11Window windowChanged size: "+this.width+"x"+this.height+" -> "+newWidth+"x"+newHeight);
- }
- width = newWidth;
- height = newHeight;
- if(!fullscreen) {
- nfs_width=width;
- nfs_height=height;
- }
- enqueueWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED);
- }
- if( 0==parentWindowHandle && ( x != newX || y != newY ) ) {
- if(DEBUG_IMPLEMENTATION) {
- System.err.println("X11Window windowChanged position: "+this.x+"/"+this.y+" -> "+newX+"x"+newY);
- }
- x = newX;
- y = newY;
- if(!fullscreen) {
- nfs_x=x;
- nfs_y=y;
- }
- enqueueWindowEvent(WindowEvent.EVENT_WINDOW_MOVED);
- }
- }
-
- /**
- * @param focusGained
- */
- private void focusChanged(boolean focusGained) {
- if (focusGained) {
- enqueueWindowEvent(WindowEvent.EVENT_WINDOW_GAINED_FOCUS);
- } else {
- enqueueWindowEvent(WindowEvent.EVENT_WINDOW_LOST_FOCUS);
- }
- }
-
- /**
- * @param focusGained
- */
- private void visibleChanged(boolean visible) {
- // FIXME .. this.visible = visible ;
- }
-
private void windowCreated(long windowHandle) {
this.windowHandle = windowHandle;
}
diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
index 0e93fc0bd..99b4314a3 100644
--- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
+++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
@@ -35,6 +35,7 @@ package com.jogamp.newt.opengl;
import com.jogamp.newt.*;
import com.jogamp.newt.event.*;
+import com.jogamp.newt.util.*;
import com.jogamp.nativewindow.impl.RecursiveToolkitLock;
import javax.media.nativewindow.*;
import javax.media.opengl.*;
@@ -55,22 +56,34 @@ import java.util.*;
*/
public class GLWindow extends Window implements GLAutoDrawable {
private Window window;
- private boolean runPumpMessages;
/**
* Constructor. Do not call this directly -- use {@link #create()} instead.
*/
protected GLWindow(Window window) {
+ this.startTime = System.currentTimeMillis();
this.window = window;
this.window.setHandleDestroyNotify(false);
- this.runPumpMessages = ( null == getScreen().getDisplay().getEDTUtil() ) ;
window.addWindowListener(new WindowAdapter() {
+ public void windowRepaint(WindowUpdateEvent e) {
+ if( !windowIsLocked() && null == getAnimator() ) {
+ display();
+ }
+ }
+
public void windowResized(WindowEvent e) {
sendReshape = true;
+ if( !windowIsLocked() && null == getAnimator() ) {
+ display();
+ }
}
public void windowDestroyNotify(WindowEvent e) {
- sendDestroy = true;
+ if( !windowIsLocked() && null == getAnimator() ) {
+ destroy();
+ } else {
+ sendDestroy = true;
+ }
}
});
}
@@ -128,31 +141,6 @@ public class GLWindow extends Window implements GLAutoDrawable {
return window.getWrappedWindow();
}
- /**
- * EXPERIMENTAL<br>
- * Enable or disables running the {@link Display#pumpMessages} in the {@link #display()} call.<br>
- * The default behavior is to run {@link Display#pumpMessages}.<P>
- *
- * The idea was that in a single threaded environment with one {@link Display} and many {@link Window}'s,
- * a performance benefit was expected while disabling the implicit {@link Display#pumpMessages} and
- * do it once via {@link GLWindow#runCurrentThreadPumpMessage()} <br>
- * This could not have been verified. No measurable difference could have been recognized.<P>
- *
- * Best performance has been achieved with one GLWindow per thread.<br>
- *
- * Enabling local pump messages while using the EDT,
- * {@link com.jogamp.newt.NewtFactory#setUseEDT(boolean)},
- * will result in an exception.
- *
- * @deprecated EXPERIMENTAL, semantic is about to be removed after further verification.
- */
- public void setRunPumpMessages(boolean onoff) {
- if( onoff && null!=getScreen().getDisplay().getEDTUtil() ) {
- throw new GLException("GLWindow.setRunPumpMessages(true) - Can't do with EDT on");
- }
- runPumpMessages = onoff;
- }
-
protected void createNativeImpl() {
shouldNotCallThis();
}
@@ -178,7 +166,7 @@ public class GLWindow extends Window implements GLAutoDrawable {
// Lock: Have to cover whole workflow (dispose all, context, drawable and window)
windowLock();
try {
- if(null==window || window.isDestroyed()) {
+ if( isDestroyed() ) {
return; // nop
}
if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) {
@@ -186,21 +174,20 @@ public class GLWindow extends Window implements GLAutoDrawable {
e1.printStackTrace();
}
- if ( null != context && context.isCreated() && null != drawable && drawable.isRealized() ) {
- // Catch dispose GLExceptions by GLEventListener, just 'print' them
- // so we can continue with the destruction.
- try {
- helper.invokeGL(drawable, context, disposeAction, null);
- } catch (GLException gle) {
- gle.printStackTrace();
+ if( window.isNativeWindowValid() && null != drawable && drawable.isRealized() ) {
+ if( null != context && context.isCreated() ) {
+ // Catch dispose GLExceptions by GLEventListener, just 'print' them
+ // so we can continue with the destruction.
+ try {
+ helper.invokeGL(drawable, context, disposeAction, null);
+ } catch (GLException gle) {
+ gle.printStackTrace();
+ }
+
+ context.destroy();
+ context = null;
}
- }
- if (context != null && null != drawable && drawable.isRealized() ) {
- context.destroy();
- context = null;
- }
- if (drawable != null) {
drawable.setRealized(false);
drawable = null;
}
@@ -228,7 +215,7 @@ public class GLWindow extends Window implements GLAutoDrawable {
* @see #destroy()
*/
public void destroy(boolean deep) {
- if(!isDestroyed()) {
+ if( !isDestroyed() ) {
runOnEDTIfAvail(true, new DestroyAction(deep));
}
}
@@ -318,6 +305,9 @@ public class GLWindow extends Window implements GLAutoDrawable {
public void requestFocus() {
window.requestFocus();
}
+ public void setFocusAction(FocusRunnable focusAction) {
+ window.setFocusAction(focusAction);
+ }
public Insets getInsets() {
return window.getInsets();
@@ -340,9 +330,8 @@ public class GLWindow extends Window implements GLAutoDrawable {
public boolean setFullscreen(boolean fullscreen) {
return window.setFullscreen(fullscreen);
}
- protected boolean setFullscreenImpl(boolean fullscreen, int x, int y, int w, int h) {
+ protected void setFullscreenImpl(boolean fullscreen, int x, int y, int w, int h) {
shouldNotCallThis();
- return false;
}
public boolean isVisible() {
@@ -369,8 +358,11 @@ public class GLWindow extends Window implements GLAutoDrawable {
return window.isFullscreen();
}
- public void sendEvent(NEWTEvent e) {
- window.sendEvent(e);
+ public void enqueueEvent(boolean wait, com.jogamp.newt.event.NEWTEvent event) {
+ window.enqueueEvent(wait, event);
+ }
+ public boolean consumeEvent(NEWTEvent e) {
+ return window.consumeEvent(e);
}
public void addSurfaceUpdatedListener(int index, SurfaceUpdatedListener l) {
@@ -418,6 +410,12 @@ public class GLWindow extends Window implements GLAutoDrawable {
return window.getKeyListeners();
}
+ public void sendWindowEvent(int eventType) {
+ window.sendWindowEvent(eventType);
+ }
+ public void enqueueWindowEvent(boolean wait, int eventType) {
+ window.enqueueWindowEvent(wait, eventType);
+ }
public void addWindowListener(int index, WindowListener l) {
window.addWindowListener(index, l);
}
@@ -430,6 +428,12 @@ public class GLWindow extends Window implements GLAutoDrawable {
public WindowListener[] getWindowListeners() {
return window.getWindowListeners();
}
+ public void setPropagateRepaint(boolean v) {
+ window.setPropagateRepaint(v);
+ }
+ public void windowRepaint(int x, int y, int width, int height) {
+ window.windowRepaint(x, y, width, height);
+ }
public String toString() {
return "NEWT-GLWindow[ \n\tHelper: "+helper+", \n\tDrawable: "+drawable + /** ", \n\tWindow: "+window+", \n\tFactory: "+factory+ */ "]";
@@ -487,8 +491,17 @@ public class GLWindow extends Window implements GLAutoDrawable {
helper.removeGLEventListener(listener);
}
+ public void setAnimator(Thread animator) {
+ helper.setAnimator(animator);
+ window.setPropagateRepaint(null==animator);
+ }
+
+ public Thread getAnimator() {
+ return helper.getAnimator();
+ }
+
public void invoke(boolean wait, GLRunnable glRunnable) {
- helper.invoke(wait, glRunnable);
+ helper.invoke(this, wait, glRunnable);
}
public void display() {
@@ -498,28 +511,26 @@ public class GLWindow extends Window implements GLAutoDrawable {
public void display(boolean forceReshape) {
if( null == window ) { return; }
+ if(sendDestroy || ( null!=window && window.hasDeviceChanged() && GLAutoDrawable.SCREEN_CHANGE_ACTION_ENABLED ) ) {
+ sendDestroy=false;
+ destroy();
+ return;
+ }
+
if( null == context && window.isVisible() ) {
// retry native window and drawable/context creation
setVisible(true);
}
- if( window.isNativeWindowValid() && null != context ) {
- if(runPumpMessages) {
- window.getScreen().getDisplay().pumpMessages();
+ if( window.isVisible() && window.isNativeWindowValid() && null != context ) {
+ if(forceReshape) {
+ sendReshape = true;
}
- if(sendDestroy || window.hasDeviceChanged() && GLAutoDrawable.SCREEN_CHANGE_ACTION_ENABLED) {
- destroy();
- sendDestroy=false;
- } else if ( window.isVisible() ) {
- if(forceReshape) {
- sendReshape = true;
- }
- windowLock();
- try{
- helper.invokeGL(drawable, context, displayAction, initAction);
- } finally {
- windowUnlock();
- }
+ windowLock();
+ try{
+ helper.invokeGL(drawable, context, displayAction, initAction);
+ } finally {
+ windowUnlock();
}
}
}
@@ -550,7 +561,7 @@ public class GLWindow extends Window implements GLAutoDrawable {
public void run() {
// Lock: Locked Surface/Window by MakeCurrent/Release
helper.init(GLWindow.this);
- startTime = System.currentTimeMillis();
+ startTime = System.currentTimeMillis(); // overwrite startTime to real init one
curTime = startTime;
if(perfLog) {
lastCheck = startTime;
@@ -564,10 +575,7 @@ public class GLWindow extends Window implements GLAutoDrawable {
public void run() {
// Lock: Locked Surface/Window by display _and_ MakeCurrent/Release
if (sendReshape) {
- int width = getWidth();
- int height = getHeight();
- getGL().glViewport(0, 0, width, height);
- helper.reshape(GLWindow.this, 0, 0, width, height);
+ helper.reshape(GLWindow.this, 0, 0, getWidth(), getHeight());
sendReshape = false;
}
@@ -593,8 +601,8 @@ public class GLWindow extends Window implements GLAutoDrawable {
private DisplayAction displayAction = new DisplayAction();
public long getStartTime() { return startTime; }
- public long getCurrentTime() { return curTime; }
- public long getDuration() { return curTime-startTime; }
+ public long getCurrentTime() { curTime = System.currentTimeMillis(); return curTime; }
+ public long getDuration() { return getCurrentTime()-startTime; }
public int getTotalFrames() { return totalFrames; }
private long startTime = 0;
diff --git a/src/newt/classes/com/jogamp/newt/Insets.java b/src/newt/classes/com/jogamp/newt/util/Insets.java
index e440892f0..068cc1dfb 100644
--- a/src/newt/classes/com/jogamp/newt/Insets.java
+++ b/src/newt/classes/com/jogamp/newt/util/Insets.java
@@ -30,7 +30,7 @@
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
*/
-package com.jogamp.newt;
+package com.jogamp.newt.util;
/**
* Simple class representing insets.
diff --git a/src/newt/native/BroadcomEGL.c b/src/newt/native/BroadcomEGL.c
index 7bb21cd3b..7bb21cd3b 100755..100644
--- a/src/newt/native/BroadcomEGL.c
+++ b/src/newt/native/BroadcomEGL.c
diff --git a/src/newt/native/KDWindow.c b/src/newt/native/KDWindow.c
index 82f2ba7df..82f2ba7df 100755..100644
--- a/src/newt/native/KDWindow.c
+++ b/src/newt/native/KDWindow.c
diff --git a/src/newt/native/NewtMacWindow.m b/src/newt/native/NewtMacWindow.m
index ae658b908..ae658b908 100755..100644
--- a/src/newt/native/NewtMacWindow.m
+++ b/src/newt/native/NewtMacWindow.m
diff --git a/src/newt/native/WindowsWindow.c b/src/newt/native/WindowsWindow.c
index 5e3311d3b..cda6a4086 100755..100644
--- a/src/newt/native/WindowsWindow.c
+++ b/src/newt/native/WindowsWindow.c
@@ -109,15 +109,17 @@
#define STD_PRINT(...) fprintf(stderr, __VA_ARGS__); fflush(stderr)
-static jmethodID sizeChangedID = NULL;
static jmethodID insetsChangedID = NULL;
+static jmethodID sizeChangedID = NULL;
static jmethodID positionChangedID = NULL;
static jmethodID focusChangedID = NULL;
+static jmethodID visibleChangedID = NULL;
static jmethodID windowDestroyNotifyID = NULL;
static jmethodID windowDestroyedID = NULL;
-static jmethodID enqueueMouseEventID = NULL;
-static jmethodID enqueueKeyEventID = NULL;
-static jmethodID sendPaintEventID = NULL;
+static jmethodID windowRepaintID = NULL;
+static jmethodID sendMouseEventID = NULL;
+static jmethodID sendKeyEventID = NULL;
+static jmethodID focusActionID = NULL;
static RECT* UpdateInsets(JNIEnv *env, HWND hwnd, jobject window);
@@ -506,7 +508,7 @@ static int WmChar(JNIEnv *env, jobject window, UINT character, UINT repCnt,
if (character == VK_RETURN) {
character = J_VK_ENTER;
}
- (*env)->CallVoidMethod(env, window, enqueueKeyEventID,
+ (*env)->CallVoidMethod(env, window, sendKeyEventID,
(jint) EVENT_KEY_TYPED,
GetModifiers(),
(jint) -1,
@@ -551,7 +553,7 @@ static int WmKeyDown(JNIEnv *env, jobject window, UINT wkey, UINT repCnt,
character = WindowsKeyToJavaChar(wkey, modifiers, SAVE);
*/
- (*env)->CallVoidMethod(env, window, enqueueKeyEventID,
+ (*env)->CallVoidMethod(env, window, sendKeyEventID,
(jint) EVENT_KEY_PRESSED,
modifiers,
(jint) jkey,
@@ -562,7 +564,7 @@ static int WmKeyDown(JNIEnv *env, jobject window, UINT wkey, UINT repCnt,
WM_KEYDOWN.
*/
if (jkey == J_VK_DELETE) {
- (*env)->CallVoidMethod(env, window, enqueueKeyEventID,
+ (*env)->CallVoidMethod(env, window, sendKeyEventID,
(jint) EVENT_KEY_TYPED,
GetModifiers(),
(jint) -1,
@@ -586,7 +588,7 @@ static int WmKeyUp(JNIEnv *env, jobject window, UINT wkey, UINT repCnt,
character = WindowsKeyToJavaChar(wkey, modifiers, SAVE);
*/
- (*env)->CallVoidMethod(env, window, enqueueKeyEventID,
+ (*env)->CallVoidMethod(env, window, sendKeyEventID,
(jint) EVENT_KEY_RELEASED,
modifiers,
(jint) jkey,
@@ -595,23 +597,27 @@ static int WmKeyUp(JNIEnv *env, jobject window, UINT wkey, UINT repCnt,
return 0;
}
-static void NewtWindows_requestFocus (HWND hwnd, BOOL topLevel, BOOL reparented) {
- DBG_PRINT("*** WindowsWindow: requestFocus.0 window %p\n", (void*)hwnd);
- if (IsWindow(hwnd)) {
- UINT flags = SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
- if(reparented) {
- flags |= SWP_FRAMECHANGED;
- }
- SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, flags);
- DBG_PRINT("*** WindowsWindow: requestFocus.1\n");
- SetForegroundWindow(hwnd); // Slightly Higher Priority
- DBG_PRINT("*** WindowsWindow: requestFocus.2\n");
- SetFocus(hwnd);// Sets Keyboard Focus To TheWindow
- DBG_PRINT("*** WindowsWindow: requestFocus.3\n");
- if(topLevel) {
- SetActiveWindow(hwnd);
+static void NewtWindows_requestFocus (JNIEnv *env, jobject window, HWND hwnd, BOOL reparented) {
+ HWND pHwnd = GetParent(hwnd);
+ HWND current = GetFocus();
+ DBG_PRINT("*** WindowsWindow: requestFocus.0 parent %p, window %p, isCurrent %d\n",
+ (void*) pHwnd, (void*)hwnd, current==hwnd);
+ if(reparented || current!=hwnd) {
+ if( JNI_FALSE == (*env)->CallBooleanMethod(env, window, focusActionID) ) {
+ UINT flags = SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
+ if(reparented) {
+ flags |= SWP_FRAMECHANGED;
+ }
+ SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, flags);
+ SetForegroundWindow(hwnd); // Slightly Higher Priority
+ SetFocus(hwnd);// Sets Keyboard Focus To Window
+ if(NULL!=pHwnd) {
+ SetActiveWindow(hwnd);
+ }
+ DBG_PRINT("*** WindowsWindow: requestFocus.X1\n");
+ } else {
+ DBG_PRINT("*** WindowsWindow: requestFocus.X0\n");
}
- DBG_PRINT("*** WindowsWindow: requestFocus.X\n");
}
}
@@ -706,6 +712,7 @@ static void WmSize(JNIEnv *env, HWND wnd, jobject window, UINT type)
static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
+ LRESULT res = 0;
int useDefWindowProc = 0;
JNIEnv *env = NULL;
jobject window = NULL;
@@ -798,8 +805,9 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
case WM_LBUTTONDOWN:
- NewtWindows_requestFocus ( wnd, FALSE, FALSE ); // request focus on this window, if not already ..
- (*env)->CallVoidMethod(env, window, enqueueMouseEventID,
+ DBG_PRINT("*** WindowsWindow: LBUTTONDOWN\n");
+ NewtWindows_requestFocus ( env, window, wnd, FALSE ); // request focus on this window, if not already ..
+ (*env)->CallVoidMethod(env, window, sendMouseEventID,
(jint) EVENT_MOUSE_PRESSED,
GetModifiers(),
(jint) LOWORD(lParam), (jint) HIWORD(lParam),
@@ -808,7 +816,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
break;
case WM_LBUTTONUP:
- (*env)->CallVoidMethod(env, window, enqueueMouseEventID,
+ (*env)->CallVoidMethod(env, window, sendMouseEventID,
(jint) EVENT_MOUSE_RELEASED,
GetModifiers(),
(jint) LOWORD(lParam), (jint) HIWORD(lParam),
@@ -817,8 +825,9 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
break;
case WM_MBUTTONDOWN:
- NewtWindows_requestFocus ( wnd, FALSE, FALSE ); // request focus on this window, if not already ..
- (*env)->CallVoidMethod(env, window, enqueueMouseEventID,
+ DBG_PRINT("*** WindowsWindow: MBUTTONDOWN\n");
+ NewtWindows_requestFocus ( env, window, wnd, FALSE ); // request focus on this window, if not already ..
+ (*env)->CallVoidMethod(env, window, sendMouseEventID,
(jint) EVENT_MOUSE_PRESSED,
GetModifiers(),
(jint) LOWORD(lParam), (jint) HIWORD(lParam),
@@ -827,7 +836,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
break;
case WM_MBUTTONUP:
- (*env)->CallVoidMethod(env, window, enqueueMouseEventID,
+ (*env)->CallVoidMethod(env, window, sendMouseEventID,
(jint) EVENT_MOUSE_RELEASED,
GetModifiers(),
(jint) LOWORD(lParam), (jint) HIWORD(lParam),
@@ -836,8 +845,9 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
break;
case WM_RBUTTONDOWN:
- NewtWindows_requestFocus ( wnd, FALSE, FALSE ); // request focus on this window, if not already ..
- (*env)->CallVoidMethod(env, window, enqueueMouseEventID,
+ DBG_PRINT("*** WindowsWindow: RBUTTONDOWN\n");
+ NewtWindows_requestFocus ( env, window, wnd, FALSE ); // request focus on this window, if not already ..
+ (*env)->CallVoidMethod(env, window, sendMouseEventID,
(jint) EVENT_MOUSE_PRESSED,
GetModifiers(),
(jint) LOWORD(lParam), (jint) HIWORD(lParam),
@@ -846,7 +856,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
break;
case WM_RBUTTONUP:
- (*env)->CallVoidMethod(env, window, enqueueMouseEventID,
+ (*env)->CallVoidMethod(env, window, sendMouseEventID,
(jint) EVENT_MOUSE_RELEASED,
GetModifiers(),
(jint) LOWORD(lParam), (jint) HIWORD(lParam),
@@ -855,7 +865,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
break;
case WM_MOUSEMOVE:
- (*env)->CallVoidMethod(env, window, enqueueMouseEventID,
+ (*env)->CallVoidMethod(env, window, sendMouseEventID,
(jint) EVENT_MOUSE_MOVED,
GetModifiers(),
(jint) LOWORD(lParam), (jint) HIWORD(lParam),
@@ -871,7 +881,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
eventPt.x = x;
eventPt.y = y;
ScreenToClient(wnd, &eventPt);
- (*env)->CallVoidMethod(env, window, enqueueMouseEventID,
+ (*env)->CallVoidMethod(env, window, sendMouseEventID,
(jint) EVENT_MOUSE_WHEEL_MOVED,
GetModifiers(),
(jint) eventPt.x, (jint) eventPt.y,
@@ -881,17 +891,19 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
}
case WM_SETFOCUS:
- (*env)->CallVoidMethod(env, window, focusChangedID,
- (jlong)wParam, JNI_TRUE);
+ (*env)->CallVoidMethod(env, window, focusChangedID, JNI_TRUE);
useDefWindowProc = 1;
break;
case WM_KILLFOCUS:
- (*env)->CallVoidMethod(env, window, focusChangedID,
- (jlong)wParam, JNI_FALSE);
+ (*env)->CallVoidMethod(env, window, focusChangedID, JNI_FALSE);
useDefWindowProc = 1;
break;
+ case WM_SHOWWINDOW:
+ (*env)->CallVoidMethod(env, window, visibleChangedID, wParam==TRUE?JNI_TRUE:JNI_FALSE);
+ break;
+
case WM_MOVE:
DBG_PRINT("*** WindowsWindow: WM_MOVE window %p, %d/%d\n", wnd, (int)LOWORD(lParam), (int)HIWORD(lParam));
(*env)->CallVoidMethod(env, window, positionChangedID,
@@ -901,21 +913,24 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
case WM_PAINT: {
RECT r;
- if (GetUpdateRect(wnd, &r, FALSE)) {
- if ((r.right-r.left) > 0 && (r.bottom-r.top) > 0) {
- (*env)->CallVoidMethod(env, window, sendPaintEventID,
- 0, r.left, r.top, r.right-r.left, r.bottom-r.top);
+ useDefWindowProc = 0;
+ if (GetUpdateRect(wnd, &r, TRUE /* erase background */)) {
+ /*
+ jint width = r.right-r.left;
+ jint height = r.bottom-r.top;
+ if (width > 0 && height > 0) {
+ (*env)->CallVoidMethod(env, window, windowRepaintID, r.left, r.top, width, height);
}
ValidateRect(wnd, &r);
- useDefWindowProc = 0;
- } else {
- useDefWindowProc = 1;
+ */
}
break;
}
case WM_ERASEBKGND:
// ignore erase background
+ (*env)->CallVoidMethod(env, window, windowRepaintID, 0, 0, -1, -1);
useDefWindowProc = 0;
+ res = 1;
break;
@@ -926,7 +941,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
if (useDefWindowProc)
return DefWindowProc(wnd, message, wParam, lParam);
- return 0;
+ return res;
}
/*
@@ -1052,24 +1067,29 @@ JNIEXPORT jint JNICALL Java_com_jogamp_newt_impl_windows_WindowsScreen_getHeight
JNIEXPORT jboolean JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_initIDs0
(JNIEnv *env, jclass clazz)
{
- sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(II)V");
insetsChangedID = (*env)->GetMethodID(env, clazz, "insetsChanged", "(IIII)V");
+ sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(II)V");
positionChangedID = (*env)->GetMethodID(env, clazz, "positionChanged", "(II)V");
- focusChangedID = (*env)->GetMethodID(env, clazz, "focusChanged", "(JZ)V");
+ focusChangedID = (*env)->GetMethodID(env, clazz, "focusChanged", "(Z)V");
+ visibleChangedID = (*env)->GetMethodID(env, clazz, "visibleChanged", "(Z)V");
windowDestroyNotifyID = (*env)->GetMethodID(env, clazz, "windowDestroyNotify", "()V");
windowDestroyedID = (*env)->GetMethodID(env, clazz, "windowDestroyed", "()V");
- enqueueMouseEventID = (*env)->GetMethodID(env, clazz, "enqueueMouseEvent", "(IIIIII)V");
- enqueueKeyEventID = (*env)->GetMethodID(env, clazz, "enqueueKeyEvent", "(IIIC)V");
- sendPaintEventID = (*env)->GetMethodID(env, clazz, "sendPaintEvent", "(IIIII)V");
- if (sizeChangedID == NULL ||
- insetsChangedID == NULL ||
+ windowRepaintID = (*env)->GetMethodID(env, clazz, "windowRepaint", "(IIII)V");
+ sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(IIIIII)V");
+ sendKeyEventID = (*env)->GetMethodID(env, clazz, "sendKeyEvent", "(IIIC)V");
+ focusActionID = (*env)->GetMethodID(env, clazz, "focusAction", "()Z");
+
+ if (insetsChangedID == NULL ||
+ sizeChangedID == NULL ||
positionChangedID == NULL ||
focusChangedID == NULL ||
+ visibleChangedID == NULL ||
windowDestroyNotifyID == NULL ||
windowDestroyedID == NULL ||
- enqueueMouseEventID == NULL ||
- sendPaintEventID == NULL ||
- enqueueKeyEventID == NULL)
+ windowRepaintID == NULL ||
+ sendMouseEventID == NULL ||
+ sendKeyEventID == NULL ||
+ focusActionID == NULL)
{
return JNI_FALSE;
}
@@ -1139,13 +1159,6 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_CreateWi
#endif
UpdateInsets(env, window, obj);
-
- ShowWindow(window, SW_SHOWNORMAL);
- if(NULL!=parentWindow) {
- NewtWindows_requestFocus ( window, FALSE, FALSE ); // request focus on this window, if not already ..
- } /* else {
- // top level already capable of receiving [keyboard] events
- } */
}
#ifdef UNICODE
@@ -1215,13 +1228,13 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_MonitorF
JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_setVisible0
(JNIEnv *_env, jclass clazz, jlong window, jboolean visible)
{
- HWND hWnd = (HWND) (intptr_t) window;
- DBG_PRINT("*** WindowsWindow: setVisible window %p, visible: %d\n", hWnd, (int)visible);
+ HWND hwnd = (HWND) (intptr_t) window;
+ DBG_PRINT("*** WindowsWindow: setVisible window %p, visible: %d\n", hwnd, (int)visible);
if (visible) {
- SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
- ShowWindow(hWnd, SW_SHOW);
+ SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
+ ShowWindow(hwnd, SW_SHOW);
} else {
- ShowWindow(hWnd, SW_HIDE);
+ ShowWindow(hwnd, SW_HIDE);
}
}
@@ -1292,14 +1305,14 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_setPositi
}
}
-static void NewtWindows_reparentWindow(HWND hwndP, HWND hwnd, jint x, jint y, jint width, jint height, jboolean bIsUndecorated)
+static void NewtWindows_reparentWindow(JNIEnv *env, jobject obj, HWND hwndP, HWND hwnd, BOOL visible,
+ jint x, jint y, jint width, jint height, jboolean bIsUndecorated)
{
UINT flags;
HWND hWndInsertAfter;
DWORD windowStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN ;
- BOOL isVisible = IsWindowVisible(hwnd);
- DBG_PRINT("*** WindowsWindow: reparentWindow.1 parent %p, window %p, %d/%d %dx%d undeco %d visible %d\n", (void*)hwndP, (void*)hwnd, x, y, width, height, bIsUndecorated, isVisible);
+ DBG_PRINT("*** WindowsWindow: reparentWindow.1 parent %p, window %p, %d/%d %dx%d undeco %d\n", (void*)hwndP, (void*)hwnd, x, y, width, height, bIsUndecorated);
if (!IsWindow(hwnd)) {
DBG_PRINT("*** WindowsWindow: reparentWindow failure: Passed window %p is invalid\n", (void*)hwnd);
return;
@@ -1309,8 +1322,8 @@ static void NewtWindows_reparentWindow(HWND hwndP, HWND hwnd, jint x, jint y, ji
return;
}
- if (isVisible) {
- windowStyle |= WS_VISIBLE;
+ if(visible) {
+ windowStyle |= WS_VISIBLE ;
}
// order of call sequence: (MS documentation)
@@ -1337,10 +1350,6 @@ static void NewtWindows_reparentWindow(HWND hwndP, HWND hwnd, jint x, jint y, ji
DBG_PRINT("*** WindowsWindow: reparentWindow.4\n");
}
- if(isVisible) {
- NewtWindows_requestFocus ( hwnd, ( NULL == hwndP ) ? TRUE : FALSE, TRUE );
- }
-
DBG_PRINT("*** WindowsWindow: reparentWindow.X\n");
}
@@ -1356,13 +1365,12 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_setFullsc
HWND hwndP = (HWND) (intptr_t) parent;
HWND hwnd = (HWND) (intptr_t) window;
HWND hWndInsertAfter;
- DWORD windowStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
BOOL isVisible = IsWindowVisible(hwnd);
DBG_PRINT("*** WindowsWindow: setFullscreen.1 parent %p, window %p, %d/%d %dx%d undeco %d visible\n",
parent, window, x, y, width, height, bIsUndecorated, isVisible);
- NewtWindows_reparentWindow(hwndP, hwnd, x, y, width, height, bIsUndecorated);
+ NewtWindows_reparentWindow(env, obj, hwndP, hwnd, FALSE, x, y, width, height, bIsUndecorated);
if ( NULL == hwndP ) {
flags = SWP_SHOWWINDOW;
@@ -1371,9 +1379,12 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_setFullsc
flags = SWP_NOACTIVATE | SWP_NOZORDER;
hWndInsertAfter = 0;
}
-
SetWindowPos(hwnd, hWndInsertAfter, x, y, width, height, flags);
+ if(isVisible) {
+ NewtWindows_requestFocus ( env, obj, hwnd, TRUE ); // request focus on this window, if not already ..
+ }
+
DBG_PRINT("*** WindowsWindow: setFullscreen.X\n");
(*env)->CallVoidMethod(env, obj, sizeChangedID, (jint) width, (jint) height); // resize necessary ..
}
@@ -1388,8 +1399,14 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_reparentW
{
HWND hwndP = (HWND) (intptr_t) parent;
HWND hwnd = (HWND) (intptr_t) window;
+ BOOL isVisible = IsWindowVisible(hwnd);
+
+ NewtWindows_reparentWindow(env, obj, hwndP, hwnd, FALSE, x, y, width, height, bIsUndecorated);
+
+ if(isVisible) {
+ NewtWindows_requestFocus ( env, obj, hwnd, TRUE ); // request focus on this window, if not already ..
+ }
- NewtWindows_reparentWindow(hwndP, hwnd, x, y, width, height, bIsUndecorated);
}
/*
@@ -1416,8 +1433,9 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_setTitle0
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_requestFocus0
- (JNIEnv *env, jclass clazz, jlong parent, jlong window)
+ (JNIEnv *env, jobject obj, jlong window)
{
- NewtWindows_requestFocus ( (HWND) (intptr_t) window, (0 == parent) ? TRUE : FALSE, FALSE ) ;
+ DBG_PRINT("*** WindowsWindow: RequestFocus0\n");
+ NewtWindows_requestFocus ( env, obj, (HWND) (intptr_t) window, FALSE ) ;
}
diff --git a/src/newt/native/X11Window.c b/src/newt/native/X11Window.c
index a521d2dbd..60caab662 100755..100644
--- a/src/newt/native/X11Window.c
+++ b/src/newt/native/X11Window.c
@@ -151,14 +151,17 @@ static const char * const ClazzNameNewtWindow =
"com/jogamp/newt/Window";
static jclass newtWindowClz=NULL;
-static jmethodID windowChangedID = NULL;
+static jmethodID sizeChangedID = NULL;
+static jmethodID positionChangedID = NULL;
static jmethodID focusChangedID = NULL;
static jmethodID visibleChangedID = NULL;
static jmethodID windowDestroyNotifyID = NULL;
static jmethodID windowDestroyedID = NULL;
+static jmethodID windowRepaintID = NULL;
static jmethodID windowCreatedID = NULL;
-static jmethodID enqueueMouseEventID = NULL;
-static jmethodID enqueueKeyEventID = NULL;
+static jmethodID sendMouseEventID = NULL;
+static jmethodID sendKeyEventID = NULL;
+static jmethodID focusActionID = NULL;
static jmethodID displayCompletedID = NULL;
@@ -291,8 +294,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Display_CompleteDisplay0
* Window
*/
-// #define WINDOW_EVENT_MASK ( FocusChangeMask | StructureNotifyMask | ExposureMask | VisibilityNotify )
-#define WINDOW_EVENT_MASK ( FocusChangeMask | StructureNotifyMask | VisibilityNotify )
+#define WINDOW_EVENT_MASK ( FocusChangeMask | StructureNotifyMask | ExposureMask )
static int putPtrIn32Long(unsigned long * dst, uintptr_t src) {
int i=0;
@@ -371,18 +373,42 @@ static jobject getJavaWindowProperty(JNIEnv *env, Display *dpy, Window window, j
return jwindow;
}
-static void NewtWindows_requestFocus0 (Display *dpy, Window w, XWindowAttributes *xwa) {
- // Avoid 'BadMatch' errors from XSetInputFocus, ie if window is not viewable
- if(xwa->map_state == IsViewable) {
- XSetInputFocus(dpy, w, RevertToParent, CurrentTime);
+/**
+static Window NewtWindows_getParent (Display *dpy, Window w) {
+ Window root_return=0;
+ Window parent_return=0;
+ Window *children_return=NULL;
+ unsigned int nchildren_return=0;
+
+ Status res = XQueryTree(dpy, w, &root_return, &parent_return, &children_return, &nchildren_return);
+ if(NULL!=children_return) {
+ XFree(children_return);
+ }
+ if(0!=res) {
+ return parent_return;
+ }
+ return 0;
+} */
+
+static void NewtWindows_requestFocus0 (JNIEnv *env, jobject window, Display *dpy, Window w, XWindowAttributes *xwa) {
+ Window focus_return;
+ int revert_to_return;
+ XGetInputFocus(dpy, &focus_return, &revert_to_return);
+ if(focus_return!=w) {
+ // Avoid 'BadMatch' errors from XSetInputFocus, ie if window is not viewable
+ if( JNI_FALSE == (*env)->CallBooleanMethod(env, window, focusActionID) ) {
+ if(xwa->map_state == IsViewable) {
+ XSetInputFocus(dpy, w, RevertToParent, CurrentTime);
+ }
+ }
}
}
-static void NewtWindows_requestFocus1 (Display *dpy, Window w) {
+static void NewtWindows_requestFocus1 (JNIEnv *env, jobject window, Display *dpy, Window w) {
XWindowAttributes xwa;
XGetWindowAttributes(dpy, w, &xwa);
- NewtWindows_requestFocus0 (dpy, w, &xwa);
+ NewtWindows_requestFocus0 (env, window, dpy, w, &xwa);
XSync(dpy, False);
}
@@ -504,32 +530,38 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Display_DispatchMessages
switch(evt.type) {
case ButtonPress:
- NewtWindows_requestFocus1 ( dpy, evt.xany.window );
- (*env)->CallVoidMethod(env, jwindow, enqueueMouseEventID, (jint) EVENT_MOUSE_PRESSED,
+ NewtWindows_requestFocus1 ( env, jwindow, dpy, evt.xany.window );
+ (*env)->CallVoidMethod(env, jwindow, sendMouseEventID,
+ (jint) EVENT_MOUSE_PRESSED,
(jint) evt.xbutton.state,
(jint) evt.xbutton.x, (jint) evt.xbutton.y, (jint) evt.xbutton.button, 0 /*rotation*/);
break;
case ButtonRelease:
- (*env)->CallVoidMethod(env, jwindow, enqueueMouseEventID, (jint) EVENT_MOUSE_RELEASED,
+ (*env)->CallVoidMethod(env, jwindow, sendMouseEventID,
+ (jint) EVENT_MOUSE_RELEASED,
(jint) evt.xbutton.state,
(jint) evt.xbutton.x, (jint) evt.xbutton.y, (jint) evt.xbutton.button, 0 /*rotation*/);
break;
case MotionNotify:
- (*env)->CallVoidMethod(env, jwindow, enqueueMouseEventID, (jint) EVENT_MOUSE_MOVED,
+ (*env)->CallVoidMethod(env, jwindow, sendMouseEventID,
+ (jint) EVENT_MOUSE_MOVED,
(jint) evt.xmotion.state,
(jint) evt.xmotion.x, (jint) evt.xmotion.y, (jint) 0, 0 /*rotation*/);
break;
case KeyPress:
- (*env)->CallVoidMethod(env, jwindow, enqueueKeyEventID, (jint) EVENT_KEY_PRESSED,
+ (*env)->CallVoidMethod(env, jwindow, sendKeyEventID,
+ (jint) EVENT_KEY_PRESSED,
(jint) evt.xkey.state,
X11KeySym2NewtVKey(keySym), (jchar) keyChar);
break;
case KeyRelease:
- (*env)->CallVoidMethod(env, jwindow, enqueueKeyEventID, (jint) EVENT_KEY_RELEASED,
+ (*env)->CallVoidMethod(env, jwindow, sendKeyEventID,
+ (jint) EVENT_KEY_RELEASED,
(jint) evt.xkey.state,
X11KeySym2NewtVKey(keySym), (jchar) keyChar);
- (*env)->CallVoidMethod(env, jwindow, enqueueKeyEventID, (jint) EVENT_KEY_TYPED,
+ (*env)->CallVoidMethod(env, jwindow, sendKeyEventID,
+ (jint) EVENT_KEY_TYPED,
(jint) evt.xkey.state,
(jint) -1, (jchar) keyChar);
break;
@@ -546,9 +578,10 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Display_DispatchMessages
(unsigned int)evt.xconfigure.window, (unsigned int)evt.xconfigure.event, (unsigned int)evt.xconfigure.above,
evt.xconfigure.x, evt.xconfigure.y, evt.xconfigure.width, evt.xconfigure.height,
evt.xconfigure.override_redirect);
- (*env)->CallVoidMethod(env, jwindow, windowChangedID,
- (jint) evt.xconfigure.x, (jint) evt.xconfigure.y,
+ (*env)->CallVoidMethod(env, jwindow, sizeChangedID,
(jint) evt.xconfigure.width, (jint) evt.xconfigure.height);
+ (*env)->CallVoidMethod(env, jwindow, positionChangedID,
+ (jint) evt.xconfigure.x, (jint) evt.xconfigure.y);
break;
case ClientMessage:
if (evt.xclient.send_event==True && evt.xclient.data.l[0]==(Atom)wmDeleteAtom) {
@@ -568,25 +601,28 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Display_DispatchMessages
(*env)->CallVoidMethod(env, jwindow, focusChangedID, JNI_FALSE);
break;
+ case Expose:
+ DBG_PRINT( "X11: event . Expose call 0x%X %d/%d %dx%d\n", (unsigned int)evt.xexpose.window,
+ evt.xexpose.x, evt.xexpose.y, evt.xexpose.width, evt.xexpose.height);
+
+ if (evt.xexpose.width > 0 && evt.xexpose.height > 0) {
+ (*env)->CallVoidMethod(env, jwindow, windowRepaintID,
+ evt.xexpose.x, evt.xexpose.y, evt.xexpose.width, evt.xexpose.height);
+ }
+ break;
+
case MapNotify:
DBG_PRINT( "X11: event . MapNotify call 0x%X\n", (unsigned int)evt.xunmap.window);
- // FIXME (*env)->CallVoidMethod(env, jwindow, visibleChangedID, JNI_TRUE);
+ (*env)->CallVoidMethod(env, jwindow, visibleChangedID, JNI_TRUE);
break;
case UnmapNotify:
DBG_PRINT( "X11: event . UnmapNotify call 0x%X\n", (unsigned int)evt.xunmap.window);
- // FIXME (*env)->CallVoidMethod(env, jwindow, visibleChangedID, JNI_FALSE);
+ (*env)->CallVoidMethod(env, jwindow, visibleChangedID, JNI_FALSE);
break;
// unhandled events .. yet ..
- case VisibilityNotify:
- DBG_PRINT( "X11: event . VisibilityNotify call 0x%X\n", (unsigned int)evt.xvisibility.window);
- break;
- case Expose:
- DBG_PRINT( "X11: event . Expose call 0x%X\n", (unsigned int)evt.xexpose.window);
- /* FIXME: Might want to send a repaint event .. */
- break;
default:
DBG_PRINT("X11: event . unhandled %d 0x%X call 0x%X\n", evt.type, evt.type, (unsigned int)evt.xunmap.window);
}
@@ -653,23 +689,29 @@ JNIEXPORT jint JNICALL Java_com_jogamp_newt_impl_x11_X11Screen_getHeight0
JNIEXPORT jboolean JNICALL Java_com_jogamp_newt_impl_x11_X11Window_initIDs0
(JNIEnv *env, jclass clazz)
{
- windowChangedID = (*env)->GetMethodID(env, clazz, "windowChanged", "(IIII)V");
+ sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(II)V");
+ positionChangedID = (*env)->GetMethodID(env, clazz, "positionChanged", "(II)V");
focusChangedID = (*env)->GetMethodID(env, clazz, "focusChanged", "(Z)V");
visibleChangedID = (*env)->GetMethodID(env, clazz, "visibleChanged", "(Z)V");
windowDestroyNotifyID = (*env)->GetMethodID(env, clazz, "windowDestroyNotify", "()V");
windowDestroyedID = (*env)->GetMethodID(env, clazz, "windowDestroyed", "()V");
+ windowRepaintID = (*env)->GetMethodID(env, clazz, "windowRepaint", "(IIII)V");
windowCreatedID = (*env)->GetMethodID(env, clazz, "windowCreated", "(J)V");
- enqueueMouseEventID = (*env)->GetMethodID(env, clazz, "enqueueMouseEvent", "(IIIIII)V");
- enqueueKeyEventID = (*env)->GetMethodID(env, clazz, "enqueueKeyEvent", "(IIIC)V");
+ sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(IIIIII)V");
+ sendKeyEventID = (*env)->GetMethodID(env, clazz, "sendKeyEvent", "(IIIC)V");
+ focusActionID = (*env)->GetMethodID(env, clazz, "focusAction", "()Z");
- if (windowChangedID == NULL ||
+ if (sizeChangedID == NULL ||
+ positionChangedID == NULL ||
focusChangedID == NULL ||
visibleChangedID == NULL ||
windowDestroyNotifyID == NULL ||
windowDestroyedID == NULL ||
+ windowRepaintID == NULL ||
windowCreatedID == NULL ||
- enqueueMouseEventID == NULL ||
- enqueueKeyEventID == NULL) {
+ sendMouseEventID == NULL ||
+ sendKeyEventID == NULL ||
+ focusActionID == NULL) {
return JNI_FALSE;
}
return JNI_TRUE;
@@ -749,12 +791,17 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_newt_impl_x11_X11Window_CreateWindow0
pVisualQuery=NULL;
}
- attrMask = ( CWBackPixel | CWBorderPixel | CWColormap | CWOverrideRedirect ) ;
+ attrMask = ( CWBackingStore | CWBackingPlanes | CWBackingPixel | CWBackPixel |
+ CWBorderPixel | CWColormap | CWOverrideRedirect ) ;
memset(&xswa, 0, sizeof(xswa));
xswa.override_redirect = ( 0 != parent ) ? True : False ;
xswa.border_pixel = 0;
xswa.background_pixel = 0;
+ xswa.backing_store=NotUseful; /* NotUseful, WhenMapped, Always */
+ xswa.backing_planes=0; /* planes to be preserved if possible */
+ xswa.backing_pixel=0; /* value to use in restoring planes */
+
xswa.colormap = XCreateColormap(dpy,
windowParent, // XRootWindow(dpy, scrn_idx),
visual,
@@ -781,6 +828,7 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_newt_impl_x11_X11Window_CreateWindow0
setJavaWindowProperty(env, dpy, window, javaObjectAtom, (*env)->NewGlobalRef(env, obj));
+ // XClearWindow(dpy, window);
XSync(dpy, False);
{
@@ -806,7 +854,7 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_newt_impl_x11_X11Window_CreateWindow0
* Signature: (JJ)V
*/
JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Window_CloseWindow0
- (JNIEnv *env, jobject obj, jlong display, jlong window, jlong javaObjectAtom)
+ (JNIEnv *env, jobject obj, jlong display, jlong window, jlong javaObjectAtom, jlong wmDeleteAtom)
{
Display * dpy = (Display *) (intptr_t) display;
Window w = (Window)window;
@@ -827,14 +875,19 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Window_CloseWindow0
_throwNewRuntimeException(dpy, env, "Internal Error .. Window global ref not the same!");
return;
}
- (*env)->DeleteGlobalRef(env, jwindow);
XSync(dpy, False);
XSelectInput(dpy, w, 0);
XUnmapWindow(dpy, w);
+
+ // Drain all events related to this window ..
+ JNICALL Java_com_jogamp_newt_impl_x11_X11Display_DispatchMessages0(env, obj, display, javaObjectAtom, wmDeleteAtom);
+
XDestroyWindow(dpy, w);
XSync(dpy, False);
+ (*env)->DeleteGlobalRef(env, jwindow);
+
DBG_PRINT( "X11: CloseWindow END\n");
(*env)->CallVoidMethod(env, obj, windowDestroyedID);
@@ -915,13 +968,20 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Window_setPosition0
}
static void NewtWindows_reparentWindow
- (Display * dpy, Screen * scrn, Window w, XWindowAttributes *xwa, jlong jparent, jint x, jint y, jboolean undecorated, jboolean isVisible)
+ (JNIEnv *env, jobject obj,
+ Display * dpy, Screen * scrn, Window w, XWindowAttributes *xwa, jlong jparent,
+ jint x, jint y, jboolean undecorated, jboolean isVisible)
{
Window parent = (0!=jparent)?(Window)jparent:XRootWindowOfScreen(scrn);
DBG_PRINT( "X11: reparentWindow dpy %p, parent %p/%p, win %p, %d/%d undec %d\n",
(void*)dpy, (void*) jparent, (void*)parent, (void*)w, x, y, undecorated);
+ // don't propagate events during reparenting
+ // long orig_xevent_mask = xwa->your_event_mask ;
+ /* XSelectInput(dpy, w, orig_xevent_mask & ~ ( StructureNotifyMask ) );
+ XSync(dpy, False); */
+
if(0 != jparent) {
// move into parent ..
NewtWindows_setDecorations (dpy, w, False);
@@ -955,6 +1015,14 @@ static void NewtWindows_reparentWindow
XSync(dpy, False);
}
+ /* XSelectInput(dpy, w, orig_xevent_mask);
+ XSync(dpy, False); */
+
+ if(JNI_TRUE == isVisible) {
+ NewtWindows_requestFocus0 ( env, obj, dpy, w, xwa );
+ XSync(dpy, False);
+ }
+
DBG_PRINT( "X11: reparentWindow X\n");
}
@@ -984,7 +1052,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Window_setPosSizeDecor0
XSync(dpy, False);
XGetWindowAttributes(dpy, w, &xwa);
- NewtWindows_reparentWindow(dpy, scrn, w, &xwa, jparent, x, y, undecorated, isVisible);
+ NewtWindows_reparentWindow(env, obj, dpy, scrn, w, &xwa, jparent, x, y, undecorated, isVisible);
XSync(dpy, False);
memset(&xwc, 0, sizeof(XWindowChanges));
@@ -993,12 +1061,6 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Window_setPosSizeDecor0
xwc.width=width;
xwc.height=height;
XConfigureWindow(dpy, w, CWX|CWY|CWWidth|CWHeight, &xwc);
-
- if(JNI_TRUE == isVisible) {
- XGetWindowAttributes(dpy, w, &xwa);
- NewtWindows_requestFocus0 ( dpy, w, &xwa );
- XSync(dpy, False);
- }
}
/*
@@ -1025,7 +1087,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Window_reparentWindow0
XSync(dpy, False);
XGetWindowAttributes(dpy, w, &xwa);
- NewtWindows_reparentWindow(dpy, scrn, w, &xwa, jparent, x, y, undecorated, isVisible);
+ NewtWindows_reparentWindow(env, obj, dpy, scrn, w, &xwa, jparent, x, y, undecorated, isVisible);
XSync(dpy, False);
DBG_PRINT( "X11: reparentWindow0 X\n");
@@ -1039,7 +1101,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Window_reparentWindow0
JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Window_requestFocus0
(JNIEnv *env, jobject obj, jlong display, jlong window)
{
- NewtWindows_requestFocus ( (Display *) (intptr_t) display, (Window)window ) ;
+ NewtWindows_requestFocus1 ( env, obj, (Display *) (intptr_t) display, (Window)window ) ;
}
/*