Skip to content

Instantly share code, notes, and snippets.

@zzjjzzgggg
Forked from andrewmcdonough/swind
Last active February 11, 2018 15:51
Show Gist options
  • Select an option

  • Save zzjjzzgggg/8b6a428f0af5bad305f7841820fb1305 to your computer and use it in GitHub Desktop.

Select an option

Save zzjjzzgggg/8b6a428f0af5bad305f7841820fb1305 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.
# sudo apt install xdotool
# get screen width
width=`xdotool getdisplaygeometry | awk '{print $1;}'`
# get screen height
height=`xdotool getdisplaygeometry | awk '{print $2;}'`
# get current focused window
winid=`xdotool getwindowfocus`
# window will be resized to half screen width
HalfWidth=$(( $width/2 ))
HalfHeight=$(( $height/2 ))
OneThirdHeight=$(( $height/3 ))
TwoThirdsHeight=$(( $OneThirdHeight*2 ))
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 $HalfWidth $height
;;
'right')
xdotool windowmove $winid $HalfWidth 0
xdotool windowsize $winid $HalfWidth $height
;;
'top')
xdotool windowmove $winid 0 0
xdotool windowsize $winid $width $HalfHeight
;;
'bottom')
xdotool windowmove $winid 0 $HalfHeight
xdotool windowsize $winid $width $HalfHeight
;;
'top-left')
xdotool windowmove $winid 0 0
xdotool windowsize $winid $HalfWidth $TwoThirdsHeight
;;
'top-right')
xdotool windowmove $winid $HalfWidth 0
xdotool windowsize $winid $HalfWidth $TwoThirdsHeight
;;
'bottom-left')
xdotool windowmove $winid 0 $OneThirdHeight
xdotool windowsize $winid $HalfWidth $TwoThirdsHeight
;;
'bottom-right')
xdotool windowmove $winid $HalfWidth $OneThirdHeight
xdotool windowsize $winid $HalfWidth $TwoThirdsHeight
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment