Skip to content

feat: add KDE Plasma 6 window positioning handler#864

Open
SemmerSky wants to merge 1 commit into
dynobo:mainfrom
SemmerSky:pr/feat-kwin6-positioning
Open

feat: add KDE Plasma 6 window positioning handler#864
SemmerSky wants to merge 1 commit into
dynobo:mainfrom
SemmerSky:pr/feat-kwin6-positioning

Conversation

@SemmerSky
Copy link
Copy Markdown

@SemmerSky SemmerSky commented May 20, 2026

Problem

The existing kscript handler stopped working in Plasma 5.71 due to API changes (workspace.clientList() and client.geometry were removed). On Plasma 6 Wayland with multiple monitors, NormCap overlay windows pile up on the primary monitor instead of spanning all screens — making it practically unusable in multi-monitor setups.

Solution

New kwin6 handler using the updated Plasma 6 JavaScript API:

  • workspace.windowList() (with workspace.windows as a fallback property for minor-version differences)
  • window.frameGeometry = Qt.rect(x, y, w, h) for positioning (stable since Plasma 6.0)

The handler is selected automatically on KDE Plasma 6+ and falls back gracefully to kscript on Plasma 5.

Implementation notes

  • Uses jeepney for D-Bus calls, consistent with ADR 006
  • json.dumps() for the window title in the JS snippet correctly escapes quotes, backslashes, and newlines in window titles
  • Unloads any leftover script before loading fresh, fixes repeated captures in edge cases
  • Cleans up the temp .js file in a finally block on all code paths
  • @functools.cache on _get_plasma_major_version() to avoid repeated plasmashell subprocess calls

Tests

13 tests covering:

  • is_compatible() for KDE/non-KDE, Plasma 5/6, unknown version
  • is_installed() returning bool without raising
  • JS generation and D-Bus call verification
  • Special character escaping in window titles (quotes, backslashes, newlines, tabs)
  • Graceful handling when KWin rejects the script (negative return code)

Testing

Tested on Fedora 44, KDE Plasma 6.3, Wayland, 3-monitor setup. All 3 monitors are positioned correctly.

The existing kscript handler stopped working in Plasma 5.71 due to API
changes. On Plasma 6 Wayland, NormCap overlay windows pile up on the
primary monitor instead of spanning all screens correctly.

New kwin6 handler using the updated Plasma 6 JavaScript API:
- workspace.windowList() (or workspace.windows as fallback property)
- window.frameGeometry = Qt.rect(...) for positioning

Implementation details:
- Uses jeepney for D-Bus calls (consistent with ADR 006)
- json.dumps() for the window title in the JS snippet — prevents
  injection if the title contains quotes or backslashes
- Unloads any leftover script before loading fresh (fixes repeated
  captures hanging in rare cases)
- Cleans up temp .js file in a finally block on all code paths
- @functools.cache on _get_plasma_major_version() to avoid repeated
  plasmashell subprocess calls

Includes 13 tests covering compatibility checks, JS generation,
special character escaping, and D-Bus error handling.

Tested on Fedora 44, KDE Plasma 6.3, Wayland, 3-monitor setup.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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