Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions modules/juce_gui_basics/native/juce_WaylandSurfaceScale_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ WaylandSurfaceScale::Update WaylandSurfaceScale::setOverrideScale (std::optional
});
}

WaylandSurfaceScale::Update WaylandSurfaceScale::inheritPreferredScales (const WaylandSurfaceScale& other)
{
return updateScaleState ([&]
{
// Stands in for the compositor's preferences until it sends this surface its own.
// The override belongs to the other surface's component, so it isn't taken.
if (! preferredFractionalScale120.has_value())
preferredFractionalScale120 = other.preferredFractionalScale120;

if (! preferredBufferScale.has_value())
preferredBufferScale = other.preferredBufferScale;
});
}

std::optional<double> WaylandSurfaceScale::getOverrideScale() const
{
return overrideScale;
Expand Down Expand Up @@ -432,6 +446,26 @@ class WaylandSurfaceScaleTests final : public UnitTest
expectEquals (state.getScaleFactor(), 2.0);
});

testCase ("A surface uses inherited preferred scales until it receives its own", [&]
{
WaylandSurfaceScale owner;
owner.setOutputScale (2);
owner.setPreferredFractionalScale120 (144);
owner.setOverrideScale (1.5);

WaylandSurfaceScale state;
state.setOutputScale (2);
state.inheritPreferredScales (owner);
expectEquals (state.getScaleFactor(), 1.2);
expect (! state.getOverrideScale().has_value());

state.setPreferredFractionalScale120 (180);
expectEquals (state.getScaleFactor(), 1.5);

state.inheritPreferredScales (owner);
expectEquals (state.getScaleFactor(), 1.5);
});

// JUCE scale override.
testCase ("Only changes to the JUCE scale factor are reported", [&]
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class WaylandSurfaceScale final
Update setPreferredBufferScale (int scale);
Update setOutputScale (int scale);
Update setOverrideScale (std::optional<double> scale);
Update inheritPreferredScales (const WaylandSurfaceScale& other);

std::optional<double> getOverrideScale() const;
double getScaleFactor() const;
Expand Down
22 changes: 21 additions & 1 deletion modules/juce_gui_basics/native/juce_Windowing_wayland_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,11 @@ class WaylandComponentPeer final : public ComponentPeer,

// No repaint or listener notification is needed while the peer is being constructed.
surfaceScale.setOutputScale (getScaleForSurfaceOutputs());

// The compositor sends a new surface its preferred scale only after a roundtrip, but a popup
// may need its scale straight away: PopupMenu sizes itself by comparing it with its target's.
if (const auto* owner = getPopupOwner())
surfaceScale.inheritPreferredScales (owner->surfaceScale);
createScaleObjects();
updateToplevelSizeConstraints();
WaylandProtocol::wlSurfaceAddListener (surface.get(), &surfaceListener, callbackState.get());
Expand Down Expand Up @@ -1744,10 +1749,25 @@ class WaylandComponentPeer final : public ComponentPeer,
{
auto* windowSystem = WaylandWindowSystem::getInstance();

return surfaceOutputs.getLargestScale (windowSystem->getLargestOutputScale(),
// Until the surface has entered an output, guess the scale it will get there.
const auto* owner = getPopupOwner();
const auto scaleWithoutOutputs = owner != nullptr ? owner->surfaceScale.getIntegerCompositorScale()
: windowSystem->getLargestOutputScale();

return surfaceOutputs.getLargestScale (scaleWithoutOutputs,
[windowSystem] (wl_output* output) { return windowSystem->getScaleForOutput (output); });
}

// A popup almost always opens on the output of the window it belongs to, so until the compositor
// reports the popup's own scale, the popup takes that window's.
const WaylandComponentPeer* getPopupOwner() const
{
if (const auto* popupRole = getPopupRole(); popupRole != nullptr && popupRole->owner.has_value())
return popupRole->owner->toplevel.get();

return nullptr;
}

void updateOutputScale()
{
const auto update = surfaceScale.setOutputScale (getScaleForSurfaceOutputs());
Expand Down
Loading