Skip to the text
KDOS
Menu
kdos.dev KDOS from Scratch KDOS 0.2 · 4dd4a10 · 2026-11-30 Contents Index

358.16. kwin-script-kdos-window-memory-1.0.0

KDOS window memory for KWin — a program's window opens where its last one closed

Version 1.0.0, release 1
Source tree src/desktop/kwin-script-kdos-window-memory/
Phase 50_desktop (Desktop), 71 of 92 in build order
Licence MIT
Homepage https://github.com/kunaldawn/kdos
Build time 0.1 SBU
Installed size 33.0 KiB in 3 files
Recipe src/desktop/kwin-script-kdos-window-memory/kpkgbuild

About

kwin-script-kdos-window-memory remembers where your windows were. It does three things:

On Wayland a program cannot place its own window, so without this script every window opens wherever KWin’s placement puts it, at the size its program picked.

It is a KWin script written in QML, a KWin/Script package installed to /usr/share/kwin/scripts/kdos_window_memory/, on by default and turned off on System Settings’ KWin Scripts page. It records one place per program, by application id, in $XDG_STATE_HOME/kdos/window-memory, most recent first and at most 200 programs.

Why it is in KDOS

The comment above the 4 ports from kdos-kwin-motion to kwin-script-kdos-window-memory in script/phases/50_desktop/packages.txt:

KWin's KDOS pieces: the CRT motion effects, the key card on Meta+F1, run-or-raise for the terminal programs and the window position memory.

Sources

None: the port builds from its own directory, /kdos/src/desktop/kwin-script-kdos-window-memory.

Dependencies

Depends on: cmake, ninja, extra-cmake-modules, kpackage, kwin, qt6-qtdeclarative.

Required by (1): kde-plasma.

Installation

From the repository root, inside the build container, this is the line kdosbuild runs for the port:

script/chroot/exec.sh bash -c 'source script/phases/50_desktop/phase.env && kpkg install kwin-script-kdos-window-memory'

What kpkg does

kpkg runs these steps, in this order, as root inside the chroot. The port directory is /kdos/src/desktop/kwin-script-kdos-window-memory.

1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.

2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.

SRC_ROOT=/var/cache/kpkg/work/kwin-script-kdos-window-memory
SRC=$SRC_ROOT/kwin-script-kdos-window-memory-1.0.0
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"

Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.

3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:

cmake -S "$PORT_SRC" -B build -G Ninja \
	-D CMAKE_INSTALL_PREFIX=/usr \
	-D KDE_INSTALL_LIBDIR=lib \
	-D CMAKE_BUILD_TYPE=Release \
	-D BUILD_TESTING=OFF \
	-Wno-dev
cmake --build build
DESTDIR=$PKG cmake --install build

The switches, and why each is set:

The common switches of each build system are explained in the Flag glossary.

4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/kwin-script-kdos-window-memory, prunes what the image does not ship, lints the tree and rolls it reproducibly:

tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
    --mtime=@$SOURCE_DATE_EPOCH \
    --use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
    -cf kwin-script-kdos-window-memory-1.0.0-1.tar.xz -C "$PKG" .

5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/kwin-script-kdos-window-memory, and runs the triggers its paths call for.

Other files in the port directory, read by build.sh: CMakeLists.txt, package/, tests/.

Contents

Installed directories: /usr/share/kwin/scripts/kdos_window_memory.

Notes

A window’s maximised and full-screen state is read after the commit that carries it, through Qt.callLater from frameGeometryChanged, maximizedChanged and fullScreenChanged: KWin emits the new frame before it updates maximizeMode and fullScreen, so a sample taken in the signal would record the maximised frame as the floating one and miss the rectangle an un-maximise returns to. The record is the rectangle the window floats at.

What it leaves alone matters as much as what it moves. It does not place:

A window rule that forces a position wins, because KWin refuses the move; a rule that only sets the first position is overridden.

A Wayland client’s window carries no type, so splash and dialog are false for a QSplashScreen or a parentless message box. The fixed size drops the notices of qBittorrent and KGet and Hydrogen’s splash, none of which can be resized. A resizable splash or notice (FreeCAD’s splash, Chromium’s terms window) is a prelude: a window its process closes within three seconds before opening the next, or within three seconds after opening the next beside it, as a QSplashScreen does on finish(). Its rectangle is not recorded, and the record is marked lead.

Nothing about a splash is known until it closes, so the mark is what spares the next one: the first window of a launch whose record carries it is left at KWin’s placement and its own size, and the window that follows it within three seconds, or opens beside it, is restored. A first window that outlives that interval and has no successor within it was the program’s own, so its close records its rectangle without the mark; a program that stops showing its notice (Chromium’s appears once) is left at KWin’s placement for one launch.

A remembered place is moved and shrunk into the usable area of the screen nearest to it, so a window remembered on a screen that is gone, or on a wider one, opens whole on one that is there. The record keeps the remembered rectangle while the window holds the shrunk one, and takes a new one only after the window has reached it and then changed, or is moved or resized by hand. Each record carries the screen’s device pixel ratio; a record made at another ratio restores the place and leaves the size to the program. A record without a ratio matches any.

KWin places a window once, at its first size, and a later resize keeps the top-left. A window with no record whose top-left lies within 64 pixels of the centre of the usable area, and that is larger than 128 pixels in either direction, was placed at a placeholder size (VICE maps 1x1 and grows to 789x604; the Help Center’s first commit is tiny), and is centred again and fitted into the area. KWin does not shrink a window a program sizes larger than the usable area either (Chromium’s first window, with no record, maps taller than the screen), so any other new window with no record that runs past the area is moved and shrunk into it. Both are tried when the window opens and on each frame change for two seconds, until one fires once or the window is moved by hand.

A KXmlGui program with no saved size opens its first window at its widgets’ minimum, and on Wayland nothing makes it larger: Kate maps at about 640x510 with its status bar cut, Dolphin at 760x580 with its Places labels cut. A window with no record whose first real size (not a placeholder) is under half the usable area in either direction is grown to at least 60% of the area’s width and 70% of its height, never smaller than it opened and never past the area, and centred in the usable area of the screen it opened on (firstSize() in memory.js); on a 1920x1080 screen with no panel that is 1152x756.

The grow is tried in the same two seconds as the recentre, only for a window eligible() passes, floating and with no record, so a dialog, a transient, a window that cannot be resized and a maximised window keep their size. growable() skips a window with no server-side border, read when its size is: a splash, a frameless first-run notice or a program drawing its own title bar, which picks its own first size. On a first launch nothing else tells a splash from the window after it, so a splash that does carry a border is grown; its record is dropped as a prelude’s when it closes.

The programs whose small window is their design are in keepOwnSize: KCalc, Kalk, Qalculate, KColorChooser, KCharSelect, KTeaTime and KTimer, each by the application id its desktop file names. The grown rectangle is recorded when the window closes, like any other, so a size the person gives it wins from the next launch. The window size does not reach Dolphin’s Places panel, which opens at the width its own size hint asks for (see kio).

Two settings, in kwinrc under [Script-kdos_window_memory]:

Key Default Effect
Exclude the built-in list A comma-separated list of application ids, which replaces the built-in one
RememberDesktop off Also moves a window back to the virtual desktop it closed on, and the view with it

The file is written by QSettings through a temporary file and a rename, so a crash leaves the old record or the new one, never half of one. A program opened and closed in the same place costs no write.