aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt/classes
diff options
context:
space:
mode:
Diffstat (limited to 'src/newt/classes')
-rw-r--r--src/newt/classes/com/jogamp/newt/Window.java34
-rw-r--r--src/newt/classes/com/jogamp/newt/opengl/GLWindow.java19
-rw-r--r--src/newt/classes/jogamp/newt/DisplayImpl.java8
-rw-r--r--src/newt/classes/jogamp/newt/WindowImpl.java72
-rw-r--r--src/newt/classes/jogamp/newt/driver/x11/X11Screen.java28
-rw-r--r--src/newt/classes/jogamp/newt/driver/x11/X11Window.java36
6 files changed, 161 insertions, 36 deletions
diff --git a/src/newt/classes/com/jogamp/newt/Window.java b/src/newt/classes/com/jogamp/newt/Window.java
index 24555bf39..a69b8dbb3 100644
--- a/src/newt/classes/com/jogamp/newt/Window.java
+++ b/src/newt/classes/com/jogamp/newt/Window.java
@@ -225,6 +225,40 @@ public interface Window extends NativeWindow, WindowClosingProtocol {
String getTitle();
+ boolean isPointerVisible();
+
+ /**
+ * Makes the pointer visible or invisible.
+ *
+ * @param pointerVisible defaults to <code>true</code> for platforms w/ visible pointer,
+ * otherwise defaults to <code>true</code>, eg. Android.
+ * @see #confinePointer(boolean)
+ */
+ void setPointerVisible(boolean pointerVisible);
+
+ boolean isPointerConfined();
+
+ /**
+ * Confine the pointer to this window, ie. pointer jail.
+ * <p>
+ * In combination w/ {@link #warpPointer(int, int)}
+ * and maybe {@link #setPointerVisible(boolean)} a simple mouse
+ * navigation can be realized.</p>
+ *
+ * @param confine defaults to <code>false</code>.
+ */
+ void confinePointer(boolean confine);
+
+ /**
+ * Moves the pointer to x/y relative to this window's origin.
+ *
+ * @param x relative pointer x position within this window
+ * @param y relative pointer y position within this window
+ *
+ * @see #confinePointer(boolean)
+ */
+ void warpPointer(int x, int y);
+
/** Defining ids for the reparenting strategy */
public interface ReparentAction {
/** No native reparenting valid */
diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
index 3a49c06f0..5001e55e5 100644
--- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
+++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
@@ -215,10 +215,29 @@ public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer, FPSC
return window.getTitle();
}
+ public final boolean isPointerVisible() {
+ return window.isPointerVisible();
+ }
+
+ public final void setPointerVisible(boolean mouseVisible) {
+ window.setPointerVisible(mouseVisible);
+ }
+
+ public final boolean isPointerConfined() {
+ return window.isPointerConfined();
+ }
+
+ public final void confinePointer(boolean grab) {
+ window.confinePointer(grab);
+ }
+
public final void setUndecorated(boolean value) {
window.setUndecorated(value);
}
+ public final void warpPointer(int x, int y) {
+ window.warpPointer(x, y);
+ }
public final boolean isUndecorated() {
return window.isUndecorated();
}
diff --git a/src/newt/classes/jogamp/newt/DisplayImpl.java b/src/newt/classes/jogamp/newt/DisplayImpl.java
index 2d251614b..908a44ea2 100644
--- a/src/newt/classes/jogamp/newt/DisplayImpl.java
+++ b/src/newt/classes/jogamp/newt/DisplayImpl.java
@@ -438,15 +438,15 @@ public abstract class DisplayImpl extends Display {
}
}
- public interface DisplayRunnable {
- Object run(long dpy);
+ public interface DisplayRunnable<T> {
+ T run(long dpy);
}
- public final Object runWithLockedDisplayHandle(DisplayRunnable action) {
+ public final <T> T runWithLockedDisplayHandle(DisplayRunnable<T> action) {
final AbstractGraphicsDevice aDevice = getGraphicsDevice();
if(null == aDevice) {
throw new RuntimeException("null device - not initialized: "+this);
}
- Object res;
+ T res;
aDevice.lock();
try {
res = action.run(aDevice.getHandle());
diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java
index 00911443a..7bef0b564 100644
--- a/src/newt/classes/jogamp/newt/WindowImpl.java
+++ b/src/newt/classes/jogamp/newt/WindowImpl.java
@@ -96,6 +96,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
protected String title = "Newt Window";
protected boolean undecorated = false;
protected boolean alwaysOnTop = false;
+ private boolean pointerVisible = true;
+ private boolean pointerConfined = false;
private LifecycleHook lifecycleHook = null;
private DestroyAction destroyAction = new DestroyAction();
@@ -280,6 +282,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
createNativeImpl();
screen.addScreenModeListener(screenModeListenerImpl);
setTitleImpl(title);
+ setPointerVisibleImpl(pointerVisible);
+ confinePointerImpl(pointerConfined);
if(waitForVisible(true, false)) {
if(isFullscreen()) {
fullscreen = false;
@@ -522,6 +526,10 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
*/
protected abstract void updateInsetsImpl(Insets insets);
+ protected boolean setPointerVisibleImpl(boolean pointerVisible) { return false; }
+ protected boolean confinePointerImpl(boolean confine) { return false; }
+ protected void warpPointerImpl(int x, int y) { }
+
//----------------------------------------------------------------------
// NativeSurface
//
@@ -1216,20 +1224,6 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
return capsRequested;
}
- public String getTitle() {
- return title;
- }
-
- public void setTitle(String title) {
- if (title == null) {
- title = "";
- }
- this.title = title;
- if(0 != getWindowHandle()) {
- setTitleImpl(title);
- }
- }
-
private class DecorationActionImpl implements Runnable {
boolean undecorated;
@@ -1328,6 +1322,55 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
return alwaysOnTop || fullscreen ;
}
+ public String getTitle() {
+ return title;
+ }
+ public void setTitle(String title) {
+ if (title == null) {
+ title = "";
+ }
+ this.title = title;
+ if(0 != getWindowHandle()) {
+ setTitleImpl(title);
+ }
+ }
+
+ public boolean isPointerVisible() {
+ return pointerVisible;
+ }
+ public void setPointerVisible(boolean pointerVisible) {
+ if(this.pointerVisible != pointerVisible) {
+ boolean setVal = 0 == getWindowHandle();
+ if(!setVal) {
+ setVal = setPointerVisibleImpl(pointerVisible);
+ }
+ if(setVal) {
+ this.pointerVisible = pointerVisible;
+ }
+ }
+ }
+ public boolean isPointerConfined() {
+ return pointerConfined;
+ }
+
+ public void confinePointer(boolean confine) {
+ if(this.pointerConfined != confine) {
+ boolean setVal = 0 == getWindowHandle();
+ if(!setVal) {
+ setVal = confinePointerImpl(confine);
+ }
+ if(setVal) {
+ this.pointerConfined = confine;
+ }
+ }
+ }
+
+ public void warpPointer(int x, int y) {
+ if(0 != getWindowHandle()) {
+ warpPointerImpl(x, y);
+ }
+ }
+
public void requestFocus() {
enqueueRequestFocus(true);
}
@@ -1368,7 +1411,6 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
return fullscreen;
}
-
//----------------------------------------------------------------------
// Window
//
diff --git a/src/newt/classes/jogamp/newt/driver/x11/X11Screen.java b/src/newt/classes/jogamp/newt/driver/x11/X11Screen.java
index a67352138..af96dc460 100644
--- a/src/newt/classes/jogamp/newt/driver/x11/X11Screen.java
+++ b/src/newt/classes/jogamp/newt/driver/x11/X11Screen.java
@@ -53,8 +53,8 @@ public class X11Screen extends ScreenImpl {
protected void createNativeImpl() {
// validate screen index
- Long handle = (Long) display.runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable() {
- public Object run(long dpy) {
+ Long handle = display.runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable<Long>() {
+ public Long run(long dpy) {
long handle = GetScreen0(dpy, screen_idx);
if(0 != handle) {
setScreenSize(getWidth0(dpy, screen_idx), getHeight0(dpy, screen_idx));
@@ -79,8 +79,8 @@ public class X11Screen extends ScreenImpl {
private int nmode_number;
protected int[] getScreenModeFirstImpl() {
- return (int[]) runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable() {
- public Object run(long dpy) {
+ return runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable<int[]>() {
+ public int[] run(long dpy) {
// initialize iterators and static data
nrotations = getAvailableScreenModeRotations0(dpy, screen_idx);
if(null==nrotations || 0==nrotations.length) {
@@ -108,8 +108,8 @@ public class X11Screen extends ScreenImpl {
protected int[] getScreenModeNextImpl() {
// assemble: w x h x bpp x f x r
- return (int[]) runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable() {
- public Object run(long dpy) {
+ return runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable<int[]>() {
+ public int[] run(long dpy) {
/**
System.err.println("******** mode: "+nmode_number);
System.err.println("rot "+nrotation_index);
@@ -172,8 +172,8 @@ public class X11Screen extends ScreenImpl {
}
protected ScreenMode getCurrentScreenModeImpl() {
- return (ScreenMode) runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable() {
- public Object run(long dpy) {
+ return runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable<ScreenMode>() {
+ public ScreenMode run(long dpy) {
int resNumber = getNumScreenModeResolutions0(dpy, screen_idx);
if(0==resNumber) {
return null;
@@ -222,8 +222,8 @@ public class X11Screen extends ScreenImpl {
throw new RuntimeException("ScreenMode not element of ScreenMode list: "+screenMode);
}
final long t0 = System.currentTimeMillis();
- Boolean done = (Boolean) runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable() {
- public Object run(long dpy) {
+ boolean done = runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable<Boolean>() {
+ public Boolean run(long dpy) {
boolean done = false;
int resNumber = getNumScreenModeResolutions0(dpy, screen_idx);
int resIdx = getScreenModesIdx2NativeIdx().get(screenModeIdx);
@@ -243,19 +243,19 @@ public class X11Screen extends ScreenImpl {
}
return Boolean.valueOf(done);
}
- });
+ }).booleanValue();
- if(!done.booleanValue()) {
+ if(done) {
System.err.println("X11Screen.setCurrentScreenModeImpl: TO ("+SCREEN_MODE_CHANGE_TIMEOUT+") reached: "+
(System.currentTimeMillis()-t0)+"ms");
}
- return done.booleanValue();
+ return done;
}
//----------------------------------------------------------------------
// Internals only
//
- private final Object runWithLockedDisplayHandle(DisplayRunnable action) {
+ private final <T> T runWithLockedDisplayHandle(DisplayRunnable<T> action) {
return display.runWithLockedDisplayHandle(action);
// return runWithTempDisplayHandle(action);
}
diff --git a/src/newt/classes/jogamp/newt/driver/x11/X11Window.java b/src/newt/classes/jogamp/newt/driver/x11/X11Window.java
index dfb84f6f8..c435f993c 100644
--- a/src/newt/classes/jogamp/newt/driver/x11/X11Window.java
+++ b/src/newt/classes/jogamp/newt/driver/x11/X11Window.java
@@ -129,14 +129,41 @@ public class X11Window extends WindowImpl {
@Override
protected void setTitleImpl(final String title) {
- runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable() {
+ runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable<Object>() {
public Object run(long dpy) {
setTitle0(dpy, getWindowHandle(), title);
return null;
}
});
}
+
+ @Override
+ protected boolean setPointerVisibleImpl(final boolean pointerVisible) {
+ return runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable<Boolean>() {
+ public Boolean run(long dpy) {
+ return Boolean.valueOf(setPointerVisible0(getDisplayEDTHandle(), getWindowHandle(), pointerVisible));
+ }
+ }).booleanValue();
+ }
+ @Override
+ protected boolean confinePointerImpl(final boolean confine) {
+ return runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable<Boolean>() {
+ public Boolean run(long dpy) {
+ return Boolean.valueOf(confinePointer0(getDisplayEDTHandle(), getWindowHandle(), confine));
+ }
+ }).booleanValue();
+ }
+
+ @Override
+ protected void warpPointerImpl(final int x, final int y) {
+ runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable<Boolean>() {
+ public Boolean run(long dpy) {
+ return Boolean.valueOf(warpPointer0(getDisplayEDTHandle(), getWindowHandle(), x, y));
+ }
+ });
+ }
+
protected Point getLocationOnScreenImpl(final int x, final int y) {
// X11Util.GetRelativeLocation: locks display already !
return X11Util.GetRelativeLocation( getScreen().getDisplay().getHandle(), getScreenIndex(), getWindowHandle(), 0 /*root win*/, x, y);
@@ -153,7 +180,7 @@ public class X11Window extends WindowImpl {
private final long getDisplayEDTHandle() {
return ((X11Display) getScreen().getDisplay()).getEDTHandle();
}
- private final Object runWithLockedDisplayHandle(DisplayRunnable action) {
+ private final <T> T runWithLockedDisplayHandle(DisplayRunnable<T> action) {
return ((DisplayImpl) getScreen().getDisplay()).runWithLockedDisplayHandle(action);
// return runWithTempDisplayHandle(action);
}
@@ -168,6 +195,9 @@ public class X11Window extends WindowImpl {
private native void setTitle0(long display, long windowHandle, String title);
private native void requestFocus0(long display, long windowHandle, boolean force);
private native long getParentWindow0(long display, long windowHandle);
-
+ private native boolean setPointerVisible0(long display, long windowHandle, boolean visible);
+ private native boolean confinePointer0(long display, long windowHandle, boolean grab);
+ private native boolean warpPointer0(long display, long windowHandle, int x, int y);
+
private long windowHandleClose;
}