initial commit

This commit is contained in:
2025-06-03 14:16:01 +03:00
commit 6fed9ef617
683 changed files with 109296 additions and 0 deletions

54
xss-lock/NEWS Normal file
View File

@@ -0,0 +1,54 @@
0.3.0
-----
* New option --tranfer-sleep-lock gives lockers control over the inhibit delay.
Two bash scripts are included to use this with existing lockers. (Bumps
required glib version from 2.30 to 2.32.)
* Don't kill locker on forced ScreenSaverOff event. This resulted in killing
the locker upon returning to the VT running X after switching to another VT.
Since there is no reliable way to detect VT-switching, this is necessary to
keep things secure without enabling DontVTSwitch in xorg.conf.
Now the only difference between `xset s reset` and sending SIGHUP to xss-lock
(while the locker is active) is that the former resets the idle hint and
(with DPMS) turns the screen back on. Killing the locker process directly is
now the only way to deactivate the locker programmatically. Perhaps the next
release will include something like `xss-lock-command` to provide more
fine-grained control over a running xss-lock instance.
* Type 'm' for tmpfiles.d introduced in systemd-208 is more suitable for
modifying sysfs brightness file permissions.
* Add zsh and bash completion.
* Update man page.
0.2.2
-----
* Updated dim-screen script (fading, configuration at the top).
0.2.1
-----
* xdg-screensaver patch + man page note.
* New options: --quiet and --verbose.
0.2.0
-----
* Set idle hint on logind session.
* Fix bugs related to notifier and (--ignore-)sleep.
0.1.1
-----
* Warning message for additional X errors that pop up in the event loop.
* Allow building with glib>=2.30 (exit status of notifier/locker is not
checked for <2.34).
* Typo fixes and other small improvements to documentation.

65
xss-lock/dim-screen.sh Normal file
View File

@@ -0,0 +1,65 @@
#!/bin/bash
# Example notifier script -- lowers screen brightness, then waits to be killed
# and restores previous brightness on exit.
## CONFIGURATION ##############################################################
# Brightness will be lowered to this value.
min_brightness=0
# If your video driver works with xbacklight, set -time and -steps for fading
# to $min_brightness here. Setting steps to 1 disables fading.
fade_time=200
fade_steps=20
# If you have a driver without RandR backlight property (e.g. radeon), set this
# to use the sysfs interface and create a .conf file in /etc/tmpfiles.d/
# containing the following line to make the sysfs file writable for group
# "users":
#
# m /sys/class/backlight/acpi_video0/brightness 0664 root users - -
#
#sysfs_path=/sys/class/backlight/acpi_video0/brightness
# Time to sleep (in seconds) between increments when using sysfs. If unset or
# empty, fading is disabled.
fade_step_time=0.05
###############################################################################
get_brightness() {
if [[ -z $sysfs_path ]]; then
brightnessctl g
else
cat $sysfs_path
fi
}
set_brightness() {
if [[ -z $sysfs_path ]]; then
xbacklight -steps 1 -set $1
else
echo $1 > $sysfs_path
fi
}
fade_brightness() {
if [[ -z $sysfs_path ]]; then
xbacklight -time $fade_time -steps $fade_steps -set $1
elif [[ -z $fade_step_time ]]; then
set_brightness $1
else
local level
for level in $(eval echo {$(get_brightness)..$1}); do
set_brightness $level
sleep $fade_step_time
done
fi
}
trap 'exit 0' TERM INT
trap "set_brightness $(get_brightness); kill %%" EXIT
fade_brightness $min_brightness
sleep 2147483647 &
wait

21
xss-lock/dim-screen2.sh Normal file
View File

@@ -0,0 +1,21 @@
#!/bin/bash
# Fade the screen and wait. Needs xbacklight.
# When receiving SIGHUP, stop fading and set backlight to original brightness.
# When receiving SIGTERM, wait a bit, and set backlight to original brightness
# (this prevents the screen from flashing before it is turned completely off
# by DPMS in the locker command).
min_brightness=30
fade_time=2000
fade_steps=70
BRIGHTNESS=$(xbacklight -get)
trap "xbacklight -set $BRIGHTNESS" EXIT
trap 'kill %%; exit 0' HUP
trap 'sleep 1s; kill %%; exit 0' TERM
xbacklight -time $fade_time -steps $fade_steps -set $min_brightness &
wait
sleep infinity & # No, sleeping in the foreground does not work
wait

63
xss-lock/dim-screen3.sh Executable file
View File

@@ -0,0 +1,63 @@
#!/bin/bash
# Example notifier script -- lowers screen brightness, then waits to be killed
# and restores previous brightness on exit.
## CONFIGURATION ##############################################################
# Brightness will be lowered to this value.
min_brightness=0
# If you have a driver without RandR backlight property (e.g. radeon), set this
# to use the sysfs interface and create a .conf file in /etc/tmpfiles.d/
# containing the following line to make the sysfs file writable for group
# "users":
#
# m /sys/class/backlight/acpi_video0/brightness 0664 root users - -
#
#sysfs_path=/sys/class/backlight/acpi_video0/brightness
# Time to sleep (in seconds) between increments when using sysfs. If unset or
# empty, fading is disabled.
fade_step_time=0.05
###############################################################################
get_brightness() {
brightnessctl get # Get current brightness level
}
set_brightness() {
brightnessctl set $1 # Set brightness to the specified percentage
}
fade_brightness() {
local current_brightness=$(get_brightness)
local target_brightness=$1
if [[ $current_brightness -eq $target_brightness ]]; then
return # No need to change brightness
fi
local step
local fade_steps=$(( (current_brightness - target_brightness) / 1000 ))
local increment=1000
for (( step=0; step<fade_steps; step++ )); do
if [[ ! -e /tmp/asleepin ]]; then
exit 0
fi
local new_brightness=$(( current_brightness - increment * (step + 1) ))
set_brightness $new_brightness
sleep $fade_step_time
done
set_brightness $target_brightness # Ensure we set to the exact target
}
trap 'exit 0' TERM INT
trap "set_brightness $(get_brightness); kill %%" EXIT
fade_brightness $min_brightness
sleep 2147483647 &
wait

60
xss-lock/dim-screen3.sh ! Normal file
View File

@@ -0,0 +1,60 @@
#!/bin/bash
# Example notifier script -- lowers screen brightness, then waits to be killed
# and restores previous brightness on exit.
## CONFIGURATION ##############################################################
# Brightness will be lowered to this value.
min_brightness=0
# If you have a driver without RandR backlight property (e.g. radeon), set this
# to use the sysfs interface and create a .conf file in /etc/tmpfiles.d/
# containing the following line to make the sysfs file writable for group
# "users":
#
# m /sys/class/backlight/acpi_video0/brightness 0664 root users - -
#
#sysfs_path=/sys/class/backlight/acpi_video0/brightness
# Time to sleep (in seconds) between increments when using sysfs. If unset or
# empty, fading is disabled.
fade_step_time=0.05
###############################################################################
get_brightness() {
brightnessctl get # Get current brightness level
}
set_brightness() {
brightnessctl set $1 # Set brightness to the specified percentage
}
fade_brightness() {
local current_brightness=$(get_brightness)
local target_brightness=$1
if [[ $current_brightness -eq $target_brightness ]]; then
return # No need to change brightness
fi
local step
local fade_steps=$(( (current_brightness - target_brightness) / 1000 ))
local increment=1000
for (( step=0; step<fade_steps; step++ )); do
local new_brightness=$(( current_brightness - increment * (step + 1) ))
set_brightness $new_brightness
sleep $fade_step_time
done
set_brightness $target_brightness # Ensure we set to the exact target
}
trap 'exit 0' TERM INT
trap "set_brightness $(get_brightness); kill %%" EXIT
fade_brightness $min_brightness
sleep 2147483647 &
wait

View File

@@ -0,0 +1,48 @@
#!/bin/bash
# Example locker script -- demonstrates how to use the --transfer-sleep-lock
# option with a fixed delay to give simple lockers a little bit of time to lock
# the screen before the system goes the sleep.
## CONFIGURATION ##############################################################
# Command to start the locker (should not fork)
locker="xlock +resetsaver"
# Delay in seconds. Note that by default systemd-logind allows a maximum sleep
# delay of 5 seconds.
sleep_delay=1
# Run before starting the locker
pre_lock() {
#mpc pause
return
}
# Run after the locker exits
post_lock() {
return
}
###############################################################################
pre_lock
# kill locker if we get killed
trap 'kill %%' TERM INT
if [[ -e /dev/fd/${XSS_SLEEP_LOCK_FD:--1} ]]; then
# lock fd is open, make sure the locker does not inherit a copy
$locker {XSS_SLEEP_LOCK_FD}<&- &
sleep $sleep_delay
# now close our fd (only remaining copy) to indicate we're ready to sleep
exec {XSS_SLEEP_LOCK_FD}<&-
else
$locker &
fi
wait # for locker to exit
post_lock

View File

@@ -0,0 +1,51 @@
#!/bin/bash
# Example locker script -- demonstrates how to use the --transfer-sleep-lock
# option with i3lock's forking mode to delay sleep until the screen is locked.
## CONFIGURATION ##############################################################
# Options to pass to i3lock
i3lock_options="-d"
# Run before starting the locker
pre_lock() {
#mpc pause
return
}
# Run after the locker exits
post_lock() {
return
}
###############################################################################
pre_lock
# We set a trap to kill the locker if we get killed, then start the locker and
# wait for it to exit. The waiting is not that straightforward when the locker
# forks, so we use this polling only if we have a sleep lock to deal with.
if [[ -e /dev/fd/${XSS_SLEEP_LOCK_FD:--1} ]]; then
kill_i3lock() {
pkill -xu $EUID "$@" i3lock
}
trap kill_i3lock TERM INT
# we have to make sure the locker does not inherit a copy of the lock fd
i3lock $i3lock_options {XSS_SLEEP_LOCK_FD}<&-
# now close our fd (only remaining copy) to indicate we're ready to sleep
exec {XSS_SLEEP_LOCK_FD}<&-
while kill_i3lock -0; do
sleep 0.5
done
else
trap 'kill %%' TERM INT
i3lock -n $i3lock_options &
wait
fi
post_lock

View File

@@ -0,0 +1,20 @@
diff -u old/xdg-screensaver new/xdg-screensaver
--- old/xdg-screensaver 2013-05-21 15:08:51.152812849 +0200
+++ new/xdg-screensaver 2013-05-21 15:13:16.843096616 +0200
@@ -825,13 +825,13 @@
{
case "$1" in
suspend)
- xset s off > /dev/null
+ screensaver_suspend_loop eval killall -HUP xss-lock '||' xset s reset > /dev/null 2>&1
result=$?
;;
resume)
- xset s default > /dev/null
- result=$?
+ # Automatic resume when $screensaver_file disappears
+ result=0
;;
activate)

13
xss-lock/xss-lock.service Normal file
View File

@@ -0,0 +1,13 @@
[Unit]
Description=Auto lock
PartOf=graphical-session.target
[Service]
Type=simple
# You must arrange to run `systemctl --user import-environment
# XDG_SESSION_ID` in your X environment prior to launching the user
# session, e.g. in your `.xsessionrc` or similar.
ExecStart=/usr/bin/xss-lock -l -s ${XDG_SESSION_ID} -- i3lock
[Install]
WantedBy=graphical-session.target