# Component::addToDesktop() and setAlwaysOnTop()

**URL:** <https://forum.juce.com/t/component-addtodesktop-and-setalwaysontop/717>\
**Category:** General JUCE discussion\
**Created:** [March 8, 2006, 6:21pm UTC](https://forum.juce.com/t/component-addtodesktop-and-setalwaysontop/717 "2006-03-08T18:21:45Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![thomas](https://avatars.discourse-cdn.com/v4/letter/t/e36b37/32.png) [@thomas](https://forum.juce.com/u/thomas)\
**Post date:** [March 8, 2006, 6:21pm UTC](https://forum.juce.com/t/component-addtodesktop-and-setalwaysontop/717/1 "2006-03-08T18:21:45Z")

</div>

I need one of my components to be draggable outside the window like in the “misc widgets” page of the demo application. the behavior I need is the same one as the toolbars of photoshop for example.

I used addToDesktop(), but the window doesn’t stay on top of the main window if focus goes from this window to the main one.  
Then I used setAlwaysOnTop(), which let the window on top of other, but also on top of other applications.

The setAlwaysOnTop() should be replaced by two different functions like setAlwaysOnTopOfOtherComponents() and setAlwaysOnTopOfOtherDesktopWindows(),

Or is there other way to do this ?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [March 8, 2006, 7:09pm UTC](https://forum.juce.com/t/component-addtodesktop-and-setalwaysontop/717/2 "2006-03-08T19:09:00Z")

</div>

sure, but it’d be very hard to actually do that… Why not just make it always on top while it’s being dragged?

---

<div class="post-metadata">

**Author:** ![thomas](https://avatars.discourse-cdn.com/v4/letter/t/e36b37/32.png) [@thomas](https://forum.juce.com/u/thomas)\
**Post date:** [March 8, 2006, 9:24pm UTC](https://forum.juce.com/t/component-addtodesktop-and-setalwaysontop/717/3 "2006-03-08T21:24:15Z")

</div>

Don’t know what you mean exactly,  
Maybe I’ve not been very clear in what I’d like to do :

I’d like the component to stay on top of my application, but not on top of other application…  
which looks impossible after you do addToDesktop()

this is a common behaviour for draggable toolbars, like in visual studio if your drag out properties pannel. Or like the photoshop’s toolbars …

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [March 8, 2006, 9:26pm UTC](https://forum.juce.com/t/component-addtodesktop-and-setalwaysontop/717/4 "2006-03-08T21:26:31Z")

</div>

yes, I understand. I want to do some toolbar classes soon anyway, so will see if I can find a good solution then.

---

<div class="post-metadata">

**Author:** ![thomas](https://avatars.discourse-cdn.com/v4/letter/t/e36b37/32.png) [@thomas](https://forum.juce.com/u/thomas)\
**Post date:** [March 8, 2006, 11:34pm UTC](https://forum.juce.com/t/component-addtodesktop-and-setalwaysontop/717/5 "2006-03-08T23:34:28Z")

</div>

ok thanks !

---

<div class="post-metadata">

**Author:** ![OvermindDL1](https://avatars.discourse-cdn.com/v4/letter/o/a8b319/32.png) [@OvermindDL1](https://forum.juce.com/u/OvermindDL1)\
**Post date:** [March 9, 2006, 12:39am UTC](https://forum.juce.com/t/component-addtodesktop-and-setalwaysontop/717/6 "2006-03-09T00:39:02Z")

</div>

As an interim, you could do it so your main window, whenever it gets focus/redrawn/whatever, bring to top all of your other toolbar windows too. Mabye just always have the toolbar windows to be always on top when your app is focuesed, then removed from always on top when out of focus?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [March 9, 2006, 8:38am UTC](https://forum.juce.com/t/component-addtodesktop-and-setalwaysontop/717/7 "2006-03-09T08:38:58Z")

</div>

> [@OvermindDL1](#):
>
> As an interim, you could do it so your main window, whenever it gets focus/redrawn/whatever, bring to top all of your other toolbar windows too. Mabye just always have the toolbar windows to be always on top when your app is focuesed, then removed from always on top when out of focus?

yes, that’s the sort of thing I did in tracktion to keep the vst windows on top.

---

<div class="post-metadata">

**Author:** ![thomas](https://avatars.discourse-cdn.com/v4/letter/t/e36b37/32.png) [@thomas](https://forum.juce.com/u/thomas)\
**Post date:** [March 10, 2006, 8:39am UTC](https://forum.juce.com/t/component-addtodesktop-and-setalwaysontop/717/8 "2006-03-10T08:39:07Z")

</div>

That solved the problem thanks,

More precisely for those with same problem :

Use the focusGained(), focusLost() and minimisationStateChanged() callbacks of the main window to set the toolbars visible or invisible.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [March 10, 2006, 9:28am UTC](https://forum.juce.com/t/component-addtodesktop-and-setalwaysontop/717/9 "2006-03-10T09:28:13Z")

</div>

In fact a neater way (which might also catch some events that you’d otherwise miss) would be to use TopLevelWindow::activeWindowStatusChanged() and isActiveWindow()

---

<div class="post-metadata">

**Author:** ![jimw](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimw/32/539_2.png) [@jimw](https://forum.juce.com/u/jimw)\
**Post date:** [April 6, 2013, 2:20am UTC](https://forum.juce.com/t/component-addtodesktop-and-setalwaysontop/717/10 "2013-04-06T02:20:58Z")

</div>

Holy old thread revival, Batman! 🙂

I was being good and doing some research on my question before asking it, and came across this thread. Basically I want to do almost exactly what was described above:

> [@jules](#):
>
> [quote=“OvermindDL1”]As an interim, you could do it so your main window, whenever it gets focus/redrawn/whatever, bring to top all of your other toolbar windows too. Mabye just always have the toolbar windows to be always on top when your app is focuesed, then removed from always on top when out of focus?

yes, that’s the sort of thing I did in tracktion to keep the vst windows on top.[/quote]

Has anything changed with the recommended way of doing this in the intervening 7 years?? 🙂

Specifically, I have a plugin hosting app, and I want the plugins to be always on top _within my app_ only, but not system-wide. setAlwaysOnTop() sets the plugin windows to be always on top system-wide. I’m fine with adding platform-specific code, I’ve already done that to address this on the Mac side.

Alternatively, is there a way to get notification of when the application is switched away from the foreground? I could hide all the plugin windows when app is switched out. Note that my app also has other windows besides the “main” one and the plugin windows, for example there’s a separate prefs window. So when the prefs window is open, the main app window is not in focus, but this is not a case where I want to hide the plugin windows. I only want to do it when the entire app is actually switched out of the foreground.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [April 6, 2013, 11:49am UTC](https://forum.juce.com/t/component-addtodesktop-and-setalwaysontop/717/11 "2013-04-06T11:49:09Z")

</div>

No, don’t think I’ve added anything new to address this since this thread was started.

---

<div class="post-metadata">

**Author:** ![RiphRaph](https://avatars.discourse-cdn.com/v4/letter/r/97f17d/32.png) [@RiphRaph](https://forum.juce.com/u/RiphRaph)\
**Post date:** [February 3, 2014, 2:26pm UTC](https://forum.juce.com/t/component-addtodesktop-and-setalwaysontop/717/12 "2014-02-03T14:26:37Z")

</div>

Hi Jules,

I use a topLevelWindow component on which I do a AddToDesktop to display warning messages in my plugin.

Like the other people on this thread, I want the warning window to be on top of the plugin window but only inside the DAW scope.

On PC, this works perfectly but on Mac, the warning window is either behing the plugin (if setAlwaysOnTop(false)) or on top of all apps (if setAlwaysOnTop(true)).&nbsp;

I can't find any satisfying workaround to have a proper display.

The workaround that consists of changing the setAlwaysOnTop flag in focusGained() and focusLost() partially solves the problem. A major issue remains: If a topLevel window is displayed, and the user clicks outside the DAW and click back into the DAW, the topLevel window gets stuck behind the plugin,the DAW is unaccessable and I have to move the plugin to access the warning window to close it...

I'm amazed to see that this thread is 8-year-old and that no solution has been found yet.

Is there a chance to have a proper management of windows display on Mac soon?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [February 3, 2014, 3:54pm UTC](https://forum.juce.com/t/component-addtodesktop-and-setalwaysontop/717/13 "2014-02-03T15:54:44Z")

</div>

> Is there a chance to have a proper management of windows display on Mac soon?

No. Like I've said a million times, you shouldn't be popping out windows from a plugin - it's just not going to work on all hosts with all their different windowing arrangements. Especially now there are all kinds of extra confusions when you start getting 32/64-bit bridging processes, so that host/plugin windows are running in completely&nbsp;separate processes.

If you're just showing&nbsp;a warning message, why not just use a lightweight component inside your plugin window? Nothing can go wrong with that.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [May 12, 2017, 10:03am UTC](https://forum.juce.com/t/component-addtodesktop-and-setalwaysontop/717/14 "2017-05-12T10:03:16Z")

</div>

Closed on May 12, 2017, 10:03am UTC


