fix(brightness): guard keyboard backlight state across lock and idle blanking - #11404
Open
cleon01day wants to merge 1 commit into
Open
fix(brightness): guard keyboard backlight state across lock and idle blanking#11404cleon01day wants to merge 1 commit into
cleon01day wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Guard keyboard backlight saved state against zero-clobbering and ensure reliable brightness restoration across lock-screen blanking, idle sleep, and system resume.
Context & Problem
When locking the session in Omarchy, or when displays blank while locked, the keyboard backlight fails to turn back on after unlocking or waking the system (
brightness = 0). The user is left in the dark until they manually adjust brightness using the brightness function keys.This issue is especially prominent on laptops with autonomous firmware LED power management, such as Apple T2 MacBooks (
106b:180[12]) where the internal keyboard and backlight hang off thet2bce_vhcivirtual USB host controller (configured viainstall/hardware/apple/fix-t2.sh):shell/plugins/lock/Service.qml,blankProcessexecutesomarchy-brightness-keyboard off; omarchy-brightness-display off.bin/omarchy-brightness-keyboard,direction == "off"executesbrightnessctl -sd "$device" set 0.0whenoffis called (either from the autonomous hardware timeout, repeated blanking events, or screen sleep preceding lock),brightnessctl -sblindly writes0into the state file (${XDG_RUNTIME_DIR}/brightnessctl/leds/<device>).finishUnlock()invokesomarchy-system-wake, which callsomarchy-brightness-keyboard restore.restorereads0from the corrupted state file, and because the virtual USB controller initializes registers at0upon resume, userspace actively commands the backlight to remain dark.Solution
offagainst Zero-Clobbering inbin/omarchy-brightness-keyboard:Only pass
-s(save) tobrightnessctlwhencurrent_brightness > 0. If the backlight is already at 0, turn off without overwriting the positive saved state buffer.Persist non-zero user target levels to
${XDG_STATE_HOME:-$HOME/.local/state}/omarchy/keyboard-brightnessupon explicit adjustments (up,down,cycle) and positiveoffcalls.restorewith Graceful Fallback:brightnessctl -rd "$device".Update
default/systemd/system-sleep/keyboard-backlightto include apostresume handler that restores the backlight level after hibernation.Added
test/shell.d/brightness-keyboard-test.shasserting zero-clobber protection, state fallback resolution, and step calculations.Verification
linux-t2witht2bce_vhci) running Hyprland + Quickshell.offcalls preserve saved positive brightness../test/cli: all 105 tests passed.test/shell.d/brightness-keyboard-test.sh: all 6 assertions passed.test/shell.d/system-sleep-ownership-migration-test.sh: all 32 assertions passed.