Code:
#!/bin/bash
##################################################################
#
# Angelehnt an:
# http://wwww.ubuntuforums.org/showthread.php?t=1294661
# http://linuxundich.de/de/ubuntu/aero-snap-mit-gnome-und-compiz/
#
##################################################################
DEVICES=`xinput -list | grep "slave pointer" | grep -iv "virtual" | grep id= | sed 's:.*id=\([0-9]*\).*:\1:' `
DEVICE_ARRAY=($DEVICES)
DX=2
DY=42
WIDTH=$(xdpyinfo | grep 'dimensions:' | cut -f 2 -d ':' | cut -f 1 -d 'x')
HEIGHT=$(xdpyinfo | grep 'dimensions:' | cut -f 2 -d ':' | cut -f 2 -d 'x' | cut -f 1 -d p)
WIDTH=$((WIDTH+1-1)) #Damit Leerzeichen in WIDTH u. HEIGHT wegfallen... Geht bestimmt "schöner"
HEIGHT=$((HEIGHT+1-1))
HWIDTH=$(($WIDTH/2-$DX))
HHEIGHT=$(($HEIGHT/2-$DY))
TOLERANCE=3
do_choice() {
X=$(xdotool getmouselocation | awk '{print $1}' | cut -d : -f 2)
Y=$(xdotool getmouselocation | awk '{print $2}' | cut -d : -f 2)
#Horizontal
C=0 #center
if [ $X -le $TOLERANCE ]; then
C=1 #left
fi
if [ $X -ge $(($WIDTH-$TOLERANCE)) ]; then
C=2 #right
fi
#Vertikal
if [ $Y -le $TOLERANCE ]; then
C=$((C+3)) #top
fi
if [ $Y -ge $(($HEIGHT-$TOLERANCE)) ]; then
C=$((C+6)) #bottom
fi
case $C in
# 0) center
1) wmctrl -r :ACTIVE: -b remove,maximized_horz && wmctrl -r :ACTIVE: -b add,maximized_vert && wmctrl -r :ACTIVE: -e 0,0,0,$HWIDTH,0 ;; #left
2) wmctrl -r :ACTIVE: -b remove,maximized_horz && wmctrl -r :ACTIVE: -b add,maximized_vert && wmctrl -r :ACTIVE: -e 0,$((HWIDTH+DX)),0,$HWIDTH,0 ;; #right
3) wmctrl -r :ACTIVE: -b remove,maximized_vert && wmctrl -r :ACTIVE: -b add,maximized_horz && wmctrl -r :ACTIVE: -e 0,0,0,0,$HHEIGHT ;; #top
6) wmctrl -r :ACTIVE: -b remove,maximized_vert && wmctrl -r :ACTIVE: -b add,maximized_horz && wmctrl -r :ACTIVE: -e 0,0,$((HHEIGHT+DY)),$WIDTH,$HHEIGHT ;; #bottom
4) wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz && wmctrl -r :ACTIVE: -e 0,0,0,$HWIDTH,$HHEIGHT ;; #topleft
5) wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz && wmctrl -r :ACTIVE: -e 0,$((HWIDTH+DX)),0,$HWIDTH,$HHEIGHT ;; #topright
7) wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz && wmctrl -r :ACTIVE: -e 0,0,$((HHEIGHT+DY)),$HWIDTH,$HHEIGHT ;; #bottomleft
8) wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz && wmctrl -r :ACTIVE: -e 0,$((HWIDTH+DX)),$((HHEIGHT+DY)),$HWIDTH,$HHEIGHT ;; #bottomright
esac
}
#Ermittlem, ob Button gedrückt ist
DOWN=0
for i in ${!DEVICE_ARRAY[@]}
do
if [ `xinput --query-state ${DEVICE_ARRAY[i]} | grep down` ]; then
DOWN=1
fi
done
#Button gerückt?
if [ $DOWN -gt 0 ]; then
#Prüfe solange, bis Button losgelassen wurde...
while [ $DOWN -gt 0 ]
do
DOWN=0
for i in ${!DEVICE_ARRAY[@]}
do
if [ `xinput --query-state ${DEVICE_ARRAY[i]} | grep down` ];then
DOWN=1
fi
done
done
#...dann nehme Aktionen vor.
do_choice
fi
Bookmarks