-
-
Save bdowling/ad87c58362af7c28806bb2292436222d 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'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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. | |
# Added fetching display geometry | |
# Added window search feature to allow moving another named window, e.g. | |
# swind right --name right-window | |
# | |
cmd="$1" | |
shift | |
if [ -n "$1" ]; then | |
winid=$(xdotool search "$@" | head -1) | |
else | |
winid=$(xdotool getwindowfocus) | |
fi | |
read width height <<< $(xdotool getdisplaygeometry) | |
# This is used to adjust for window decoration in half-height layouts (title bars) | |
border=23 | |
halfwidth=$(( $width/2 )) | |
fullheight=$(( $height/2 - $border * 2 )) | |
halfheight=$(( $height/2 - $border * 2 )) | |
case "$cmd" in | |
'') | |
echo "Usage: $0 <left|right|top|bottom|top-left|top-right|bottom-left|bottom-right> [optional window search]" | |
echo "" | |
echo "Search options are passed to 'xdotool search' e.g." | |
echo " $0 left --name findwindowbyname" | |
echo "---------------" | |
xdotool search | |
;; | |
'left') | |
xdotool windowsize $winid $halfwidth $height | |
xdotool windowmove $winid 0 0 | |
;; | |
'right') | |
xdotool windowsize $winid $halfwidth $height | |
xdotool windowmove $winid $halfwidth 0 | |
;; | |
'top') | |
xdotool windowsize $winid $width $halfheight | |
xdotool windowmove $winid 0 0 | |
;; | |
'bottom') | |
xdotool windowsize $winid $width $halfheight | |
xdotool windowmove $winid 0 $halfheight | |
;; | |
'top-left') | |
xdotool windowsize $winid $halfwidth $fullheight | |
xdotool windowmove $winid 0 0 | |
;; | |
'top-right') | |
xdotool windowsize $winid $halfwidth $fullheight | |
xdotool windowmove $winid $halfwidth 0 | |
;; | |
'bottom-left') | |
xdotool windowsize $winid $halfwidth $fullheight | |
xdotool windowmove $winid 0 $(( $halfwidth + $border * 2 )) | |
;; | |
'bottom-right') | |
xdotool windowsize $winid $halfwidth $fullheight | |
xdotool windowmove $winid $halfwidth $(( $halfwidth + $border * 2 )) | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment