[Proposal] conditional timeouts
David96 opened this issue · 6 comments
I would like to suggest adding something like "conditional timeouts". Basically, a timeout would get an optional parameter with the path to some script/program that would be executed and conditional on its exit code, the actual command would be run.
A possible syntax for that would be:
timeout <timeout> <timeout command> [if <condition command>] [resume <resume command>]
I think this is a rather simple design that could accommodate multiple use cases such as #28 and #50 (for the first one, one could add one timeout per display checking whether the streaming application one uses is running fullscreen, for the second one, the mentioned edge case probably wouldn't be possible to achieve but the other part should be easy).
Another possible design might be to group timeouts by conditions, but I think the suggested one is probably easier to implement.
If you think such a feature is worth adding and we can agree on a design, I'd be willing to try to implement it.
How would swayidle figure out that the condition no longer prevents the timeout from firing?
Use-case is the following:
- User watches a video fullscreen.
- Time passes.
- The timeout kicks in, swayidle executes the condition command, which returns 1. swayidle doesn't blank the screen.
- The video finishes.
- Time passes.
- swayidle should blank the screen, but doesn't.
For all my usecases I would probably go back to my computer at some point after the timeout is blocked by the condition, do something and therefore restart the whole timer anyway so I guess I didn't give that part any thoughts.
If I understand your scenario right, it would basically require restarting the timer at the point the condition is no longer true - I don't think this simple design can cover this.
Edit: I think this is also very similar to the edge case in #50
We also are having headaches in the sxmo community. We are relying on swayidle to put the phone in a deeper state :
unlock -> locked (screen input locked) -> off (screen disabled) -> crust (suspended)
We got an additional script that check if the phone can be considered as "idle" and another if it "can_suspend" (no mpd music, no ssh session, by example).
As @emersion said, we need a way to loop somehow. The go_deeper behavior should try to trigger every 8 seconds. If the is_idle, can_suspend script said no, we have to retry in 8 seconds (without any user action that will restart the swayidle duration).
I'll probably open a dedicated issue to discuss futher but I think we need a way to reset the idle duration from inside swayidle :
swayidle -w timeout-loop 8 "go_deeper"
This will run the go_deeper at 8 seconds. This script could do it shit to not actually go deeper in some condition. If it does not, it return a non zero exit code. This exit code will make swayidle to retry 8 seconds later.
I think this new timeout-loop
would solve most of our issues
edit: maybe a simple loop 8 "go_deeper"
would be enough. But then, it will just trigger periodically independently of success or failure. But it is perfect for our sxmo use cases
edit2: timeout 8 "go_deeper" loop 2
as retry redo every 2 seconds
If I understand you correctly your desired behavior is already possible with my PR by replacing the cmd->timeout in this line: https://github.com/swaywm/swayidle/pull/98/files#diff-a0cb465674c1b01a07d361f25a0ef2b0214b7dfe9412b7777f89add956da10ecR613 by 8s. By doing that, once the condition is false once, it gets retried every 8s.
I'm using the PR since quite some time now btw and it works perfectly for me. Setting that timeout to something small by default (what something small is would need to be discussed) would solve the problem that the condition doesn't get reevaluated I think.