No immediate plans… Not being much of a linux guru, I often leave this kind of thing until people suggest bits of code as a starting point, because although it’s usually simple enough to write the code for windowing tasks, the almost total lack of documentation means that it can be a PITA to figure out where to begin.
Let’s start by reviewing the existing implementation. Looking at the JuceDemo->DnD, it’s not fully functional. Internal dnd works, but it doesn’t react to incoming files from external applications. After reviewing the specs (http://www.newplanetsoftware.com/xdnd/), working through juce_linux_Windowing.cpp and looking at a lot of code from other implementations, I think I’ve got it fixed with the patch below.
It has been tested successfully with the following filemanagers:
[list]
[]Dolphin (KDE default)[/]
[]Konqueror (older KDE/QT default)[/]
[]Nautilus (GNOME/GTK default)[/]
[]Thunar (XFCE/Enlightenment default)[/]
[]PCMan (LXDE default)[/]
[/list]
Please let me know if you have any questions or comments.
I intend to continue by fixing TextDragAndDropTarget to actually receive text (like text/plain) and not treat it like incoming files. That might depend somewhat on your acceptance of the patch below, so I’ll be very grateful for a prompt review!
Oh and one more thing: Some implementations (read QT/KDE) don’t actually make the dragged filenames available until the very drop, so callbacks fileDragEnter/fileDragMove/fileDragExit promised at http://www.rawmaterialsoftware.com/api/classFileDragAndDropTarget.html may or may not be called during the DnD operation. In essence, they get called with GTK-based drag-sources, but not with QT-based.
if ((clientMsg.data.l[1] & 1) != 0) // more than three supported mime types
{
ScopedXLock xlock;
GetXProperty prop (dragAndDropSourceWindow, Atoms::get().XdndTypeList, 0, 0x8000000L, false, XA_ATOM);
@@ -2440,7 +2453,7 @@ private:
}
}
if (srcMimeTypeAtomList.size() == 0)
if (srcMimeTypeAtomList.size() == 0) // no mime types yet, look up the (max) three sent in the message
{
for (int i = 2; i < 5; ++i)
if (clientMsg.data.l[i] != None)
@@ -2456,8 +2469,10 @@ private:
const Atoms& atoms = Atoms::get();
for (int i = 0; i < srcMimeTypeAtomList.size() && dragAndDropCurrentMimeType == 0; ++i)
for (int j = 0; j < numElementsInArray (atoms.allowedMimeTypes); ++j)
{
if (srcMimeTypeAtomList[i] == atoms.allowedMimeTypes[j])
dragAndDropCurrentMimeType = atoms.allowedMimeTypes[j];
Great, thank you. This is what I’m hoping to do for Linux DnD:
Complete the existing implementation
[list]
[] Implement return of “silent rectangle” to XdndPosition messages (basically tells the source “as long as you stay within this rect, don’t bother sending XdndPosition messages unless your control keys change”).[/]
[] Handle dropped url:s, like from Firefox[/]
[] Handle dropped text (TextDragAndDropTarget)[/][/list] Hopefully
[list]
[] Ability to act as Xdnd source, implement performExternalDragDropOfFiles() & performExternalDragDropOfText()[/][/list]
Suggestions and comments are very welcome. I also have a question:
During the DnD transaction, there is a negotiation of “Action”. Action is “what should I do once the file is received - copy it / move it / link to it /ask the user / private action”. Somewhat like right-dragging in MS Windows. My question: Is this implemented somewhere at all in JUCE, like callbacks or other info about suggested action after a file drop?
This patch adds Linux support for TextDragAndDropTarget, and extends FileDragAndDropTarget support for other data-urls than “file://…”, like dropping a www-url from Firefox.
BTW, none of the patches you’ve posted have ever worked for me… They all just give me error messages when I try to apply them. It’s not a line-endings problem, is there a linux/mac format difference? (seems unlikely)
My workflow is to branch of the current tip, apply a clean version of my additions (you know, filtering out all the DBG and std::cout), then git diff master…new_branch and paste that in the forum.
Just merged with tip including the fixes for Linux DnD (a25acde). There is one thing from my patch that I believe got lost: In order to receive other incoming text/uri-list than “file://…”, like www-urls dragged from a browser, the below patch (or something similar) needs to be applied.
[code]diff --git a/modules/juce_gui_basics/native/juce_linux_Windowing.cpp b/modules/juce_gui_basics/native/juce_linux_Windowing.cpp
index a207b61…4c189a6 100644
— a/modules/juce_gui_basics/native/juce_linux_Windowing.cpp
+++ b/modules/juce_gui_basics/native/juce_linux_Windowing.cpp
@@ -2516,7 +2516,7 @@ private:
if (Atoms::isMimeTypeFile (dragAndDropCurrentMimeType))
{
for (int i = 0; i < lines.size(); ++i)
Yeah, I know, but for me to drop the file in and review the changes in my git client can’t go wrong, whereas the last time I tried to apply your diff, I wasted half an hour messing about with line-endings trying to make it work, then gave up and merged it all by hand…
Anyway, thanks for the changes, I’ll have a look asap!