It is a lot of code, but I shall give the gist.
Activating is done with:
(gnus-demon-add-handler 'dcbl-gnus-idle-daemon 1 nil)
I changed the last parameter to nil, so the daemon routine is called
every minute. If the system has been idle, or not.
The routine itself (which calls other functions again) is:
(defun dcbl-gnus-idle-daemon ()
"Do potential time consuming things when Emacs is idle;
At the moment:
- dcbl-gnus-delay-send-queue
- gnus-group-get-new-news.
- gnus-group-expire-all-groups"
(setq dcbl-gnus-current-log-format 'start)
(let ((log-enter-and-leave (and (integerp dcbl-gnus-idle-daemon-do-log)
(>= dcbl-gnus-idle-daemon-do-log 10)))
(start-time (current-time)))
(when log-enter-and-leave
(dcbl-gnus-log-message (format "Starting gnus-idle-daemon (%s, %s)"
(current-time) (current-idle-time))))
(when (and dcbl-gnus-idle-daemon-semafoor
(>= (time-difference dcbl-gnus-idle-daemon-semafoor (current-time))
(* 15 +seconds-in-minute+)))
(setq dcbl-gnus-current-log-format 'start)
(dcbl-gnus-log-message "ERROR: Needed to reset gnus-idle-daemon-semafoor")
(setq dcbl-gnus-idle-daemon-semafoor nil))
(unless dcbl-gnus-idle-daemon-semafoor
(setq dcbl-gnus-idle-daemon-semafoor (current-time))
(condition-case err
;; Protected form.
(dolist (poll-element dcbl-gnus-poll-struct)
(dcbl-gnus-idle-daemon-call-function poll-element))
;; The handler.
(error
(dcbl-gnus-log-message (format
"Error in dcbl-gnus-idle-daemon dolist: %s"
err))
nil))
(setq dcbl-gnus-idle-daemon-semafoor nil))
(when log-enter-and-leave
(dcbl-gnus-log-message (format "Leaving gnus-idle-daemon (%s, %s)"
(time-difference-formatted start-time)
(current-idle-time))))))
When not using Emacs, but playing a video through mpv, I get:
2018-01-10 22:32:35: Starting gnus-idle-daemon ((23126 34419 369076 610000), (0 0 658640 85000))
22:32:36: Leaving gnus-idle-daemon (1 second, (0 1 392452 151000))
2018-01-10 22:33:35: Starting gnus-idle-daemon ((23126 34479 369090 736000), (0 0 753334 161000))
22:33:36: Leaving gnus-idle-daemon (1 second, (0 1 562405 319000))
2018-01-10 22:34:35: Starting gnus-idle-daemon ((23126 34539 368969 98000), (0 0 673375 295000))
22:34:36: Leaving gnus-idle-daemon (1 second, (0 1 432972 290000))
So mpv looks to make Emacs think it is not idle at all.
After this I let Emacs be idle for a few minutes and this gave the
following:
2018-01-10 22:42:35: Starting gnus-idle-daemon ((23126 35019 371985 309000), (0 59 125327 787000))
22:42:36: Leaving gnus-idle-daemon (1 second, (0 60 16979 177000))
2018-01-10 22:43:35: Starting gnus-idle-daemon ((23126 35079 371650 415000), (0 59 52674 710000))
22:43:36: Leaving gnus-idle-daemon (1 second, (0 59 827891 167000))
2018-01-10 22:44:35: Starting gnus-idle-daemon ((23126 35139 370952 276000), (0 59 165616 289000))
22:44:36: Leaving gnus-idle-daemon (1 second, (0 59 913835 893000))
2018-01-10 22:45:35: Starting gnus-idle-daemon ((23126 35199 371468 342000), (0 59 196502 494000))
22:45:36: Leaving gnus-idle-daemon (1 second, (0 60 8895 962000))
So my routine does nothing to change idle time, but when coming back,
it is as if idle time was reset.