Only minimize windows on one screen
The script below can be used to (only) minimize windows on the left screen or only on the right screen.
The script is run with either
2 as argument, depending on which screen you'd like to minimize the windows.
scr = sys.argv
# find the right side of the left screen
edge = [int(s.split("x")) for s in get("xrandr").split() if "+0+" in s]
# read the window list
wlist = [w.split() for w in get(["wmctrl", "-lG"]).splitlines()]
for w in wlist:
# retrieve the window id and -position
w_id = w; xpos = int(w)
# check the position of the window, decide action depending on arg.
test = xpos < edge if scr == "1" else xpos >= edge
# check if the window is "normal" and / or minimized
w_data = get(["xprop", "-id", w_id])
if all([not "_NET_WM_STATE_HIDDEN" in w_data,
"_NET_WM_WINDOW_TYPE_NORMAL" in w_data]):
subprocess.Popen(["xdotool", "windowminimize", w_id])
How to use
The script needs both
sudo apt-get install xdotool wmctrl
Copy the script into an empty file, save it as
To run it:
python3 /path/to/min_screen.py 1
to minimize windows on the left screen, and
python3 /path/to/min_screen.py 2
to minimize windows only on the right screen
- If all works fine, add it to a shortcut key
- The script assumes python3 is installed, but the code is not python3 specific I believe.
- The script was written on
Unity, but unlike workspaces (viewports), handling the screens should not make a difference.
- The script will not minimize windows with pid 0 (Idle or other
tkinterwindows for example). If that is an issue, please mention. Can be solved.
The script first looks up the right edge of the left screen, by looking up the string with
+0+ in the output of
xrandr, looking like:
The first section,
1680, is the widht of the left screen. Subsequently, all we have to do is look into the window list (
wmctrl -lG) and see which of the windows is "below" or "above"
1680, and act accordingly, minimizing with the command
xdotool windowminimize <window_id> (or not).
Th "test" finally (
xprop -id <window_id> is to check if we are dealing with a "normal" window (instead of e.g. your desktop, which is also listed as a window), and if the window is already minimized.
See also the comment in the script.
Binding the script to a keyboard shortcut
1. On Lubuntu
To edit global keyboard shortcuts in Lubuntu see Lubuntu minimize all show desktop keyboard shortcut?
In this case: save script from this answer into a file on the computer, make this file executable, open
/.config/openbox/lubuntu-rc.xml and replace
/path/to/show_desktop.pyis (of course) the path to the script, and either
2 the targeted screen. Make the script executable.
Restart computer to reload config.
Make the script executable and choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command:
...to a shortcut of your choice