Handle logind inhibitors
AdrianVovk opened this issue · 6 comments
Title explains it all. swaidle doesn't seem to handle logind's idle inhibitors.
I'd like to implement a toggle in my shell that turns on the idle inhibitor, but that doesn't work via dbus and setting up the Wayland protocol for that toggle is infeasible.
So would the correct behavior be for swayidle
to execute all idle inhibitors before executing the command associated with a timeout
block?
And then you would block swayidle's timeouts by executing something like systemd-inhibit --what=idle sleep 1d
?
@electrickite I found a specific swayidle setup that cause a glitch where the first time systemd-inhibit --what=idle
is run, swaylock will react to the property change event but won't find the lock, while it will find it the second time you run the same command.
To reproduce:
$ swayidle -d \
timeout 5 'echo timeout 5' \
timeout 10 'echo timeout 10' \
resume 'echo resume' \
before-sleep 'echo before-sleep' \
lock 'echo lock'
This will produce the following initial output:
Got timeout
Register idle timeout at 5000 ms
Setup idle
Command: echo timeout 5
Got timeout
Register idle timeout at 10000 ms
Setup idle
Command: echo timeout 10
Setup resume
Command: echo resume
Got before-sleep
Command: echo before-sleep
Setup sleep lock: echo before-sleep
Got lock
Command: echo lock
Setup lock hook: echo lock
No config file found.
Using session: /org/freedesktop/login1/session/_320
Got sleep lock: 11
Enable idle timeouts
Register with timeout: 10000
Register with timeout: 5000
Then, running systemd-inhibit --what=idle sleep infinity
will produce the following swayidle output:
PropertiesChanged signal received
Got PropertyChanged: org.freedesktop.login1.Manager
PropertiesChanged signal received
Got PropertyChanged: org.freedesktop.login1.Manager
Logind idle inhibitor not found
Then, killing systemd-inhibit
and so releasing the lock:
PropertiesChanged signal received
Got PropertyChanged: org.freedesktop.login1.Manager
Logind idle inhibitor not found
Now, running systemd-inhibit --what=idle sleep infinity
again will produce the expected result:
PropertiesChanged signal received
Got PropertyChanged: org.freedesktop.login1.Manager
Logind idle inhibitor found
Disable idle timeouts
I wonder whether there's some sort of conflict between the inhibitors set by swayidle and the one externally set by systemd-inhibit
.
Even more weird, the following setup will make swayidle never find the lock:
swayidle -d \
before-sleep 'echo before-sleep' \
lock 'echo lock'
Looks like before-sleep
and lock
, when together, cause the glitch: removing either one of them or the other will make swaylock properly find the inhibitor lock all the times that a property change is triggered.
Actually just this is enough to reproduce:
swayidle -d lock 'echo lock'
With this setup, the lock is find only the first time, and then never again. Weird.
@michelesr I am unable to reproduce on my system. Using the commands you listed above, I see the lock found consistently. Possible there is some sort of race condition I am not experiencing, but I do not see it at first glance.
@electrickite I traced the execution with gdb and got the following:
Breakpoint 1, get_logind_idle_inhibit () at ../main.c:222
222 sd_bus_message_unref(reply);
(gdb) display locks
1: locks = 0x555555567fa0 "idle"
(gdb) next
223 return strstr(locks, "idle") != NULL;
1: locks = 0x555555567fa0 "`"
(gdb) continue
Continuing.
Logind idle inhibitor not found