Przeglądaj źródła

Issue #174: drops reach plugins on X11 too (separate process included)

- XDND goes to the deepest XdndAware window under the pointer (JUCE fix 33), so a
  plugin editor embedded through XEmbed gets the file, in LYNX's plugin window and
  in the window of LYNX's separate plugin process, as OLE and AppKit already do.
- With LYNX's hook installed it alone decides whether a point is outside (JUCE fix
  32): on X11 JUCE's own lookup found nothing over LYNX's windows while the drag
  image was under the mouse. LYNX's lookup passes over windows that let the mouse
  through.
- --plugwintest's drop check reads the plugin's state through JUCE's VST3 wrapper.

Checked on a private X server with Chan Sampler 1.7.1 (VST3, CLAP, VST3 in a
separate process): a real drag from the Browser loads the sample in the plugin.
Ka1-S 3 tygodni temu
rodzic
commit
ff9fa73e63
3 zmienionych plików z 55 dodań i 10 usunięć
  1. 10 7
      cmake/LynxPatchJuce.cmake
  2. 16 2
      src/Main.cpp
  3. 29 1
      src/ui/ExternalDrag.cpp

+ 10 - 7
cmake/LynxPatchJuce.cmake

@@ -189,12 +189,15 @@
 #    `lynxExternalDropAtHook` (set by LYNX, ui/ExternalDrag.cpp) says that a screen point is a plugin's own editor (or
 #    another program's window above LYNX's): there the drag counts as outside (after 300 ms instead of 700, and even
 #    when a LYNX drop target is behind the plugin), and goes on as the file drag the plugin's own drop target gets.
-#    Without the hook: JUCE's test only.
+#    With the hook it alone decides: on X11 JUCE's Desktop::findComponentAt found nothing over LYNX's own windows
+#    while the drag image (a window of ours that lets the mouse through) was under the mouse. Without it: JUCE's test.
 # 33. Linux/BSD only, juce_gui_basics/native/juce_DragAndDrop_linux.cpp (issue #174): JUCE's XDND source sends a drag to
 #    the first XdndAware window under the pointer from the root down. Every JUCE window is XdndAware, so a plugin editor
-#    embedded in a LYNX window (its own XdndAware X window, reparented into LYNX's XEmbed host) never got it: LYNX's
-#    window took the drop. Below one of the app's OWN windows the search now goes on to a deeper XdndAware window (the
-#    plugin's) and sends it there; another program's windows are searched as before.
+#    embedded in a window (its own XdndAware X window, reparented into the host's XEmbed window: in LYNX's plugin window,
+#    or in the window of LYNX's separate plugin process) never got it: the host's window took the drop and had nobody to
+#    give it to. The search now goes on below an XdndAware window to the deepest XdndAware window under the pointer, the
+#    one that receives it, as OLE (Windows) and AppKit (macOS) pick the innermost registered window. A program with one
+#    XdndAware window (most) is reached as before.
 #
 # Used by CMake (lynx_patch_juce on the fetched JUCE) and by scripts/build-windows-zig.sh, which runs this file with
 # `cmake -DJUCE_DIR=<a copy of JUCE's juce_gui_basics module> -P cmake/LynxPatchJuce.cmake`.
@@ -243,9 +246,9 @@ function(lynx_patch_juce_file file)
             "        dragInfo.clear();|NL|        srcMimeTypeAtomList.clear();|NL||NL|        dragAndDropCurrentMimeType = 0;"
             "        dragInfo.clear();|NL|        srcMimeTypeAtomList.clear();|NL|        finishAfterDropDataReceived = false; // LYNX patch (issue #11): not left over from a failed drop|NL||NL|        dragAndDropCurrentMimeType = 0;")
 
-        lynx_juce_fix("XDND target below our own windows" "LYNX patch (issue #174): below one of our own windows"
+        lynx_juce_fix("XDND target: the deepest aware window" "LYNX patch (issue #174): a deeper XdndAware window"
             "        if (isWindowDnDAware (target))|NL|            return target;|NL|"
-            "        if (isWindowDnDAware (target))|NL|        {|NL|            // LYNX patch (issue #174): below one of our own windows a deeper XdndAware window (a hosted plugin's editor,|NL|            // embedded through XEmbed) is the target, not our window around it|NL|            if (getPeerFor (target) != nullptr)|NL|            {|NL|                ::Window lynxChild = None, lynxRoot;|NL|                int lynxPos;|NL|                unsigned int lynxMask;|NL||NL|                if (X11Symbols::getInstance()->xQueryPointer (getDisplay(), target, &lynxRoot, &lynxChild, &lynxPos, &lynxPos, &lynxPos, &lynxPos, &lynxMask)|NL|                    && lynxChild != None)|NL|                    if (const auto deeper = externalFindDragTargetWindow (lynxChild); deeper != None)|NL|                        return deeper;|NL|            }|NL||NL|            return target;|NL|        }|NL|")
+            "        if (isWindowDnDAware (target))|NL|        {|NL|            // LYNX patch (issue #174): a deeper XdndAware window under the pointer (a plugin's editor embedded through|NL|            // XEmbed) is the target, not the host window around it|NL|            ::Window lynxChild = None, lynxRoot;|NL|            int lynxPos;|NL|            unsigned int lynxMask;|NL||NL|            if (X11Symbols::getInstance()->xQueryPointer (getDisplay(), target, &lynxRoot, &lynxChild, &lynxPos, &lynxPos, &lynxPos, &lynxPos, &lynxMask)|NL|                && lynxChild != None)|NL|                if (const auto deeper = externalFindDragTargetWindow (lynxChild); deeper != None)|NL|                    return deeper;|NL||NL|            return target;|NL|        }|NL|")
     elseif(file MATCHES "juce_DragAndDropContainer.cpp$")
         lynx_juce_fix("external drop hook: declaration" "LYNX patch (issue #174): a place on screen"
             "bool juce_performDragDropText (const String&, bool& shouldStop);|NL|"
@@ -255,7 +258,7 @@ function(lynx_patch_juce_file file)
             "            auto now = Time::getCurrentTime();|NL|            // LYNX patch (issue #174): over a hosted plugin's editor no target of ours counts (it is the plugin's)|NL|            const auto lynxOutside = lynxExternalDropAtHook != nullptr && lynxExternalDropAtHook (screenPos);|NL||NL|            if (getCurrentlyOver() != nullptr && ! lynxOutside)|NL|                lastTimeOverTarget = now;|NL|            else if (now > lastTimeOverTarget + RelativeTime::milliseconds (lynxOutside ? 300 : 700))|NL|                checkForExternalDrag (details, screenPos, lynxOutside);")
         lynx_juce_fix("external drop hook: the test" "LYNX patch (issue #174): `outside`"
             "    void checkForExternalDrag (DragAndDropTarget::SourceDetails& details, Point<int> screenPos)|NL|    {|NL|        if (! hasCheckedForExternalDrag)|NL|        {|NL|            if (Desktop::getInstance().findComponentAt (screenPos) == nullptr)"
-            "    // LYNX patch (issue #174): `outside`: the hook said the point is a plugin's editor or another program's window|NL|    void checkForExternalDrag (DragAndDropTarget::SourceDetails& details, Point<int> screenPos, bool outside = false)|NL|    {|NL|        if (! hasCheckedForExternalDrag)|NL|        {|NL|            if (outside || Desktop::getInstance().findComponentAt (screenPos) == nullptr)")
+            "    // LYNX patch (issue #174): `outside`: the hook said the point is a plugin's editor or another program's window.|NL|    // With the hook it alone decides (on X11 findComponentAt found nothing over our own windows: the drag image|NL|    // under the mouse, a window of ours, counted as covering them).|NL|    void checkForExternalDrag (DragAndDropTarget::SourceDetails& details, Point<int> screenPos, bool outside = false)|NL|    {|NL|        if (! hasCheckedForExternalDrag)|NL|        {|NL|            if (lynxExternalDropAtHook != nullptr ? outside : Desktop::getInstance().findComponentAt (screenPos) == nullptr)")
     elseif(file MATCHES "juce_PopupMenu.cpp$")
         lynx_juce_fix("submenu corridor" "LYNX patch (issue #18): the way across"
             "        return areaTowardsSubMenu.contains (newGlobalPos.toFloat());|NL|    }"

+ 16 - 2
src/Main.cpp

@@ -6935,8 +6935,22 @@ private:
                 juce::MemoryBlock state;
                 instance->getStateInformation (state);
                 const auto name = dropFile.getFileNameWithoutExtension().toStdString();
-                const auto* bytes = static_cast<const char*> (state.getData());
-                const auto received = ! name.empty() && std::search (bytes, bytes + state.getSize(), name.begin(), name.end()) != bytes + state.getSize();
+                auto holds = [&name] (const juce::MemoryBlock& block) {
+                    const auto* bytes = static_cast<const char*> (block.getData());
+                    return ! name.empty() && std::search (bytes, bytes + block.getSize(), name.begin(), name.end()) != bytes + block.getSize();
+                };
+                auto received = holds (state);
+                // (JUCE's VST3 host keeps the plugin's own state base64-encoded inside an XML of its own)
+                auto xml = juce::AudioProcessor::getXmlFromBinary (state.getData(), (int) state.getSize());
+                if (xml == nullptr)
+                    xml = juce::parseXML (state.toString());
+                if (! received && xml != nullptr)
+                    for (auto* e : xml->getChildIterator())
+                    {
+                        juce::MemoryBlock inner;
+                        if (inner.fromBase64Encoding (e->getAllSubText().trim()) && holds (inner))
+                            received = true;
+                    }
                 step ("drop_received=" + juce::String ((int) received));
             }
 

+ 29 - 1
src/ui/ExternalDrag.cpp

@@ -22,6 +22,34 @@ bool otherProgramAt (juce::Point<int> screenPos);
 
 namespace
 {
+// LYNX's component at a screen point. On X11 JUCE's own lookup (Desktop::findComponentAt) asks each window whether a
+// window of ours above it covers the point, and the drag image under the mouse (a window that lets the mouse through)
+// counts: over LYNX's own windows it found nothing. Here windows that let the mouse through are passed over; other
+// programs' windows were already ruled out (otherProgramAt). Elsewhere JUCE's lookup is right.
+juce::Component* componentAt (juce::Point<int> screenPos)
+{
+#if JUCE_LINUX || JUCE_BSD
+    auto& desktop = juce::Desktop::getInstance();
+    for (int i = desktop.getNumComponents(); --i >= 0;)
+    {
+        auto* c = desktop.getComponent (i);
+        if (c == nullptr || ! c->isVisible() || ! c->getScreenBounds().contains (screenPos))
+            continue;
+        if (auto* peer = c->getPeer(); peer != nullptr && (peer->getStyleFlags() & juce::ComponentPeer::windowIgnoresMouseClicks) != 0)
+            continue;
+        bool self = true, children = true;
+        c->getInterceptsMouseClicks (self, children);
+        if (! self && ! children)
+            continue;
+        if (auto* hit = c->getComponentAt (c->getLocalPoint (nullptr, screenPos)))
+            return hit;
+    }
+    return nullptr;
+#else
+    return juce::Desktop::getInstance().findComponentAt (screenPos);
+#endif
+}
+
 bool hookAt (juce::Point<int> screenPos)
 {
     return placeAt (screenPos) != Place::lynx;
@@ -51,7 +79,7 @@ Place placeAt (juce::Point<int> screenPos)
 #endif
     // (on Windows and macOS JUCE's own hit test already leaves out a point where another program's window is in front;
     // MainComponent puts JUCE's list of LYNX's windows in screen order when a drag starts)
-    auto* c = juce::Desktop::getInstance().findComponentAt (screenPos);
+    auto* c = componentAt (screenPos);
     if (c == nullptr)
         return Place::otherProgram;
     return isHostedPluginEditor (c) ? Place::pluginEditor : Place::lynx;