diff options
author | jc00ke <jesse@jc00ke.com> | 2013-11-24 21:43:12 -0800 |
---|---|---|
committer | jc00ke <jesse@jc00ke.com> | 2016-06-17 21:29:00 -0700 |
commit | 5d45b1f52f386bd525b0cb791edf960c259fa3c3 (patch) | |
tree | 2e81e9b3ce7cd49ef04819e79fcbb8f6aaf23fa8 | |
parent | Adding move window script (diff) | |
download | move-to-next-monitor-5d45b1f52f386bd525b0cb791edf960c259fa3c3.tar.gz move-to-next-monitor-5d45b1f52f386bd525b0cb791edf960c259fa3c3.tar.bz2 move-to-next-monitor-5d45b1f52f386bd525b0cb791edf960c259fa3c3.zip |
Support monitors in vertical positions too
-rwxr-xr-x | move-to-next-monitor | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/move-to-next-monitor b/move-to-next-monitor index 7ddb6b0..5530d9b 100755 --- a/move-to-next-monitor +++ b/move-to-next-monitor @@ -2,7 +2,6 @@ # # Move the current window to the next monitor. # -# Only works on a horizontal monitor setup. # Also works only on one X screen (which is the most common case). # # Props to @@ -14,7 +13,9 @@ # will sometimes give a "-0-0" geometry. This is why we resort to "xwininfo". screen_width=`xdpyinfo | awk '/dimensions:/ { print $2; exit }' | cut -d"x" -f1` +screen_height=`xdpyinfo | awk '/dimensions:/ { print $2; exit }' | cut -d"x" -f2` display_width=`xdotool getdisplaygeometry | cut -d" " -f1` +display_height=`xdotool getdisplaygeometry | cut -d" " -f2` window_id=`xdotool getactivewindow` # Remember if it was maximized. @@ -35,6 +36,8 @@ y=`expr $y - $y_offset` # Compute new X position new_x=`expr $x + $display_width` +# Compute new Y position +new_y=`expr $y + $display_height` # If we would move off the right-most monitor, we set it to the left one. # We also respect the window's width here: moving a window off more than half its width won't happen. @@ -43,13 +46,23 @@ if [ `expr $new_x + $width / 2` -gt $screen_width ]; then new_x=`expr $new_x - $screen_width` fi +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 - $screen_height` +fi + # Don't move off the left side. if [ $new_x -lt 0 ]; then new_x=0 fi +# Don't move off the bottom +if [ $new_y -lt 0 ]; then + new_y=0 +fi + # Move the window -xdotool windowmove $window_id $new_x $y +xdotool windowmove $window_id $new_x $new_y # Maximize window again, if it was before if [ -n "${window_state}" ]; then |