branch: externals/org commit 693df6fd90daaa3c982450b5978d9c203d8b629f Author: Nathaniel Nicandro <nathanielnican...@gmail.com> Commit: Ihor Radchenko <yanta...@posteo.net>
lisp/org-clock.el: Add support for logind * lisp/org-timer.el (org-logind-dbus-session-path): New variable. (org-logind-user-idle-seconds): New function. (org-user-idle-seconds): Use them. * etc/ORG-NEWS (Add support for ~logind~ idle time in ~org-user-idle-seconds~): Document the new feature. --- etc/ORG-NEWS | 7 +++++++ lisp/org-clock.el | 30 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 4ca13af17b..4d45e65076 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -112,6 +112,13 @@ official [[https://clojure.org/guides/deps_and_cli][Clojure CLI tools]]. The command can be customized with ~ob-clojure-cli-command~. ** New features +*** Add support for ~logind~ idle time in ~org-user-idle-seconds~ + +When Emacs is built with =dbus= support and +the =org.freedesktop.login1= interface is available, fallback to +checking the =IdleSinceHint= property when +determining =org-user-idle-seconds= as the penultimate step. + *** ~org-metaup~ and ~org-metadown~ now act on headings in region When region is active and starts at a heading, ~org-metaup~ and diff --git a/lisp/org-clock.el b/lisp/org-clock.el index a300df8ff4..482b3c5a8f 100644 --- a/lisp/org-clock.el +++ b/lisp/org-clock.el @@ -51,6 +51,9 @@ (declare-function org-dynamic-block-define "org" (type func)) (declare-function w32-notification-notify "w32fns.c" (&rest params)) (declare-function w32-notification-close "w32fns.c" (&rest params)) +(declare-function dbus-list-activatable-names "dbus" (&optional bus)) +(declare-function dbus-call-method "dbus" (bus service path interface method &rest args)) +(declare-function dbus-get-property "dbus" (bus service path interface property)) (defvar org-frame-title-format-backup nil) (defvar org-state) @@ -1214,6 +1217,26 @@ If `only-dangling-p' is non-nil, only ask to resolve dangling "Return the current X11 idle time in seconds." (/ (string-to-number (shell-command-to-string org-clock-x11idle-program-name)) 1000)) +(defvar org-logind-dbus-session-path + (when (and (boundp 'dbus-runtime-version) + (require 'dbus nil t) + (member "org.freedesktop.login1" (dbus-list-activatable-names))) + (dbus-call-method + :system "org.freedesktop.login1" + "/org/freedesktop/login1" + "org.freedesktop.login1.Manager" + "GetSessionByPID" (emacs-pid))) + "D-Bus session path for the elogind interface.") + +(defun org-logind-user-idle-seconds () + "Return the number of idle seconds for the user according to logind." + (- (float-time) + (/ (dbus-get-property + :system "org.freedesktop.login1" + org-logind-dbus-session-path + "org.freedesktop.login1.Session" "IdleSinceHint") + 1e6))) + (defun org-user-idle-seconds () "Return the number of seconds the user has been idle for. This routine returns a floating point number." @@ -1222,6 +1245,13 @@ This routine returns a floating point number." (org-mac-idle-seconds)) ((and (eq window-system 'x) org-x11idle-exists-p) (org-x11-idle-seconds)) + ((and + org-logind-dbus-session-path + (dbus-get-property + :system "org.freedesktop.login1" + org-logind-dbus-session-path + "org.freedesktop.login1.Session" "IdleHint")) + (org-logind-user-idle-seconds)) (t (org-emacs-idle-seconds))))