Bug 1164 - Drag and Drop integration
Summary: Drag and Drop integration
Status: UNCONFIRMED
Alias: None
Product: Newt
Classification: JogAmp
Component: core (show other bugs)
Version: 1
Hardware: All all
: --- enhancement
Assignee: Sven Gothel
URL:
Depends on:
Blocks:
 
Reported: 2015-06-13 13:56 CEST by Johann Sorel
Modified: 2016-10-12 10:46 CEST (History)
1 user (show)

See Also:
Type: FEATURE
SCM Refs:
Workaround: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Johann Sorel 2015-06-13 13:56:48 CEST
I'm not sure if this more related to drag&drop or to the clipboard but here is the point.

The objective is to be able to catch dragged files or objects from the system on the newt window. This would allow to obtain a better integration of the application in the operating system.

Some examples :
- image/3d model viewers
- archive managers

It would allow the user to drag the files over the application to add them, much more convenient then a file chooser.

Doing it the otherway (application to OS) would be interesting too, but one thing at the time :).
Comment 1 jeremy.lugat 2016-10-12 10:46:18 CEST
In our software, we decide to use Newt, but in order to don't change mouse and key events API, we decide to get mouseEvent and keyEvent from Newt, convert them into AWTEvent and dispatch them to component.

We have some problems, particularly on DnD : I doesn't work.
So we modify to code in order to bypass Newt Mouse and Key Event, and keep AWTEvent. So we have event as usual and it works.

We only change it for Linux (X11).

Here is the diff for v2.2.4 tag :

diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
index 2ba030f..86dd3fe 100644
--- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
+++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
@@ -68,6 +68,7 @@
 import javax.media.opengl.GLSharedContextSetter;
 
 import jogamp.newt.WindowImpl;
+import jogamp.newt.driver.x11.WindowDriver;
 import jogamp.opengl.GLAutoDrawableBase;
 import jogamp.opengl.GLContextImpl;
 import jogamp.opengl.GLDrawableImpl;
@@ -144,6 +145,13 @@
             });
         this.window.setLifecycleHook(new GLLifecycleHook());
     }
+    
+    protected GLWindow(final Window window, boolean ignoreMouseAndKeyEvent){
+        this(window);
+        if(this.window instanceof WindowDriver){
+            ((WindowDriver) this.window).setIgnoreMouseAndKeyEvent(ignoreMouseAndKeyEvent);
+        }
+    }
 
     @Override
     public final Object getUpstreamWidget() {
@@ -168,6 +176,10 @@
         return new GLWindow(NewtFactory.createWindow(caps));
     }
 
+    public static GLWindow create(final GLCapabilitiesImmutable caps, boolean ignoreMouseAndKeyEvent) {
+        return new GLWindow(NewtFactory.createWindow(caps),ignoreMouseAndKeyEvent);
+    }
+    
     /**
      * Creates a new GLWindow attaching a new Window referencing the given Screen
      * with the given GLCapabilities.
diff --git a/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java
index afa9786..8db15ba 100644
--- a/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java
@@ -67,6 +67,8 @@
 
     private static final int defaultIconDataSize;
     private static final Buffer defaultIconData;
+    
+    private boolean ignoreMouseAndKeyEvent = false;
 
     static {
         ScreenDriver.initSingleton();
@@ -419,6 +421,10 @@
     public final void enqueueKeyEvent(final boolean wait, final short eventType, final int modifiers, final short keyCode, final short keySym, final char keyChar) {
         throw new InternalError("XXX: Adapt Java Code to Native Code Changes");
     }
+    
+    public void setIgnoreMouseAndKeyEvent(boolean ignore){
+        ignoreMouseAndKeyEvent = ignore;
+    }
 
     //----------------------------------------------------------------------
     // Internals only
@@ -444,12 +450,12 @@
                              visualID, javaObjectAtom, windowDeleteAtom,
                              x, y, width, height, autoPosition, flags,
                              pixelDataSize,
-                             pixels, Buffers.getDirectBufferByteOffset(pixels), true /* pixels_is_direct */);
+                             pixels, Buffers.getDirectBufferByteOffset(pixels), true /* pixels_is_direct */,ignoreMouseAndKeyEvent);
     }
     private native long CreateWindow0(long parentWindowHandle, long display, int screen_index,
                                       int visualID, long javaObjectAtom, long windowDeleteAtom,
                                       int x, int y, int width, int height, boolean autoPosition, int flags,
-                                      int pixelDataSize, Object pixels, int pixels_byte_offset, boolean pixels_is_direct);
+                                      int pixelDataSize, Object pixels, int pixels_byte_offset, boolean pixels_is_direct, boolean ignoreMouseAndKeyEvent);
     private native void CloseWindow0(long display, long windowHandle, long javaObjectAtom, long windowDeleteAtom /*, long kbdHandle*/ ); // XKB disabled for now
     private native void reconfigureWindow0(long display, int screen_index, long parentWindowHandle, long windowHandle,
                                            long windowDeleteAtom, int x, int y, int width, int height, int flags);
diff --git a/src/newt/native/X11Window.c b/src/newt/native/X11Window.c
index 2cc66c7..fdb187b 100644
--- a/src/newt/native/X11Window.c
+++ b/src/newt/native/X11Window.c
@@ -522,7 +522,8 @@
                              jint visualID, 
                              jlong javaObjectAtom, jlong windowDeleteAtom, 
                              jint x, jint y, jint width, jint height, jboolean autoPosition, int flags,
-                             jint pixelDataSize, jobject pixels, jint pixels_byte_offset, jboolean pixels_is_direct)
+                             jint pixelDataSize, jobject pixels, jint pixels_byte_offset, jboolean pixels_is_direct,
+                             jboolean ignoreMouseAndKeyEvent)
 {
     Display * dpy = (Display *)(intptr_t)display;
     Atom wm_delete_atom = (Atom)windowDeleteAtom;
@@ -597,9 +598,15 @@
     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.event_mask  = X11_MOUSE_EVENT_MASK;
-    xswa.event_mask |= KeyPressMask | KeyReleaseMask ;
-    xswa.event_mask |= FocusChangeMask | SubstructureNotifyMask | StructureNotifyMask | ExposureMask ;
+    if(ignoreMouseAndKeyEvent){
+    	xswa.event_mask = FocusChangeMask | SubstructureNotifyMask | StructureNotifyMask | ExposureMask ;
+    }
+    else
+    {
+	    xswa.event_mask  = X11_MOUSE_EVENT_MASK;
+	    xswa.event_mask |= KeyPressMask | KeyReleaseMask ;
+	    xswa.event_mask |= FocusChangeMask | SubstructureNotifyMask | StructureNotifyMask | ExposureMask ;
+    }
 
     xswa.colormap = XCreateColormap(dpy,
                                     windowParent,