-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpushpop
More file actions
executable file
·96 lines (83 loc) · 2.02 KB
/
pushpop
File metadata and controls
executable file
·96 lines (83 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
ACTION=auto
FILENAME=${HOME}/.pushpop
while getopts a:i:e:f: FLAG; do
ARGS=1;
case $FLAG in
i)
WINDOW=$OPTARG
;;
a)
ACTION=$OPTARG
;;
f)
FILENAME=$OPTARG
;;
e)
EXPIRES=$OPTARG
;;
esac
done
if [ ! -e $FILENAME ]; then
touch $FILENAME
fi
NOW=$(date +"%s")
if [ "${WINDOW}x" == "x" ]; then
WINDOWID=$(xdotool getactivewindow)
WINDOWPID=$(xdotool getactivewindow getwindowpid)
WINDOW="${WINDOWID}-${WINDOWPID}"
fi
if [ "$ACTION" == "auto" ]; then
grep -q $WINDOW $FILENAME
if [ $? -eq 0 ]; then
ACTION="pop"
else
ACTION="push"
fi
fi
function get_position()
{
FILENAME=$1
WINDOW=$2
grep $WINDOW $FILENAME| tail -1
}
function get_window_position()
{
WINDOW=$1
eval $(xdotool getwindowgeometry --shell $WINDOW)
local frame=$(xprop -id $WINDOW|grep _NET_FRAME_EXTENTS |awk -F[=,] '{print $2, $3}')
if [ "x${frame}" != "x" ]; then
frame_width=$(echo $frame|cut -d ' ' -f 1)
frame_height=$(echo $frame|cut -d ' ' -f 2)
fi
NEW_X=$(( $X - $frame_width ))
NEW_Y=$(( $Y - $frame_height ))
echo ${NEW_X},${NEW_Y},${WIDTH},${HEIGHT} $SCREEN
}
if [ "$ACTION" == "push" ]; then
WINDOWPOS=$(get_window_position $WINDOW)
SIZEDATA=$(get_position $FILENAME $WINDOW)
NEWSIZEDATA=$(echo $WINDOW $WINDOWPOS $NOW)
if [ "${SIZEDATA}" != "${NEWSIZEDATA}" ]; then
echo $NEWSIZEDATA >> $FILENAME
fi
fi
if [ "$ACTION" == "pop" ]; then
TMPFILE=$(mktemp)
SIZEDATA=$(get_position $FILENAME $WINDOW)
if [ -n "$EXPIRES" ]; then
TIME=$(echo $SIZEDATA|awk '{print $4}')
AGE=$(expr $NOW - $TIME)
if [ "$AGE" -lt "$EXPIRES" ]; then
echo $SIZEDATA
fi
else
echo $SIZEDATA
fi
grep -v "$SIZEDATA" $FILENAME > $TMPFILE
if [ $? -le 1 ]; then
mv -f $TMPFILE $FILENAME;
else
rm $TMPFILE
fi
fi