Browse Source

LinuxComponentPeer: Fix scaling in custom windows created by plugins

Previously, things like PopupMenus which were created in their own
windows were not being scaled correctly on HiDPI displays on Linux.

This patch forces the display scale to 1.0 in plugins, meaning that
the transform applied to the main plugin window is the sole source
of truth for component scaling in plugins.
tags/2021-05-28
reuk 4 years ago
parent
commit
7a0b17c0d3
3 changed files with 15 additions and 15 deletions
  1. +11
    -11
      modules/juce_gui_basics/native/juce_linux_Windowing.cpp
  2. +3
    -3
      modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp
  3. +1
    -1
      modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.h

+ 11
- 11
modules/juce_gui_basics/native/juce_linux_Windowing.cpp View File

@@ -85,8 +85,8 @@ public:
updateScaleFactorFromNewBounds (bounds, false);
auto physicalBounds = (parentWindow == 0 ? Desktop::getInstance().getDisplays().logicalToPhysical (bounds)
: bounds * currentScaleFactor);
auto physicalBounds = parentWindow == 0 ? Desktop::getInstance().getDisplays().logicalToPhysical (bounds)
: bounds * currentScaleFactor;
WeakReference<Component> deletionChecker (&component);
@@ -103,13 +103,16 @@ public:
Point<int> getScreenPosition (bool physical) const
{
auto parentPosition = XWindowSystem::getInstance()->getParentScreenPosition();
auto physicalParentPosition = XWindowSystem::getInstance()->getPhysicalParentScreenPosition();
auto parentPosition = parentWindow == 0 ? Desktop::getInstance().getDisplays().physicalToLogical (physicalParentPosition)
: physicalParentPosition / currentScaleFactor;
auto screenBounds = (parentWindow == 0 ? bounds
: bounds.translated (parentPosition.x, parentPosition.y));
auto screenBounds = parentWindow == 0 ? bounds
: bounds.translated (parentPosition.x, parentPosition.y);
if (physical)
return Desktop::getInstance().getDisplays().logicalToPhysical (screenBounds.getTopLeft());
return parentWindow == 0 ? Desktop::getInstance().getDisplays().logicalToPhysical (screenBounds.getTopLeft())
: screenBounds.getTopLeft() * currentScaleFactor;
return screenBounds.getTopLeft();
}
@@ -314,8 +317,8 @@ public:
updateScaleFactorFromNewBounds (physicalBounds, true);
bounds = (parentWindow == 0 ? Desktop::getInstance().getDisplays().physicalToLogical (physicalBounds)
: physicalBounds / currentScaleFactor);
bounds = parentWindow == 0 ? Desktop::getInstance().getDisplays().physicalToLogical (physicalBounds)
: physicalBounds / currentScaleFactor;
}
}
@@ -433,9 +436,6 @@ private:
//==============================================================================
void updateScaleFactorFromNewBounds (const Rectangle<int>& newBounds, bool isPhysical)
{
if (! JUCEApplicationBase::isStandaloneApp())
return;
Point<int> translation = (parentWindow != 0 ? getScreenPosition (isPhysical) : Point<int>());
const auto& desktop = Desktop::getInstance();


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

@@ -1799,14 +1799,14 @@ Rectangle<int> XWindowSystem::getWindowBounds (::Window windowH, ::Window parent
}
else
{
parentScreenPosition = Desktop::getInstance().getDisplays().physicalToLogical (Point<int> (rootX, rootY));
parentScreenPosition = Point<int> (rootX, rootY);
}
}
return { wx, wy, (int) ww, (int) wh };
}
Point<int> XWindowSystem::getParentScreenPosition() const
Point<int> XWindowSystem::getPhysicalParentScreenPosition() const
{
return parentScreenPosition;
}
@@ -2424,7 +2424,7 @@ Array<Displays::Display> XWindowSystem::findDisplays (float masterScale) const
+ ((static_cast<double> (crtc->height) * 25.4 * 0.5) / static_cast<double> (output->mm_height));
auto scale = DisplayHelpers::getDisplayScale (output->name, d.dpi);
scale = (scale <= 0.1 ? 1.0 : scale);
scale = (scale <= 0.1 || ! JUCEApplicationBase::isStandaloneApp()) ? 1.0 : scale;
d.scale = masterScale * scale;


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

@@ -109,7 +109,7 @@ public:
BorderSize<int> getBorderSize (::Window) const;
Rectangle<int> getWindowBounds (::Window, ::Window parentWindow);
Point<int> getParentScreenPosition() const;
Point<int> getPhysicalParentScreenPosition() const;
bool contains (::Window, Point<int> localPos) const;


Loading…
Cancel
Save