[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] org-user-idle-seconds: Add support for logind

From: Nathaniel Nicandro
Subject: [PATCH] org-user-idle-seconds: Add support for logind
Date: Tue, 21 Mar 2023 10:39:52 -0500
User-agent: mu4e 1.8.13; emacs 28.2


I would like to submit a patch that adds support for logind to
`org-user-idle-seconds`.  This patch has been working for me for a long
while now and I thought it time for me to submit it.  I've contributed
to Emacs in the past so my paperwork should be on file.

Let me know if any changes should be made.

lisp/org-clock.el | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index f869b0b..9d34a72 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -51,6 +51,9 @@ (declare-function org-table-goto-line "org-table" (n))
 (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 
 (defvar org-frame-title-format-backup nil)
 (defvar org-state)
@@ -1214,6 +1217,25 @@ (defun org-x11-idle-seconds ()
   "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))))
+(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 +1244,13 @@ (defun org-user-idle-seconds ()
    ((and (eq window-system 'x) org-x11idle-exists-p)
+   ((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))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]