From 600ebcac40ee2d13947701fffc51ea93887db89c Mon Sep 17 00:00:00 2001
From: Sven Gothel <sgothel@jausoft.com>
Date: Mon, 10 Oct 2011 08:05:26 +0200
Subject: NEWT Pointer Feature: Add Windows impl. ; Fix test (warp action) ;
 Minor cleanup in X11

---
 src/newt/classes/jogamp/newt/WindowImpl.java       |  2 ++
 .../jogamp/newt/driver/windows/WindowsWindow.java  | 40 ++++++++++++++++++++++
 .../classes/jogamp/newt/driver/x11/X11Window.java  | 19 +++++-----
 3 files changed, 53 insertions(+), 8 deletions(-)

(limited to 'src/newt/classes/jogamp')

diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java
index 7bef0b564..b5cd3e5fd 100644
--- a/src/newt/classes/jogamp/newt/WindowImpl.java
+++ b/src/newt/classes/jogamp/newt/WindowImpl.java
@@ -1357,6 +1357,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
         if(this.pointerConfined != confine) {
             boolean setVal = 0 == getWindowHandle();
             if(!setVal) {
+                requestFocus();
+                warpPointer(width/2, height/2);
                 setVal = confinePointerImpl(confine);
             }
             if(setVal) {
diff --git a/src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java b/src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java
index ee057fb8f..6e1444da3 100644
--- a/src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java
+++ b/src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java
@@ -188,6 +188,43 @@ public class WindowsWindow extends WindowImpl {
         setTitle0(getWindowHandle(), title);
     }
 
+    @Override
+    protected boolean setPointerVisibleImpl(final boolean pointerVisible) {
+        final Boolean[] res = new Boolean[] { Boolean.FALSE };
+        
+        this.runOnEDTIfAvail(true, new Runnable() {
+            public void run() {
+                res[0] = Boolean.valueOf(setPointerVisible0(getWindowHandle(), pointerVisible));
+            }
+        });
+        return res[0].booleanValue();
+    }
+
+    @Override
+    protected boolean confinePointerImpl(final boolean confine) {
+        final Boolean[] res = new Boolean[] { Boolean.FALSE };
+        
+        this.runOnEDTIfAvail(true, new Runnable() {
+            public void run() {
+                final Point p0 = getLocationOnScreenImpl(0, 0);
+                res[0] = Boolean.valueOf(confinePointer0(getWindowHandle(), confine, 
+                        p0.getX(), p0.getY(), p0.getX()+width, p0.getY()+height));
+            }
+        });
+        return res[0].booleanValue();
+    }
+    
+    @Override
+    protected void warpPointerImpl(final int x, final int y) {        
+        this.runOnEDTIfAvail(true, new Runnable() {
+            public void run() {
+                final Point sPos = getLocationOnScreenImpl(x, y);
+                warpPointer0(getWindowHandle(), sPos.getX(), sPos.getY());
+            }
+        });
+        return;
+    }
+        
     protected Point getLocationOnScreenImpl(int x, int y) {
         return GDI.GetRelativeLocation( getWindowHandle(), 0 /*root win*/, x, y);
     }
@@ -211,4 +248,7 @@ public class WindowsWindow extends WindowImpl {
     private static native void setTitle0(long windowHandle, String title);
     private native void requestFocus0(long windowHandle, boolean force);
 
+    private static native boolean setPointerVisible0(long windowHandle, boolean visible);
+    private static native boolean confinePointer0(long windowHandle, boolean grab, int l, int t, int r, int b);
+    private static native void warpPointer0(long windowHandle, int x, int y);    
 }
diff --git a/src/newt/classes/jogamp/newt/driver/x11/X11Window.java b/src/newt/classes/jogamp/newt/driver/x11/X11Window.java
index c435f993c..2b6bac215 100644
--- a/src/newt/classes/jogamp/newt/driver/x11/X11Window.java
+++ b/src/newt/classes/jogamp/newt/driver/x11/X11Window.java
@@ -157,9 +157,10 @@ public class X11Window extends WindowImpl {
     
     @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));
+        runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable<Object>() {
+            public Object run(long dpy) {
+                warpPointer0(getDisplayEDTHandle(), getWindowHandle(), x, y);
+                return null;
             }
         });
     }
@@ -186,18 +187,20 @@ public class X11Window extends WindowImpl {
     }
 
     protected static native boolean initIDs0();
+    
     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, int flags); 
     private native void CloseWindow0(long display, long windowHandle, long javaObjectAtom, long windowDeleteAtom);
     private native void reconfigureWindow0(long display, int screen_index, long parentWindowHandle, long windowHandle,
                                            int x, int y, int width, int height, int flags);    
-    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 static native void setTitle0(long display, long windowHandle, String title);
+    private static native long getParentWindow0(long display, long windowHandle);
+    private static native boolean setPointerVisible0(long display, long windowHandle, boolean visible);
+    private static native boolean confinePointer0(long display, long windowHandle, boolean grab);
+    private static native void warpPointer0(long display, long windowHandle, int x, int y);
     
     private long   windowHandleClose;
 }
-- 
cgit v1.2.3