2020-08-29 16:54:04 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
[ -z "$1" ] && exit # If $1 is left, hovers in the bottom left, if right, the bottom right
|
|
|
|
current=$(xdotool getwindowfocus)
|
2021-02-18 18:18:08 +01:00
|
|
|
|
|
|
|
# xrandr is quite slow in execution. displayselect will generate a new one in postrun.
|
2021-02-26 09:06:18 +01:00
|
|
|
# Otherwise if none exist this script will run xrandr once. Changing display setups will not be detected.
|
2021-02-18 18:18:08 +01:00
|
|
|
if [ -f /tmp/dims ]; then
|
|
|
|
dims="$(cat /tmp/dims)"
|
|
|
|
else
|
|
|
|
dims="$(xrandr --screen 0 | grep ' connected' | grep -v '^\s*$' | sed 's/ primary//' | cut -d ' ' -f3 | tee -i '/tmp/dims')"
|
|
|
|
fi
|
2021-02-18 15:54:42 +01:00
|
|
|
horizontal_offset="$( echo "$dims" | cut -d '+' -f2 )"
|
2021-02-18 18:18:08 +01:00
|
|
|
mouse_location_horizontal="$(xdotool getmouselocation | grep -Eo 'x:[0-9]{1,5}' | tr -d 'x:')"
|
|
|
|
# var passed is an accumulator for screens that fit the current mouse location or less
|
2021-02-18 15:54:42 +01:00
|
|
|
for screen in $horizontal_offset; do
|
|
|
|
[ "$screen" -lt "$mouse_location_horizontal" ] && passed="$(printf '%s\n%s\n' "$passed" "$screen")"
|
|
|
|
done
|
2021-02-18 18:18:08 +01:00
|
|
|
# take max of all screens to the left of mouse
|
2021-02-18 15:54:42 +01:00
|
|
|
offset_of_screen_mouse_is_on="$(echo "$passed" | sort -n | tail -n1)"
|
|
|
|
dim="$( echo "$dims" | grep "+$offset_of_screen_mouse_is_on+" )"
|
|
|
|
screenwidth="$( echo "$dim" | grep -Eo '^[0-9]{1,5}x' | tr -d 'x')"
|
|
|
|
screenheight="$( echo "$dim" | grep -Eo 'x[0-9]{1,5}+' | tr -d 'x+')"
|
|
|
|
|
2021-02-18 18:18:08 +01:00
|
|
|
# Adjust here for larger/smaller windows
|
2021-02-26 09:06:18 +01:00
|
|
|
newheight=$(( 2 * screenheight / 5 ))
|
|
|
|
newwidth=$(( 2 * screenwidth / 5 ))
|
2021-02-18 18:18:08 +01:00
|
|
|
# fit your borderwidth setup of your WM or windows could bleed over to other display
|
2023-10-12 15:12:12 +02:00
|
|
|
borderwidth=1
|
2020-08-29 16:54:04 +02:00
|
|
|
|
2021-02-26 09:06:18 +01:00
|
|
|
# see https://specifications.freedesktop.org/wm-spec/wm-spec-1.3.html for gravity specs
|
2021-06-12 18:27:40 +02:00
|
|
|
# I do not believe that gravity is being respected in dwm.
|
2020-08-29 16:54:04 +02:00
|
|
|
case "$1" in
|
2021-02-18 15:54:42 +01:00
|
|
|
left) horizontal=$(( borderwidth ))
|
2021-02-26 09:06:18 +01:00
|
|
|
vertical=$(( screenheight - newheight - 2 * borderwidth ))
|
|
|
|
gravity=7 #gravity of southwest
|
|
|
|
;;
|
2021-02-18 15:54:42 +01:00
|
|
|
right) horizontal=$(( screenwidth - newwidth - 2 * borderwidth ))
|
2021-02-26 09:06:18 +01:00
|
|
|
vertical=$(( screenheight - newheight - 2 * borderwidth ))
|
|
|
|
gravity=9 #gravity of southeast
|
|
|
|
;;
|
2020-08-29 16:54:04 +02:00
|
|
|
esac
|
2021-02-18 15:54:42 +01:00
|
|
|
|
2021-02-26 09:06:18 +01:00
|
|
|
wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz
|
|
|
|
wmctrl -r :ACTIVE: -e $gravity,$horizontal,$vertical,$newwidth,$newheight
|