diff --git a/modules/juce_gui_basics/native/juce_linux_Windowing.cpp b/modules/juce_gui_basics/native/juce_linux_Windowing.cpp index 6489771623..e94d482d19 100644 --- a/modules/juce_gui_basics/native/juce_linux_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_linux_Windowing.cpp @@ -333,18 +333,30 @@ public: void setParentWindow (::Window newParent) { parentWindow = newParent; } //============================================================================== + bool isConstrainedNativeWindow() const + { + return constrainer != nullptr + && (styleFlags & (windowHasTitleBar | windowIsResizable)) == (windowHasTitleBar | windowIsResizable) + && ! isKioskMode(); + } + void updateWindowBounds() { - jassert (windowH != 0); - if (windowH != 0) + if (windowH == 0) { - auto physicalBounds = XWindowSystem::getInstance()->getWindowBounds (windowH, parentWindow); + jassertfalse; + return; + } - updateScaleFactorFromNewBounds (physicalBounds, true); + if (isConstrainedNativeWindow()) + XWindowSystem::getInstance()->updateConstraints (windowH); - bounds = parentWindow == 0 ? Desktop::getInstance().getDisplays().physicalToLogical (physicalBounds) - : physicalBounds / currentScaleFactor; - } + auto physicalBounds = XWindowSystem::getInstance()->getWindowBounds (windowH, parentWindow); + + updateScaleFactorFromNewBounds (physicalBounds, true); + + bounds = parentWindow == 0 ? Desktop::getInstance().getDisplays().physicalToLogical (physicalBounds) + : physicalBounds / currentScaleFactor; } void updateBorderSize() 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 27e7dd99ba..7d543132a7 100644 --- a/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp +++ b/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp @@ -1720,6 +1720,8 @@ void XWindowSystem::setBounds (::Window windowH, Rectangle newBounds, bool } } + updateConstraints (windowH, *peer); + XWindowSystemUtilities::ScopedXLock xLock; if (auto hints = makeXFreePtr (X11Symbols::getInstance()->xAllocSizeHints())) @@ -1729,14 +1731,6 @@ void XWindowSystem::setBounds (::Window windowH, Rectangle newBounds, bool hints->y = newBounds.getY(); hints->width = newBounds.getWidth(); hints->height = newBounds.getHeight(); - - if ((peer->getStyleFlags() & ComponentPeer::windowIsResizable) == 0) - { - hints->min_width = hints->max_width = hints->width; - hints->min_height = hints->max_height = hints->height; - hints->flags |= PMinSize | PMaxSize; - } - X11Symbols::getInstance()->xSetWMNormalHints (display, windowH, hints.get()); } @@ -1750,6 +1744,40 @@ void XWindowSystem::setBounds (::Window windowH, Rectangle newBounds, bool } } +void XWindowSystem::updateConstraints (::Window windowH) const +{ + if (auto* peer = getPeerFor (windowH)) + updateConstraints (windowH, *peer); +} + +void XWindowSystem::updateConstraints (::Window windowH, ComponentPeer& peer) const +{ + XWindowSystemUtilities::ScopedXLock xLock; + + if (auto hints = makeXFreePtr (X11Symbols::getInstance()->xAllocSizeHints())) + { + if ((peer.getStyleFlags() & ComponentPeer::windowIsResizable) == 0) + { + hints->min_width = hints->max_width = peer.getBounds().getWidth(); + hints->min_height = hints->max_height = peer.getBounds().getHeight(); + hints->flags = PMinSize | PMaxSize; + } + else if (auto* c = peer.getConstrainer()) + { + const auto windowBorder = peer.getFrameSize(); + const auto leftAndRight = windowBorder.getLeftAndRight(); + const auto topAndBottom = windowBorder.getTopAndBottom(); + hints->min_width = jmax (1, c->getMinimumWidth() - leftAndRight); + hints->max_width = jmax (1, c->getMaximumWidth() - leftAndRight); + hints->min_height = jmax (1, c->getMinimumHeight() - topAndBottom); + hints->max_height = jmax (1, c->getMaximumHeight() - topAndBottom); + hints->flags = PMinSize | PMaxSize; + } + + X11Symbols::getInstance()->xSetWMNormalHints (display, windowH, hints.get()); + } +} + bool XWindowSystem::contains (::Window windowH, Point localPos) const { ::Window root, child; diff --git a/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.h b/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.h index 2c1191a6c0..9877165c1b 100644 --- a/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.h +++ b/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.h @@ -177,6 +177,7 @@ public: void setIcon (::Window , const Image&) const; void setVisible (::Window, bool shouldBeVisible) const; void setBounds (::Window, Rectangle, bool fullScreen) const; + void updateConstraints (::Window) const; BorderSize getBorderSize (::Window) const; Rectangle getWindowBounds (::Window, ::Window parentWindow); @@ -316,6 +317,7 @@ private: void dismissBlockingModals (LinuxComponentPeer*) const; void dismissBlockingModals (LinuxComponentPeer*, const XConfigureEvent&) const; + void updateConstraints (::Window, ComponentPeer&) const; ::Window findTopLevelWindowOf (::Window) const;