What I want to do?
I want to be able to click on a window (terminal window, any software window, etc...) to activate it and click on a shortcut key which will resize and move the active window to a specified size and xy coordinates on the screen. I will have several windows open (about 20) and I want to split them in a grid 3 x 3 per working environment very easily instead of adjusting them manually.
What I have tried so far
I have searched online and it appears the package xdotool
provides the functionality to do that. I am trying to assign keys 1 to 9 (because I want a 3 x 3 grid) to adjust automatically each selected window to the respective position in a given working environment. Below, it is displayed a script that achieves partially what I want to do. The script below, which was based from here, only adjusts the terminal window (because the script is run there) when an argument is supplied. How can I change this script so that it will run continuously so that when I select any window, I can press a key from 1 to 9 and the active window will be automatically resized and moved?
#!/bin/bash
grabbing screen width and height
SIZE=xdpyinfo | awk '/dimensions/{print $2}'
SW=echo $SIZE | cut -f1 -dx
SH=echo $SIZE | cut -f2 -dx
function that changes a window's position and size
function set_win {
# args: pos_x, pos_y size_x, size_y
# don't move Desktop
if [ "$(xdotool getactivewindow getwindowname)" != "Desktop" ]; then
xdotool getactivewindow windowsize $3 $4
xdotool getactivewindow windowmove $1 $2
fi
}
case "$1" in
1) set_win 0 0 $((SW/3)) $((SH/3)) ;;
2) set_win $((SW/3)) 0 $((SW/3)) $((SH/3)) ;;
3) set_win $((2*SW/3)) 0 $((SW/3)) $((SH/3)) ;;
4) set_win 0 $((SH/3)) $((SW/3)) $((SH/3)) ;;
5) set_win $((SW/3)) $((SH/3)) $((SW/3)) $((SH/3)) ;;
6) set_win $((2*SW/3)) $((SH/3)) $((SW/3)) $((SH/3)) ;;
7) set_win 0 $((2*SH/3)) $((SW/3)) $((SH/3)) ;;
8) set_win $((SW/3)) $((2*SH/3)) $((SW/3)) $((SH/3)) ;;
9) set_win $((2*SW/3)) $((2*SH/3)) $((SW/3)) $((SH/3)) ;;
esac