Skip to content

Add functions to save and restore window positions

Nate Graham requested to merge work/ngraham/save-window-positions into master

These functions allow an application to save and restore the positions of its windows. Positions are stored on a per-screen-arrangement basis.

For example with a single screen connected, the config file would have entries like this in it:

eDP-1 XPosition=140
eDP-1 YPosition=340

When a second screen is connected, the following gets saved:

eDP-1 HDMI-1 XPosition=3878
eDP-1 HDMI-1 YPosition=29

This ensures that each separate screen arrangement can have its own saved window position, which is handy for the use case where you have a laptop that you plug into an external screen some of the time. It also allows the position to get restored to the correct screen when there are multiple screens.

This is a necessary first step to getting KDE apps to save their window positions on X11 The next step would be calling the new functions from KXMLGui and Kirigami apps, and then porting all apps that manually invoke KWindowConfig::saveWindowSize() and KWindowConfig::restoreWindowSize() to also invoke KWindowConfig::saveWindowPosition() and KWindowConfig::restoreWindowPosition() in the same places.

The functions only work on X11 or other non-Wayland platforms. On Wayland, the compositor has sole dominion over window positioning so a compositor-specific solution much be adopted instead, such as https://bugs.kde.org/show_bug.cgi?id=15329.

CCBUG: 415150

Edited by Nate Graham

Merge request reports