modified slightly the script so it also works when the windows are maximized