View previous topic :: View next topic |
Author |
Message |
eeckwrk99 Apprentice
Joined: 14 Mar 2021 Posts: 232 Location: Gentoo forums
|
Posted: Tue Oct 08, 2024 2:52 pm Post subject: [SOLVED] Help with xidlehook and manual screen locking |
|
|
I'm using xidlehook to automatically lock my X session then turn display off after a specified amount of time.
I'm using the suggested systemd service unit:
Code: | % systemctl --user cat xidlehook.service
# /home/eeckwrk/.config/systemd/user/xidlehook.service
[Unit]
Description=Automatically lock screen with Xidlehook
[Service]
Type=simple
Environment=DISPLAY=:0
Environment=XIDLEHOOK_SOCK=%t/xidlehook.socket
ExecStart=/home/eeckwrk/.local/bin/xidlehook --detect-sleep --not-when-audio --not-when-fullscreen --socket $XIDLEHOOK_SOCK --timer 300 '/usr/bin/betterlockscreen --lock --off 30 -- --color 000000' '' |
This works as expected: after 300 seconds of inactivity, the screen is locked via betterlockscreen, then the monitor is turned off after 30 seconds (--off 30 is basically running xset dpms 30 before locking the screen and restoring the default value after unlocking).
However, when I manually lock my session with an AwesomeWM keybinding:
Code: | awful.key({ modkey }, "x", function()
awful.spawn("betterlockscreen --lock -- --color 000000")
end, { description = "Lock screen", group = "Awesome" }) |
xidlehook.service timer still runs, of course. 300 seconds after the manual locking, the unit tries to lock the screen, but since the screen is already locked, betterlockscreen detects that another i3lock process is already running and exits:
Code: | % journalctl --user -u xidlehook.service
Oct 08 19:10:05 gentoo-desktop xidlehook[436228]: [B] Betterlockscreen
Oct 08 19:10:05 gentoo-desktop xidlehook[436239]: 433493
Oct 08 19:10:05 gentoo-desktop xidlehook[436239]: 433494
Oct 08 19:10:05 gentoo-desktop xidlehook[436228]: [!] i3lock already running |
Relevant part of betterlockscreen binary content:
Code: | lockinit() {
if pgrep -u "$USER" "$i3lockcolor_bin"; then
echof error "i3lock already running"
exit 1
fi
echof act "Running prelock..."
prelock |
At this point, 300 seconds later, the monitor is turned off - due to the default DPMS timeout being used instead, in my case 600:
Code: | % xset q | awk '/^[[:blank:]]*DPMS is/ {print $(NF)}'
Enabled
% cut -d ' ' -f4 <<< "$(xset q | sed -n '25p')
600 |
Quoting the project README:
xidlehook README wrote: | A common use case of xidlehook is using it to run a lockscreen. To then manually lock the screen, you could first decide what ID the timer has, either by counting the indexes yourself of the timers you inform xidlehook of (starting from 0), or by querying timer information after starting it:
Code: | # Check what timer(s) you want to trigger...
xidlehook-client --socket /path/to/xidlehook.sock query |
And then bind a hotkey or bash alias to lock it:
Code: | # Trigger it/them
xidlehook-client --socket /path/to/xidlehook.sock control --action trigger --timer <my timer id> |
|
Could this socket API feature help in my situation? Not sure how to proceed.
What I'd like to achieve in a nutshell:
- Being able to manually lock the session with a keybinding, then automatically turning the display off after 30 seconds
- If no activity for 300 seconds, having the session automatically locked and then the display being turned off after 30 seconds
For now, the manual locking seems to conflict with the default xidlehook timer.
I thought I'd ask here because xidlehook maintainer sadly passed away a few years ago now so the project isn't very active anymore...
Thanks in advance for any input!
Last edited by eeckwrk99 on Wed Oct 09, 2024 9:40 am; edited 1 time in total |
|
Back to top |
|
|
eeckwrk99 Apprentice
Joined: 14 Mar 2021 Posts: 232 Location: Gentoo forums
|
Posted: Wed Oct 09, 2024 9:40 am Post subject: |
|
|
After tinkering a bit, I found a solution. My AwesomeWM keybinding now runs this script to lock:
Code: | awful.key({ modkey }, "x", function()
awful.spawn.with_shell("/path/to/script.sh")
end, { description = "Lock screen", group = "Awesome" }), |
Code: | #!/usr/bin/env bash
# Disable xidlehook.service timer before locking
xidlehook-client --socket /run/user/1000/xidlehook.socket control --action disable --timer 0
# Lock the session and turn the monitor off after 30 seconds
betterlockscreen --lock --off 30 -- --color 000000
# Enable xidlehook.service timer again after unlocking
xidlehook-client --socket /run/user/1000/xidlehook.socket control --action enable --timer 0
# Reset the idle timer
xidlehook-client --socket /run/user/1000/xidlehook.socket reset-idle |
This script works fine. xidlehook.service timer is disabled so I'm no longer getting any [!] i3lock already running error after manually locking.
After unlocking, the original timer kicks in after 300 seconds thanks to the reset-idle command (the last one). |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|