-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlock.sh
executable file
·65 lines (50 loc) · 1.78 KB
/
lock.sh
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
#/bin/bash
readonly CORNERSIZE=10 # Use same value use in xautolock config (default 10)
readonly TIMER=10
# If One of those app run, then do no run slock
isAppRunning() {
flash_process=`pgrep -l plugin-containe | grep -wc plugin-containe`
if [[ $flash_process -ge 1 ]];then
return 0
fi
parole_process=`pgrep -lc parole`
if [ $parole_process -ge 1 ]; then
return 0
fi
impress_run=`ps -aux | grep "soffice.bin --impress" | wc -l`
if [ $impress_run -ge 2 ]; then
return 0
fi
return 1
}
# Hack the mouse in corner
isInCorner() {
# Screen height (SCREEN_Y) and Width (SCREEN_X)
eval $(xrandr | grep '*' | grep -o -E "[0-9]+x[0-9]+" | sed -e "s/\([0-9]*\)/SCREEN_X=\1/" -e "s/x\([0-9]*\)/\nSCREEN_Y=\1/")
# Mouse position
eval $(xdotool getmouselocation --shell)
WIDTH_MAX=$(($SCREEN_X - $CORNERSIZE - 1));
HEIGHT_MAX=$(($SCREEN_Y - $CORNERSIZE - 1));
# Case line 131
# https://github.com/l0b0/xautolock/blob/93741214ba41b82ad1a6bd56ad5da28cfb4fe87a/src/engine.c
if [[ ( $X -le $CORNERSIZE && $X -ge 0 && $Y -le $CORNERSIZE && $Y -ge 0)
|| ( $X -ge $WIDTH_MAX && $Y -le $CORNERSIZE )
|| ( $X -le $CORNERSIZE && $Y -ge HEIGHT_MAX )
|| ( $X -ge $WIDTH_MAX && $Y -ge $HEIGHT_MAX ) ]]; then
return 0;
fi
return 1;
}
if isInCorner; then
slock;
fi
if isAppRunning; then
dpmsStatus=`xset -q | grep -ce 'DPMS is Enabled'` # DPMS is at 1 if you check "Presentation mod"
if [ $dpmsStatus == 1 ];then
notify-send -t 5000 -- "Lock screen in $TIMER seconds"
sleep $TIMER;
slock;
fi
fi
# Here is my command :D
# xautolock -detectsleep -time 1 -locker "~/lock.sh" -nowlocker "slock" -corners 000+ -cornerdelay 3