Skip to content

Instantly share code, notes, and snippets.

@huned
Created May 25, 2021 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huned/bd38e144e1fe403112af918d237e5423 to your computer and use it in GitHub Desktop.
Save huned/bd38e144e1fe403112af918d237e5423 to your computer and use it in GitHub Desktop.
Command-line utility to position windows
#!/bin/bash
set -x
dim=$(wmctrl -d | head -n 1 | grep -Eho '[0-9]{4}x[0-9]{3,4}' | tail -n 1)
width=$(echo $dim | cut -d x -f 1)
#height=$(echo $dim | cut -d x -f 2)
height=2130
margin=0
maxWidth=$(( $width - 2*$margin ))
halfWidth=$(( $width/2 - 2*$margin ))
#TODO maxHeight=$(( $height - 2*$margin ))
maxHeight=$(( $height - 2*$margin ))
halfHeight=$(( $height/2 - 2*$margin ))
if [[ $1 == 'c' ]]; then
x=$(( $width/3 + $margin))
y=$margin
w=$(( $width/3 - 2*$margin))
h=$maxHeight
elif [[ $1 == 'f' ]]; then
x=$margin
y=$margin
w=$maxWidth
h=$maxHeight
elif [[ $1 == 'l' ]]; then
x=$margin
y=$margin
w=$halfWidth
h=$maxHeight
elif [[ $1 == 'r' ]]; then
x=$(( $width / 2 + $margin))
y=$margin
w=$halfWidth
h=$maxHeight
elif [[ $1 == 't' ]]; then
x=$margin
y=$margin
w=$maxWidth
h=$halfHeight
elif [[ $1 == 'b' ]]; then
x=$margin
y=$(( $height / 2 + $margin))
w=$maxWidth
h=$halfHeight
elif [[ $1 == 'tl' || $1 == 'lt' ]]; then
x=$margin
y=$margin
w=$halfWidth
h=$halfHeight
elif [[ $1 == 'bl' || $1 == 'lb' ]]; then
x=$margin
y=$(( $height / 2 + $margin))
w=$halfWidth
h=$halfHeight
elif [[ $1 == 'tr' || $1 == 'rt' ]]; then
x=$(( $width / 2 + $margin))
y=$margin
w=$halfWidth
h=$halfHeight
elif [[ $1 == 'br' || $1 == 'rb' ]]; then
x=$(( $width / 2 + $margin))
y=$(( $height / 2 + $margin))
w=$halfWidth
h=$halfHeight
fi
wmctrl -r :ACTIVE: -e 0,${x},${y},${w},${h}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment