Skip to content

Instantly share code, notes, and snippets.

@ryot4
Created September 7, 2016 13:24
Show Gist options
  • Save ryot4/84ff632f7faf59ece66741c355248b88 to your computer and use it in GitHub Desktop.
Save ryot4/84ff632f7faf59ece66741c355248b88 to your computer and use it in GitHub Desktop.
Move the active X11 window in the specified direction
#!/bin/sh
# dependency: xdotool and wmctrl
eval $(xdotool getactivewindow getwindowgeometry --shell)
DESKTOP=$(wmctrl -d | awk '{ print $4 }' | tr x ' ')
DWIDTH=$(echo $DESKTOP | cut -d ' ' -f 1)
DHEIGHT=$(echo $DESKTOP | cut -d ' ' -f 2)
case $1 in
left)
X=0
# West
GRAVITY=4
;;
right)
X=$((DWIDTH - WIDTH))
# East
GRAVITY=6
;;
up)
Y=0
# North
GRAVITY=2
;;
down)
Y=$((DHEIGHT - HEIGHT))
# South
GRAVITY=8
;;
*)
echo 'unknown direction'
exit 1
;;
esac
wmctrl -r :ACTIVE: -e "$GRAVITY,$X,$Y,-1,-1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment