diff --git a/BREAKING-CHANGES.txt b/BREAKING-CHANGES.txt index e9a2b033e6..bdfe0191e0 100644 --- a/BREAKING-CHANGES.txt +++ b/BREAKING-CHANGES.txt @@ -4,6 +4,30 @@ JUCE breaking changes develop ======= +Change +------ +The ComponentPeer::getFrameSize() function has been deprecated on Linux. + +Possible Issues +--------------- +Deprecation warnings will be seen when compiling code which uses this function +and eventually builds will fail when it is later removed from the API. + +Workaround +---------- +Use the ComponentPeer::getFrameSizeIfPresent() function. The new function returns +an OptionalBorderSize object. Use operator bool() to determine if the border size +is valid, then access the value using operator*() only if it is. + +Rationale +--------- +The XWindow system cannot return a valid border size immediately after window +creation. ComponentPeer::getFrameSize() returns a default constructed +BorderSize instance in such cases that corresponds to a frame size of +zero. That however can be a valid value, and needs to be treated differently +from the situation when the frame size is not yet available. + + Change ------ The return type of XWindowSystem::getBorderSize() was changed to diff --git a/extras/Projucer/Source/Application/jucer_MainWindow.cpp b/extras/Projucer/Source/Application/jucer_MainWindow.cpp index ca750a3e23..b12e2419c6 100644 --- a/extras/Projucer/Source/Application/jucer_MainWindow.cpp +++ b/extras/Projucer/Source/Application/jucer_MainWindow.cpp @@ -1012,7 +1012,8 @@ void MainWindowList::checkWindowBounds (MainWindow& windowToCheck) auto screenLimits = Desktop::getInstance().getDisplays().getDisplayForRect (windowBounds)->userArea; if (auto* peer = windowToCheck.getPeer()) - peer->getFrameSize().subtractFrom (screenLimits); + if (const auto frameSize = peer->getFrameSizeIfPresent()) + frameSize->subtractFrom (screenLimits); auto constrainedX = jlimit (screenLimits.getX(), jmax (screenLimits.getX(), screenLimits.getRight() - windowBounds.getWidth()), windowBounds.getX()); auto constrainedY = jlimit (screenLimits.getY(), jmax (screenLimits.getY(), screenLimits.getBottom() - windowBounds.getHeight()), windowBounds.getY()); diff --git a/modules/juce_audio_plugin_client/Standalone/juce_StandaloneFilterWindow.h b/modules/juce_audio_plugin_client/Standalone/juce_StandaloneFilterWindow.h index 58b458da9f..da537399b2 100644 --- a/modules/juce_audio_plugin_client/Standalone/juce_StandaloneFilterWindow.h +++ b/modules/juce_audio_plugin_client/Standalone/juce_StandaloneFilterWindow.h @@ -983,7 +983,8 @@ private: const auto windowBorders = [&]() -> BorderSize { if (auto* peer = owner.getPeer()) - return peer->getFrameSize(); + if (const auto frameSize = peer->getFrameSizeIfPresent()) + return *frameSize; return {}; }(); diff --git a/modules/juce_gui_basics/layout/juce_ComponentBoundsConstrainer.cpp b/modules/juce_gui_basics/layout/juce_ComponentBoundsConstrainer.cpp index 9ea63b2151..58f016197b 100644 --- a/modules/juce_gui_basics/layout/juce_ComponentBoundsConstrainer.cpp +++ b/modules/juce_gui_basics/layout/juce_ComponentBoundsConstrainer.cpp @@ -114,7 +114,8 @@ void ComponentBoundsConstrainer::setBoundsForComponent (Component* component, else { if (auto* peer = component->getPeer()) - border = peer->getFrameSize(); + if (const auto frameSize = peer->getFrameSizeIfPresent()) + border = *frameSize; auto screenBounds = Desktop::getInstance().getDisplays().getDisplayForPoint (targetBounds.getCentre())->userArea; diff --git a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm index 960d53e7a2..762077e21d 100644 --- a/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm +++ b/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm @@ -2390,7 +2390,16 @@ private: { if (auto* constrainer = owner->getConstrainer()) { - const auto originalBounds = owner->getFrameSize().addedTo (owner->getComponent().getScreenBounds()).toFloat(); + const auto originalBounds = [&]() -> Rectangle + { + const auto screenBounds = owner->getComponent().getScreenBounds(); + + if (const auto frameSize = owner->getFrameSizeIfPresent()) + return frameSize->addedTo (screenBounds).toFloat(); + + return screenBounds.toFloat(); + }(); + const auto expanded = originalBounds.withWidth ((float) constrainer->getMaximumWidth()) .withHeight ((float) constrainer->getMaximumHeight()); const auto constrained = expanded.constrainedWithin (convertToRectFloat (flippedScreenRect (r))); diff --git a/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp b/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp index 85c581c234..fecddb9200 100644 --- a/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp +++ b/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp @@ -1744,7 +1744,13 @@ void XWindowSystem::setBounds (::Window windowH, Rectangle newBounds, bool X11Symbols::getInstance()->xSetWMNormalHints (display, windowH, hints.get()); } - auto windowBorder = peer->getFrameSize(); + const auto windowBorder = [&]() -> BorderSize + { + if (const auto& frameSize = peer->getFrameSizeIfPresent()) + return *frameSize; + + return {}; + }(); X11Symbols::getInstance()->xMoveResizeWindow (display, windowH, newBounds.getX() - windowBorder.getLeft(), @@ -1774,7 +1780,14 @@ void XWindowSystem::updateConstraints (::Window windowH, ComponentPeer& peer) co } else if (auto* c = peer.getConstrainer()) { - const auto windowBorder = peer.getFrameSize(); + const auto windowBorder = [&]() -> BorderSize + { + if (const auto& frameSize = peer.getFrameSizeIfPresent()) + return *frameSize; + + return {}; + }(); + const auto factor = peer.getPlatformScaleFactor(); const auto leftAndRight = windowBorder.getLeftAndRight(); const auto topAndBottom = windowBorder.getTopAndBottom(); diff --git a/modules/juce_gui_basics/windows/juce_ComponentPeer.h b/modules/juce_gui_basics/windows/juce_ComponentPeer.h index 42d5718f2c..0ae006c62e 100644 --- a/modules/juce_gui_basics/windows/juce_ComponentPeer.h +++ b/modules/juce_gui_basics/windows/juce_ComponentPeer.h @@ -260,6 +260,9 @@ public: Whether or not the window has a normal window frame depends on the flags that were set when the window was created by Component::addToDesktop() */ + #if JUCE_LINUX || JUCE_BSD + [[deprecated ("Use getFrameSizeIfPresent instead.")]] + #endif virtual BorderSize getFrameSize() const = 0; /** This is called when the window's bounds change. diff --git a/modules/juce_gui_basics/windows/juce_ResizableWindow.cpp b/modules/juce_gui_basics/windows/juce_ResizableWindow.cpp index c766f54fcf..437475c7e5 100644 --- a/modules/juce_gui_basics/windows/juce_ResizableWindow.cpp +++ b/modules/juce_gui_basics/windows/juce_ResizableWindow.cpp @@ -532,9 +532,12 @@ String ResizableWindow::getWindowStateAsString() #if JUCE_LINUX if (auto* peer = isOnDesktop() ? getPeer() : nullptr) { - const auto frameSize = peer->getFrameSize(); - stateString << " frame " << frameSize.getTop() << ' ' << frameSize.getLeft() - << ' ' << frameSize.getBottom() << ' ' << frameSize.getRight(); + if (const auto optionalFrameSize = peer->getFrameSizeIfPresent()) + { + const auto& frameSize = *optionalFrameSize; + stateString << " frame " << frameSize.getTop() << ' ' << frameSize.getLeft() + << ' ' << frameSize.getBottom() << ' ' << frameSize.getRight(); + } } #endif @@ -610,7 +613,9 @@ bool ResizableWindow::restoreWindowStateFromString (const String& s) if (peer != nullptr) { - peer->getFrameSize().subtractFrom (newPos); + if (const auto frameSize = peer->getFrameSizeIfPresent()) + frameSize->subtractFrom (newPos); + peer->setNonFullScreenBounds (newPos); }