109 lines
2.9 KiB
Bash
Executable File
109 lines
2.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# 2022 R. Branten
|
|
# ----
|
|
# 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
|
|
# ----
|
|
|
|
# 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 1
|
|
fi
|
|
|
|
# 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:]]\+$)
|
|
local margin=26 # For window decoration subtract margin
|
|
echo $((screen_height - panel_height - margin))
|
|
}
|
|
|
|
# extract and set argument
|
|
case $1 in
|
|
center)
|
|
# center window, unused as native window size is used
|
|
WIDTH=100%
|
|
XPOS=50%
|
|
MESSAGE="center"
|
|
;;
|
|
center50)
|
|
# set window to 50% of screen and place in center of screen
|
|
WIDTH=50%
|
|
XPOS=25%
|
|
MESSAGE="50% center"
|
|
;;
|
|
left25)
|
|
# put a window to 25% of screen and place in left side of screen
|
|
WIDTH=25%
|
|
XPOS=0%
|
|
MESSAGE="25% left"
|
|
;;
|
|
right25)
|
|
# put a window to 25% of screen and place in right side of screen
|
|
WIDTH=25%
|
|
XPOS=75%
|
|
MESSAGE="25% right"
|
|
;;
|
|
left50)
|
|
# put a window to 50% of screen and place in left side of screen
|
|
WIDTH=50%
|
|
XPOS=0%
|
|
MESSAGE="50% left"
|
|
;;
|
|
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
|
|
WIDTH=25%
|
|
XPOS=25%
|
|
MESSAGE="25% left from center"
|
|
;;
|
|
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
|
|
|
|
# get current window
|
|
currentWindow=$(xdotool getactivewindow)
|
|
|
|
# undo maximized
|
|
wmctrl -ir "$currentWindow" -b remove,maximized_vert,maximized_horz
|
|
|
|
# resize
|
|
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: "${MESSAGE}"
|