open child windows in center of parent not desktop

This commit is contained in:
Ray Elliott 2022-08-16 13:49:36 +01:00
parent 274ede7dbe
commit 476b0ba197
1 changed files with 41 additions and 2 deletions

View File

@ -7,6 +7,39 @@ consequences=$4
title=$(xtitle "$wid") title=$(xtitle "$wid")
role="$(xprop -id "$wid" WM_WINDOW_ROLE | awk -F '"' '{print $2}')" role="$(xprop -id "$wid" WM_WINDOW_ROLE | awk -F '"' '{print $2}')"
parent_id="$(xprop -id "$wid" WM_TRANSIENT_FOR | awk -F '# ' '{print $2}')"
# notify-send $1 "$2 | $3 | $4"
# put child windows in center of parent window instead of desktop center
if [ -n "$parent_id" ] ; then
parent_class="$(xprop -id "$parent_id" WM_CLASS | awk -F '"' '{print $2}')"
if [ "$parent_class" = chromium ] ; then
parent_x="$(xdotool getwindowgeometry --shell $parent_id | grep X | awk -F '=' '{print $2}')"
parent_y="$(xdotool getwindowgeometry --shell $parent_id | grep Y | awk -F '=' '{print $2}')"
parent_width="$(xdotool getwindowgeometry --shell $parent_id | grep WIDTH | awk -F '=' '{print $2}')"
parent_height="$(xdotool getwindowgeometry --shell $parent_id | grep HEIGHT | awk -F '=' '{print $2}')"
width="$(xdotool getwindowgeometry --shell $wid | grep WIDTH | awk -F '=' '{print $2}')"
height="$(xdotool getwindowgeometry --shell $wid | grep HEIGHT | awk -F '=' '{print $2}')"
x="$((parent_x + parent_width / 2 - width / 2))"
y="$((parent_y + parent_height / 2 - height / 2))"
# without an echo, the xdotool command will not work.
# it appears that xdotool runs before the window is created if no echo is used.
# using a sleep command instead of echo just causes a delay in the window opening.
# so it appears the output to stdout (or whatever) causes bspwm to open the window
echo ""
xdotool windowmove "$wid" "$x" "$y"
exit
# notify-send $parent_id "$parent_class | $parent_x , $parent_y | $parent_width x $parent_height"
# notify-send $wid "$width x $height"
# (sleep 2 ; notify-send $wid "xdotool windowmove --sync $wid $x $y") &
fi
fi
if [ $class = "Thunderbird" ] && [ $role = "messageWindow" ] || [ $role = "Msgcompose" ] ; then if [ $class = "Thunderbird" ] && [ $role = "messageWindow" ] || [ $role = "Msgcompose" ] ; then
echo "state=floating" echo "state=floating"
@ -26,8 +59,14 @@ fi
#place floating windows #place floating windows
#adapted from https://github.com/baskerville/bspwm/issues/263 #adapted from https://github.com/baskerville/bspwm/issues/263
floats=$(bspc query -N -n .floating -d .focused | wc -l) # floats=$(bspc query -N -n .floating -d .focused | wc -l)
xdotool windowmove --sync $wid $(( 50 + 50 * floats )) 300 # if [ $floats -gt 0 ] ; then
# echo ""
# xdotool windowmove --relative $wid $(( 50 * floats )) $(( 50 * floats ))
# why does --relative option not work?
# notify-send $floats "xdotool windowmove --relative $wid $(( 50 * floats )) $(( 50 * floats ))"
# exit
# fi
case "$role" in case "$role" in
messageWindow) messageWindow)