~scriptstiling
10 itemsDownload ./*


..
xrectsel
drawterm
ext.grid
grid
gridmacro
gridmacro.kde
snap.all
snap.grid
split.grid
swap.grid


tilingswap.grid
1 1405 years agoDownloadRawClose


#!/bin/bash
#
#   Author:         Twily                                              2015
#   Description:    Make two windows replace each other's position and size
#   Requires:       wmctrl, xdotool, xwininfo
#   Usage:          $ sh ./swap.grid
#                   (Eg.: Bind script to trigger on hotkey W-z)
#

ACT=$(xdotool getactivewindow) && WNAME=$(xdotool getactivewindow getwindowname)
if [ "$WNAME" == "Desktop" ]; then exit 3; fi

D=0                 # Decoration heigth
M=0                 # Border width

if [ "$D" -gt "0" ]; then D=$(( $D + $M )); fi

getwindowgeometry() {
    unset X Y W H ID
    eval $(xwininfo -id $1 | 
        sed -n -e "s/^ \+Absolute upper-left X: \+\([0-9]\+\).*/X=\1/p" \
               -e "s/^ \+Absolute upper-left Y: \+\([0-9]\+\).*/Y=\1/p" \
               -e "s/^ \+Width: \+\([0-9]\+\).*/W=\1/p" \
               -e "s/^ \+Height: \+\([0-9]\+\).*/H=\1/p" \
               -e "s/^.*\+Window id: \+\([0-9a-fx]\+\).*/ID=\1/p" )

        X=$(( $X - $M ))
        Y=$(( $Y - $M - $D ))
}

getwindowgeometry $ACT
aX=$X && aY=$Y
aW=$W && aH=$H

getwindowgeometry 0

# Filter window names
case "$(xdotool getwindowname $ID)" in
    "")         exit 3 ;;
    "Desktop")  exit 3 ;;
esac

wmctrl -i -r $ID -e 0,$aX,$aY,$aW,$aH
wmctrl -i -r $ACT -e 0,$X,$Y,$W,$H

exit 0

Top
twily at twily dot info
©twily.info 2013 - 2021



1 576 426 visits
... ^ v