Last active
October 15, 2021 20:30
-
-
Save ukn/329c2f4542e043ffab2f5ceef0442ee8 to your computer and use it in GitHub Desktop.
Resize active window to 1/3 of the screen and position it in the middle, right or left part of the display
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Resize active window to 1/3 of the screen and position it in the middle, right or left part of the display | |
# Tested with XFCE (xserver) and ultra wide monitor (3440x1440) | |
# | |
# based on: https://askubuntu.com/questions/104155/center-a-window-via-command-line#answer-571711 | |
# Can this be calculated automagically? | |
taskBarHeight=63 | |
# Get display WIDTH and HEIGHT | |
eval $(xdotool getdisplaygeometry --shell) | |
# Possible window X positions | |
middleX=$((WIDTH/3)) | |
leftX=0 | |
rightX=$((WIDTH/3 * 2)) | |
# Window width to be 1/3 of the screen | |
sizeX=$((WIDTH/3 - 1)) | |
# Get active window position X | |
eval $(xdotool getactivewindow getwindowgeometry --shell | egrep 'X=') | |
# Had to add 6 pixels to calculations | |
padding=6 | |
if (( "$X" == $((middleX + padding)) )); then | |
newPos=$rightX | |
elif (( "$X" == $((rightX + padding)) )); then | |
newPos=$leftX | |
else | |
newPos=$middleX | |
fi | |
# DEBUG | |
#echo $X,$leftX,$middleX,$rightX | |
xdotool getactivewindow windowsize "$sizeX" "$((HEIGHT - taskBarHeight))" | |
xdotool getactivewindow windowmove "$newPos" "0" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment