Skip to content

Instantly share code, notes, and snippets.

@andrewmcdonough
Created March 31, 2009 16:02
Show Gist options
  • Save andrewmcdonough/88246 to your computer and use it in GitHub Desktop.
Save andrewmcdonough/88246 to your computer and use it in GitHub Desktop.
A bash script to move the focused window in X to different parts of the screen. Most useful when you assign shortcut keys to the various options, e.g. assign '<Super>Up' to run 'swind up'
#!/bin/bash
# Written by Andrew McDonough
# Prerequisites: xdotool must be installed and in your path (http://tinyurl.com/xdotool)
# A simple bash script that uses xdotool to move the window that is currently in focus to different parts of the screen.
# Particularly useful for reading web pages with flexible layouts on wide monitors.
# Assign the various options to keyboard shortcuts e.g. '<Super>Left' assigned to 'swind left'
# See http://tinyurl.com/ubuntukeys for help with assigning keyboard shortcuts.
# Change the following to suit your own monitor's resolution. Mine is 1920x1200
width=1920
height=1200
winid=`xdotool getwindowfocus`
case "$1" in
'')
echo "Usage: swind <left|right|top|bottom|top-left|top-right|bottom-left|bottom-right>"
;;
'left')
xdotool windowmove $winid 0 0
xdotool windowsize $winid $(( $width/2 )) $height
;;
'right')
xdotool windowmove $winid $(( $width/2)) 0
xdotool windowsize $winid $(( $width/2)) $height
;;
'top')
xdotool windowmove $winid 0 0
xdotool windowsize $winid $width $(( $height/2 ))
;;
'bottom')
xdotool windowmove $winid 0 $(( $height/2 ))
xdotool windowsize $winid $width $(( $height/2 ))
;;
'top-left')
xdotool windowmove $winid 0 0
xdotool windowsize $winid $(( $width/2 )) $(( $height/2))
;;
'top-right')
xdotool windowmove $winid $(( $width/2)) 0
xdotool windowsize $winid $(( $width/2 )) $(( $height/2 ))
;;
'bottom-left')
xdotool windowmove $winid 0 $(( $width/2 ))
xdotool windowsize $winid $(( $width/2 )) $(( $height/2 ))
;;
'bottom-right')
xdotool windowmove $winid $(( $width/2)) $(( $height/2 ))
xdotool windowsize $winid $(( $width/2 )) $(( $height/2 ))
;;
esac
@andrewmcdonough
Copy link
Author

@clarkburbidge I haven't used this in a while, but it sounds like you haven't installed xdotool, or that it's not in your path. You can check this by typing xdotool on the terminal. If it's not installed, try visiting http://www.semicomplete.com/projects/xdotool and installing.

@bdowling
Copy link

bdowling commented Sep 3, 2016

Thanks for this nice little wrapper around xdotool to make some convenient window moves. I found it useful. I made a quick fork with a couple additions:

  • Added fetching display geometry dynamic
  • Added window search feature to allow moving another named window, e.g.
    • swind right --name right-window
  • Resized before move seemed to work more reliably in my WM setup.

https://gist.github.com/bdowling/ad87c58362af7c28806bb2292436222d

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