summaryrefslogtreecommitdiff
path: root/scripts/xflock4
blob: bff32b2e89a3d7b9470c3e38e99c476896551f31 (plain)
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
#!/bin/sh
#
#  xfce4
#
#  Copyright (C) 1999, 2003 Olivier Fourdan (fourdan@xfce.org)
#  Copyright (C) 2011       Guido Berhoerster (guido+xfce.org@berhoerster.name)
#  Copyright (C) 2015, 2018 Simon Steinbeiß (simon@xfce.org)
#  Copyright (C) 2011, 2022 Jarno Suni (8@iki.fi)
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#

# Wait a bit so that user have time to raise finger from a key if
# the script is run in terminal.
[ -t 0 ] && sleep 1

# First test for the command set in the session's xfconf channel
LOCK_CMD=$(xfconf-query -c xfce4-session -p /general/LockCommand)

# Lock by xscreensaver or gnome-screensaver, if a respective daemon is running
for lock_cmd in \
    "$LOCK_CMD" \
    "xfce4-screensaver-command --lock" \
    "xscreensaver-command -lock" \
    "gnome-screensaver-command --lock"
do
    if [ ! -z "$lock_cmd" ]; then
        $lock_cmd >/dev/null 2>&1 && exit
    fi
done

# else run another access locking utility, if installed
for lock_cmd in \
  "xlock -mode blank" \
  "slock"
  do
    set -- $lock_cmd
    if command -v -- $1 >/dev/null 2>&1; then
        $lock_cmd >/dev/null 2>&1 &
	# turn off display backlight:
	xset dpms force off
        exit
    fi
done

# else access locking failed
exit 1