1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-02-07 04:10:08 +00:00

LinuxComponentPeer: Use constrainer to limit native window size

This commit is contained in:
reuk 2021-10-18 15:41:25 +01:00
parent 6244fc293f
commit 05c2261efe
No known key found for this signature in database
GPG key ID: 9ADCD339CFC98A11
3 changed files with 58 additions and 16 deletions

View file

@ -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);
updateScaleFactorFromNewBounds (physicalBounds, true);
bounds = parentWindow == 0 ? Desktop::getInstance().getDisplays().physicalToLogical (physicalBounds)
: physicalBounds / currentScaleFactor;
jassertfalse;
return;
}
if (isConstrainedNativeWindow())
XWindowSystem::getInstance()->updateConstraints (windowH);
auto physicalBounds = XWindowSystem::getInstance()->getWindowBounds (windowH, parentWindow);
updateScaleFactorFromNewBounds (physicalBounds, true);
bounds = parentWindow == 0 ? Desktop::getInstance().getDisplays().physicalToLogical (physicalBounds)
: physicalBounds / currentScaleFactor;
}
void updateBorderSize()

View file

@ -1720,6 +1720,8 @@ void XWindowSystem::setBounds (::Window windowH, Rectangle<int> 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<int> 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<int> 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<int> localPos) const
{
::Window root, child;

View file

@ -177,6 +177,7 @@ public:
void setIcon (::Window , const Image&) const;
void setVisible (::Window, bool shouldBeVisible) const;
void setBounds (::Window, Rectangle<int>, bool fullScreen) const;
void updateConstraints (::Window) const;
BorderSize<int> getBorderSize (::Window) const;
Rectangle<int> 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;