From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carsten Dominik Subject: Re: [PATCH 1/2] Add an X11 equivalent to org-mac-idle-seconds. Date: Thu, 22 Oct 2009 15:16:52 +0200 Message-ID: <3C44EFF7-9FAA-47AA-8DD4-51A798C33A78@gmail.com> References: <1256118769-787-1-git-send-email-ahktenzero@mohorovi.cc> <1256118769-787-2-git-send-email-ahktenzero@mohorovi.cc> Mime-Version: 1.0 (Apple Message framework v936) Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N0xXO-0006E8-U0 for emacs-orgmode@gnu.org; Thu, 22 Oct 2009 09:17:07 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N0xXJ-0006Br-1t for emacs-orgmode@gnu.org; Thu, 22 Oct 2009 09:17:05 -0400 Received: from [199.232.76.173] (port=42957 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N0xXI-0006BW-Au for emacs-orgmode@gnu.org; Thu, 22 Oct 2009 09:17:00 -0400 Received: from postduif.ic.uva.nl ([145.18.40.180]:50471) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N0xXH-0004Cb-Oq for emacs-orgmode@gnu.org; Thu, 22 Oct 2009 09:17:00 -0400 In-Reply-To: <1256118769-787-2-git-send-email-ahktenzero@mohorovi.cc> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: James TD Smith Cc: emacs-orgmode@gnu.org Applied, thanks. - Carsten On Oct 21, 2009, at 11:52 AM, James TD Smith wrote: > This needs a small C program (in UTILITIES/x11idle.c) to work. > --- > .gitignore | 1 + > ChangeLog | 6 +++++- > UTILITIES/x11idle.c | 21 +++++++++++++++++++++ > lisp/ChangeLog | 8 +++++++- > lisp/org-clock.el | 10 ++++++++-- > 5 files changed, 42 insertions(+), 4 deletions(-) > create mode 100644 UTILITIES/x11idle.c > > diff --git a/.gitignore b/.gitignore > index ab68b2a..c21fc91 100644 > --- a/.gitignore > +++ b/.gitignore > @@ -58,3 +58,4 @@ TODO > # fill-column: 72 > # mode: conf > # End: > +/UTILITIES/x11idle > diff --git a/ChangeLog b/ChangeLog > index 95387ea..77cca37 100644 > --- a/ChangeLog > +++ b/ChangeLog > @@ -1,3 +1,8 @@ > +2009-10-21 James TD Smith > + > + * UTILITIES/x11idle.c: Add a small C program which outputs the X11 > + idle time > + > 2009-09-16 Carsten Dominik > > * Makefile: Add dependencies for org-crypt.el. > @@ -65,4 +70,3 @@ > 2008-04-25 Carsten Dominik > > * Makefile (BATCH): Fix the path to the local lisp files. > - > diff --git a/UTILITIES/x11idle.c b/UTILITIES/x11idle.c > new file mode 100644 > index 0000000..33d0035 > --- /dev/null > +++ b/UTILITIES/x11idle.c > @@ -0,0 +1,21 @@ > +#include > +#include > + > +/* Based on code from > + * http://coderrr.wordpress.com/2008/04/20/getting-idle-time-in-unix/ > + * > + * compile with 'gcc -l Xss x11idle.c -o x11idle' and copy x11idle > into your > + * path > + */ > +main() { > + XScreenSaverInfo *info = XScreenSaverAllocInfo(); > + Display *display = XOpenDisplay(0); > + > + //check that X11 is running or else you get a segafult/coredump > + if (display != NULL) { > + XScreenSaverQueryInfo(display, DefaultRootWindow(display), info); > + } > + XScreenSaverQueryInfo(display, DefaultRootWindow(display), info); > + printf("%u\n", info->idle); > + return 0; > +} > diff --git a/lisp/ChangeLog b/lisp/ChangeLog > index bcd6a8a..75bdc38 100755 > --- a/lisp/ChangeLog > +++ b/lisp/ChangeLog > @@ -37,6 +37,12 @@ > modeline when habits are being displayed (if that module is being > loaded). > > +2009-10-21 James TD Smith > + > + * org-clock.el (org-x11-idle-seconds): Add a method to get the X11 > + idle time using the xscreensaver extension. > + (org-user-idle-seconds): Use X11 idle time if available. > + > 2009-10-20 Carsten Dominik > > * org-agenda.el (org-agenda-next-line): New command. > @@ -161,7 +167,7 @@ > currently active clock if the user has exceeded the time returned > by `org-user-idle-seconds', based on the value of > `org-clock-idle-time'. > - (org-clock-in): If, after resolving clocks, > + (org-clock-in): If, after resolving clocks, > (org-clock-out): Cancel the `org-clock-idle-timer' on clock out. > > * org-clock.el (org-clock-resolve-clock): New function that > diff --git a/lisp/org-clock.el b/lisp/org-clock.el > index c7ebbf8..fddf3f8 100644 > --- a/lisp/org-clock.el > +++ b/lisp/org-clock.el > @@ -762,16 +762,22 @@ non-dangling (i.e., currently open and valid) > clocks." > "Return the current Mac idle time in seconds" > (string-to-number (shell-command-to-string "ioreg -c IOHIDSystem | > perl -ane 'if (/Idle/) {$idle=(pop @F)/1000000000; print $idle; > last}'"))) > > +(defun org-x11-idle-seconds () > + "Return the current X11 idle time in seconds" > + (/ (string-to-number (shell-command-to-string "x11idle")) 1000)) > + > (defun org-user-idle-seconds () > "Return the number of seconds the user has been idle for. > This routine returns a floating point number." > - (if (eq system-type 'darwin) > + (if (or (eq system-type 'darwin) (eq window-system 'x)) > (let ((emacs-idle (org-emacs-idle-seconds))) > ;; If Emacs has been idle for longer than the user's > ;; `org-clock-idle-time' value, check whether the whole system has > ;; really been idle for that long. > (if (> emacs-idle (* 60 org-clock-idle-time)) > - (min emacs-idle (org-mac-idle-seconds)) > + (min emacs-idle (if (eq system-type 'darwin) > + (org-mac-idle-seconds) > + (org-x11-idle-seconds))) > emacs-idle)) > (org-emacs-idle-seconds))) > > -- > 1.6.3.3 > > > > _______________________________________________ > Emacs-orgmode mailing list > Remember: use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode - Carsten