From 7a0b17c0d39fbda40df65e7c2e4b917c31bf77c2 Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 3 Mar 2021 16:52:10 +0000 Subject: [PATCH] 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. --- .../native/juce_linux_Windowing.cpp | 22 +++++++++---------- .../native/x11/juce_linux_XWindowSystem.cpp | 6 ++--- .../native/x11/juce_linux_XWindowSystem.h | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/modules/juce_gui_basics/native/juce_linux_Windowing.cpp b/modules/juce_gui_basics/native/juce_linux_Windowing.cpp index ea597e3347..453abc8417 100644 --- a/modules/juce_gui_basics/native/juce_linux_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_linux_Windowing.cpp @@ -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 deletionChecker (&component); @@ -103,13 +103,16 @@ public: Point 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& newBounds, bool isPhysical) { - if (! JUCEApplicationBase::isStandaloneApp()) - return; - Point translation = (parentWindow != 0 ? getScreenPosition (isPhysical) : Point()); const auto& desktop = Desktop::getInstance(); 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 b8e6e0c7ed..4d0c06a390 100644 --- a/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp +++ b/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.cpp @@ -1799,14 +1799,14 @@ Rectangle XWindowSystem::getWindowBounds (::Window windowH, ::Window parent } else { - parentScreenPosition = Desktop::getInstance().getDisplays().physicalToLogical (Point (rootX, rootY)); + parentScreenPosition = Point (rootX, rootY); } } return { wx, wy, (int) ww, (int) wh }; } -Point XWindowSystem::getParentScreenPosition() const +Point XWindowSystem::getPhysicalParentScreenPosition() const { return parentScreenPosition; } @@ -2424,7 +2424,7 @@ Array XWindowSystem::findDisplays (float masterScale) const + ((static_cast (crtc->height) * 25.4 * 0.5) / static_cast (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; 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 3f804a2fc6..dda192484d 100644 --- a/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.h +++ b/modules/juce_gui_basics/native/x11/juce_linux_XWindowSystem.h @@ -109,7 +109,7 @@ public: BorderSize getBorderSize (::Window) const; Rectangle getWindowBounds (::Window, ::Window parentWindow); - Point getParentScreenPosition() const; + Point getPhysicalParentScreenPosition() const; bool contains (::Window, Point localPos) const;