This is a stupid hack to remember window positions in KDE Plasma Wayland. It's not intended to be a proper solution, but rather a simple and stupid implementation that might or might not work for you. It's no substitute for a proper implementation in KWin.
- Install
uv
with your package manager, or from GitHub. - Clone this repository with
git clone https://github.com/jinliu/waycosh.git
.
cd waycosh; ./run.sh
- The first time might take a while, because it needs to download dependencies first.
- Now your window positions should be (kind of) remembered when the program is running.
- Press
Ctrl-C
to exit the program. - Your window positions will be saved automatically, and also before the program exits.
This program groups windows by paths of their executables. E.g., all Dolphin windows are grouped together by "/usr/bin/dolphin". When the last window of a group (e.g. the last Dolphin window) is closed, its position is saved in "~/.local/share/waycosh/state.json". Then, when a new window opens, and there is no other window in the same group (e.g. there are no open Dolphin windows), the remembered position is restored.
I.e., it only remembers the last closed window from an executable and only restores the position for the next new window from the same executable. All other new windows are placed by KWin.
This obviously won't work for Google Chrome web apps, because they are all grouped with the main Chrome executable.
It won't work for multi-window apps either, because it only remembers one window.
It probably will put your windows outside the screen if you change the scaling factor or the screen configuration. You can delete "~/.local/share/waycosh/state.json" to reset the positions if that happens.
Probably a lot more. It's a stupid hack, remember?
- Please report bugs to my repo, not to KDE. This is not a proper solution, and it's not KDE's fault if it doesn't work for you. Remember to close this program and re-test without it before reporting a bug to KDE.
- Don't expect this to work perfectly. But I do plan to improve it while keeping it simple and stupid. So I'd appreciate your feedback and suggestions.
- Also you are encouraged to tinker with the code. You might want to start with
event_handler.py
andwindow_registry.py
.
This program uploads a script (see kwin_script.py
) to KWin, which reports back to the main program via DBus, on KWin's windowAdded
and windowRemoved
signal. The main program then determines if the window position should be remembered (on windowRemoved
), or the window should be moved to the remembered position (on windowAdded
). For the latter case, the main program sends back a DBus message to the KWin script to move the window.
This essentially makes it possible to do KWin scripting outside KWin. Benefits:
- You can't do disk IO in KWin scripts, making it impossible to save window positions. You can do that and all other things in an external program.
- You don't have to use js.
- KWin scripts run in KWin's main thread, so they can't do heavy work, otherwise it will slow down KWin. But since KWin scripts call DBus asynchronously, you can take as much time as you like in the external program before sending a reply back to KWin.