Skip to content

omamobile-keys: put the brightness back only after the panel is off - #640

Merged
derekross merged 3 commits into
derekross:mainfrom
Somnius:keys-flash-1110
Nov 11, 2026
Merged

derekross merged 3 commits into
derekross:mainfrom
Somnius:keys-flash-1110

Conversation

@Somnius

@Somnius Somnius commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

@derekross, small one, found while I was testing suspend on the 8 Pro: when you press Power on the unlocked desktop the screen flashes the lock screen at full brightness for a moment and then goes black. It's in omamobile-keys.

What happens in short_press: it sets the backlight to 0, locks, asks Hyprland to switch the display off with omarchy-brightness-display off, and then puts the saved brightness back straight away so the next wake isn't dark. The catch is that Hyprland says the display is off right away (dpmsStatus is false about 0.09 s after the call), but the panel only goes off when the compositor commits it, a bit later. On the 8 Pro bl_power is root-only, so the script's own panel_power 4 does nothing for the user and the panel follows only when the kernel commits the DPMS. So the brightness comes back while the panel is still on and showing the lock screen.

I logged it on the phone with a loop sampling bl_power, brightness and the DSI connector's dpms every 20 ms. Before the change, one press (seconds, epoch):

748.018 brightness 0
749.139 brightness back to 2083, bl_power 0, dpms On
749.458 bl_power 4
749.678 dpms Off

So about 0.3 to 0.5 s with the panel lit at full brightness. The first thing I tried was waiting for Hyprland's own answer (screen_off), and that still flashed, because Hyprland answers early. I confirmed that with a second probe: dpmsStatus false at +0.085 s, bl_power 4 and dpms Off at +0.35 s.

The change: after omarchy-brightness-display off the key handler waits, at most 2 s by the clock, until the panel itself reads as off before it restores the brightness. "Off" means the backlight's bl_power is not 0, or a connected internal connector (DSI, eDP or LVDS) says dpms Off. Only on a machine with neither file does it use Hyprland's answer, so the old behaviour stays there. If nothing ever says off, it still restores the brightness and asks for sleep after 2 s, same as before.

With the change, same logger, one press from the unlocked desktop:

141.105 brightness 0
142.457 bl_power 4
142.488 brightness back to 2083 (31 ms after the panel went off)
142.678 dpms Off

I watched it too and there's no flash anymore, and the next wake felt a bit quicker too, but I didn't measure that.

Tests: test/keys.sh passes (8 of 8, about 40 s). The new block uses a fake sysfs (OMAMOBILE_KEYS_SYSFS) and a stand-in where Hyprland's state flips at once and the panel 0.4 s later, and checks the brightness only goes back after the panel is off, that sleep is asked for after that, that a panel that never goes off still ends the wait in about 2 s, that with no panel files Hyprland's word ends it at once, and that an unconnected connector saying Off doesn't end the wait. I also ran the same test against the old omamobile-keys and it fails on the "goes back only after the panel is off" check, so it does catch the flash.

Not done: I only tried this on my Pixel 8 Pro. I haven't checked how the DRM dpms file behaves on tegu or other devices (the comment on screen_off says tegu keeps bl_power at 0 under DPMS-off), so there the wait could end at the 2 s limit and the flash behaviour is unknown. Also left alone: omamobile-sleepd notices a wake by polling suspend_stats (5 s with the sleep toggle off, 2 s on), which is where some of the slow wake I saw comes from. That's a separate thing and I'd do it as its own PR.

A Power press on the unlocked desktop set the brightness to 0, locked,
asked Hyprland to switch the display off, and put the saved brightness
back straight away. Hyprland reports the display off at once, but the
panel only goes off when the compositor commits it, 0.3 s later on the
Pixel 8 Pro, and bl_power is not writable by the user there, so the panel
showed the lock screen at full brightness for a moment before it went
black.

Wait, at most 2 s, until the panel itself reads as off (bl_power, or the
internal connector's dpms) before the brightness goes back; Hyprland's
answer is used only on a machine with neither file. Test: the stand-in
flips Hyprland's state at once and the panel 0.4 s later, and the brightness
must come back after that; a panel that never goes off still ends the wait.
@derekross

Copy link
Copy Markdown
Owner

@Somnius thank you, this is a well-found bug and a well-measured one: the 20 ms sampler showing the brightness back at 749.139 with the panel still on until 749.458, the second probe that showed Hyprland's own answer comes too early to use, and the before and after traces make the cause and the fix easy to follow. I also like that the wait reads what the panel reports and only falls back to Hyprland where there is nothing else, that an unconnected connector can't end it, and that you ran the new test against the old script to see it fail.

I read it against the other phones. On the Pixel 7 Pro and 6 Pro nothing changes: their device packages make bl_power writable for the session user, omarchy-brightness-display off writes 4 before it returns, and your wait sees that on its first read (about 2 ms in a fake sysfs with that shape). That also explains why only the 8 Pro flashed. I'll still press the key a few times on my 7 Pro after installing it, since it's the power key.

One thing to fix before I merge:

The 2 s limit depends on the locale. bash writes EPOCHREALTIME with the locale's decimal separator, so under a comma locale ${EPOCHREALTIME/./} strips nothing and the arithmetic turns into the comma operator. I tried it with a German locale:

EPOCHREALTIME=1794354179,921121
end=2921224
bash: ((: 1794354180,029668: value too great for base (error token is "029668")

When the panel goes off the loop still ends at once, so the normal press is fine; it's the "never reads off" limit that becomes random, with an error in the journal. The script already has now (milliseconds from date) for every other time, so end=$(( $(now) + 2000 )) and (( $(now) < end )) would do, or ${EPOCHREALTIME/[.,]/}.

Two questions, neither blocks:

  • On the 9a bl_power stays 0 under DPMS off, as you noted, so there the wait ends only if the DSI connector's dpms file reads Off. I'll ask a 9a owner for that one read. If it stays On, every power-off press there would take the full 2 s; would 1 s be enough as the limit, given your 0.35 s?
  • Your 8 Pro has no udev rule that lets the session user write bl_power (the 7 Pro's is 20-omamobile-display.rules in its device package). If the HK3 panel driver's bl_power powers the panel down as the 7 Pro's does, that rule in omamobile-device-husky would make the off instant there as well. Worth a try when you next have the phone on the cable?

Could you also add the kernel (uname -r) and the omamobile-shell version your traces were taken on? I'll set the package version when I merge (omamobile-shell 0.2.118), so no need to touch version.

The 2 s limit read bash's microsecond clock variable, which is written with
the locale's decimal separator; under a comma locale the arithmetic turned
into the comma operator and the limit became random, with an error in the
journal. Use now (milliseconds from date) like the rest of the script, and
shorten the limit to 1 s: the panel took 0.35 s on the Pixel 8 Pro. The
test also checks that the script no longer reads that variable.
@derekross

Copy link
Copy Markdown
Owner

@Somnius thank you, that settles it. The limit now comes from now, the same millisecond clock the rest of the script uses, so a comma locale can't touch it, and 1 s is a sensible bound given your 0.35 s. I like that the test now refuses EPOCHREALTIME coming back. CI passed on the branch merged with today's main.

I'm setting the package version on your branch (omamobile-shell 0.2.119) and merging. I'll press the power key a few times on my Pixel 7 Pro once it is installed and note the result here.

Two things stay open, neither for this PR:

  • On the Pixel 9a bl_power stays 0 under DPMS off, so the wait there ends early only if the DSI connector's dpms file reads Off. I'll ask a 9a owner for that one read; if it stays On, a power-off press there takes 1 s longer than before.
  • If you try the bl_power udev rule on your 8 Pro (the Pixel 7 Pro's is 20-omamobile-display.rules in its device package), tell me whether the panel then goes off at once. And if you still have them, the kernel release (uname -r) and the omamobile-shell version your traces were taken on would complete the record.

@derekross
derekross merged commit 2db3f2b into derekross:main Nov 11, 2026
2 checks passed
angelrenefm added a commit to angelrenefm/omarchy-mobile that referenced this pull request Nov 12, 2026
…ey-as-android

One panel_dark, main's, with the backlight device, defined with
wait_screen_off above the switch so both modes share them; the Android
short_press waits with wait_screen_off instead of its own loop on the real
/sys, so main's flash check passes with the switch on too. The quick wake
check falls back to screen_off, as the Android press's did. test/all keeps
main's new lines and runs keys.sh with the switch off and on.

I used AI help (Claude) to work on this.
@Somnius

Somnius commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

@derekross, the two things you left open here.

The traces were taken with uname -r 7.3.0-rc6-omamobile-push1-ga291900124c4 (a local test build, described in my reply on #724, #724 (comment)) and omamobile-shell 0.2.107-1 installed. The "before" trace is the packaged omamobile-keys, and the "after" traces are my fixed script copied over it by hand.

I haven't tried a udev rule for bl_power. I wrote the attribute by hand as root on the 8 Pro: echo 4 > bl_power, then read it, the DSI connector's dpms and actual_brightness every 100 ms for a second. bl_power stayed at 4, dpms stayed On and actual_brightness stayed 2083, the kernel log showed nothing new for it, and echo 0 put it back. Nobody was looking at the screen, so I can't tell you whether it went dark. I'll try it with the phone on the cable and my eyes on it before I say more.

robertzas pushed a commit to robertzas/omarchy-mobile that referenced this pull request Nov 14, 2026
…after the panel is off (derekross#640)

A Power press on the unlocked desktop set the backlight to 0, locked, asked Hyprland for DPMS off and restored the saved brightness at once. Hyprland reports the display off before the panel is (0.3 s later on the Pixel 8 Pro, where the user can't write `bl_power`), so the lock screen flashed at full brightness. omamobile-keys now waits, at most 1 s by `date`'s clock, until the backlight's `bl_power` or a connected internal connector's `dpms` reads off, and uses Hyprland's answer only where neither file exists. Measured on a Pixel 8 Pro; on the Pixel 7 Pro and 6 Pro the first read is already off.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants