On 01/02/2023 20:15, Ihor Radchenko wrote:
+(defcustom org-clock-pgtkidle-program-name
+ (if (executable-find "jc-idle-time")
+ "jc-idle-time")
+ "Name of the program which prints idle time in milliseconds.
May I know where "jc-idle-time" is coming from? Is it a built-in command
on wayland?
During discussion in the later thread
Julien Cubizolles to emacs-orgmode. org-x11idle-exists-p with emacs
--daemon. Fri, 28 Oct 2022 00:31:23 +0200.
https://list.orgmode.org/871qqs6gqs....@free.fr
I noticed a suggestion to use a d-bus method, unfortunately it is
Gnome-specific
https://unix.stackexchange.com/questions/396911/how-can-i-tell-if-a-user-is-idle-in-wayland/
dbus-send --print-reply --dest=org.gnome.Mutter.IdleMonitor
/org/gnome/Mutter/IdleMonitor/Core org.gnome.Mutter.IdleMonitor.GetIdletime
Another interface likely may give not really reliable results:
org.freedesktop.ScreenSaver GetSessionIdleTime
https://lists.freedesktop.org/archives/xdg/2007-March/009187.html
Stephan Kulow. screensaver dbus interfaces. Mon Mar 5 05:16:39 PST 2007
Unsure if some workaround like in xprintidle should be used on this way:
https://github.com/g0hl1n/xprintidle/blob/master/xprintidle.c#L150
* Workaround: Check if if XServer is in a dpms state, check the
* current timeout for this state and add this value to
* the current idle time and return.
*/
+(defvar org-pgtkidle-exists-p
+ ;; Check that org-clock-pgtkidle-program-name exists. But don't do that on
DOS/Windows,
+ ;; since the command definitely does NOT exist there, and invoking
+ ;; COMMAND.COM on MS-Windows is a bad idea -- it hangs.
+ (and (null (memq system-type '(windows-nt ms-dos)))
+ (eq 0 (call-process-shell-command
+ (format "command -v %s" org-clock-pgtkidle-program-name)))
+ ;; Check that x11idle can retrieve the idle time
+ ;; FIXME: Why "..-shell-command" rather than just `call-process'?
+ (eq 0 (call-process-shell-command org-clock-pgtkidle-program-name))))
We may as well resolve this FIXME since we are at it.
Instead of the awkward combination of two `call-process-shell-command'
prompts, we can simply use `executable-find' + `call-process'.
Is there a reasonable way to avoid code duplication? I agree that
`executable-find' may be better since `org-clock-pgtkidle-program-name'
might contain spaces or shell specials causing issues with current code.