From f5f758c03222088e001dd073b619eb62ce8bb05c Mon Sep 17 00:00:00 2001 From: reuk Date: Mon, 30 Sep 2024 11:55:06 +0100 Subject: [PATCH] Partially revert "ComponentPeer: Add isShowing() member, which more closely matches expected behaviour of Component::isShowing" This partially reverts commit 555b667d228439e36cbcd8f820090c1882ce3d76. Using ComponentPeer::isShowing instead of ComponentPeer::isMinimised inside Component::isShowing can cause problems when displaying OpenGL components. Specifically, OpenGL components use a ComponentMovementWatcher to determine when they should be attached/detached from the parent window. The ComponentMovementWatcher updates whenever a component visibility change event is emitted, which happens in two cases: - Component::setVisible is called on the OpenGL component or an ancestor - ComponentPeer::handleMovedOrResized is called in response to a minimisation state change When handling either of these events, the ComponentMovementWatcher will call Component::isShowing to determine whether or not the component is really showing. The problem is that the result of ComponentPeer::isShowing may change independently of changes to the Component visiblity state or ComponentPeer minimisation state, so the ComponentPeerWatcher might not notify its listeners when a component is really shown/hidden. One potential workaround would be for the ComponentPeer to send notifications when the showing state of the window changes, so that the ComponentMovementWatcher can forward those notifications. The main problem with this approach is that on Windows, the window doesn't seem to receive a message on hide/show, and it's not clear whether there exists some other approach to detect a hide/show event. If there were some event we could listen for on Windows, then we could call Component::sendVisibilityChangeMessage in response to this event and things would *likely* work at that point, but this may still have unintended side-effect. As a result, I think the best approach to restore the old behaviour is to revert the change to Component::isShowing. The implementations of ComponentPeer::isShowing have been left in place so that users can do still query the real visibility state of native windows if necessary. --- modules/juce_gui_basics/components/juce_Component.cpp | 2 +- modules/juce_gui_basics/native/juce_Windowing_linux.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/juce_gui_basics/components/juce_Component.cpp b/modules/juce_gui_basics/components/juce_Component.cpp index f0e7723bc4..1db1947129 100644 --- a/modules/juce_gui_basics/components/juce_Component.cpp +++ b/modules/juce_gui_basics/components/juce_Component.cpp @@ -343,7 +343,7 @@ bool Component::isShowing() const return parentComponent->isShowing(); if (auto* peer = getPeer()) - return peer->isShowing(); + return ! peer->isMinimised(); return false; } diff --git a/modules/juce_gui_basics/native/juce_Windowing_linux.cpp b/modules/juce_gui_basics/native/juce_Windowing_linux.cpp index 599ac5e811..ae7926bb02 100644 --- a/modules/juce_gui_basics/native/juce_Windowing_linux.cpp +++ b/modules/juce_gui_basics/native/juce_Windowing_linux.cpp @@ -206,7 +206,7 @@ public: bool isShowing() const override { - return XWindowSystem::getInstance()->isMinimised (windowH); + return ! XWindowSystem::getInstance()->isMinimised (windowH); } void setFullScreen (bool shouldBeFullScreen) override