Browse Source

LinuxComponentPeer: Use constrainer to limit native window size

v6.1.6
reuk 3 years ago
parent
commit
05c2261efe
No known key found for this signature in database GPG Key ID: 9ADCD339CFC98A11
3 changed files with 57 additions and 15 deletions
  1. +19
    -7
      modules/juce_gui_basics/native/juce_linux_Windowing.cpp
  2. +36
    -8
      modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp
  3. +2
    -0
      modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.h

+ 19
- 7
modules/juce_gui_basics/native/juce_linux_Windowing.cpp View File

@@ -333,18 +333,30 @@ public:
void setParentWindow (::Window newParent) { parentWindow = newParent; } void setParentWindow (::Window newParent) { parentWindow = newParent; }
//============================================================================== //==============================================================================
bool isConstrainedNativeWindow() const
{
return constrainer != nullptr
&& (styleFlags & (windowHasTitleBar | windowIsResizable)) == (windowHasTitleBar | windowIsResizable)
&& ! isKioskMode();
}
void updateWindowBounds() 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() void updateBorderSize()


+ 36
- 8
modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp View File

@@ -1720,6 +1720,8 @@ void XWindowSystem::setBounds (::Window windowH, Rectangle<int> newBounds, bool
} }
} }
updateConstraints (windowH, *peer);
XWindowSystemUtilities::ScopedXLock xLock; XWindowSystemUtilities::ScopedXLock xLock;
if (auto hints = makeXFreePtr (X11Symbols::getInstance()->xAllocSizeHints())) 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->y = newBounds.getY();
hints->width = newBounds.getWidth(); hints->width = newBounds.getWidth();
hints->height = newBounds.getHeight(); 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()); 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 bool XWindowSystem::contains (::Window windowH, Point<int> localPos) const
{ {
::Window root, child; ::Window root, child;


+ 2
- 0
modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.h View File

@@ -177,6 +177,7 @@ public:
void setIcon (::Window , const Image&) const; void setIcon (::Window , const Image&) const;
void setVisible (::Window, bool shouldBeVisible) const; void setVisible (::Window, bool shouldBeVisible) const;
void setBounds (::Window, Rectangle<int>, bool fullScreen) const; void setBounds (::Window, Rectangle<int>, bool fullScreen) const;
void updateConstraints (::Window) const;
BorderSize<int> getBorderSize (::Window) const; BorderSize<int> getBorderSize (::Window) const;
Rectangle<int> getWindowBounds (::Window, ::Window parentWindow); Rectangle<int> getWindowBounds (::Window, ::Window parentWindow);
@@ -316,6 +317,7 @@ private:
void dismissBlockingModals (LinuxComponentPeer*) const; void dismissBlockingModals (LinuxComponentPeer*) const;
void dismissBlockingModals (LinuxComponentPeer*, const XConfigureEvent&) const; void dismissBlockingModals (LinuxComponentPeer*, const XConfigureEvent&) const;
void updateConstraints (::Window, ComponentPeer&) const;
::Window findTopLevelWindowOf (::Window) const; ::Window findTopLevelWindowOf (::Window) const;


Loading…
Cancel
Save