Skip to content

Show layouts only on screens matching their aspect ratio - #209

Open
geodro wants to merge 1 commit into
gerritdevriese:mainfrom
geodro:grid-aspect-ratio
Open

geodro wants to merge 1 commit into
gerritdevriese:mainfrom
geodro:grid-aspect-ratio

Conversation

@geodro

@geodro geodro commented Jul 28, 2026

Copy link
Copy Markdown

Layouts can now declare which screens they belong on, so a setup with monitors of different shapes does not have to cycle past layouts that make no sense on the current one.

Usage

A layout with an aspectRatio only shows up on screens with that shape:

[
  { "name": "Ultrawide Thirds", "aspectRatio": "21:9", "zones": [] },
  { "name": "Wide Enough", "aspectRatio": ">16:9", "zones": [] },
  { "name": "Desktop or Laptop", "aspectRatio": ["16:9", "16:10"], "zones": [] }
]

The value can be a ratio ("16:9", "16/9", "16x9" or a number like 1.778), a comparison (">16:9", ">=21:9", "<16:9", "<=4:3"), or an array of either, in which case one match is enough.

Screens rarely hit a ratio exactly, so a match allows 5% either way. That covers the usual 21:9 panels (2560x1080 is 2.370, 3440x1440 is 2.389) while still telling 16:9 and 16:10 apart. aspectRatioTolerance on the layout widens or tightens that.

Behaviour

  • Hidden layouts are skipped when cycling and left out of the zone selector.
  • Activate layout N on a hidden layout reports that it is not available on this screen instead of switching to it.
  • When the active layout is hidden after moving to another screen, the first available layout takes over.
  • Layouts without an aspectRatio show up everywhere, and if no layout matches the current screen they all stay available, so the selector is never empty.

Screens can change shape while nothing else is going on, so the script now listens for that: screensChanged, screenOrderChanged and virtualScreenSizeChanged on the workspace, plus geometryChanged and currentModeChanged on every screen, with the per screen signals reconnected whenever the set of screens changes. Until now the client area was only re-read at the start of a window drag, so the layout list stayed stale after a resolution change.

Notes

The matching lives in src/contents/code/aspect.mjs and is free of QML, so it can be exercised on its own. A layout without the new key behaves exactly as before. README and examples/advanced.json are updated, and the QML is qmlformat clean.

Verified so far: the matcher against real and simulated screen sizes (exact ratios, comparisons, arrays, numeric values, custom tolerance, unreadable values, cycle order with hidden layouts, and the no-match fallback), both standalone and running inside KWin's QML engine, plus the screen signals connecting on load. Wider testing on a real multi monitor setup is welcome.

A layout can set "aspectRatio" to limit itself to screens with that shape,
written as a ratio ("16:9", "16/9", "16x9" or a number), a comparison
(">16:9", "<=4:3") or an array of either. Screens rarely hit a ratio exactly,
so a match allows 5% either way, adjustable per layout with
"aspectRatioTolerance".

Hidden layouts are skipped when cycling, left out of the zone selector, and
their Activate layout shortcut reports that they are not available. When the
active layout is hidden after moving to another screen, the first available
layout takes over. Layouts without the key show up everywhere, and if no
layout matches the current screen they all stay available.

Screens can also change shape while nothing else is going on, so connect to
screensChanged, screenOrderChanged and virtualScreenSizeChanged on the
workspace, plus geometryChanged and currentModeChanged on every screen. The
client area used to be re-read only at the start of a window drag, which left
the layout list stale after a resolution change.
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.

1 participant