Work gave me a new monitor - which is a 21:9 screen, so I would like to be able to put 3 windows side by side, but ctrl
+ alt
+ keypad
shortcuts can only be used to place 2, and with this monitor those windows are almost too wide.
2 Answers
Intro
The script below serves to resize windows to 1/3 of the screen width, and place them to either left, center, or right position.There are numeric options, 0 for left, 1 for center, and 2 for right.
The script relies on xdotool
so make sure to install that with sudo apt-get install xdotool
.
In Unity, the script must operate on unmaximized windows. The reason for that is because Unity locks windows in place when they are maximized, making them not respond to whatever command xdotool
issues.
Note: This script will be updated and refined over time. I will likely add it to my personal github repository but as of right now it exists as a gist
Setting Shortcut
Go to System Settings -> Keyboard -> Shortcuts -> Custom and click on the + button in the lower left corner to create new entry. Provide a custom name and full path to script ( or bash /path/to/script ARG
) as in my example .
Save it, and click on the right field . You will be prompted to press keys that you want to correspond to this shortcut. I've set it to Ctrl Super 1.
You now have a shortcut for placing window to the left. Repeat the same steps for center and right shortcut.
Script Source
#!/bin/bash
# run script like so: bash thirds.sh NUMBER
# where NUMBER is 0,1 or 2
# 0 is left, 1 is center, 2 is right
get_screen_geometry()
{
# determine size of the desktop
xwininfo -root | \
awk -F ':' '/Width/{printf "%d",$2/3}/Height/{print $2}'
}
xdotool getactivewindow windowsize $(get_screen_geometry )
xdotool getactivewindow windowmove \
$(get_screen_geometry | awk -v POS=$1 '{ printf "%d ", POS*$1 }' ) 0
-
1
-
-
This didn't work for me until I replaced the command with
sh -c "sh ~/thirds.sh 0"
– aviatorJun 6, 2022 at 17:05
The script below is modified version of answer by Sergiy Kolodyazhnyy to resize windows to 1/3 of the screen width, and place them to either left, middle or right position with single shortcut and works on maximized windows as well.
The script relies on xdotool
so make sure to install that with sudo apt-get install xdotool
.
Add Keyboard Shortcut to the command bash thirds.sh
(with no arguements).
Here's the gist of it too.
#!/bin/bash
# assign keyboard shortcut to bash thirds.sh
# run shortcut on the window to resize
# it auto cycles to the position (0)left, (1)middle, (2)right
# create a counter file to store positions
counter="thirds-counter.txt"
if [[ -f $counter ]]; then
count=$(<$counter)
else
echo "0" > $counter
fi
# determine size of the desktop
get_screen_geometry()
{
xwininfo -root | awk -F ':' '/Width/{printf "%d",$2/3}/Height/{print $2}'
}
# unmaximize the window
xdotool key 'Ctrl+Super+Down'
sleep 1
# set size of the window to one third of total to the position 0,1,2
xdotool getactivewindow windowsize $(get_screen_geometry)
xdotool getactivewindow windowmove $(get_screen_geometry | awk -v POS=$count '{printf "%d", POS*$count}') 0
# store next position to the file
count=$(((($count+1))%3))
echo "$count" > $counter
xdotool
installed in order for this to work