Skip to content

Wayland: Start a popup with the scale of the window it belongs to - #9

Closed
topemalheiro wants to merge 1 commit into
plugdata-team:juce-masterfrom
topemalheiro:pr/wayland-popup-scale
Closed

topemalheiro wants to merge 1 commit into
plugdata-team:juce-masterfrom
topemalheiro:pr/wayland-popup-scale

Conversation

@topemalheiro

Copy link
Copy Markdown

On Wayland, a new surface learns its preferred scale from the compositor only after a roundtrip, and its outputs only after it is mapped. Until then WaylandComponentPeer reported the largest integer scale of all outputs.

PopupMenu's MenuWindow reads the platform scale of its own peer right after addToDesktop, to compare it with its target component's peer (since ab9d4d3). With fractional scaling this gives the wrong ratio. Take KDE Plasma with an output at 1.2: wl_output.scale is 2, while the window the menu is opened from reports 1.2 through wp_fractional_scale_v1. The menu gets scaleFactor 1.2 / 2 = 0.6, so it opens at 60% of its size and away from its target. On a 1.0 output next to a 1.2 one, the ratio is 0.5.

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 now takes:

  • its owner's preferred fractional and buffer scales;
  • its owner's integer scale while it hasn't entered an output.

The owner's override scale is not taken. The compositor's own values replace the guess as soon as they arrive. A unit test covers WaylandSurfaceScale::inheritPreferredScales.

Tested with plugdata's standalone on KWin 6.7.2 (run nested) with outputs at 1.2 and 1.0. An Inspector combo box menu opened at 95x77 on the 1.2 output and 79x64 on the 1.0 output before; after the change, 158x128 on both, positioned over the combo box. The main menu and the canvas right-click menu still open correctly. That build also had #8 applied. In JUCE's UnitTestRunner built from this branch, all 41 WaylandSurfaceScale cases pass, the new one included, and so do the WaylandSurfaceOutputs tests.

Not tested: other compositors (GNOME, Sway), a compositor without wp_fractional_scale_v1 (where only the integer fallback applies), a popup that opens on a different output than its owner, a plugin host that sets a scale override (only the unit test covers that the override isn't copied), and a real desktop session outside the nested compositor. All three files are only compiled on Linux/BSD, so nothing changes on Windows, macOS or iOS.

🤖 Generated with Claude Code

A new surface learns its scale from the compositor only after a roundtrip,
and the outputs it is on only after it has been mapped. Until then it
reported the largest integer scale of all outputs. PopupMenu reads the
scale of its window as soon as the window is created, to compare it with
the scale of its target component. With fractional scaling, for example a
1.2 output that the compositor rounds up to 2 for wl_output, a menu opened
from a window at 1.2 computed a scale of 1.2 / 2 = 0.6: it came up at 60%
of its size and away from its target component.

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 now takes the
preferred scales of its owner window, and uses the owner's integer scale
while it hasn't entered an output. The owner's override scale is not taken.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@timothyschoen

Copy link
Copy Markdown

Merged manually

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants