lid behavior watcher to lock session #115

Merged
zach merged 25 commits from lid-switch-behavior into main 2026-06-03 18:02:21 +02:00
Collaborator

Closes #102

Use case

Laptop users often want a quick an intuitive way to lock their session by closing the lid. This PR includes logic to have session lock on lid close before suspend (or hibernate) kicks in. Works on systemd and elogind.

Summary

  • C++ plugin added to listen to login1 PrepareForSleep signal. QML decides the action.
  • Config.json gets an entry. Entry lidWatch defaults to true if a laptop battery is detected. false if none are detected.
  • Settings window gets an entry in Lockscreen to configure if user wants it toggled.

Optional additions

  • Settings window could hide the setting if no laptop battery is detected, since the setting might be useless. Only use would be if any suspend/hibernate session would be included. Excluded due to this nuance.

Known bug/caveat

  • First lid-close after boot with lidWatch disabled can still cause a short lock-like stall on lid open. No lock screen appears. Likely separate lock-session warm-up or suspend-path behavior.
Closes #102 ### Use case Laptop users often want a quick an intuitive way to lock their session by closing the lid. This PR includes logic to have session lock on lid close before suspend (or hibernate) kicks in. Works on systemd and elogind. ### Summary - C++ plugin added to listen to login1 PrepareForSleep signal. QML decides the action. - Config.json gets an entry. Entry `lidWatch` defaults to `true` if a laptop battery is detected. `false` if none are detected. - Settings window gets an entry in `Lockscreen` to configure if user wants it toggled. ### Optional additions - Settings window could hide the setting if no laptop battery is detected, since the setting might be useless. Only use would be if any suspend/hibernate session would be included. Excluded due to this nuance. ### Known bug/caveat - First lid-close after boot with `lidWatch` disabled can still cause a short lock-like stall on lid open. No lock screen appears. Likely separate lock-session warm-up or suspend-path behavior.
AramJonghu added the enhancement label 2026-06-01 21:28:46 +02:00
AramJonghu self-assigned this 2026-06-01 21:28:46 +02:00
AramJonghu added 7 commits 2026-06-01 21:28:46 +02:00
AramJonghu requested review from Inorishio 2026-06-01 21:28:46 +02:00
AramJonghu requested review from zach 2026-06-01 21:28:46 +02:00
AramJonghu added 1 commit 2026-06-01 23:53:31 +02:00
refactor: using more oop
Lint & Format (JS/TS) / lint-format (pull_request) Successful in 14s
Python / lint-format (pull_request) Successful in 20s
Python / test (pull_request) Successful in 52s
Lint & Format (Rust) / lint-format (pull_request) Successful in 1m6s
7da2c7827a
AramJonghu added 1 commit 2026-06-01 23:59:11 +02:00
format using qmlformat
Lint & Format (JS/TS) / lint-format (pull_request) Successful in 12s
Python / lint-format (pull_request) Successful in 20s
Python / test (pull_request) Successful in 51s
Lint & Format (Rust) / lint-format (pull_request) Successful in 1m5s
ad2ee99d9c
AramJonghu added 1 commit 2026-06-02 00:03:36 +02:00
QTQuick
Lint & Format (JS/TS) / lint-format (pull_request) Successful in 12s
Python / lint-format (pull_request) Successful in 24s
Python / test (pull_request) Successful in 50s
Lint & Format (Rust) / lint-format (pull_request) Successful in 1m7s
c91b53fbaa
Author
Collaborator

Currently broken. Do not merge!

Currently broken. Do not merge!
zach reviewed 2026-06-02 11:10:08 +02:00
@@ -0,0 +9,4 @@
Connections {
function onLidClosing(): void {
root.lock.lock.locked = true;
Owner

You need to create a signal in the root Scope and call it here rather than setting the locked value directly.

Scope {
    id: root
    
    signal requestLock
    
    Connections {
    // ...

Is what I suggest, ties in nicely with a similar signal related to locking.

You need to create a signal in the root `Scope` and call it here rather than setting the locked value directly. ```qml Scope { id: root signal requestLock Connections { // ... ``` Is what I suggest, ties in nicely with a similar signal related to locking.
AramJonghu marked this conversation as resolved
zach reviewed 2026-06-02 11:34:28 +02:00
@@ -0,0 +38,4 @@
return m_available;
}
void LidWatcher::onPrepareForSleep(bool goingDown) {
Owner

Doesn't this trigger only when the system is about to suspend/hibernate? There should be a way to query the lid state directly.

Doesn't this trigger only when the system is about to suspend/hibernate? There should be a way to query the lid state directly.
Author
Collaborator

Correct. And in retrospect, not every distro has defaults where the system suspends when laptop is on AC. The idea was that it should only trigger when the system suspends or hibernates to cover it more broadly for desktops (if wished). Could be a separate plugin or addition to current implementation if that is a wish separate from laptop lid behavior.

Correct. And in retrospect, not every distro has defaults where the system suspends when laptop is on AC. The idea was that it should only trigger when the system suspends or hibernates to cover it more broadly for desktops (if wished). Could be a separate plugin or addition to current implementation if that is a wish separate from laptop lid behavior.
AramJonghu marked this conversation as resolved
zach requested changes 2026-06-02 18:25:12 +02:00
@@ -329,0 +331,4 @@
category: "lockscreen",
categoryName: "Lockscreen",
section: "Lockscreen",
keywords: ["lid", "lcck", "watch", "session", "laptop"],
Owner

Typo probably. "lcck" should be "lock"

Typo probably. `"lcck"` should be `"lock"`
AramJonghu marked this conversation as resolved
AramJonghu added 1 commit 2026-06-03 00:59:48 +02:00
Cpp changes, minor refactor plus separate signal logic, typo.
Lint & Format (JS/TS) / lint-format (pull_request) Successful in 12s
Python / lint-format (pull_request) Successful in 26s
Python / test (pull_request) Successful in 1m3s
Lint & Format (Rust) / lint-format (pull_request) Successful in 1m9s
016dcc008f
- typo in searchindex
- Cpp plugin changed to use enum lidstate
- minor refactor
- Using signals instead of direct property access.
- Using states instead
- checking lidclosed instead of preparetosleep
AramJonghu added 1 commit 2026-06-03 01:02:59 +02:00
build fix
Lint & Format (JS/TS) / lint-format (pull_request) Successful in 16s
Python / lint-format (pull_request) Successful in 23s
Python / test (pull_request) Successful in 48s
Lint & Format (Rust) / lint-format (pull_request) Successful in 1m9s
3bcdbbabbb
AramJonghu added 1 commit 2026-06-03 01:14:41 +02:00
added lock. in shell.qml, wrong scope
Lint & Format (JS/TS) / lint-format (pull_request) Successful in 12s
Python / lint-format (pull_request) Successful in 20s
Python / test (pull_request) Successful in 47s
Lint & Format (Rust) / lint-format (pull_request) Successful in 1m5s
45f36ce71c
AramJonghu added 1 commit 2026-06-03 02:05:25 +02:00
Added clang-format/tidy for additional rules. Adjusted inbranch cpp files.
Lint & Format (JS/TS) / lint-format (pull_request) Successful in 15s
Python / lint-format (pull_request) Successful in 37s
Python / test (pull_request) Successful in 59s
Lint & Format (Rust) / lint-format (pull_request) Successful in 1m20s
896e5e520d
Author
Collaborator

I added clang rules for formatting and lint. I think this can be a decently good addition. Since you write C++ the most, I'll leave it up to you if you either want some rules changed, removed, or if you do not want these in the project at all.

I also found a fix of some sorts to the Unknown argument: '-mno-direct-extern-access' warning you get including the header file. It does require changing the cmake file and a local cmake -B build. I did not commit this yet as I want your input if this hack is a fine addition.

Edit: I was not careful enough, the hack is in the files changed. We can always undo.

I added clang rules for formatting and lint. I think this can be a decently good addition. Since you write C++ the most, I'll leave it up to you if you either want some rules changed, removed, or if you do not want these in the project at all. I also found a fix of some sorts to the `Unknown argument: '-mno-direct-extern-access'` warning you get including the header file. It does require changing the cmake file and a local `cmake -B build`. I did not commit this yet as I want your input if this hack is a fine addition. Edit: I was not careful enough, the hack is in the files changed. We can always undo.
AramJonghu requested review from zach 2026-06-03 02:29:44 +02:00
AramJonghu added 1 commit 2026-06-03 02:30:17 +02:00
missing changes
Lint & Format (JS/TS) / lint-format (pull_request) Successful in 10s
Python / lint-format (pull_request) Successful in 31s
Python / test (pull_request) Successful in 50s
Lint & Format (Rust) / lint-format (pull_request) Successful in 1m3s
0584cd618e
zach requested changes 2026-06-03 10:47:14 +02:00
zach left a comment
Owner

The only thing that sticks out to me immediately is the line I commented on, other than that it looks fine to me.

Since I don't know what -mno-direct-extern-access means, are you sure using in-place substitution like this doesn't change the behavior and only makes the error disappear?

The only thing that sticks out to me immediately is the line I commented on, other than that it looks fine to me. Since I don't know what `-mno-direct-extern-access` means, are you sure using in-place substitution like this doesn't change the behavior and only makes the error disappear?
@@ -0,0 +32,4 @@
LidState m_state = Opened;
void extracted();
Owner

extracted() is declared but never implemented in the .cpp file.

`extracted()` is declared but never implemented in the `.cpp` file.
AramJonghu marked this conversation as resolved
AramJonghu added 1 commit 2026-06-03 16:27:35 +02:00
removes direct extern access, receives signal properly now, removed declaration unused method
Lint & Format (JS/TS) / lint-format (pull_request) Successful in 14s
Python / lint-format (pull_request) Successful in 21s
Python / test (pull_request) Successful in 44s
Lint & Format (Rust) / lint-format (pull_request) Successful in 1m6s
2920c57163
AramJonghu added 1 commit 2026-06-03 16:29:17 +02:00
qmlls lied to me - import ZShell returned
Lint & Format (JS/TS) / lint-format (pull_request) Successful in 11s
Python / lint-format (pull_request) Successful in 23s
Python / test (pull_request) Successful in 45s
Lint & Format (Rust) / lint-format (pull_request) Successful in 1m4s
7dbce0bf8c
AramJonghu added 1 commit 2026-06-03 16:51:20 +02:00
inability to connect to DBus.Properties resolved
Lint & Format (JS/TS) / lint-format (pull_request) Successful in 13s
Python / lint-format (pull_request) Successful in 20s
Python / test (pull_request) Successful in 51s
Lint & Format (Rust) / lint-format (pull_request) Successful in 1m3s
f9ab1e2a10
AramJonghu added 1 commit 2026-06-03 17:02:52 +02:00
troubleshooting dbus
Lint & Format (JS/TS) / lint-format (pull_request) Successful in 15s
Python / lint-format (pull_request) Successful in 19s
Python / test (pull_request) Successful in 49s
Lint & Format (Rust) / lint-format (pull_request) Successful in 1m5s
deef85d10c
AramJonghu added 2 commits 2026-06-03 17:41:41 +02:00
Took caelestia lid logic (prepare to sleep) instead
Lint & Format (JS/TS) / lint-format (pull_request) Successful in 12s
Python / lint-format (pull_request) Successful in 19s
Python / test (pull_request) Successful in 45s
Lint & Format (Rust) / lint-format (pull_request) Successful in 1m3s
0d8f558f66
AramJonghu added 1 commit 2026-06-03 17:44:12 +02:00
forgotton import and removal LidService
Lint & Format (JS/TS) / lint-format (pull_request) Successful in 11s
Python / lint-format (pull_request) Successful in 26s
Python / test (pull_request) Successful in 41s
Lint & Format (Rust) / lint-format (pull_request) Successful in 1m4s
a19701222b
AramJonghu added 1 commit 2026-06-03 17:47:25 +02:00
fix typo
Lint & Format (JS/TS) / lint-format (pull_request) Successful in 11s
Python / lint-format (pull_request) Successful in 18s
Python / test (pull_request) Successful in 44s
Lint & Format (Rust) / lint-format (pull_request) Successful in 1m5s
6f856e2162
AramJonghu requested review from zach 2026-06-03 17:49:30 +02:00
Author
Collaborator

Resolved many issues by using Caelestia's implementation instead. With great assistance from @zach, got it to work.

Resolved many issues by using Caelestia's implementation instead. With great assistance from @zach, got it to work.
AramJonghu added 1 commit 2026-06-03 17:59:16 +02:00
removal reduntant config option and settings, unused lines in Lock.qml
Lint & Format (JS/TS) / lint-format (pull_request) Successful in 11s
Python / lint-format (pull_request) Successful in 21s
Python / test (pull_request) Successful in 52s
Lint & Format (Rust) / lint-format (pull_request) Successful in 1m4s
a128c0fa40
AramJonghu added 1 commit 2026-06-03 18:01:23 +02:00
unused imports in shell.qml
Lint & Format (JS/TS) / lint-format (pull_request) Successful in 11s
Python / lint-format (pull_request) Successful in 21s
Python / test (pull_request) Successful in 51s
Lint & Format (Rust) / lint-format (pull_request) Successful in 1m4s
59789ab8d3
zach merged commit b6e7ee7a54 into main 2026-06-03 18:02:21 +02:00
AramJonghu deleted branch lid-switch-behavior 2026-06-03 18:02:32 +02:00
Sign in to join this conversation.