Stop reboot backlight flicker with force-only PWM updates
This commit is contained in:
1 parent
d61f2848db
commit
7a2b965ce3
10 files changed
+93
-62
No files matched your search
@@ -24,6 +24,9 @@ depend() {
|
||||
start_pre() {
|
||||
mkdir -p /run/bananarchy
|
||||
chmod 0755 /run/bananarchy
|
||||
# /run is tmpfs: clear stale transition guards after every reboot.
|
||||
rm -f /run/bananarchy/cover-bl-force \
|
||||
/run/bananarchy/cover-power-state 2>/dev/null || true
|
||||
}
|
||||
|
||||
start() {
|
||||
|
||||
@@ -7,15 +7,15 @@ set -u
|
||||
export DISPLAY="${DISPLAY:-:0}"
|
||||
case "${1:-}" in
|
||||
reinit)
|
||||
xset dpms force off >/dev/null 2>&1 || true
|
||||
timeout 1 xset dpms force off >/dev/null 2>&1 || true
|
||||
sleep 0.08
|
||||
xset dpms force on >/dev/null 2>&1 || true
|
||||
timeout 1 xset dpms force on >/dev/null 2>&1 || true
|
||||
;;
|
||||
on)
|
||||
xset dpms force on >/dev/null 2>&1 || true
|
||||
timeout 1 xset dpms force on >/dev/null 2>&1 || true
|
||||
;;
|
||||
off)
|
||||
xset dpms force off >/dev/null 2>&1 || true
|
||||
timeout 1 xset dpms force off >/dev/null 2>&1 || true
|
||||
;;
|
||||
*)
|
||||
printf 'Usage: %s [reinit|on|off]\n' "${0##*/}" >&2; exit 1 ;;
|
||||
|
||||
Binary file not shown.
@@ -3,6 +3,10 @@
|
||||
# Invoked by the backlight udev rule (as root) and by sxmo_wm.sh display on
|
||||
# (via doas). The 2720 Flip shares one PWM backlight between both panels:
|
||||
# it is active-low for the cover and active-high for the main panel.
|
||||
#
|
||||
# The daemon calls this helper with "force" only on a real cover-state
|
||||
# transition. Plain udev events are idempotent and must never toggle bl_power,
|
||||
# or they create a feedback loop that flickers the active panel.
|
||||
set -u
|
||||
|
||||
BR_PATH=/sys/class/backlight/backlight/brightness
|
||||
@@ -11,14 +15,17 @@ KBD_PATH=/sys/class/leds/white:kbd_backlight/brightness
|
||||
RL_PATH=/sys/devices/system/cpu/cpufreq/schedutil/rate_limit_us
|
||||
COVER_MARKER=/run/bananarchy/cover-backlight
|
||||
FORCE_MARKER=/run/bananarchy/cover-bl-force
|
||||
STATE_CACHE=/run/bananarchy/cover-power-state
|
||||
LID_STATE=/run/bananarchy/lid-state
|
||||
CONF=/etc/bananarchy/cover-display.conf
|
||||
COVER_BL_LEVEL=14
|
||||
COVER_BL_INVERT=1
|
||||
FORCE=0
|
||||
|
||||
# A forced PWM update rewrites brightness/bl_power itself. Ignore the nested
|
||||
# udev events so the two-step update cannot recurse.
|
||||
if [ -f "$FORCE_MARKER" ]; then
|
||||
[ "${1:-}" = "force" ] && FORCE=1
|
||||
|
||||
# Nested udev events during a forced update must not re-enter the helper.
|
||||
if [ "$FORCE" -eq 0 ] && [ -f "$FORCE_MARKER" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
@@ -48,14 +55,7 @@ set_if_changed() {
|
||||
[ "$_cur" = "$_want" ] || printf '%s\n' "$_want" > "$_path" 2>/dev/null || true
|
||||
}
|
||||
|
||||
force_backlight() {
|
||||
_want_br="$1"
|
||||
_want_blp="$2"
|
||||
printf '1\n' > "$FORCE_MARKER" 2>/dev/null || true
|
||||
set_if_changed "$BL_POWER_PATH" "4"
|
||||
printf '%s\n' "$_want_br" > "$BR_PATH" 2>/dev/null || true
|
||||
set_if_changed "$BL_POWER_PATH" "$_want_blp"
|
||||
printf '%s\n' "$_want_br" > "$BR_PATH" 2>/dev/null || true
|
||||
cleanup_force() {
|
||||
rm -f "$FORCE_MARKER" 2>/dev/null || true
|
||||
}
|
||||
|
||||
@@ -64,11 +64,12 @@ force_dpms() {
|
||||
_cur="$(read_value "$DPMS_PATH")"
|
||||
[ "$_cur" = "$_want" ] && return 0
|
||||
_mode="$(printf '%s' "$_want" | tr 'A-Z' 'a-z')"
|
||||
DISPLAY=:0 xset dpms force "$_mode" >/dev/null 2>&1 || true
|
||||
DISPLAY=:0 timeout 1 xset dpms force "$_mode" >/dev/null 2>&1 || true
|
||||
}
|
||||
|
||||
br="$(read_value "$BR_PATH")"
|
||||
case "$br" in ''|*[!0-9]*) br=1 ;; esac
|
||||
blp="$(read_value "$BL_POWER_PATH")"
|
||||
lid="$(read_value "$LID_STATE")"
|
||||
marker=""
|
||||
[ -r "$COVER_MARKER" ] && marker="$(read_value "$COVER_MARKER")"
|
||||
@@ -83,49 +84,62 @@ else
|
||||
DARK_BLP=4
|
||||
fi
|
||||
|
||||
# An open flip always wins: remove a stale cover marker and restore the
|
||||
# active-high internal-panel backlight before applying normal DPMS rules.
|
||||
DESIRED_BR="$br"
|
||||
DESIRED_BLP="$blp"
|
||||
DESIRED_DPMS="On"
|
||||
DESIRED_KBD=""
|
||||
DESIRED_KEY="normal"
|
||||
|
||||
if [ "$lid" = "open" ]; then
|
||||
DESIRED_KEY="open:$COVER_BL_LEVEL:0:On:absent:$COVER_BL_INVERT"
|
||||
DESIRED_BR="$COVER_BL_LEVEL"
|
||||
DESIRED_BLP="0"
|
||||
DESIRED_DPMS="On"
|
||||
rm -f "$COVER_MARKER" 2>/dev/null || true
|
||||
force_backlight "$COVER_BL_LEVEL" "0"
|
||||
force_dpms "On"
|
||||
if [ -w "$RL_PATH" ]; then
|
||||
printf '40000\n' > "$RL_PATH" 2>/dev/null || true
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# While the cover owns the bus, the marker content selects its state:
|
||||
# 1 = cover lit, 0 = cover dark. Never let the closed-lid hard gate force
|
||||
# brightness 0 here, because that would turn the active-low cover backlight on.
|
||||
if [ -f "$COVER_MARKER" ]; then
|
||||
set_if_changed "$KBD_PATH" "0"
|
||||
elif [ -f "$COVER_MARKER" ]; then
|
||||
DESIRED_KBD="0"
|
||||
DESIRED_DPMS="On"
|
||||
if [ "$marker" = "1" ]; then
|
||||
force_backlight "$LIT_BR" "0"
|
||||
force_dpms "On"
|
||||
DESIRED_KEY="lit:$LIT_BR:0:On:1:$COVER_BL_INVERT"
|
||||
DESIRED_BR="$LIT_BR"
|
||||
DESIRED_BLP="0"
|
||||
else
|
||||
force_backlight "$DARK_BR" "$DARK_BLP"
|
||||
force_dpms "On"
|
||||
DESIRED_KEY="dark:$DARK_BR:$DARK_BLP:On:0:$COVER_BL_INVERT"
|
||||
DESIRED_BR="$DARK_BR"
|
||||
DESIRED_BLP="$DARK_BLP"
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Hard gate: while the flip is closed no path may relight the main panel or
|
||||
# the keypad backlight. The cover daemon keeps gpio13 low in this state.
|
||||
if ! "${BANANARCHY_LID_GATE:-/usr/bin/bananarchy-lid-gate.sh}"; then
|
||||
set_if_changed "$KBD_PATH" "0"
|
||||
force_backlight "0" "4"
|
||||
force_dpms "Off"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$br" -eq 0 ]; then
|
||||
force_dpms "Off"
|
||||
elif ! "${BANANARCHY_LID_GATE:-/usr/bin/bananarchy-lid-gate.sh}"; then
|
||||
DESIRED_KEY="closed:0:4:Off:absent:$COVER_BL_INVERT"
|
||||
DESIRED_BR="0"
|
||||
DESIRED_BLP="4"
|
||||
DESIRED_DPMS="Off"
|
||||
DESIRED_KBD="0"
|
||||
else
|
||||
force_dpms "On"
|
||||
[ "$br" -eq 0 ] && DESIRED_DPMS="Off"
|
||||
DESIRED_KEY="normal:$br:$blp:$DESIRED_DPMS:absent:$COVER_BL_INVERT"
|
||||
fi
|
||||
|
||||
if [ "$br" -ne 0 ] && [ -w "$RL_PATH" ]; then
|
||||
if [ "$FORCE" -eq 1 ]; then
|
||||
cleanup_force
|
||||
printf '1\n' > "$FORCE_MARKER" 2>/dev/null || true
|
||||
trap cleanup_force EXIT INT TERM HUP
|
||||
set_if_changed "$BL_POWER_PATH" "4"
|
||||
set_if_changed "$BR_PATH" "$DESIRED_BR"
|
||||
set_if_changed "$BL_POWER_PATH" "$DESIRED_BLP"
|
||||
set_if_changed "$BR_PATH" "$DESIRED_BR"
|
||||
else
|
||||
set_if_changed "$BL_POWER_PATH" "$DESIRED_BLP"
|
||||
set_if_changed "$BR_PATH" "$DESIRED_BR"
|
||||
fi
|
||||
|
||||
[ -n "$DESIRED_KBD" ] && set_if_changed "$KBD_PATH" "$DESIRED_KBD"
|
||||
force_dpms "$DESIRED_DPMS"
|
||||
|
||||
if [ "$FORCE" -eq 1 ]; then
|
||||
printf '%s\n' "$DESIRED_KEY" > "$STATE_CACHE" 2>/dev/null || true
|
||||
cleanup_force
|
||||
trap - EXIT INT TERM HUP
|
||||
elif [ "$br" -ne 0 ] && [ -w "$RL_PATH" ]; then
|
||||
printf '40000\n' > "$RL_PATH" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
|
||||
Reference in new issue
Block a user