Last active
June 3, 2016 21:58
-
-
Save jonhoo/6053203 to your computer and use it in GitHub Desktop.
Script for slicing and aerosnapping X windows in an EWMH compatible WM
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 | |
if [[ $# -eq 0 ]]; then | |
echo "Usage: $0 top|right|bottom|left [maximized]" | |
exit 1 | |
fi | |
active=`xprop -root _NET_ACTIVE_WINDOW | sed 's/^.*# //'` | |
if [[ $active == "0x0" ]]; then | |
echo "No active window found (_NET_ACTIVE_WINDOW == 0x0)" | |
exit 2 | |
fi | |
ismh=`xwininfo -wm -id $active | grep "Maximized Horz"` | |
ismv=`xwininfo -wm -id $active | grep "Maximized Vert"` | |
if [[ $2 == "maximized" ]]; then | |
rootgeo=`xprop -root _NET_DESKTOP_GEOMETRY | sed 's/^.* = \([0-9]*\), \([0-9]*\)/\1 \2/'` | |
w=`echo "$rootgeo" | cut -d' ' -f1` | |
h=`echo "$rootgeo" | cut -d' ' -f2` | |
x=0 | |
y=0 | |
echo "Base geometry: ${w}x${h}+${x}+${y}" | |
else | |
geometry=`xwininfo -id $active` | |
w=`echo "$geometry" | grep "Width" | sed 's/^.*:\s*//'` | |
h=`echo "$geometry" | grep "Height" | sed 's/^.*:\s*//'` | |
x=`echo "$geometry" | grep "Absolute upper-left X" | sed 's/^.*:\s*//'` | |
y=`echo "$geometry" | grep "Absolute upper-left Y" | sed 's/^.*:\s*//'` | |
echo "Base geometry: ${w}x${h}+${x}+${y}" | |
rx=`echo "$geometry" | grep "Relative upper-left X" | sed 's/^.*:\s*//'` | |
ry=`echo "$geometry" | grep "Relative upper-left Y" | sed 's/^.*:\s*//'` | |
x=`echo $x-$rx | bc` | |
y=`echo $y-$ry | bc` | |
echo "Adjusted geometry: ${w}x${h}+${x}+${y}" | |
fi | |
if [[ $1 == "top" ]]; then | |
h=`printf %d $(echo "$h/2" | bc)` | |
elif [[ $1 == "bottom" ]]; then | |
h=`printf %d $(echo "$h/2" | bc)` | |
y=`printf %d $(echo "$y+$h" | bc)` | |
elif [[ $1 == "left" ]]; then | |
w=`printf %d $(echo "$w/2" | bc)` | |
elif [[ $1 == "right" ]]; then | |
w=`printf %d $(echo "$w/2" | bc)` | |
x=`printf %d $(echo "$x+$w" | bc)` | |
fi | |
echo "New geometry: ${w}x${h}+${x}+${y}" | |
wmctrl -r :ACTIVE: -e 0,$x,$y,$w,$h |
For "Aero Snap"-like functionality, append this to .pekwm/mouse:
ScreenEdge {
Down {
EnterMoving = "Any Any" { Actions = "Exec slicewin bottom maximized" }
}
Up {
EnterMoving = "Any Any" { Actions = "Exec slicewin top maximized" }
}
Left {
EnterMoving = "Any Any" { Actions = "Exec slicewin left maximized" }
}
Right {
EnterMoving = "Any Any" { Actions = "Exec slicewin right maximized" }
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example pekwm config: