Преглед изворни кода

Merge branch 'feature/dock188a'

Ka1-S пре 3 недеља
родитељ
комит
9bf2f8515f

+ 59 - 0
docs/analise/REA_rodada188a.md

@@ -0,0 +1,59 @@
+# Round 188a: issue #116, docked plugin windows, slice 2 (all panels native)
+
+Design: `REA_rodada181c.md` (approved). Slice 1: `REA_rodada186a.md` §2. This slice is step (c) of that design.
+
+## 1. What FL does (FL 2026 v26.1.7, 2026-11-09 07:59, shots E:\lynx-work\dock188a\shots\fl-*.png)
+Default template, the 808 Kick's Sampler opened from the Channel rack (docked, FL's default), Mixer already shown:
+- fl-03: the plugin window opens in front of the Channel rack and the Mixer.
+- fl-04: a click on the Mixer's title brings the Mixer in front of the plugin; the rack stays behind it.
+- fl-05: a click on the plugin's title brings it back in front of the Mixer.
+- fl-06: F7 shows the Piano roll (maximised) in front of everything, the plugin included. fl-07: F7 again hides it,
+  the plugin is where it was.
+- fl-08: F5 shows the Playlist in front of the plugin. fl-09: a click on the plugin brings it back in front of the
+  Playlist. fl-10: a click on the Playlist's title strip brings the Playlist in front again.
+- Detached (from 181c, f116h–j): a detached plugin window stays on top whatever panel is clicked.
+
+So every floating panel behaves like the Channel rack: the clicked (or called) one comes in front of the docked
+plugin windows, the others keep their place.
+
+## 2. What LYNX does now (LYNX_DOCKED_PLUGINS=1; without it nothing changes)
+- `Workspace::isNativePanel`: the Playlist, Channel rack, Piano roll and Mixer frames are native child windows of the
+  main window (unless detached). The Browser, a background panel always below them, stays a plain component.
+- `applyLayout` no longer brings every native panel to the front: a native panel moves only when it is out of order,
+  just above the panel before it (`nativechild::keepAbove`), so a docked plugin window keeps its place after any
+  layout change. A panel shown by its key (F5..F9, `show` / `toggle`) or maximised comes in front of the docked
+  plugin windows, as in fl-06 / fl-08. A click on a panel brings it in front (slice 1).
+- The hover value tip (Settings › General) also reads controls in native panels.
+- `--plugwintest` dock mode now runs the real main component (real panels) and checks, for the Channel rack,
+  Playlist, Piano roll and Mixer: native child, plugin in front when opened, the panel in front after its click, the
+  others still behind the plugin, the plugin in front after its click; then a layout change elsewhere (Browser hidden
+  and shown) keeps the plugin in front, F9's `show (mixer)` brings the Mixer in front, and the Detached round trip
+  (owned top-level window above every clicked panel, saved flag, docked again). `LYNX_PLUGWIN_STEP_MS` sets how
+  long each state is held (default 3000 ms, for screenshots).
+- `--plugwintest` with an instrument: the test adds the channel after the song's own channels and now looks for the
+  plugin in that channel (it looked at channel 0, so instruments were "not hosted").
+
+## 3. Best way?
+- **FL:** above (shots fl-03…fl-10, 181c f116e–j).
+- **Ableton:** Live has no floating panels; plugin windows are separate top-level windows that always float over the
+  main window (Options › "Auto-Hide Plug-In Windows", "Multiple Plug-In Windows"). That is LYNX's Detached.
+- **Users:** FL users get lost when a docked plugin goes behind a panel and ask for "detached by default" / a hotkey
+  (forum.image-line.com/viewtopic.php?p=1874369 "Detach all plugins doesn't work", p=2031644 "Plugins always on top",
+  p=1692944 "Always visible option for plugin windows").
+- **Verdict:** FL-exact docking as the default (the approved design), keeping the per-plugin Detached toggle. Worth
+  adding later, as an option: FL's General › "Detach all new plugins" (seen in 186a), which covers the users'
+  "detached by default" request in FL's own way.
+
+## 4. Known limits left
+- Lightweight overlays drawn over the workspace (setup overlay, drag highlights painted by the main component) stay
+  under the native panels; drag images are desktop windows, so drags show.
+- No fade when a native panel opens or closes. DPI changes are not passed to docked editors yet.
+- The .flp Detached bit is still not mapped (step d).
+
+## 5. Proof (cloud build run 42605112824, "round build: success")
+- `--plugwintest` dock mode, ValhallaFreqEcho (effect) and LYNX FM10 (instrument, the case that was "not hosted"):
+  every check `=1`, `dock_result=OK`, `result=OK` (E:\lynx-work\dock188a\rep-effA.txt, rep-instA.txt).
+- `--selftest`: result=OK.
+- Idle CPU of the plain app, 30 s after 15 s settling, alternating runs: off 14.1 % / 7.9 %, docked 7.1 % / 14.4 %
+  of one core. The spread is between runs, not between modes: no idle cost measured.
+- FL | LYNX sheets: E:\lynx-work\dock188a\shots\116-4…116-11.

+ 89 - 34
src/Main.cpp

@@ -3812,49 +3812,96 @@ private:
             juce::AudioPluginInstance* instance = nullptr;
             juce::AudioProcessorParameter* checked = nullptr;
             std::unique_ptr<juce::DocumentWindow> mainWindow; // stands for LYNX's main window (window ownership)
+            lynx::Workspace* workspace = nullptr; // LYNX_PLUGWIN_DOCK=1: the real main window's desktop (issue #116)
+            int channelIndex = -1;                // an instrument: its channel (added after the song's own channels)
+            int stepMs = 3000;                    // dock mode: each state held that long (screenshots)
             bool keysDone = false;
-            std::unique_ptr<lynx::Workspace> workspace;       // LYNX_PLUGWIN_DOCK=1: its desktop (issue #116)
             bool dockOk = true;
             std::function<void (bool)> done;
 
-            // issue #116 (with LYNX_DOCKED_PLUGINS=1 and LYNX_PLUGWIN_DOCK=1): FL's docked window goes behind a clicked
-            // Channel rack and comes back in front when clicked; Detached reopens it as a window of its own
+            // issue #116 (with LYNX_DOCKED_PLUGINS=1 and LYNX_PLUGWIN_DOCK=1), FL's f116 sequence for every floating
+            // panel: the docked plugin window goes behind a clicked panel and comes back in front when clicked; a
+            // panel called by its key comes in front too; Detached reopens it as a window of its own, which stays above
+            // every panel clicked (it is owned by the main window).
+            const std::array<lynx::workspace::Panel, 4> dockPanels { lynx::workspace::Panel::channelRack, lynx::workspace::Panel::playlist,
+                                                                     lynx::workspace::Panel::pianoRoll, lynx::workspace::Panel::mixer };
+            const int dockSteps = 2 * 4 + 5;
+
+            void* panelHandle (lynx::workspace::Panel p) const { return workspace->getFrame (p).getWindowHandle(); }
+
             void dockCheck (int at)
             {
                 using lynx::workspace::Panel;
                 auto* main = mainWindow->getWindowHandle();
-                auto* rack = workspace->getFrame (Panel::channelRack).getWindowHandle();
                 auto* plug = lynx::PluginWindows::hostWindowHandle (*instance);
                 auto expect = [this] (const juce::String& name, bool value) {
                     step (name + "=" + juce::String ((int) value));
                     dockOk = dockOk && value;
                 };
+                auto id = [] (Panel p) { return juce::String (lynx::workspace::panelId (p)); };
                 if (at == 0)
                 {
                     expect ("docked", lynx::PluginWindows::isDocked (*instance));
-                    expect ("rack_native_child", rack != nullptr && rack != main && lynx::nativechild::parentOf (rack) == main);
                     expect ("plugin_native_child", plug != nullptr && lynx::nativechild::parentOf (plug) == main);
-                    expect ("plugin_above_rack_when_opened", lynx::nativechild::isAbove (plug, rack));
-                    workspace->activate (Panel::channelRack); // a click on the rack
-                    expect ("rack_above_plugin_after_rack_click", lynx::nativechild::isAbove (rack, plug));
+                    for (auto p : dockPanels)
+                    {
+                        auto* h = panelHandle (p);
+                        expect (id (p) + "_visible", workspace->isPanelVisible (p));
+                        expect (id (p) + "_native_child", h != nullptr && h != main && lynx::nativechild::parentOf (h) == main);
+                        expect ("plugin_above_" + id (p) + "_when_opened", lynx::nativechild::isAbove (plug, h));
+                    }
+                    expect ("browser_plain", ! workspace->isNativePanel (Panel::browser));
                 }
-                else if (at == 1)
+                if (at < 2 * 4)
                 {
-                    lynx::PluginWindows::open ({}, *instance, {}); // (open again = bring the open one in front)
-                    expect ("plugin_above_rack_after_plugin_click", lynx::nativechild::isAbove (plug, rack));
+                    const auto p = dockPanels[at / 2];
+                    if (at % 2 == 0)
+                    {
+                        workspace->activate (p); // a click on the panel
+                        expect (id (p) + "_above_plugin_after_its_click", lynx::nativechild::isAbove (panelHandle (p), plug));
+                        // the plugin stays above the panels nobody clicked
+                        for (auto other : dockPanels)
+                            if (other != p)
+                                expect ("plugin_above_" + id (other) + "_after_" + id (p) + "_click", lynx::nativechild::isAbove (plug, panelHandle (other)));
+                    }
+                    else
+                    {
+                        lynx::PluginWindows::open ({}, *instance, {}); // (open again = a click on the plugin)
+                        expect ("plugin_above_" + id (p) + "_after_plugin_click", lynx::nativechild::isAbove (plug, panelHandle (p)));
+                    }
+                    return;
+                }
+                if (at == 8)
+                {
+                    // a layout change elsewhere (a panel resized, the Browser shown) keeps the plugin in front; a panel
+                    // called by its key comes in front of it
+                    workspace->hide (Panel::browser);
+                    workspace->show (Panel::browser);
+                    for (auto p : dockPanels)
+                        expect ("plugin_above_" + id (p) + "_after_layout_change", lynx::nativechild::isAbove (plug, panelHandle (p)));
+                    workspace->show (Panel::mixer);
+                    expect ("mixer_above_plugin_after_show", lynx::nativechild::isAbove (panelHandle (Panel::mixer), plug));
                 }
-                else if (at == 2)
+                else if (at == 9)
                     lynx::PluginWindows::setDetached (*instance, true);
-                else if (at == 3)
+                else if (at == 10)
                 {
                     expect ("detached_reopened", lynx::PluginWindows::isOpen (*instance) && ! lynx::PluginWindows::isDocked (*instance));
                     expect ("detached_owned_by_main", plug != nullptr && lynx::nativechild::ownerOf (plug) == main);
-                    expect ("detached_saved", find() == instance && engineRef()->detached);
+                    expect ("detached_saved", find() == instance && engineRef() != nullptr && engineRef()->detached);
+                    for (auto p : dockPanels)
+                        workspace->activate (p);
+                }
+                else if (at == 11)
+                {
+                    // (an owned top-level window: above the main window and so above all its child windows)
+                    expect ("detached_stays_above_clicked_panels", plug != nullptr && lynx::nativechild::ownerOf (plug) == main
+                                                                       && lynx::nativechild::parentOf (plug) != main && lynx::PluginWindows::isOpen (*instance));
                     lynx::PluginWindows::setDetached (*instance, false);
                 }
                 else
                 {
-                    expect ("docked_again", lynx::PluginWindows::isDocked (*instance) && ! engineRef()->detached);
+                    expect ("docked_again", lynx::PluginWindows::isDocked (*instance) && engineRef() != nullptr && ! engineRef()->detached);
                     step (juce::String ("dock_result=") + (dockOk ? "OK" : "FAILED"));
                 }
             }
@@ -3863,7 +3910,7 @@ private:
             {
                 const auto& song = engine->getSong();
                 if (instrument)
-                    return song.channels.empty() ? nullptr : &song.channels.back().plugin;
+                    return channelIndex < 0 || channelIndex >= (int) song.channels.size() ? nullptr : &song.channels[(size_t) channelIndex].plugin;
                 return song.mixer.size() < 2 || song.mixer[1].effects.empty() ? nullptr : &song.mixer[1].effects[0].plugin;
             }
 
@@ -3877,8 +3924,7 @@ private:
             {
                 if (instrument)
                 {
-                    // (the channel added last: the engine's default song may already have some)
-                    if (auto* p = dynamic_cast<lynx::PluginInstrument*> (engine->getChannelInstrument ((int) engine->getSong().channels.size() - 1).get()))
+                    if (auto* p = dynamic_cast<lynx::PluginInstrument*> (engine->getChannelInstrument (channelIndex).get()))
                         return &p->getInstance();
                 }
                 else if (auto* p = dynamic_cast<lynx::PluginEffect*> (engine->getEffect (1, 0).get()))
@@ -3941,13 +3987,13 @@ private:
                         step ("browser_lists=" + juce::String (lynx::pluginpresetui::userPresets (instance->getName()).size()));
                     }
 
-                    // (the channel added last, as find() above: the engine's default song may already have some)
-                    std::shared_ptr<void> owner = instrument ? std::shared_ptr<void> (engine->getChannelInstrument ((int) engine->getSong().channels.size() - 1))
+                    std::shared_ptr<void> owner = instrument ? std::shared_ptr<void> (engine->getChannelInstrument (channelIndex))
                                                              : std::shared_ptr<void> (engine->getEffect (1, 0));
                     lynx::PluginWindows::open (owner, *instance, instance->getName(),
                                                { engine.get(), [this] (lynx::Song& song) -> lynx::PluginRef* {
                                                     if (instrument)
-                                                        return song.channels.empty() ? nullptr : &song.channels.back().plugin;
+                                                        return channelIndex < 0 || channelIndex >= (int) song.channels.size()
+                                                                   ? nullptr : &song.channels[(size_t) channelIndex].plugin;
                                                     return song.mixer.size() < 2 || song.mixer[1].effects.empty() ? nullptr : &song.mixer[1].effects[0].plugin;
                                                 }, instrument });
                     owner.reset();
@@ -3961,7 +4007,7 @@ private:
                     keysDone = ! lynx::pluginKeysTestTick (*instance->getActiveEditor(),
                                                            [this] (bool on) {
                                                                engine->editSong ([this, on] (lynx::Song& song) {
-                                                                   (instrument ? song.channels.back().plugin : song.mixer[1].effects[0].plugin).hostKeysFirst = on;
+                                                                   (instrument ? song.channels[(size_t) channelIndex].plugin : song.mixer[1].effects[0].plugin).hostKeysFirst = on;
                                                                });
                                                            },
                                                            [this] (const juce::String& line) { step (line); });
@@ -3969,13 +4015,16 @@ private:
                 if (phase == 1 && ticks == 20 && checked != nullptr)
                     step ("param_after_1s=" + juce::String (checked->getValue(), 4));
                 // (3 s apart: time for screenshots of each state)
-                if (phase == 1 && workspace != nullptr && dockStep < 5 && elapsedMs >= (dockStep + 1) * 3000)
+                if (phase == 1 && workspace != nullptr && dockStep < dockSteps && elapsedMs >= (dockStep + 1) * stepMs)
                     dockCheck (dockStep++);
-                if (phase == 1 && elapsedMs >= seconds * 1000 && (workspace == nullptr || dockStep >= 5)) // remove the plugin from the song
+                if (phase == 1 && elapsedMs >= seconds * 1000 && (workspace == nullptr || dockStep >= dockSteps)) // remove the plugin from the song
                 {
                     engine->editSong ([this] (lynx::Song& song) {
                         if (instrument)
-                            song.channels.clear();
+                        {
+                            if (channelIndex >= 0 && channelIndex < (int) song.channels.size())
+                                song.channels.erase (song.channels.begin() + channelIndex);
+                        }
                         else
                             song.mixer[1].effects.clear();
                     });
@@ -4004,10 +4053,8 @@ private:
             juce::MessageManager::callAsync ([this, test] {
                 lynx::setMainWindowForOwnership (nullptr);
                 lynx::PluginWindows::setDockWorkspace (nullptr);
-                if (test->mainWindow != nullptr)
-                    test->mainWindow->clearContentComponent();
                 test->workspace = nullptr;
-                test->mainWindow = nullptr;
+                test->mainWindow = nullptr; // (dock mode: the main component with it, before the engine)
                 test->engine = nullptr;
                 delete test;
                 quit();
@@ -4018,17 +4065,24 @@ private:
         test->mainWindow->setBounds (20, 20, 300, 200);
         if (juce::SystemStats::getEnvironmentVariable ("LYNX_PLUGWIN_DOCK", {}) == "1" && lynx::nativechild::dockingEnabled())
         {
-            test->workspace = std::make_unique<lynx::Workspace>();
-            test->mainWindow->setContentNonOwned (test->workspace.get(), false);
-            test->mainWindow->setBounds (20, 20, 1200, 760);
-            lynx::PluginWindows::setDockWorkspace (test->workspace.get());
+            // the real main window's contents (it docks plugin windows in its own desktop), so the panels are real
+            juce::LookAndFeel::setDefaultLookAndFeel (&lookAndFeel);
+            auto* ui = new lynx::MainComponent (*test->engine, false);
+            test->mainWindow->setUsingNativeTitleBar (true);
+            test->mainWindow->setContentOwned (ui, false);
+            test->mainWindow->setBounds (20, 20, 1500, 900);
+            test->workspace = &ui->workspaceForTest();
+            if (const auto ms = juce::SystemStats::getEnvironmentVariable ("LYNX_PLUGWIN_STEP_MS", {}).getIntValue(); ms > 0)
+                test->stepMs = ms;
         }
         test->mainWindow->setVisible (true);
         lynx::setMainWindowForOwnership (test->mainWindow.get());
         if (test->workspace != nullptr)
         {
-            test->workspace->show (lynx::workspace::Panel::channelRack);
-            test->step ("dock_test=1 rack_visible=" + juce::String ((int) test->workspace->isPanelVisible (lynx::workspace::Panel::channelRack)));
+            using lynx::workspace::Panel;
+            for (auto p : { Panel::playlist, Panel::mixer, Panel::pianoRoll, Panel::channelRack })
+                test->workspace->show (p);
+            test->step ("dock_test=2 rack_visible=" + juce::String ((int) test->workspace->isPanelVisible (Panel::channelRack)));
         }
         auto& host = test->engine->getPluginHost();
         test->step ("plugins_in_file=" + juce::String (host.addPluginFile (juce::File (pluginPath))));
@@ -4058,6 +4112,7 @@ private:
                 c.name = ref.name;
                 c.instrument = lynx::InstrumentKind::plugin;
                 c.plugin = ref;
+                test->channelIndex = (int) song.channels.size();
                 song.channels.push_back (c);
             }
             else

+ 2 - 1
src/ui/MainComponent.cpp

@@ -6514,7 +6514,8 @@ void MainComponent::updateHoverValue (juce::Component* hovered, const ui::Hint&
     }
     const auto at = juce::Desktop::getInstance().getMainMouseSource().getScreenPosition().roundToInt();
     const auto show = hovered != nullptr && hint.value.isNotEmpty() && ! juce::ModifierKeys::currentModifiers.isAnyMouseButtonDown()
-                      && hovered->getTopLevelComponent() == getTopLevelComponent();
+                      && (hovered->getTopLevelComponent() == getTopLevelComponent()
+                          || (bool) hovered->getTopLevelComponent()->getProperties().getWithDefault ("lynxNativeChild", false));
     if (! show)
     {
         if (hoverTipShown)

+ 1 - 0
src/ui/MainComponent.h

@@ -109,6 +109,7 @@ public:
     // --uiperf (round 173f): the default layout with these panels shown too (the reporter's Channel Rack + Mixer)
     void showPanelsForSnapshot (std::initializer_list<workspace::Panel> panels);
     void openQuickAddForTest() { showQuickAdd(); } // --windowtest
+    Workspace& workspaceForTest() { return workspace; } // --plugwintest dock mode (issue #116)
     void waitForBrowserForSnapshot() { browser.waitForListing (5000); }
     juce::StringArray getMenuNamesForSnapshot() { return getMenuBarNames(); }
     juce::PopupMenu getMenuForSnapshot (int index) { return getMenuForIndex (index, {}); }

+ 18 - 0
src/ui/NativeChild.cpp

@@ -116,6 +116,24 @@ void refresh (juce::Component& c, juce::Component& area)
     place (c, area, bounds);
 }
 
+void keepAbove (juce::Component& c, juce::Component* below)
+{
+    if (below == nullptr || ! isAttached (c) || ! isAttached (*below))
+        return;
+    auto* self = c.getWindowHandle();
+    auto* under = below->getWindowHandle();
+    if (self == nullptr || under == nullptr || self == under || isAbove (self, under))
+        return;
+   #if JUCE_WINDOWS
+    // SetWindowPos puts a window just below its "insert after" window: the one right above `below`, or the top
+    const auto above = GetWindow (static_cast<HWND> (under), GW_HWNDPREV);
+    SetWindowPos (static_cast<HWND> (self), above != nullptr ? above : HWND_TOP, 0, 0, 0, 0,
+                  SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
+   #else
+    c.toFront (false);
+   #endif
+}
+
 void forwardUnusedKeys (juce::Component& c)
 {
     c.addKeyListener (&keyForwarder()); // (JUCE adds a listener once)

+ 5 - 0
src/ui/NativeChild.h

@@ -29,6 +29,11 @@ juce::Rectangle<int> boundsIn (const juce::Component& c, const juce::Component&
 // back at the same place in `area`.
 void refresh (juce::Component& c, juce::Component& area);
 
+// Stacking among the attached siblings without disturbing the others: if `c` is not above `below` it goes just above it
+// (under whatever was right above `below`); `below` == nullptr: nothing. Elsewhere than Windows: `c` comes to the front
+// when it has to move.
+void keepAbove (juce::Component& c, juce::Component* below);
+
 // Keys nothing in an attached component used: they don't travel up to the main window by themselves (it is another
 // native window), so `c` hands them to the main window's shortcuts (the secondary windows' route, ui/WindowOwner.h).
 void forwardUnusedKeys (juce::Component& c);

+ 37 - 4
src/ui/Workspace.cpp

@@ -703,6 +703,8 @@ bool Workspace::toggle (Panel panel)
 {
     const auto visible = layout.toggle (panel);
     applyLayout (true);
+    if (visible)
+        nativeToFront (panel);
     return visible;
 }
 
@@ -710,6 +712,15 @@ void Workspace::show (Panel panel)
 {
     layout.show (panel);
     applyLayout (true);
+    nativeToFront (panel);
+}
+
+void Workspace::nativeToFront (Panel panel)
+{
+    // issue #116: a panel called by its key (F5..F9) or maximised comes in front of the docked plugin windows too, as a
+    // click on it does (applyLayout keeps them where they were among the panels)
+    if (auto& frame = *frames[(std::size_t) panel]; isNativePanel (panel) && nativechild::isAttached (frame) && frame.isVisible())
+        frame.toFront (false);
 }
 
 void Workspace::hide (Panel panel)
@@ -722,6 +733,7 @@ void Workspace::toggleMaximised (Panel panel)
 {
     layout.toggleMaximised (panel);
     applyLayout();
+    nativeToFront (panel);
 }
 
 void Workspace::setDetached (Panel panel, bool detached)
@@ -845,7 +857,9 @@ std::vector<juce::Rectangle<int>> Workspace::otherPanelBounds (Panel panel) cons
 
 bool Workspace::isNativePanel (Panel panel) const
 {
-    return nativechild::dockingEnabled() && panel == Panel::channelRack && ! layout[panel].detached;
+    // every floating panel (the Playlist, Channel rack, Piano roll and Mixer, slice 2); the Browser is a background
+    // panel, always below them and the docked plugin windows, so it stays a plain component (REA_rodada181c)
+    return nativechild::dockingEnabled() && ! isBackgroundPanel (panel) && ! layout[panel].detached;
 }
 
 juce::Component& Workspace::getFrame (Panel panel) const
@@ -932,6 +946,7 @@ void Workspace::applyLayout (bool fadePanels)
         bool in;
     };
     std::vector<Fade> fades;
+    std::array<bool, workspace::panelCount> nativeShown {}; // (native panels that were hidden and show now)
 
     for (int i = 0; i < workspace::panelCount; ++i)
     {
@@ -987,7 +1002,9 @@ void Workspace::applyLayout (bool fadePanels)
             placeFrame (frame, state.maximised ? getLocalBounds() : toJuce (state.bounds));
             if (nativechild::isAttached (frame))
             {
-                frame.setVisible (state.visible && isVisible()); // (no fade: a child window has no transparency)
+                const auto show = state.visible && isVisible();
+                nativeShown[(std::size_t) i] = show && ! frame.isVisible();
+                frame.setVisible (show); // (no fade: a child window has no transparency)
             }
             // a panel the user opens or closes fades in or out (Settings › General › Animations, round 179a), after
             // the stacking order below is set
@@ -1004,9 +1021,25 @@ void Workspace::applyLayout (bool fadePanels)
         frame.refreshButtons();
     }
 
-    // stacking order (back to front): the background panels first, then the floating ones
+    // stacking order (back to front): the background panels first, then the floating ones. Issue #116: native panels
+    // are only moved when they are out of order, and then just above the panel before them, so a docked plugin window
+    // keeps its place among them (a layout change elsewhere doesn't hide it); a panel that shows now comes in front of
+    // everything (F7, F9: as a click on it, FL brings it in front of the docked plugin windows).
+    juce::Component* nativeBelow = nullptr;
     for (auto panel : layout.stacking())
-        frames[(std::size_t) panel]->toFront (false);
+    {
+        auto& frame = *frames[(std::size_t) panel];
+        if (! nativechild::isAttached (frame))
+        {
+            frame.toFront (false);
+            continue;
+        }
+        if (nativeShown[(std::size_t) panel])
+            frame.toFront (false);
+        else
+            nativechild::keepAbove (frame, nativeBelow);
+        nativeBelow = &frame;
+    }
 
     // The animator's timer runs only during a fade. Closing fades a picture of the panel placed right behind it (so
     // after the stacking above), and the panel itself is hidden at once. Opening: the frame is opaque (it hides what is

+ 1 - 0
src/ui/Workspace.h

@@ -123,6 +123,7 @@ private:
     struct PeerWatch;
     std::unique_ptr<PeerWatch> peerWatch;
     std::vector<juce::Component::SafePointer<juce::Component>> dockedFrames;
+    void nativeToFront (Panel panel);
     void rehostNativeFrames(); // the main window's native window was (re)created or the desktop moved in it
     void applyLayout (bool fadePanels = false); // fadePanels: a panel the user opened or closed fades (round 179a)
     void setFocusedPanel (Panel panel);