Hindsight (Ubunutu 20.04)

Troy Williams



Hindsight is a simple tool to record the position and size of all the active windows on Ubuntu and restore those positions later.


The problem in Ubuntu 20.04 (at least), Gnome has trouble handling the window positions when you have multiple monitors, each set up with very different resolutions. It is particularly pronounced when locking the system. Suppose one monitor wakes up faster than the other monitor. In that case, the system assumes it is gone and proceeds to place all the windows onto one monitor in a random mess. I currently have one monitor set to 1920 x 1080 and another to 3840 x 2160 (4k). My primary is the 4k monitor, and it is the slow one to wake up. I have found this very annoying when you have dozens of windows open across multiple virtual desktops!

The idea is to launch a script when you log in to monitor the system for a lock event. When the lock event is detected, the script calls hindsight and records the positions and sizes of the windows. When the script sees the unlock event, it calls hindsight. It restores the window to their original position (even to the original virtual desktop).

It is a pretty neat app and will save some time. Usually, I have 20 or so windows scattered over several virtual desktops. It is tedious to reposition and resize the windows by hand every time I return to my computer.

Here is the project on Github, and you can also access it on PyPI.

NOTE: It only records information about windows that are currently open. If you record the position of the windows and open a new one, the new window will not be affected. If a window is closed, nothing will happen. It is ignored.

Getting Started

You can install the package from PyPi:

$ pip install hindsight-ubuntu

Verify it is installed correctly:

$ hindsight --version

Save the current window sizes and positions:

$ hindsight save

Restore the current window sizes and positions:

$ hindsight restore

NOTE: You can also install it from the Github repo. You will find the instructions here

.bashrc alias

I find it helpful to have bash aliases set up to initiate the save/restore. In some cases, I have found that the monitor didn’t wake up fast enough, and the windows were not correctly positioned. In those cases, simply executing $hindsight restore did the trick (the positions were correctly recorded when the system locked).

alias hsr="/path/to/hindsight restore"
alias hss="/path/to/hindsight save"

NOTE: You can determine the path to hindsight with the following command $ type hindsight.

Startup Script

I am also quite lazy and would forget to record the positions. I use a script that can detect when the system locks and unlocks. Most likely, you will need to modify the path to the repository to save/restore the window positions. You will need to change the path in the following line:


NOTE: You can find the path to hindsight by: $ type hindsight

NOTE: Sometimes, the script doesn’t work all of the time. The system may not move some of the windows to the correct virtual desktop. I find simply running $ hindsight restore manually fixes things.

NOTE: You add the script to the startup applications to launch when you first log in to the system, and it will continue to run until you log out.

Configuration File

If you find that the windows are not being positioned quite right, you can modify the configuration file and provide adjustments for specific classes of windows. The configuration file is located in the sample folder. It can be placed in ~/.config/bluebill.net/ hindsight/settings.yaml. This will will be used for fine tuning the window placement. It is structured as below:

# Hindsight
# ---------
# https://github.com/TroyWilliams3687/hindsight

# The configuration file allows you to customize Hindsight for your system. It
# allows you to set the scale and specific positions for specific windows that
# don't seem to follow the rules.

# Location - ~/.config/bluebill.net/hindsight/settings.yaml

# ---------
# Scale

# Adjust the scale ratio if you have monitors at different resolution. Find the
# min and max values for the width and height and divide them to get a proper
# aspect ratio. For example, I have two monitors with the following resolutions:

#         w  x h
# m1 = [1920, 1080]
# m2 = [3840, 2160]

# scale_x = m1[0] / m2[0] = 0.5
# scale_y = m1[1] / m2[1] = 0.5

scale_x: 0.5 # Default 1.0
scale_y: 0.5 # Default 1.0

# ---------
# Window Fine Tuning

# Some windows will simply not play nice with the system. You can specify part
# of the text that is in the window title (that is how the system knows which
# window to use). You also can specify the x and y position of the upper left
# corner of the window. If one coordinate does not require an adjustment, set it
# to 0.

# NOTE: Default is empty

# NOTE: The text is case-sensitive

  - title_text: "Firefox"
    x: -7
    y: -8
  - title_text: "Discord"
    x: -10
    y: 0

NOTE: The idea is to tweak windows that don’t quite line back up. This can be for a variety reason. They are using different window systems.

NOTE: Be default no scale will be applied and not position corrections will be applied.