Skip to content

Persist per-screen/per-desktop layout assignment across sessions - #212

Open
reg3x wants to merge 1 commit into
gerritdevriese:mainfrom
reg3x:persist-layout-per-screen
Open

Persist per-screen/per-desktop layout assignment across sessions#212
reg3x wants to merge 1 commit into
gerritdevriese:mainfrom
reg3x:persist-layout-per-screen

Conversation

@reg3x

@reg3x reg3x commented Aug 10, 2026

Copy link
Copy Markdown

Problem

With trackLayoutPerScreen or trackLayoutPerDesktop enabled, each screen/desktop's active layout is only tracked in the in-memory screenLayouts property. Nothing loads or saves it, so every KWin restart (login/reboot) resets everything back to layout index 0 — multi-monitor users have to manually reassign each screen's layout every session.

Why not KWin.writeConfig?

That's the obvious first approach, but it doesn't exist for KWin scripts — only KWin effects get a writable config API. Calling it throws a runtime TypeError (confirmed via journalctl). This is a hard platform limitation for scripts, not an oversight.

Fix

Persist screenLayouts using QML's own Settings type (QtCore module) instead, which is independent of KWin's config API. Also bounds-checks the restored layout index in getCurrentLayout() so a stale value (e.g. after layouts are edited/removed) falls back to 0 instead of returning something out of range.

Testing

Verified across a full reboot on a real 2-monitor setup (one normal, one rotated 90°), tested against the 0.9.2 release's code structure — each screen came back on its previously-assigned layout with no manual intervention. This PR ports the same fix onto main's current refactored structure (getLayoutKey()/trackLayoutPerDesktop), confirmed with qmlformat and a clean make build, but not independently re-verified live against main specifically — loading a second script instance for testing risks colliding with global shortcuts from an already-running kzones session, so I didn't want to test on my live daily setup. Flagging this so it gets a real functional pass from CI/review before merge.

trackLayoutPerScreen and trackLayoutPerDesktop only tracked the active
layout for each screen/desktop in memory (the screenLayouts property),
with nothing to load or save it. Every KWin restart reset all
screens/desktops back to layout 0, so multi-monitor users had to
manually reassign each screen's layout every login.

KWin.writeConfig isn't available to scripts (only effects), so this
persists screenLayouts via QML's own Settings type (QtCore module)
instead, which is independent of KWin's config API. Also bounds-checks
the restored layout index in getCurrentLayout() so a stale value (e.g.
after layouts are edited or removed) falls back to 0 instead of
returning an out-of-range index.

Tested against the 0.9.2 release structure with a full reboot on a
2-monitor setup (one normal, one rotated 90 degrees) - each screen came
back on its previously-assigned layout. This patch targets main's
current refactored structure (getLayoutKey/trackLayoutPerDesktop),
confirmed with qmlformat and a clean build, but not independently
re-verified live against main's exact code since loading a second
script instance risks colliding with global shortcuts from an
already-running kzones session.
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