aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt/classes/com
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2010-09-03 00:06:03 +0300
committerSven Gothel <[email protected]>2010-09-03 00:06:03 +0300
commit340b1ceb07907be113e33c54d084e53ddc93e368 (patch)
tree2839cd761cbe52ee39151ef24f5c7c4ddca36b5d /src/newt/classes/com
parent1b2f7ebe62ce661eb32cc9caf74c6c49c8c5f15a (diff)
NEWT: Focus Fix + Cleanup
Issueing 'requestFocus' via the native EDT dispatch loop may cause a deadlock, due to a possible implicite AWT requestFocus call (NewtCanvasAWT). Approach: RequestFocus issued directly, by Window.requestFocus() and the native EDT dispatch loop, is queued for later execution by EDT. This shall decouple a possible native windowing TK resource collision. - X11Windows.c: Add missing 'reparented' param for requestFocus to force requestFocus after reparenting. - AWTWindow.java: Add requestFocusImpl() +++ NEWT: Cleanup - Remove Event Type Bits in: - EventListener.h - NEWTEventListener.java - Remove InputEvent 'consume' status -
Diffstat (limited to 'src/newt/classes/com')
-rw-r--r--src/newt/classes/com/jogamp/newt/Display.java6
-rw-r--r--src/newt/classes/com/jogamp/newt/Window.java28
-rw-r--r--src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java30
-rw-r--r--src/newt/classes/com/jogamp/newt/event/InputEvent.java9
-rw-r--r--src/newt/classes/com/jogamp/newt/event/NEWTEvent.java9
-rw-r--r--src/newt/classes/com/jogamp/newt/event/NEWTEventConsumer.java4
-rw-r--r--src/newt/classes/com/jogamp/newt/event/NEWTEventListener.java5
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/awt/AWTDisplay.java2
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/awt/AWTWindow.java8
9 files changed, 56 insertions, 45 deletions
diff --git a/src/newt/classes/com/jogamp/newt/Display.java b/src/newt/classes/com/jogamp/newt/Display.java
index 00abd8406..b9ef93572 100644
--- a/src/newt/classes/com/jogamp/newt/Display.java
+++ b/src/newt/classes/com/jogamp/newt/Display.java
@@ -181,7 +181,7 @@ public abstract class Display {
}
}
- public boolean runCreateAndDestroyOnEDT() {
+ protected boolean getShallRunOnEDT() {
return true;
}
@@ -232,7 +232,7 @@ public abstract class Display {
public void runOnEDTIfAvail(boolean wait, final Runnable task) {
EDTUtil _edtUtil = getEDTUtil();
- if(runCreateAndDestroyOnEDT() && null!=_edtUtil) {
+ if(getShallRunOnEDT() && null!=_edtUtil) {
_edtUtil.invoke(wait, task);
} else {
task.run();
@@ -363,7 +363,7 @@ public abstract class Display {
enqueueEvent(false, event);
}
} else {
- throw new RuntimeException("Event source not a NEWT one: "+source.getClass().getName()+", "+source);
+ throw new RuntimeException("Event source not NEWT: "+source.getClass().getName()+", "+source);
}
eventTask.notifyIssuer();
}
diff --git a/src/newt/classes/com/jogamp/newt/Window.java b/src/newt/classes/com/jogamp/newt/Window.java
index 0ec8a109b..d002791ca 100644
--- a/src/newt/classes/com/jogamp/newt/Window.java
+++ b/src/newt/classes/com/jogamp/newt/Window.java
@@ -297,12 +297,21 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer
}
public void requestFocus() {
- if(0 != windowHandle) {
- requestFocusImpl();
- }
+ enqueueRequestFocus(false); // FIXME: or shall we wait ?
}
protected void requestFocusImpl() {}
+ class RequestFocusAction implements Runnable {
+ public void run() {
+ Window.this.requestFocusImpl();
+ }
+ }
+ RequestFocusAction requestFocusAction = new RequestFocusAction();
+
+ public void enqueueRequestFocus(boolean wait) {
+ runOnEDTIfAvail(wait, requestFocusAction);
+ }
+
/**
* 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,
@@ -985,20 +994,19 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer
switch(e.getEventType()) {
case WindowEvent.EVENT_WINDOW_REPAINT:
if( windowIsLocked() ) {
+ // make sure only one repaint event is queued
if(!repaintQueued) {
repaintQueued=true;
return false;
- } else {
- return true;
}
- } else {
- if(DEBUG_IMPLEMENTATION) {
+ return true;
+ }
+ if(DEBUG_IMPLEMENTATION) {
System.out.println("Window.windowRepaint: "+e);
// Exception ee = new Exception("Window.windowRepaint: "+e);
// ee.printStackTrace();
- }
- repaintQueued=false;
}
+ repaintQueued=false; // no repaint event queued
break;
default:
break;
@@ -1009,6 +1017,8 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer
getInnerWindow().consumeKeyEvent((KeyEvent)e);
} else if(e instanceof MouseEvent) {
getInnerWindow().consumeMouseEvent((MouseEvent)e);
+ } else {
+ throw new NativeWindowException("Unexpected NEWTEvent type " + e);
}
return true;
}
diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
index 6fd924e66..57647df5c 100644
--- a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
+++ b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
@@ -96,7 +96,7 @@ public class NewtCanvasAWT extends java.awt.Canvas {
if(DEBUG_IMPLEMENTATION) {
System.out.println("FocusActionImpl.run() "+Window.getThreadName());
}
- NewtCanvasAWT.this.requestFocusAWT();
+ NewtCanvasAWT.this.requestFocusAWTParent();
}
}
FocusActionImpl focusActionImpl = new FocusActionImpl();
@@ -213,12 +213,11 @@ public class NewtCanvasAWT extends java.awt.Canvas {
}
}
- void requestFocusAWT() {
+ final void requestFocusAWTParent() {
super.requestFocus();
}
- public void requestFocus() {
- super.requestFocus();
+ final void requestFocusNEWTChild() {
if(null!=newtChild) {
newtChild.setFocusAction(null);
newtChild.requestFocus();
@@ -226,32 +225,31 @@ public class NewtCanvasAWT extends java.awt.Canvas {
}
}
+ public void requestFocus() {
+ requestFocusAWTParent();
+ requestFocusNEWTChild();
+ }
+
public boolean requestFocus(boolean temporary) {
boolean res = super.requestFocus(temporary);
- if(res && null!=newtChild) {
- newtChild.setFocusAction(null);
- newtChild.requestFocus();
- newtChild.setFocusAction(focusAction);
+ if(res) {
+ requestFocusNEWTChild();
}
return res;
}
public boolean requestFocusInWindow() {
boolean res = super.requestFocusInWindow();
- if(res && null!=newtChild) {
- newtChild.setFocusAction(null);
- newtChild.requestFocus();
- newtChild.setFocusAction(focusAction);
+ if(res) {
+ requestFocusNEWTChild();
}
return res;
}
public boolean requestFocusInWindow(boolean temporary) {
boolean res = super.requestFocusInWindow(temporary);
- if(res && null!=newtChild) {
- newtChild.setFocusAction(null);
- newtChild.requestFocus();
- newtChild.setFocusAction(focusAction);
+ if(res) {
+ requestFocusNEWTChild();
}
return res;
}
diff --git a/src/newt/classes/com/jogamp/newt/event/InputEvent.java b/src/newt/classes/com/jogamp/newt/event/InputEvent.java
index 02fbe59ef..d014de7f3 100644
--- a/src/newt/classes/com/jogamp/newt/event/InputEvent.java
+++ b/src/newt/classes/com/jogamp/newt/event/InputEvent.java
@@ -48,17 +48,9 @@ public abstract class InputEvent extends NEWTEvent
protected InputEvent(int eventType, Object source, long when, int modifiers) {
super(eventType, source, when);
- this.consumed=false;
this.modifiers=modifiers;
}
- public void consume() {
- consumed=true;
- }
-
- public boolean isConsumed() {
- return consumed;
- }
public int getModifiers() {
return modifiers;
}
@@ -94,6 +86,5 @@ public abstract class InputEvent extends NEWTEvent
return "InputEvent[modifiers:"+modifiers+", "+super.toString()+"]";
}
- private boolean consumed;
private int modifiers;
}
diff --git a/src/newt/classes/com/jogamp/newt/event/NEWTEvent.java b/src/newt/classes/com/jogamp/newt/event/NEWTEvent.java
index 9afcb840c..c85fc5f64 100644
--- a/src/newt/classes/com/jogamp/newt/event/NEWTEvent.java
+++ b/src/newt/classes/com/jogamp/newt/event/NEWTEvent.java
@@ -40,6 +40,13 @@ import java.util.*;
* NEWT events are provided for notification purposes ONLY;<br>
* The NEWT will automatically handle the event semantics internally, regardless of whether a program is receiving these events or not.<br>
* The actual event semantic is processed before the event is send.<br>
+ *
+ * Event type registry:<br>
+ * <ul>
+ * <li> WindowEvent <code>100..10x</code></li>
+ * <li> MouseEvent <code>200..20x</code></li>
+ * <li> KeyEvent <code>300..30x</code></li>
+ * </ul><br>
*/
public class NEWTEvent extends java.util.EventObject {
private boolean isSystemEvent;
@@ -61,6 +68,8 @@ public class NEWTEvent extends java.util.EventObject {
// 2: com.jogamp.newt.Window
// 2: com.jogamp.newt.event.awt.AWTNewtEventFactory
//
+ // FIXME: verify the isSystemEvent evaluation
+ //
static final String WindowClazzName = "com.jogamp.newt.Window" ;
static final String AWTNewtEventFactoryClazzName = "com.jogamp.newt.event.awt.AWTNewtEventFactory" ;
diff --git a/src/newt/classes/com/jogamp/newt/event/NEWTEventConsumer.java b/src/newt/classes/com/jogamp/newt/event/NEWTEventConsumer.java
index e37c820a1..d3d897f3b 100644
--- a/src/newt/classes/com/jogamp/newt/event/NEWTEventConsumer.java
+++ b/src/newt/classes/com/jogamp/newt/event/NEWTEventConsumer.java
@@ -36,8 +36,8 @@ public interface NEWTEventConsumer {
/**
* Consume the event
*
- * @return true if the event can be consumed now,
- * otherwise propagate it later.
+ * @return true if the event has been consumed,
+ * otherwise it returns false for later propagation.
*/
public boolean consumeEvent(NEWTEvent event);
}
diff --git a/src/newt/classes/com/jogamp/newt/event/NEWTEventListener.java b/src/newt/classes/com/jogamp/newt/event/NEWTEventListener.java
index 2a187f8c4..90d00383d 100644
--- a/src/newt/classes/com/jogamp/newt/event/NEWTEventListener.java
+++ b/src/newt/classes/com/jogamp/newt/event/NEWTEventListener.java
@@ -37,10 +37,5 @@ import com.jogamp.newt.*;
public interface NEWTEventListener extends java.util.EventListener
{
- public static final int WINDOW = 1 << 0;
- public static final int MOUSE = 1 << 1;
- public static final int KEY = 1 << 2;
- public static final int SURFACE = 1 << 3;
-
}
diff --git a/src/newt/classes/com/jogamp/newt/impl/awt/AWTDisplay.java b/src/newt/classes/com/jogamp/newt/impl/awt/AWTDisplay.java
index e705d364a..92c4e53eb 100644
--- a/src/newt/classes/com/jogamp/newt/impl/awt/AWTDisplay.java
+++ b/src/newt/classes/com/jogamp/newt/impl/awt/AWTDisplay.java
@@ -54,7 +54,7 @@ public class AWTDisplay extends Display {
protected void closeNative() { }
- public boolean runCreateAndDestroyOnEDT() {
+ protected boolean getShallRunOnEDT() {
return false;
}
protected void dispatchMessagesNative() { /* nop */ }
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 56e5a4240..db55aee6f 100644
--- a/src/newt/classes/com/jogamp/newt/impl/awt/AWTWindow.java
+++ b/src/newt/classes/com/jogamp/newt/impl/awt/AWTWindow.java
@@ -84,6 +84,14 @@ public class AWTWindow extends Window {
// non fullscreen dimensions ..
private int nfs_width, nfs_height, nfs_x, nfs_y;
+ protected void requestFocusImpl() {
+ runOnEDT(true, new Runnable() {
+ public void run() {
+ container.requestFocus();
+ }
+ });
+ }
+
protected void setTitleImpl(final String title) {
runOnEDT(true, new Runnable() {
public void run() {