diff --git a/windowmanagement.sh b/windowmanagement.sh index 3726514..402e06b 100755 --- a/windowmanagement.sh +++ b/windowmanagement.sh @@ -2,68 +2,106 @@ # 2022 R. Branten # ---- -# position windows +# This script manages window positioning and sizing on X11 systems +# It allows positioning windows in different preset layouts using xdotool and wmctrl +# Requires xdpyinfo, xdotool and wmctrl to be installed # ---- -# get witdh of screen, not needed as percentages work just fine + +# check if xdpyinfo is installed +if ! command -v xdpyinfo &> /dev/null +then + notify-send WindowManagement: "xdpyinfo not installed" + exit 1 +fi # check if xdotool is installed if ! command -v xdotool &> /dev/null then notify-send WindowManagement: "xdotool not installed" - exit + exit 1 fi -SCREENWIDTH=$(xdpyinfo | awk '/dimensions/{print $2}' | grep -oE ^[[:digit:]]\+) -SCREENHEIGHT=$(xdpyinfo | awk '/dimensions/{print $2}' | grep -oE [[:digit:]]\+$) -PANELHEIGHT=$(xdotool getwindowgeometry $(xdotool search --onlyvisible --class 'panel') | awk '/Geometry/{print $2}' | grep -oE [[:digit:]]\+$) -HEIGHT=$SCREENHEIGHT-$PANELHEIGHT +# check if wmctrl is installed +if ! command -v wmctrl &> /dev/null +then + notify-send WindowManagement: "wmctrl not installed" + exit 1 +fi + +# Function to get usable screen height (screen height minus panel height) +get_usable_height() { + local screen_height=$(xdpyinfo | awk '/dimensions/{print $2}' | grep -oE [[:digit:]]\+$) + local panel_height=$(xdotool getwindowgeometry $(xdotool search --onlyvisible --class 'panel') | awk '/Geometry/{print $2}' | grep -oE [[:digit:]]\+$) + echo $((screen_height - panel_height)) +} # extract and set argument case $1 in - center) # 100% window size centered + center) + # center window, unused as native window size is used WIDTH=100% - HEIGHT=100% - XPOS=0% + XPOS=50% + MESSAGE="center" ;; - center50) # 50% window size smack in the middle + center50) + # set window to 50% of screen and place in center of screen WIDTH=50% XPOS=25% + MESSAGE="50% center" ;; - left25) # 25% window size left side of screen + left25) + # put a window to 25% of screen and place in left side of screen WIDTH=25% XPOS=0% + MESSAGE="25% left" ;; - right25) # 25% window size right side of screen + right25) + # put a window to 25% of screen and place in right side of screen WIDTH=25% XPOS=75% + MESSAGE="25% right" ;; - left50) # 25% window size left side of screen + left50) + # put a window to 50% of screen and place in left side of screen WIDTH=50% XPOS=0% + MESSAGE="50% left" ;; - right50) # 25% window size right side of screen + right50) + # put a window to 50% of screen and place in right side of screen WIDTH=50% XPOS=50% + MESSAGE="50% right" ;; - centerleft25) # 25% window size left side of center screen + centerleft25) + # 25% window size left side of center screen WIDTH=25% XPOS=25% + MESSAGE="25% left from center" ;; - centerright25) # 25% window size right side of center screen + centerright25) + # 25% window size right side of center screen WIDTH=25% XPOS=50% + MESSAGE="25% right from center" ;; *) + echo "usage: $0 [center|center50|left25|right25|left50|right50|centerleft25|centerright25]" exit ;; esac -# resize window -#xdotool getactivewindow windowsize $WIDTH $HEIGHT -xdotool getactivewindow windowsize $WIDTH 95% +# get current window +currentWindow=$(xdotool getactivewindow) -# move window to location +# undo maximized +wmctrl -ir $currentWindow -b remove,maximized_vert,maximized_horz + +# resize window use 95% of height +xdotool getactivewindow windowsize $WIDTH $(get_usable_height) + +# move window to location steer clear of top xdotool getactivewindow windowmove $XPOS 0.1 # display alert window -notify-send WindowManagement: "${1}" +notify-send WindowManagement: "${MESSAGE}"