Skip to main content

wm-win-tool

Store desktops, geometries, and shade states of X11 windows, selected by window title and class patterns, in order to restore their layouts later on.

The primary reason for this program to exist is Firefox, that fails to restore its session properly under usual X11 window managers (KF5 in my case).

Note, that the problem is well known, but unfortunately, little has been done in the last 13 years to solve this issue.

This program is an humble attempt to solve it manually/externally, but might prove useful for other constellations as well.

Usage:

wm-win-tool [-hVvfbr] [-c class][-t title] store
wm-win-tool [-hVvfbr] [-c class][-t title] restore [arg]
wm-win-tool [-hVvb][-c class][-t title] curlist [max]
wm-win-tool [-hVv] list [max]
       -h, --help           this message
       -V, --version        print version and exit
       -v, --verbose        verbose mode (cumulative)
       -f, --force          force store
       -b, --bracket        use the bracket pattern
       -r, --regexp         class and title pattern are regexp
       -c, --class class    match window class
       -t, --title title    match window title

Commands

store will save the geometry, desktop, and shaded state of selected windows by class or pattern, unless the previous state is unchanged or the operation is enforced with --force.

restore will restore the window geometries, matched by class or pattern, arg is either a timestamp from the store list, or a relative index (eg. -1 for the latest session [default], -2 for the one before...).

Note, that the selection parameters for store and restore should match.

Use the curlist command to test your current selection options.

list shows the available sessions up to an optional maximum number of items to be restored, sorted by date (descending).

Options

--class and --title are simple case sensitive wildcard pattern, that can be supplied multiple times to match a subset of windows. --regexp switches them to regular expression matching. Make sure to properly quote such arguments.

The --bracket option just matches the part of the window title in square brackets, eg.: [title] long title will just match [title]. This is most useful in conjunction with Firefox and the Window Titler addon.

Example Usage

Casual approach to restore your Firefox session:

wm-win-tool -bc Navigator.Firefox store

will save every Firefox window, and

wm-win-tool -bc Navigator.Firefox restore

will restore all recognized windows. The only downside is, that the window titles must match exactly to be restored correctly. So better make sure to run this tool right before leaving the session.

A more robust approach to the issue in question: install the Window Titler addon and supply all windows, that you want to have managed with a unique title, that appears in square brackets in front of the window title. This provides a static title, independent from which tab is actived.

Now saving a session is as easy as:

wm-win-tool -vb store

You can run this command as many times as you want. As long as the session wasn't changed meanwhile, it won't store a new session (unless the --force option is supplied).

After reboot, you may wish to restore this session:

wm-win-tool -vb restore

é voila, the windows move to their original desktops, and have their former geometry and shaded state applied.

Install

Using pip:

$ pip install wm-win-tool

From source:

$ wget https://files.pythonhosted.org/packages/source/w/wm-win-tool/wm-win-tool-<version>.tar.gz
$ tar xvf wm-win-tool-<version>.tar.gz
$ cd wm-win-tool-<version>
$ python3 setup.py install

Dependencies

You need to make sure, that the command line programs wmctrl and xprop are installed. Check with your distributions package manager..

Consequently, wm-win-tool needs a proper DISPLAY/XAUTHORITY environment setup.

Final notes

There are good chances, that the Firefox issue is fixed with Version 75. Hooray. Let's hope for the best. If all goes well, this tool provides a nice way to validate the final fix. If all windows match, it will not perform any action on (verbose) restore. 😉

The commands store and restore could be implicitly triggered, when executed via symlinks to wm-win-tool, eg.:

$ cd <whatever>/bin
$ ln -s wm-win-tool wm-win-store
$ ln -s wm-win-tool wm-win-restore

These operation modes come with some hardcoded defaults: --bracket and --verbose for the most usual usage patterns. If that's not enough, a config file option might be useful (TBD).

The session data is saved in ~/local/share/wm-win-tool.

In pathological cases (where I count in for sure), it might be advantageous to exclude Firefox from the window manager session restore completely. kwin5 is configurable as such. When executing Firefox after reboot, it will open all session windows on your current desktop then. Run wm-win-restore and be done.

If you plan to run wm-win-store from crontab -e, keep in mind, that most cron implementations suffer from variable expansion issues. Here is an example, that should work with Vixie cron:

#PATH=$HOME/bin:/bin:/usr/bin	# won't work
#XAUTHORITY=~/.Xauthority	# neither that

# store firefox window list
42 * * * * XAUTHORITY=~/.Xauthority DISPLAY=:0 wm-win-tool -b store

AUTHORITYis expanded from the shell in this case, which is necessary to operate properly. Depending on the way, you installed wm-win-tool, you might need to adjust the path as well. We also avoid using the symlink shortcut here due to its implicit verbosity level.

Some things are realized in a pretty oldschool way, eg. command line handling, but until the command line interface gets significantly more complex, I prefer to do it this way (since ages).

If you have other ideas, interesting applications, what ever, let me know.

Feedback welcome.

Metadata

Release files for wm-win-tool 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wm-win-tool 0.1.6
File Size Uploaded Provenance
wm-win-tool-0.1.6.tar.gz 18.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for wm-win-tool 0.1.6
File Interpreter ABI Platform
wm_win_tool-0.1.6-py3-none-any.whl Python 3 none any Details

Total release size: 36.8 kB

Release files / wm-win-tool-0.1.6.tar.gz

Download URL wm-win-tool-0.1.6.tar.gz
Size 18.1 kB
Tags Source
SHA-256 checksum
How to use checksums
8aa9de62b177d586d0dbf44f94e540a9fd2b1ef96e30d5f7ce81b37d664c621f
BLAKE2b-256 checksum
How to use checksums
7906abbb935b83fda29668a554b57920a2c0309550cbf745b28ad80e54a805b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.3

Release files / wm_win_tool-0.1.6-py3-none-any.whl

Download URL wm_win_tool-0.1.6-py3-none-any.whl
Size 18.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a323fdac461d65759bd0ad0bb9eca9f07157f9fab06885e9ce1069d1df7114a5
BLAKE2b-256 checksum
How to use checksums
7ed9b02c16b86d0d03d87f14d4ac4ebaa786cc829f6b977f2d6c1740501ffba7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.3

Security for wm-win-tool 0.1.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page