OS X Divvy emulation for EWMH-compliant (Unix-like) Window Managers
#!/bin/sh | |
DEST="$1" | |
if [ -z "$DEST" ]; then | |
echo "USAGE: $0 [location]" | |
echo -e "\nsupported locations: " | |
echo -e "\thalf-left, half-right" | |
echo -e "\tthird-left, third-middle, third-right" | |
echo -e "\tquarter-top-left, quarter-rop-right, quarter-bottom-left, quarter-bottom-right" | |
echo -e "\nTo make this useful, use a key shortcut for each command :)" | |
exit 1 | |
fi | |
# set system info here | |
NUM_MONITORS=3 | |
MON_HEIGHT=1080 | |
MON_WIDTH=1920 | |
# get active window data | |
ACTIVE_WINDOW_DATA=`xwininfo -id $(xprop -root | awk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}')` | |
# get the window's current position | |
X_POS=`echo "$ACTIVE_WINDOW_DATA" | grep "Absolute upper-left X" | awk '{print$4}'` | |
Y_POS=`echo "$ACTIVE_WINDOW_DATA" | grep "Absolute upper-left Y" | awk '{print$4}'` | |
echo "X: $X_POS Y: $Y_POS" | |
# determine which monitor it's on | |
for i in `seq 0 $NUM_MONITORS`; do | |
let MON_START=$MON_WIDTH*$i | |
if [ $X_POS -ge $MON_START ]; then | |
ACTIVE_MONITOR=$i | |
else | |
break | |
fi | |
done | |
# it was 0-indexed, plus one | |
let ACTIVE_MONITOR+=1 | |
echo "ACTIVE MONITOR: $ACTIVE_MONITOR" | |
if [ -z "$ACTIVE_MONITOR" ]; then | |
echo "Unable to determine which monitor we are on. What a shame. Quitting" | |
exit 1 | |
fi | |
let HALF_X_SIZE=$MON_WIDTH/2 | |
let HALF_Y_SIZE=$MON_HEIGHT/2 | |
let HALF_RIGHT_POS=($MON_WIDTH*$ACTIVE_MONITOR)-$HALF_X_SIZE | |
let HALF_LEFT_POS=($MON_WIDTH*$ACTIVE_MONITOR)-$MON_WIDTH | |
let THIRD_X_SIZE=$MON_WIDTH/3 | |
let THIRD_RIGHT_POS=($MON_WIDTH*$ACTIVE_MONITOR)-$THIRD_X_SIZE | |
let THIRD_LEFT_POS=($MON_WIDTH*$ACTIVE_MONITOR)-$MON_WIDTH | |
let THIRD_MIDDLE_POS=$THIRD_LEFT_POS+$THIRD_X_SIZE | |
let QUARTER_X_SIZE=$HALF_X_SIZE | |
let QUARTER_Y_SIZE=$MON_HEIGHT/2 | |
let QUARTER_TOP_LEFT_POS=$HALF_LEFT_POS | |
let QUARTER_TOP_RIGHT_POS=$HALF_RIGHT_POS | |
let QUARTER_BOTTOM_LEFT_POS=$HALF_LEFT_POS | |
let QUARTER_BOTTOM_RIGHT_POS=$HALF_RIGHT_POS | |
# -e GRAVITY,X_POS,Y_POS,X_WIDTH,Y_WIDTH | |
case "$DEST" in | |
half-right) | |
echo "half-right" | |
wmctrl -r :ACTIVE: -e 0,$HALF_RIGHT_POS,0,$HALF_X_SIZE,$MON_HEIGHT | |
;; | |
half-left) | |
echo "half-left" | |
wmctrl -r :ACTIVE: -e 0,$HALF_LEFT_POS,0,$HALF_X_SIZE,$MON_HEIGHT | |
;; | |
third-right) | |
echo "third left" | |
wmctrl -r :ACTIVE: -e 0,$THIRD_RIGHT_POS,0,$THIRD_X_SIZE,$MON_HEIGHT | |
;; | |
third-middle) | |
echo "third middle" | |
wmctrl -r :ACTIVE: -e 0,$THIRD_MIDDLE_POS,0,$THIRD_X_SIZE,$MON_HEIGHT | |
;; | |
third-left) | |
echo "third left" | |
wmctrl -r :ACTIVE: -e 0,$THIRD_LEFT_POS,0,$THIRD_X_SIZE,$MON_HEIGHT | |
;; | |
quarter-top-left) | |
echo "quarter top left" | |
wmctrl -r :ACTIVE: -e 0,$QUARTER_TOP_LEFT_POS,0,$QUARTER_X_SIZE,$QUARTER_Y_SIZE | |
;; | |
quarter-top-right) | |
echo "quarter top right" | |
wmctrl -r :ACTIVE: -e 0,$QUARTER_TOP_RIGHT_POS,0,$QUARTER_X_SIZE,$QUARTER_Y_SIZE | |
;; | |
quarter-bottom-left) | |
echo "quarter bottom left" | |
wmctrl -r :ACTIVE: -e 0,$QUARTER_BOTTOM_LEFT_POS,$HALF_Y_SIZE,$QUARTER_X_SIZE,$QUARTER_Y_SIZE | |
;; | |
quarter-bottom-right) | |
echo "quarter bottom right" | |
wmctrl -r :ACTIVE: -e 0,$QUARTER_BOTTOM_RIGHT_POS,$HALF_Y_SIZE,$QUARTER_X_SIZE,$QUARTER_Y_SIZE | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
What's Divvy?
Window management at its finest
... and now you can have a taste even if you don't have a mac😀