I have a function that gets called when idle, but I would like it to run only when a frame has input focus.
My current work around is to use
focus-out-hook to change the behavior when idle, but I'd like to simplify it by just having one function that would check whether or not it had focus. Here's the code I am working with:
(use-package zone :ensure shut-up :commands (zone-when-idle) :bind ("C-c z" . zone) :init (setq zone-timeout 30) (defun zone-when-idle-and-focused () "Use with `focus-in-hook' to only zone when our focus is back in Emacs." (zone-when-idle (or zone-timeout 30))) (defun zone-nodoze () "Use with `focus-out-hook' so we don't zone when our focus is elsewhere." (let ((inhibit-message t)) (zone-leave-me-alone))) (add-hook 'focus-in-hook #'zone-when-idle-and-focused) (add-hook 'focus-out-hook #'zone-nodoze) (zone-when-idle zone-timeout))