1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

DropShadower: Detect when window is no longer being displayed on the current desktop and hide shadows

This commit is contained in:
reuk 2021-10-14 19:57:44 +01:00
parent b72b155443
commit acddcd550d
No known key found for this signature in database
GPG key ID: 9ADCD339CFC98A11
2 changed files with 67 additions and 11 deletions

View file

@ -75,7 +75,8 @@ private:
JUCE_DECLARE_NON_COPYABLE (ShadowWindow)
};
class ParentVisibilityChangedListener : public ComponentListener
class ParentVisibilityChangedListener : public ComponentListener,
private Timer
{
public:
ParentVisibilityChangedListener (Component& r, ComponentListener& l)
@ -83,6 +84,9 @@ public:
{
if (auto* firstParent = root->getParentComponent())
updateParentHierarchy (firstParent);
if ((SystemStats::getOperatingSystemType() & SystemStats::Windows) != 0)
startTimerHz (20);
}
~ParentVisibilityChangedListener() override
@ -146,6 +150,11 @@ private:
withDifference (observedComponents, lastSeenComponents, [this] (auto& comp) { comp.addComponentListener (this); });
}
void timerCallback() override
{
listener->componentVisibilityChanged (*root);
}
Component* root = nullptr;
ComponentListener* listener = nullptr;
std::set<ComponentWithWeakReference> observedComponents;
@ -246,15 +255,11 @@ void DropShadower::updateShadows()
const ScopedValueSetter<bool> setter (reentrant, true);
if (owner == nullptr)
{
shadowWindows.clear();
return;
}
if (owner->isShowing()
&& owner->getWidth() > 0 && owner->getHeight() > 0
&& (Desktop::canUseSemiTransparentWindows() || owner->getParentComponent() != nullptr))
if (owner != nullptr
&& owner->isShowing()
&& owner->getWidth() > 0 && owner->getHeight() > 0
&& (Desktop::canUseSemiTransparentWindows() || owner->getParentComponent() != nullptr)
&& isWindowOnCurrentVirtualDesktop (owner->getWindowHandle()))
{
while (shadowWindows.size() < 4)
shadowWindows.add (new ShadowWindow (owner, shadow));