#!/bin/bash

# Transmission of the size of one window to another one
# Call: Control+Super+KP_Begin
# Usage: Click in the window in order to transmit its size
#	 Then click in the window which shall inherit the size of the first one

mouse_id=$(xinput --list | grep -i -m 1 'mouse' | grep -o 'id=[0-9]\+' | grep -o '[0-9]\+')

state=""; until [[ "$state" =~ "button[1]=down" ]]; do state=$(xinput --query-state $mouse_id);  done

act_id=$(printf '%1x' $(xdotool getactivewindow))
act_param=($(wmctrl -lG | grep $act_id))
act_size=(${act_param[4]} ${act_param[5]})

while [ "$(printf '%1x' $(xdotool getactivewindow))" = "$act_id" ]; do :; done
state=""; until [[ "$state" =~ "button[1]=down" ]]; do state=$(xinput --query-state $mouse_id);  done

act_id=$(xdotool getactivewindow)
xdotool windowsize $act_id ${act_size[@]}

exit 0

