Skip to content

Instantly share code, notes, and snippets.

Created February 3, 2014 11:18
Show Gist options
  • Save fvdnabee/8782219 to your computer and use it in GitHub Desktop.
Save fvdnabee/8782219 to your computer and use it in GitHub Desktop.
Moving a window to the other vertical monitor in XFCE 4
# Move the current window to the other vertical monitor. Adapted from the
# scripts for horizontal monitors at
# Only works on a 2x1 vertical monitor setup.
# Also works only on one X screen (which is the most common case).
# Props to
# Unfortunately, both "xdotool getwindowgeometry --shell $window_id" and
# checking "-geometry" of "xwininfo -id $window_id" are not sufficient, as
# the first command does not respect panel/decoration offsets and the second
# will sometimes give a "-0-0" geometry. This is why we resort to "xwininfo".
window_id=`xdotool getactivewindow`
screen_height=`xdpyinfo | awk '/dimensions:/ { print $2; exit }' | cut -d"x" -f2`
lower_display_height=`xdotool getdisplaygeometry | cut -d" " -f2`
upper_display_height=`expr $screen_height - $lower_display_height`
# Remember if it was maximized.
window_state=`xprop -id $window_id _NET_WM_STATE | awk '{ print $3 }'`
# Un-maximize current window so that we can move it
wmctrl -ir $window_id -b remove,maximized_vert,maximized_horz
# Read window position
x=`xwininfo -id $window_id | awk '/Absolute upper-left X:/ { print $4 }'`
y=`xwininfo -id $window_id | awk '/Absolute upper-left Y:/ { print $4 }'`
# Subtract any offsets caused by panels or window decorations
x_offset=`xwininfo -id $window_id | awk '/Relative upper-left X:/ { print $4 }'`
y_offset=`xwininfo -id $window_id | awk '/Relative upper-left Y:/ { print $4 }'`
x=`expr $x - $x_offset`
y=`expr $y - $y_offset`
# Compute new Y position
if [ $y -gt $upper_display_height ]; then
new_y=`expr $y - $upper_display_height` # window on lower display -> substract for new position
new_y=`expr $y + $upper_display_height` # window on upper display -> add for new position
# We respect the window's height here: moving a window off more than half its height won't happen.
height=`xdotool getwindowgeometry $window_id | awk '/Geometry:/ { print $2 }'|cut -d"x" -f2`
if [ `expr $new_y + $height / 2` -gt $screen_height ]; then
new_y=`expr $new_y - $height`
# Move the window
xdotool windowmove $window_id $x $new_y
# Maximize window again, if it was before
if [ -n "${window_state}" ]; then
wmctrl -ir $window_id -b add,maximized_vert,maximized_horz
Copy link

astamicu commented Feb 1, 2018

thank you so much 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment