summaryrefslogtreecommitdiffstats
path: root/core/modules/idleaction/data/etc/X11/Xsession.d/95-xscreensaver
blob: 86a9995acb91f6f954e422e25a02bab6b08bd86c (plain) (blame)
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
#!/bin/ash

if command -v xscreensaver; then
	DPMS=False
	AUTOLOCK=True
	NEVER_LOCK=
	secsToTime() {
		local NUM SECS MINS HRS
		NUM="$1"
		SECS=$(( NUM % 60 ))
		MINS=$(( ( NUM / 60 ) % 60 ))
		HRS=$(( ( NUM / 3600 ) % 60 ))
		printf "%02d:%02d:%02d" "$HRS" "$MINS" "$SECS"
	}
	[ -z "$UID" ] && UID=$(id -u)
	[ -z "$HOME" ] && HOME="$(getent passwd "$UID" | head -n 1 | awk -F ':' '{print $6}')"
	. /opt/openslx/config
	SBY="${SLX_SCREEN_STANDBY_TIMEOUT}"
	SVR="${SLX_SCREEN_SAVER_TIMEOUT}"
	if [ -n "${SLX_REMOTE_VNC}" ]; then
		# TODO Remove after 2021-07-01, variables should be set by slx-admin
		SVR=0
	fi
	if [ -n "${SLX_EXAM}" ]; then
		SLX_SCREEN_SAVER_GRACE_TIME=
		AUTOLOCK=False
		NEVER_LOCK=True
		SBY=0
		SVR=0
	elif [ -z "$SBY" ]; then
		SBY=0
	elif [ "$SBY" -gt 0 ] && [ "$SBY" -lt 60 ]; then
		SBY=60
	elif ! [ "$SBY" -ge 0 ]; then # isNumeric?
		SBY=0
	fi
	# Guest session/auto login, don't lock
	[ "$GUEST_SESSION" = "True" ] && NEVER_LOCK=True
	# If web based login, we can't authenticate again as we don't have the password - never lock
	if [ -z "$NEVER_LOCK" ]; then
		usrname="$( < "/etc/passwd"  awk -v "uid=$UID" -F ':' '$3 == uid {print $5; exit}' )"
		# Yes, this really checks if $usrname ends in @browser, and sets NEVER_LOCK to true if so
		[ "${usrname%"@browser"}" != "${usrname}" ] && NEVER_LOCK=True
	fi
	# Create config value for standby timeout
	if [ "$SBY" -gt 0 ]; then
		DPMS=True
		STANDBY="$( secsToTime "$SBY" )"
	else
		STANDBY="99:00:00"
	fi
	# Explicit screen saver timeout set. Handle 0 as disabled.
	# Fix values below one minute:
	if [ "$SVR" -gt 0 ] && [ "$SVR" -lt 60 ]; then
		SVR=60
	fi
	if [ "$SVR" -gt 0 ]; then
		TIMEOUT="$( secsToTime "$SVR" )"
	else
		TIMEOUT="99:00:00"
	fi
	if [ -z "$SLX_SCREEN_SAVER_GRACE_TIME" ]; then
		GRACE="99:00:00"
		AUTOLOCK=False
	else
		GRACE="$( secsToTime "$SLX_SCREEN_SAVER_GRACE_TIME" )"
	fi
	# Always overwrite this file -- better for exam mode
	cat > "$HOME/.xscreensaver" <<EOF
# Automatically generated on $(date) -- modifications might get lost
mode:         one
cycle:        99:00:00
timeout:      $TIMEOUT
lock:         $AUTOLOCK
lockTimeout:  $GRACE
fade:         False
unfade:       False
dpmsEnabled:  $DPMS
dpmsStandby:  $STANDBY
dpmsSuspend:  $STANDBY
dpmsOff:      $STANDBY
dpmsFullThrottle: True
newLoginCommand:
externalUngrabCommand: /opt/openslx/xscreensaver/ungrab
programs:     /opt/openslx/bin/bwlp-screensaver
selected:     0
EOF
	(
	# HACK: This env vars prevent xscreensaver from ever locking
	# Only one would be needed but set both in case one of them
	# gets removed in the future.
	if [ -n "$NEVER_LOCK" ]; then
		export RUNNING_UNDER_GDM="not really but yea"
		export WAYLAND_DISPLAY="none, haha"
	fi
	xscreensaver -no-splash &
	)
fi

true