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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
#!/usr/bin/env bash
#
# Hotspots for Xorg
# - Corners: BL, BR, TL, TR
# - Edges: B, T, L, R
# - Events: onEnter, onExit
#
# Dependencies: xdotool
#
# TODO:
# - better multimonitor support
# Hotspot size
SIZE=2
# Active hotspot dimensions (width, height)
B=(1100 140)
T=(700 "$SIZE")
L=(460 700)
R=(140 700)
BL=(400 400)
BR=("$SIZE" "$SIZE")
TL=(400 300)
TR=("$SIZE" "$SIZE")
# Variables to store the timestamp when the cursor entered a zone
ENTER_TIMESTAMP=0
# Function to reset the timestamp
function resetTimestamp() {
ENTER_TIMESTAMP=0
}
# Function to handle onEnter with a delay
function onEnterWithDelay() {
local zone=$1
local current_time=$(date +%s)
if ((ENTER_TIMESTAMP == 0)); then
# Cursor has just entered the zone, store the timestamp
ENTER_TIMESTAMP=$current_time
elif ((current_time - ENTER_TIMESTAMP >= 2)); then
# Cursor has been in the zone for 2 seconds or more, trigger onEnter
onEnter "$zone"
resetTimestamp
fi
}
# Function to handle onEnter event
function onEnter() {
ZONE=$1
case "$1" in
'T') eww open status &>/dev/null ;;
'R') eww open bar &>/dev/null ;;
esac
}
# Function to handle onExit event
function onExit() {
ZONE=''
case "$1" in
'T') eww close status &>/dev/null ;;
'R') eww close bar &>/dev/null ;;
esac
}
# Get screen dimensions (returns: WIDTH, HEIGHT)
eval "$(xdotool getdisplaygeometry --shell)"
# Calculate coordinates
BLY=$((HEIGHT - BL[1]))
BRX=$((WIDTH - BR[0]))
BRY=$((HEIGHT - BR[1]))
TRX=$((WIDTH - TR[0]))
BX1=$(((WIDTH - B[0]) / 2))
BX2=$(((WIDTH + B[0]) / 2))
BY=$((HEIGHT - B[1]))
LY1=$(((HEIGHT - L[1]) / 2))
LY2=$(((HEIGHT + L[1]) / 2))
RX=$((WIDTH - R[0]))
RY1=$(((HEIGHT - R[1]) / 2))
RY2=$(((HEIGHT + R[1]) / 2))
H=$((HEIGHT - SIZE))
W=$((WIDTH - SIZE))
# Watch mouse
while :; do
sleep 0.1
# Get mouse location (returns: X, Y)
eval "$(xdotool getmouselocation --shell)"
if [ "$ZONE" = "" ]; then
if [[ "$Y" -ge "$H" ]]; then
if [[ "$X" -lt "$SIZE" ]]; then
onEnterWithDelay BL
elif [[ "$X" -gt "$BX1" && "$X" -lt "$BX2" ]]; then
onEnterWithDelay B
elif [[ "$X" -gt "$W" ]]; then
onEnterWithDelay BR
fi
elif [[ "$Y" -lt "$SIZE" && "$X" -gt $((WIDTH / 3)) && "$X" -lt $((2 * WIDTH / 3)) ]]; then
onEnterWithDelay T
elif [[ "$X" -lt "$SIZE" && "$Y" -gt "$LY1" && "$Y" -lt "$LY2" ]]; then
onEnterWithDelay L
elif [[ "$X" -gt "$W" && "$Y" -gt "$RY1" && "$Y" -lt "$RY2" ]]; then
onEnterWithDelay R
fi
else
case "$ZONE" in
'B') [[ "$X" -lt "$BX1" || "$X" -gt "$BX2" || "$Y" -lt "$BY" ]] && onExit B ;;
'L') [[ "$X" -ge "${L[0]}" || "$Y" -lt "$LY1" || "$Y" -gt "$LY2" ]] && onExit L ;;
'R') [[ "$X" -le "$RX" || "$Y" -lt "$RY1" || "$Y" -gt "$RY2" ]] && onExit R ;;
'T') [[ "$X" -lt "$BX1" || "$X" -gt "$BX2" || "$Y" -gt "${T[1]}" ]] && onExit T ;;
'BL') [[ "$X" -ge "${BL[0]}" || "$Y" -lt "$BLY" ]] && onExit BL ;;
'BR') [[ "$X" -le "$BRX" || "$Y" -lt "$BRY" ]] && onExit BR ;;
'TL') [[ "$X" -ge "${TL[0]}" || "$Y" -ge "${TL[1]}" ]] && onExit TL ;;
'TR') [[ "$X" -le "$TRX" || "$Y" -ge "${TR[1]}" ]] && onExit TR ;;
esac
fi
done
|