Sample Header Ad - 728x90

Non-polling method of being notified of user activity after given idle time on desktop systems

1 vote
0 answers
102 views
There are already many questions similar to this but all the ones I could find have answers that suggest polling methods ((https://unix.stackexchange.com/a/290073/68864) , (https://askubuntu.com/a/202145)) or seem like extreme hacks ((https://unix.stackexchange.com/a/290117/68864)) , so I want to ask the same question but with the added caveat that solutions must not use polling: What I'm looking for is some kind of API that is commonly available (or easily installable) on Linux desktop systems that lets you listen for these two events: 1. The user has been "idle" (not moving the mouse, typing on the keyboard, etc.) for N seconds (where you can specify N). 2. After (1) had previously been triggered (and only then!), the user has now performed some activity and should no longer be considered idle. After this event, (1) can be re-triggered, allowing the cycle to repeat. For (1), it is not very important to me that it happens without polling, as in my use case, the tolerance for delays when reacting to this first type of event is high enough that I'm fine with polling every 10 seconds. But for event (2), the reaction should feel instant, so with polling approaches, I'd have to poll every 0.1 seconds or so, which would be an unacceptable waste of CPU time.1 So I'd consider (1) "solved" by the suggestion to use use something like xprintidle in a polling fashion, but as the definition of (2) relies on (1), I felt it should be listed here anyway. Any ideas for APIs that implement (2)? How do screensavers etc. do it? ----- 1 To understand the motivation here, compare how you would feel if e.g. dpms turned off your screen after 10 minutes and 10 seconds rather than the 10 minutes you configured vs how you would feel if there was a 10 second delay to turning it on again after detecting activity... It seems to me like most use cases imply a greater tolerance for "idle detection" than for "un-idle detection".
Asked by smheidrich (936 rep)
Dec 25, 2021, 05:15 PM