feat(power): add SleepListenerService to auto-lock on system suspend#2577
feat(power): add SleepListenerService to auto-lock on system suspend#2577l1a wants to merge 5 commits intonoctalia-dev:mainfrom
Conversation
eventualbuddha
left a comment
There was a problem hiding this comment.
I'm not a maintainer, so take the "Request Changes" review with a grain of salt. I'm just another user (CachyOS+niri+noctalia) who ran into the issue described in #2569 and went looking for a fix.
|
|
||
| onExited: (code, status) => { | ||
| Logger.w("SleepListener", "dbus-monitor exited with code " + code + ". Restarting..."); | ||
| if (root.running) { |
There was a problem hiding this comment.
There is no running property on Singleton instances (from qmllint):
Warning: Services/Power/SleepListenerService.qml:55:16: Member "running" not found on type "Singleton"
[missing-property]
if (root.running) {
^^^^^^^
This conditional should just be removed and always call restartTimer.start();.
| if (line.includes("boolean true")) { | ||
| if (Settings.data.general.lockOnSuspend) { | ||
| Logger.i("SleepListener", "System is preparing for sleep, triggering lock"); | ||
| CompositorService.lock(); |
There was a problem hiding this comment.
This is happening as a result of dbus sending the PrepareForSleep signal, but nothing in this change actually prevents sleep until the compositor lock has taken effect. I think this service should have a systemd-inhibit --what=sleep ... process that can be stopped after the lock has happened (or lockOnSuspend is disabled).
Addresses PR noctalia-dev#2577 feedback: - Fixed invalid property reference on Singleton in onExited. - Implemented systemd-inhibit to prevent race conditions during suspend. - Added verified logic to release inhibitor only after lock screen is active. - Added comprehensive documentation for the sleep listener logic.
|
Cool! Thanks for the catch. I've made the updates and tested what I can. Does it work as expected in your environment? |
Motivation
This PR addresses an issue where Noctalia fails to auto-lock the session when the system enters sleep via external triggers (such as closing a laptop lid or running
systemctl suspend).Currently, Noctalia's locking logic is primarily tied to its internal idle timer. By introducing the
SleepListenerService, the shell now eavesdrops on theorg.freedesktop.login1.Manager.PrepareForSleepDBus signal, allowing it to trigger the lock screen immediately before the system suspends.Type of Change
Related Issue
Testing
I have verified this change by running the modified shell from source and performing the following manual tests:
Manual Test Scenarios:
systemctl suspendsuccessfully triggers the lock screen.lockOnSuspendsetting is respected (disabling it prevents the auto-lock).dbus-monitorsubprocess automatically restarts if terminated.Checklist
Additional Notes
The implementation follows the established project pattern of using
Quickshell.Ioto manage system utility subprocesses (consistent withBluetoothService.qmlandClipboardService.qml). It usesSplitParserto ensure real-time, line-buffered signal detection.