changes
This commit is contained in:
1 parent
390f9bbc06
commit
0e6ee96929
3 files changed
+30
-74
No files matched your search
@@ -36,7 +36,7 @@ SECONDS=3
|
||||
|
||||
[ "${ACTION}" = "timeout" ] && {
|
||||
logger "Power held for ${SECONDS}: Shutting down system"
|
||||
poweroff
|
||||
poweroff &
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
||||
@@ -4,88 +4,46 @@
|
||||
# Only process power button events
|
||||
[ "$BUTTON" = "power" ] || exit 0
|
||||
|
||||
# Check if system is shutting down
|
||||
if pgrep poweroff >/dev/null 2>&1 || \
|
||||
pgrep halt >/dev/null 2>&1 || \
|
||||
pgrep reboot >/dev/null 2>&1; then
|
||||
logger -t display "System shutting down - skipping"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Configuration variables
|
||||
TIMEOUT_DIM=5
|
||||
TIMEOUT_OFF=3
|
||||
TIMEOUT_OFF=8
|
||||
BACKLIGHT_PATH="/sys/class/backlight/backlight"
|
||||
BRIGHTNESS_DIM_DIVISOR=8
|
||||
BRIGHTNESS_OFF=1
|
||||
|
||||
# Calculated variables
|
||||
MAX_BRIGHTNESS=$(cat $BACKLIGHT_PATH/max_brightness 2>/dev/null || echo 1785)
|
||||
BRIGHTNESS_FULL=$MAX_BRIGHTNESS
|
||||
BRIGHTNESS_DIM=$((MAX_BRIGHTNESS / BRIGHTNESS_DIM_DIVISOR))
|
||||
|
||||
# PID file for timer management
|
||||
TIMER_PID_FILE="/tmp/screen_timer.pid"
|
||||
|
||||
maybe_set_lockscreen(){
|
||||
# Check if system is shutting down
|
||||
if pgrep poweroff >/dev/null 2>&1 || \
|
||||
pgrep halt >/dev/null 2>&1 || \
|
||||
pgrep reboot >/dev/null 2>&1; then
|
||||
logger -t display "System shutting down - skipping lockscreen"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Show lockscreen if brightness is OFF
|
||||
[ -n "$1" ] && [ "$1" = "$BRIGHTNESS_OFF" ] && [ -f /etc/boot_logo.fb ] && \
|
||||
cat /etc/boot_logo.fb > /dev/fb0 2>/dev/null
|
||||
}
|
||||
|
||||
# Set brightness level
|
||||
set_brightness() {
|
||||
echo "$1" > "$BACKLIGHT_PATH/brightness"
|
||||
|
||||
# Check if we should show lockscreen
|
||||
maybe_set_lockscreen "$1"
|
||||
}
|
||||
|
||||
# Function to start a timer
|
||||
# Parameters: $1=timeout (seconds), $2=brightness level, $3=log message
|
||||
start_timer() {
|
||||
local timeout=$1
|
||||
local brightness=$2
|
||||
local log_msg=$3
|
||||
|
||||
(
|
||||
sleep "$timeout"
|
||||
logger -t display "$log_msg"
|
||||
set_brightness "$brightness"
|
||||
) >/dev/null 2>&1 </dev/null &
|
||||
|
||||
echo $!
|
||||
}
|
||||
|
||||
# Cancel all active timers
|
||||
cancel_timers() {
|
||||
if [ -f "$TIMER_PID_FILE" ]; then
|
||||
while read pid; do
|
||||
kill "$pid" 2>/dev/null
|
||||
done < "$TIMER_PID_FILE"
|
||||
rm -f "$TIMER_PID_FILE"
|
||||
fi
|
||||
}
|
||||
|
||||
# Only act on button release
|
||||
[ "${ACTION}" = "released" ] && {
|
||||
logger -t display "Button event detected"
|
||||
|
||||
# Cancel previous timers if any
|
||||
cancel_timers
|
||||
# Cancel previous timer if exists
|
||||
[ -f "$TIMER_PID_FILE" ] && kill $(cat "$TIMER_PID_FILE") 2>/dev/null
|
||||
|
||||
# Set full brightness immediately
|
||||
logger -t display "Backlight: FULL"
|
||||
set_brightness $BRIGHTNESS_FULL
|
||||
echo $BRIGHTNESS_FULL > "$BACKLIGHT_PATH/brightness"
|
||||
|
||||
# Start timer 1: DIM after TIMEOUT_DIM seconds
|
||||
pid1=$(start_timer $TIMEOUT_DIM $BRIGHTNESS_DIM "Backlight: DIM")
|
||||
echo "$pid1" >> "$TIMER_PID_FILE"
|
||||
# Start single timer: OFF + lockscreen after TIMEOUT_OFF seconds
|
||||
(
|
||||
sleep "$TIMEOUT_OFF"
|
||||
logger -t display "Backlight: OFF + lockscreen"
|
||||
echo $BRIGHTNESS_OFF > "$BACKLIGHT_PATH/brightness"
|
||||
[ -f /etc/boot_logo.fb ] && cat /etc/boot_logo.fb > /dev/fb0 2>/dev/null
|
||||
) >/dev/null 2>&1 </dev/null &
|
||||
|
||||
# Start timer 2: OFF after (TIMEOUT_DIM + TIMEOUT_OFF) seconds
|
||||
TOTAL_TIMEOUT=$((TIMEOUT_DIM + TIMEOUT_OFF))
|
||||
pid2=$(start_timer $TOTAL_TIMEOUT $BRIGHTNESS_OFF "Backlight: OFF")
|
||||
echo "$pid2" >> "$TIMER_PID_FILE"
|
||||
echo $! > "$TIMER_PID_FILE"
|
||||
}
|
||||
|
||||
exit 0
|
||||
@@ -4,17 +4,15 @@
|
||||
# Only process power button events
|
||||
[ "$BUTTON" = "power" ] || exit 0
|
||||
|
||||
# Check if system is shutting down
|
||||
if pgrep poweroff >/dev/null 2>&1 || \
|
||||
pgrep halt >/dev/null 2>&1 || \
|
||||
pgrep reboot >/dev/null 2>&1; then
|
||||
logger -t display "System shutting down - skipping"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Execute update-display on button release
|
||||
[ "${ACTION}" = "released" ] && {
|
||||
# Check if system is shutting down
|
||||
if pgrep poweroff >/dev/null 2>&1 || \
|
||||
pgrep halt >/dev/null 2>&1 || \
|
||||
pgrep reboot >/dev/null 2>&1; then
|
||||
logger -t display "System shutting down - skipping update-display"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
/usr/sbin/update-display
|
||||
}
|
||||
[ "${ACTION}" = "released" ] && /usr/sbin/update-display
|
||||
|
||||
exit 0
|
||||
Reference in new issue
Block a user