summaryrefslogtreecommitdiff
path: root/community/lightdm/lightdm-lock-screen-before-switch.patch
blob: b8b1d559cf6c1997329cfca2bc73b30e996c5cb4 (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
# HG changeset patch
# Parent b329fa1badaa454239690c3feb93d53324134915
try to lock the screen before switching users

diff --git a/utils/gdmflexiserver b/utils/gdmflexiserver
--- a/utils/gdmflexiserver
+++ b/utils/gdmflexiserver
@@ -9,9 +9,47 @@
 #
 # See http://www.gnu.org/copyleft/gpl.html for the full text of the license.
 
+PATH=/usr/local/bin:/bin:/usr/bin
+export PATH
+
 if [ -z "$XDG_SEAT_PATH" ]; then
   # something went wrong
   exit 1
 fi
 
+find_command () {
+    cmd="$1"
+    oIFS="${IFS}"; IFS=:
+    set -- ${PATH}
+    IFS="${oIFS}"
+
+    for part; do
+        [ -x "${part}/${cmd}" ] && return 0
+    done
+    return 1
+}
+
+lock_screen () {
+    for lock_cmd in \
+        "xscreensaver-command -lock" \
+        "gnome-screensaver-command --lock" \
+        "dbus-send --session --dest=org.freedesktop.ScreenSaver --type=method_call /ScreenSaver org.freedesktop.ScreenSaver.Lock"
+    do
+        ${lock_cmd} >/dev/null 2>&1 && return
+    done
+
+    for lock_cmd in \
+        "slock" \
+        "xlock -mode blank"
+    do
+        set -- ${lock_cmd}
+        if find_command "$1"; then
+            ${lock_cmd} >/dev/null 2>&1 &
+            return
+        fi
+    done
+}
+
+lock_screen
+
 dbus-send --system --type=method_call --print-reply --dest=org.freedesktop.DisplayManager $XDG_SEAT_PATH org.freedesktop.DisplayManager.Seat.SwitchToGreeter