Skip to content

Instantly share code, notes, and snippets.

@Alieff
Forked from andrewmcdonough/swind
Created August 10, 2018 02:38
Show Gist options
  • Save Alieff/fe1301c748cd856ed30e32abcb60d488 to your computer and use it in GitHub Desktop.
Save Alieff/fe1301c748cd856ed30e32abcb60d488 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment