Skip to content

omamobile-settings: lock screen timeout, and lock after 30 minutes while a keyboard is connected - #866

Open
Somnius wants to merge 15 commits into
derekross:mainfrom
Somnius:settings-lock-timeout-1117
Open

Somnius wants to merge 15 commits into
derekross:mainfrom
Somnius:settings-lock-timeout-1117

Conversation

@Somnius

@Somnius Somnius commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

This adds two things to the Display page in Settings: "Lock screen after" (30 s, 1, 2, 3 or 5 min) and "Lock after 30 minutes while a keyboard is connected", Bluetooth or USB. It also fixes two things I hit on the same page on my Pixel 8 Pro, and the page scrolls now.

It builds on the Settings app @marselnenaj started in #526. It's a great app to have on the phone, so I'd rather keep adding pages to it.

How the lock works: the phone has one timer. Omarchy's idle service locks after idle.lock seconds from shell.json, and the lock screen blanks a few seconds later, so the page says lock and screen off are the same timer. There's no Never: a phone that never locks by itself isn't offered one tap away. A 0 set by hand in shell.json still means no idle lock, and the page says so. After writing shell.json the backend runs omarchy-shell shell reloadConfig; it never touches idle on/off or Stay awake.

A changed lock time on a running shell only works with the re-arm from #879 (#879): without it the phone stops locking by itself until the shell restarts. So depends names omamobile-omarchy>=0.1.49, and this should merge after #879. The number follows whatever #879 lands as.

The keyboard part is a small user service that runs only while the toggle is on. It watches udev and writes 1800 to idle.lock while a keyboard is connected, then puts the chosen time back. lock.json is written before shell.json and marks the 1800 as ours, so a crash in between can't leave our value behind as if it were the user's, and the unit restores the chosen time when it stops. It doesn't restart on a broken shell.json and doesn't rewrite lock.json when nothing changed. It counts devices udev calls keyboards with the letter keys and space, on Bluetooth or real USB, so the phone's own keys, the OSK, uinput and headphone buttons don't count. A USB receiver or dock that exposes a full keyboard still counts; that's a known limit.

The two fixes, as separate commits, both for Settings started from a login outside the graphical session (that's how I opened it when I saw them, over SSH):

  • The refresh rate rows disappeared without HYPRLAND_INSTANCE_SIGNATURE in the environment. display.sh now finds the live socket under $XDG_RUNTIME_DIR/hypr.
  • The brightness buttons did nothing, since logind only sets the brightness for the caller's own session. display.sh now falls back to SetBrightness on the user's graphical session.

Testing: on my desktop test/all passes, with tests for the lock backend (stand-ins for omarchy-shell and systemctl), the watcher, the missing signature, and the 5 lock choices. On the phone, the first version of this ran on Omarchy 4.0.6: 1 min then 30 s from the page locked 30 s later, and with my Dell KB7120W over Bluetooth the watcher wrote its value about 2 s after connect and put my 3 min back after the keyboard went off. This head hasn't run on the phone yet. My 8 Pro is on Omarchy 4.5.0-3 now, and I’ll post the run from the review (lock times from Settings opened on the home screen, the keyboard toggle, reboots with it on and off, reloadConfig at session end) once #879’s package is on it.

Version: the numbers get set at merge (#860 first as 0.1.3, then this as 0.1.4).

Display page (from 11-16, before Never was taken out)

@derekross

Copy link
Copy Markdown
Owner

Thank you, Lef. There is a lot of care in this: nothing is written until the owner picks something, lock.json goes first with the override flag so the keyboard's 0 can't turn into the owner's "Never", a broken shell.json is left alone, and the keyboard test asks for letter keys so the phone's own buttons and a headset don't count. I ran the backend in a scratch home with the phone profile's shell.json: untouched out of the box, 180 s back after a keyboard goes, and the right recovery after a reset with the 0 in force.

It can't merge as it is, though, and the main reason is the step that makes a new time take effect:

  1. idle disable / idle enable is Stay awake. In Omarchy 4.5 the idle service's disable() calls setIdleEnabled(false), which sets Stay awake and writes ~/.local/state/omarchy/indicators/stay-awake: the quick-settings tile, the thing omamobile-sleepd refuses to sleep on, and it survives a reboot. So each tap on a lock time, and each keyboard coming or going, switches the owner's Stay awake on and off, and if the backend ends between the two calls it stays on: a phone that never locks and never sleeps. The page's runner kills a backend after 20 s and when Settings closes, and the re-arm's own worst case is about 40 s. When idle doesn't come back, lock.sh exits 3, but the runner only looks at the exit code when there is no JSON, so the page shows the new time and no error; I reproduced that with a stand-in omarchy-shell. Omarchy's own shell.json writers do something else: omarchy-shell-config writes the file and calls omarchy-shell shell reloadConfig. Please use that, and drop the disable/enable.

  2. Where the old time was held. By the sources, a new idle.lock should arrive by itself: the idle service binds the monitor's timeout to the config, the shell watches shell.json, and Quickshell 0.3.2's IdleMonitor re-creates its notification when the timeout changes. You saw 30 s not take, and I believe you; omarchy-shell idle status will say which side held the old value, since it prints lock. Could you post it before the write, after the write, and after omarchy-shell shell reloadConfig, with pacman -Q omarchy quickshell? If the service has the new number and the phone still doesn't lock, that is a bug in the idle service and belongs in our Omarchy patch series (and upstream, as you offered), not in this backend.

  3. Brightness and the signature: how was Settings started? brightnessctl asks logind for session/auto, and logind gives a caller outside any session the user's display session (I checked on systemd 262 from a user unit), which is the session your fallback looks up by hand. So an app opened from the home screen shouldn't need it. Both symptoms fit Settings started from an SSH login: there auto is the SSH session, which has no seat, and HYPRLAND_INSTANCE_SIGNATURE is missing. If that is how you ran it, the two fallbacks are harmless but the commit messages and README should say "when started from a login outside the graphical session", and main isn't broken. If the buttons really do nothing from the home screen, please post brightnessctl -d "$(omarchy-hw-display)" set 50% with its error from that same environment, because that would be a bug on every phone.

  4. The feature itself. As built, a connected keyboard means no lock and no screen-off with no limit, and a dock or receiver counts with nobody at it. That is a phone left unlocked and lit on a desk for hours, on an OLED panel. I need to decide the shape before this goes on release phones: as you have it with plainer words on the page, or a long lock time (say 30 minutes) in place of "never" while a keyboard is connected. I lean to the second; tell me if that defeats what you use it for. The same goes for "Never" as a choice.

  5. The watcher on every phone. The unit is wanted by graphical-session.target for everyone, toggle on or off. I'd rather it ran only while the toggle is on (enabled by set keyboard on, with the same restore on stop), so a phone that never uses the feature runs nothing new. Whatever the shape, Settings is on every phone, so I'll run the page on the 7 Pro before merging; from you I'd like the kernel release, package versions and a tools/phone-smoke report with the next push.

Smaller: a broken shell.json makes the watcher restart every 10 s for the whole session; the watcher rewrites lock.json on every input event even when nothing changed; and depends should name systemd and coreutils (your #860 adds them).

If you'd like something in sooner: "Lock screen after" on its own, with reloadConfig and without "Never" until I've decided, is close. The keyboard toggle and the two Display fallbacks can follow as their own PRs. On versions, this, #860 and #629 all say 0.1.3; I set the numbers at merge. This one and #860 conflict in six files, all "keep both"; I expect this one first.

@Somnius

Somnius commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @derekross, that's a big one, I didn't know idle disable was Stay awake. Fixed in d1a5618 and kept as one PR:

  1. The disable/enable is gone. After writing shell.json the backend runs omarchy-shell shell reloadConfig, like omarchy-shell-config does. If the reload fails, the value stays saved and the JSON carries the error, so the page shows it. A flag in lock.json keeps the reload pending until one works, so tapping the same time again retries instead of hiding the error. Every step is under a timeout so the backend ends well before the runner's 20 s.
  2. The idle status readings need my phone, which is off right now. I'll post before the write, after it and after reloadConfig, with pacman -Q omarchy quickshell.
  3. You're right, it was SSH. I opened Settings with runuser from an ssh login when the buttons failed. The comments, README and that commit's message now say "when Settings is started from a login outside the graphical session (for example over SSH)". Main isn't broken there.
  4. I'm fine with 30 minutes. A connected keyboard now writes 1800 instead of 0, and the owner's time comes back when it goes. If the owner picked Never it stays never; I left Never in the list until you decide, happy to drop it.
  5. The watcher only runs while the toggle is on: set keyboard on enables it, off disables it and puts the owner's time back. It's no longer wanted by graphical-session.target for everyone. If it can't start, the toggle goes back to off with an error.

The small ones: a broken shell.json logs once and the watcher keeps going instead of restarting every 10 s, lock.json is only written when something changed, and depends has systemd and coreutils. The crash order is covered too: while the 1800 is being replaced the override flag stays set until shell.json has the owner's time, so a crash can't make 1800 the owner's choice.

test/all passes on my desktop. The kernel release, package versions and a tools/phone-smoke report come with the next push, after the phone run.

@Somnius

Somnius commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

@derekross your point 2, the readings. On my 8 Pro (omarchy 4.0.6-1, quickshell 0.3.2.r7.g2b4501a-1, hyprland 0.57.0-3.2):

  • before the write: idle status lock 180
  • 3 s after writing 60 to shell.json: lock 60, no reload needed
  • after omarchy-shell shell reloadConfig: lock 60

So the service gets the new number by itself, as you read it. But the phone still never locked: untouched and unlocked for 100 s after a change to 30 s, no idle at all, not even at the old timeout. A standalone IdleMonitor in a tiny quickshell config went idle on time (5 s and 60 s), so the compositor and inhibitors are fine. A shell started with 60 already set locked 61 s later. It's the idle service's monitor: after its timeout changes on a running shell it never reports idle again.

That's a bug in the idle service, so as you said it goes in our Omarchy patch series: #879. With it, a change to 30 s locked 30 s later on the phone. With that in, this PR's reloadConfig is all the backend needs.

@derekross

Copy link
Copy Markdown
Owner

Thank you, Lef. This is the change I asked for and then some. The idle toggle is gone and nothing in the package calls an idle verb any more; a keyboard means a 30-minute lock instead of none; the watcher runs only while the toggle is on, and puts the toggle back if it can't start; a failed reload is reported with the saved values and retried. I ran test/lock-backend.sh here (it is well isolated: stand-ins for omarchy-shell and systemctl for its whole length) and it passes. Thank you also for the straight answer on the SSH launch, and for the idle status readings: they are what turned a workaround into #879.

What is left before it can merge:

  1. omamobile-omarchy 0.1.49: idle re-arms its monitor when the timeout changes #879 first, and a dependency on it. Your readings show that a change of idle.lock on a running shell leaves the phone with no idle lock at all until the shell restarts. This page is a button for exactly that, and the watcher does it at every connect and disconnect. So this merges after omamobile-omarchy 0.1.49: idle re-arms its monitor when the timeout changes #879, and depends should name omamobile-omarchy at the version omamobile-omarchy 0.1.49: idle re-arms its monitor when the timeout changes #879 lands as, so no phone can get the page without the fix.

  2. A run of this head, on Omarchy 4.5. Everything in the description ran on the first version and on 4.0.6. With omamobile-omarchy 0.1.49: idle re-arms its monitor when the timeout changes #879's patch installed and the phone on 4.5 (pacman -Q omarchy quickshell, uname -r, package versions, a tools/phone-smoke report), please post: each lock time set from Settings opened on the home screen, with omarchy-shell idle status before and after and one of them left to lock; the toggle with your Bluetooth keyboard (shell.json at 1800 while connected, your time back when it goes, systemctl --user status omamobile-lock-keyboard); a reboot with the toggle on and the keyboard connected, and one with it off; and what reloadConfig does from the unit's stop at the end of a session. I'll run the page on my Pixel 7 Pro as well before merging, as I said.

  3. "Never". Please take it out. A phone that never locks by itself isn't something I want Settings to offer one tap away; someone who really wants it can still set it in the config file.

For the merge: I'm changing the order I gave last time. #860 is now inert on every phone until the charger work lands, so I'll take it first as 0.1.3, and this one rebased onto it becomes 0.1.4. The conflicts are all "keep both"; in depends keep coreutils before systemd (your test checks for that), and the runner's list becomes display, charge, lock. I'll write the squash message by hand, since three of the older commit messages describe the idle toggle and the keyboard's 0. Could you also change the title to say "lock after 30 minutes while a keyboard is connected"?

@Somnius Somnius changed the title omamobile-settings: lock screen timeout and stay unlocked with a keyboard omamobile-settings: lock screen timeout, and lock after 30 minutes while a keyboard is connected Nov 18, 2026
@Somnius

Somnius commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

@derekross done in d85aca6:

  • Never is out: the page offers 30 s to 5 min, lock.sh set lock 0 is refused as a bad value, and the core test checks for 5 choices. A 0 written by hand in shell.json still works and the page says it's off, so nothing breaks for someone who sets it there.
  • depends names omamobile-omarchy>=0.1.49. Change the number if omamobile-omarchy 0.1.49: idle re-arms its monitor when the timeout changes #879 lands as 0.1.50.
  • Title changed to "lock after 30 minutes while a keyboard is connected", and I rewrote the description for the current head, since the old text still talked about the idle toggle and writing 0.
  • The Display page scroll fix from my last push is in too.

test/all passes here. The phone run on 4.5 comes after #879's package is on my 8 Pro, and I'll post it here.

Somnius added a commit to Somnius/omarchy-mobile that referenced this pull request Nov 18, 2026
ActionRunner and Backend's start-up probe take a backend directory
(setBackendDir, as in derekross#866); the probe now starts from the event loop so
the setter applies. The Qt tests point both at stub charge.sh scripts and
check the available and not-available answers. The helper test adds
supply=../power_supply/max77759-charger, which only the name check
refuses. README: the Battery row needs the charger present at start.

@derekross derekross left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, Lef. "Never" is out the way I hoped (a 0 set by hand still works and the page says so, and the keyboard rule still leaves it alone), the dependency on #879 is there, and the new title and description match the code. I ran test/lock-backend.sh and test/display-backend.sh on this head here; both pass, and CI is green.

Two things are left, neither a change of design:

  1. The run on your phone, on 4.5, with #879's package installed. Your 8 Pro has both now, so whenever you get to it: pacman -Q omarchy quickshell omamobile-omarchy omamobile-settings, uname -r, a tools/phone-smoke report, and then each lock time set from Settings opened on the home screen with omarchy-shell idle status before and after, and one of them left to lock; the Display page scrolled to its end with a screenshot (the scroll view is new since my last look); the toggle with your Bluetooth keyboard (shell.json at 1800 while connected, your time back when it goes, systemctl --user status omamobile-lock-keyboard); a reboot with the toggle on and the keyboard connected, and one with it off; and what reloadConfig does from the unit's stop at the end of a session. I'll run the page on my Pixel 7 Pro before merging as well.

  2. A rebase once #860 is in, which I'm merging first as 0.1.3. The two conflict in seven files, all "keep both": in depends keep coreutils before systemd and your omamobile-omarchy entry; the runner's list becomes display, charge, lock, and setBackendDir is the same on both sides; #860's core tests now point every Backend at stub directories, so yours should too. Please take 0.1.4.

On the dependency number: I plan to merge #879 as 0.1.49 ahead of #610, so >=0.1.49 stays right. If that changes I'll say so here.

…hout it

Some launch paths (the shell's processes) don't pass HYPRLAND_INSTANCE_SIGNATURE,
so hyprctl found no Hyprland and the Display page lost its refresh rate rows.
display.sh now takes it from the newest live socket under $XDG_RUNTIME_DIR/hypr.
backends/lock.sh reads and sets the screen lock time (Omarchy's idle.lock in
shell.json, the one timer that locks and then turns the screen off), and with
the keyboard toggle on writes 0 there while a Bluetooth or USB keyboard is
connected. The choice is kept in ~/.config/omamobile/lock.json; a value changed
in Omarchy's own settings is adopted, and nothing is written before the user
picks something. omamobile-lock-keyboard (a user unit) runs apply at start and
after each burst of input udev events. Tests use a fake sysfs and udev data.
… keyboard

The Display page gets 30 s, 1, 2, 3, 5 min and Never, plus an on/off for
staying unlocked while a keyboard is connected. The text says that lock and
screen off are the same timer and that Never also keeps the phone awake.
0.1.3 clashes with open derekross#629, derekross#630 and derekross#860; renumber at merge.
lock.json (with an override flag) is saved before shell.json, so our own 0 is never adopted
as the user's Never. Both files under one flock, mkstemp temp files with fsync, shell.json read
again just before the write. An unparseable or other-version shell.json is an error and nothing
is written. The 0 is only written while the watcher runs; the unit restarts always and puts the
choice back with lock.sh restore on stop. The watcher exits non-zero when udevadm monitor ends
or an apply fails, and skips the udevadm header line. Keyboards need the letter keys and space
and a name that isn't a token or scanner.
The lock tests no longer depend on whether the backend is installed on the host.
…n brightnessctl can't

Settings started from a login outside the graphical session (for example over SSH) is not in the
logind session that owns the screen, so brightnessctl's SetBrightness on the caller's session is
refused and the buttons did nothing. Fall back to the user's graphical session (loginctl Display) by
its object path.
…ng the shell

Omarchy's idle service keeps the timeout its idle monitor was made with, so a lock time changed on
the page only applied after the shell restarted (seen on the 8 Pro: 30 s set live never locked, and
locked 30 s after a shell restart). After writing idle.lock, switch idle off and on through its IPC
when idle is on and stay-awake is off. Tests never touch the host's idle service.
…er leave it off

From review: the keyboard watcher calls apply after every input change, and each re-arm restarts the
idle countdown, so re-arm only when idle.lock was really written. If idle doesn't come back on after
disable, retry and fail loudly instead of leaving the phone never locking.
… 30 min lock with a keyboard

Following Derek's review: a new idle.lock now reaches the running shell through
`omarchy-shell shell reloadConfig`, the same way omarchy-shell-config does it.
The idle disable/enable step is gone, so Stay awake is never touched. If the
reload fails, the value stays saved and the JSON carries an error the page shows.
A failed reload stays pending in lock.json and is retried on the next run until it works.
If the watcher cannot be started the toggle goes back to off; turning it off does not wait
for the unit (--no-block), since the backend has already written the choice back.

With a keyboard connected the lock is now 1800 s instead of never (a chosen
Never stays never). The watcher unit is no longer enabled for everyone: the
toggle enables and starts it, and turning it off stops and disables it, which
restores the choice. A failed apply (a broken shell.json) is logged once
instead of restarting the unit every 10 s. lock.json is only rewritten when it
changed, and depends now lists coreutils and systemd.
On the 8 Pro the keyboard toggle's text ran off the bottom of the page
and couldn't be reached. The page is now a ScrollView like the About
page.
…e idle re-arm

A phone that never locks by itself isn't offered one tap away; a 0 set by
hand in shell.json still means no idle lock, and the page says so. depends
names omamobile-omarchy>=0.1.49 (derekross#879, the number is
set at merge): without its re-arm, changing the lock time on a running shell
leaves the phone with no idle lock until the shell restarts.
@Somnius
Somnius force-pushed the settings-lock-timeout-1117 branch from d85aca6 to 854e4fb Compare November 18, 2026 18:39
@Somnius

Somnius commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

@derekross rebased on main with #860 in, and it's 0.1.4 now. The conflicts went the way you listed: depends keeps coreutils before systemd plus polkit from #860 and 'omamobile-omarchy>=0.1.49', the runner's list is display, charge, lock, one setBackendDir, and the lock tests point every Backend at the stub dirs like #860's do. test/all and tools/pr-check origin/main both pass here. The phone run on 4.5 comes when I'm at the phone.

…cher if lock.json says on

An older build could leave keyboardAwake on in lock.json with the unit never enabled, so the page showed On while nothing watched keyboards. lock.sh get now enables+starts the unit in that case and disables it when the choice is off but the unit is enabled. Never on a missing or broken lock.json; a systemctl failure comes back as an error in the JSON.
The choice is read again under the same flock as set, so a set landing meanwhile waits and wins. Only enabled/enabled-runtime and disabled from is-enabled count; anything else is reported and nothing is done.
@Somnius

Somnius commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

@derekross the run you asked for, on my 8 Pro. Versions: omarchy 4.5.0-3, quickshell 0.3.2.r7.g2b4501a-1, omamobile-omarchy 0.1.49-1 (#879), hyprland 0.57.0-3.3, kernel 7.3.0-rc6-omamobile-push1-g0124dfcad569. Settings is my combined phone build 0.1.7, which carries this PR at 854e4fb0 (before today's fix below) together with #629, #630 and #892, built from those heads. tools/phone-smoke: 17 ok, sensors and cameras skipped, no failures; the only "new dmesg" lines are the in-call AoC driver with no modem and the Wi-Fi TxCap blob notice.

  • Lock times, Settings opened from the home screen. I tapped 30 s, 1, 2, 3 and 5 min in turn; each one was in shell.json and in omarchy-shell idle status within about a second (watcher log: 21:52:52 30, 21:52:59 60, 21:53:04 120, 21:53:09 180, 21:53:14 300). I left it on 2 min from 21:53:21 and it locked by itself at 21:55:21, exactly 120 s later, with no shell restart.
  • Display page scrolled to the end: the scroll works to the bottom of the keyboard row and its note; I'll attach the screenshot here.
  • Keyboard toggle with my Dell KB7120W over Bluetooth: with the keyboard asleep shell.json stayed at my 120. When it woke at 21:57:01 it went to 1800 (lock.json kept 120 as my choice and marked 1800 as the watcher's), and when I switched the keyboard off it was back to 120 at 21:57:34. systemctl --user status omamobile-lock-keyboard was active (running) the whole time.
  • Reboot with the toggle on (keyboard off): after boot the unit was enabled and active (running), idle.lock 180.
  • Reboot with the toggle off: the unit was disabled and inactive after boot, idle.lock 180.
  • End of session: with the toggle on, a reboot's shutdown stopped the unit, its stop ran lock.sh restore, which printed {"lock":180,"keyboardAwake":true,"keyboard":false,"effective":180} (my time back, the choice kept), and the unit was stopped in the same second (08:30:53), so nothing hangs at shutdown.

One bug the run found, fixed in two commits now on the branch: after an upgrade from my older build, lock.json said keyboardAwake: true but the unit had never been enabled, so the page showed On and nothing watched keyboards (tapping Off then On fixed it). Now lock.sh get, which the page runs when it opens, brings the unit in line with the saved choice under the same lock set uses, and only acts on is-enabled saying enabled or disabled; anything else is reported, not guessed. test/all passes with new tests for both directions, a failing systemctl, an unknown is-enabled answer and a set landing in the middle. That fix itself hasn't run on the phone yet.

In CI the racing set keyboard off ends up a child of the container's PID 1,
which never reaps it, so kill -0 kept seeing the zombie and the loop never
ended (the suite was stopped after 1800 s). The racer's group also gets its
own stdout, so it can't hold get's command substitution open.
@Somnius

Somnius commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

@derekross the CI hang on this one was my new race test in test/lock-backend.sh: in the CI container the racing set keyboard off ends as a zombie under PID 1, and kill -0 still succeeds on a zombie, so the wait never ended. Fixed in 5db37629 (the job writes a done file, the test waits at most 20 s for it); the settings tests now pass in CI in about 80 s.

The red that's left is in omamobile-shell, which this PR doesn't touch: not ok - voice preview: SIGTERM stops a loop that only waits, whenever it lands with (8, 0.037, -15). It passes on main and on my other branches today, so it looks like a timing flake. I can't re-run the job from my side; could you re-run it when you look?

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