From 476b0ba19761603832479c1e1a817b80317b090b Mon Sep 17 00:00:00 2001 From: ray Date: Tue, 16 Aug 2022 13:49:36 +0100 Subject: [PATCH] open child windows in center of parent not desktop --- external.sh | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/external.sh b/external.sh index 6b1c1d5..38dd013 100755 --- a/external.sh +++ b/external.sh @@ -7,6 +7,39 @@ consequences=$4 title=$(xtitle "$wid") 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 echo "state=floating" @@ -26,8 +59,14 @@ fi #place floating windows #adapted from https://github.com/baskerville/bspwm/issues/263 -floats=$(bspc query -N -n .floating -d .focused | wc -l) -xdotool windowmove --sync $wid $(( 50 + 50 * floats )) 300 +# floats=$(bspc query -N -n .floating -d .focused | wc -l) +# 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 messageWindow)