* org-clock idle time in pgtk Emacs @ 2022-05-24 8:32 Julien Cubizolles 2022-05-24 10:27 ` Tim Cross 2022-05-25 6:38 ` Ihor Radchenko 0 siblings, 2 replies; 11+ messages in thread From: Julien Cubizolles @ 2022-05-24 8:32 UTC (permalink / raw) To: emacs-orgmode org-clock checks for the 'x window-system in order to use the program set up by org-clock-x11idle-program-name. Recent Emacs versions use the 'pgtk instead of 'x and as such will default to using org-emacs-idle-seconds in org-user-idle-seconds. The following patch provides a crude workaround. I'm using a python program (included below) to report idletime in wayland, using the idle-time module. It can be used for org-clock-x11idle-program-name. --8<---------------cut here---------------start------------->8--- modified lisp/org-clock.el @@ -1196,7 +1196,7 @@ If `only-dangling-p' is non-nil, only ask to resolve dangling (defvar org-x11idle-exists-p ;; Check that x11idle exists - (and (eq window-system 'x) + (and (or (eq window-system 'pgtk) (eq window-system 'x)) (eq 0 (call-process-shell-command (format "command -v %s" org-clock-x11idle-program-name))) ;; Check that x11idle can retrieve the idle time @@ -1213,7 +1213,7 @@ This routine returns a floating point number." (cond ((eq system-type 'darwin) (org-mac-idle-seconds)) - ((and (eq window-system 'x) org-x11idle-exists-p) + ((and (or (eq window-system 'x) (eq window-system 'pgtk)) org-x11idle-exists-p) (org-x11-idle-seconds)) (t (org-emacs-idle-seconds)))) --8<---------------cut here---------------end--------------->8--- --8<---------------cut here---------------start------------->8--- #!/usr/bin/env python3 from idle_time import IdleMonitor monitor = IdleMonitor.get_monitor() print(f"{1000*monitor.get_idle_time():.0f}") --8<---------------cut here---------------end--------------->8--- -- Julien Cubizolles ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: org-clock idle time in pgtk Emacs 2022-05-24 8:32 org-clock idle time in pgtk Emacs Julien Cubizolles @ 2022-05-24 10:27 ` Tim Cross 2022-05-25 6:38 ` Ihor Radchenko 1 sibling, 0 replies; 11+ messages in thread From: Tim Cross @ 2022-05-24 10:27 UTC (permalink / raw) To: emacs-orgmode Julien Cubizolles <j.cubizolles@free.fr> writes: > org-clock checks for the 'x window-system in order to use the program > set up by org-clock-x11idle-program-name. Recent Emacs versions use the > 'pgtk instead of 'x and as such will default to using > org-emacs-idle-seconds in org-user-idle-seconds. > I"m not sure this is accurate. You should only use the pgtk build of Emacs if your running wayland. You definitely should not use it if your running under X. The big issue is that some important key input facilities don't work correctly if you run the pgtk build under X (actually, I'm not sure they work correctly under Wayland either, but then again, Wayland is a different beast to X and differences can be expected). The pgtk build is not a replacement for the current xlib+gtk build, which will remain the correct build when running under X. Unfortunately, this does mean that if you use both X and Wayland, you likely will need two builds of Emacs. There was a fairly long discussion thread about this on emacs-devel about a month or so ago. The upshot was flagging the need to update the documentation to clarify that people should not use the pgtk build when running under X windows. I suspect this means the below patch will need further refinement. > The following patch provides a crude workaround. > > I'm using a python program (included below) to report idletime in > wayland, using the idle-time module. It can be used for > org-clock-x11idle-program-name. > > modified lisp/org-clock.el > @@ -1196,7 +1196,7 @@ If `only-dangling-p' is non-nil, only ask to resolve dangling > > (defvar org-x11idle-exists-p > ;; Check that x11idle exists > - (and (eq window-system 'x) > + (and (or (eq window-system 'pgtk) (eq window-system 'x)) > (eq 0 (call-process-shell-command > (format "command -v %s" org-clock-x11idle-program-name))) > ;; Check that x11idle can retrieve the idle time > @@ -1213,7 +1213,7 @@ This routine returns a floating point number." > (cond > ((eq system-type 'darwin) > (org-mac-idle-seconds)) > - ((and (eq window-system 'x) org-x11idle-exists-p) > + ((and (or (eq window-system 'x) (eq window-system 'pgtk)) org-x11idle-exists-p) > (org-x11-idle-seconds)) > (t > (org-emacs-idle-seconds)))) > > #!/usr/bin/env python3 > > from idle_time import IdleMonitor > > monitor = IdleMonitor.get_monitor() > print(f"{1000*monitor.get_idle_time():.0f}") ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: org-clock idle time in pgtk Emacs 2022-05-24 8:32 org-clock idle time in pgtk Emacs Julien Cubizolles 2022-05-24 10:27 ` Tim Cross @ 2022-05-25 6:38 ` Ihor Radchenko 2023-01-31 16:24 ` Julien Cubizolles 1 sibling, 1 reply; 11+ messages in thread From: Ihor Radchenko @ 2022-05-25 6:38 UTC (permalink / raw) To: Julien Cubizolles; +Cc: emacs-orgmode Julien Cubizolles <j.cubizolles@free.fr> writes: > org-clock checks for the 'x window-system in order to use the program > set up by org-clock-x11idle-program-name. Recent Emacs versions use the > 'pgtk instead of 'x and as such will default to using > org-emacs-idle-seconds in org-user-idle-seconds. > > The following patch provides a crude workaround. > > I'm using a python program (included below) to report idletime in > wayland, using the idle-time module. It can be used for > org-clock-x11idle-program-name. Thanks for the patch! As Tim pointed out, we cannot guarantee that things working on 'x build will also work on 'pgtk. Instead of abusing settings for 'x window system, can you please introduce a new function org-pgtk-idle-seconds using a new variable org-clock-pgtkidle-program-name, similar to org-x11-idle-seconds, and then update org-user-idle-seconds? Please, make sure that the pgtk option works on Wayland as well (or not, but we will then need to wait until someone tests the patch on Wayland). Best, Ihor ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: org-clock idle time in pgtk Emacs 2022-05-25 6:38 ` Ihor Radchenko @ 2023-01-31 16:24 ` Julien Cubizolles 2023-02-01 13:15 ` Ihor Radchenko 0 siblings, 1 reply; 11+ messages in thread From: Julien Cubizolles @ 2023-01-31 16:24 UTC (permalink / raw) To: emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 447 bytes --] Ihor Radchenko <yantar92@gmail.com> writes: > > As Tim pointed out, we cannot guarantee that things working on 'x build > will also work on 'pgtk. Instead of abusing settings for 'x window > system, can you please introduce a new function org-pgtk-idle-seconds > using a new variable org-clock-pgtkidle-program-name, similar to > org-x11-idle-seconds, and then update org-user-idle-seconds? Sorry for the delay, here is a patch to that effect. [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: org-clock.patch --] [-- Type: text/x-diff, Size: 2641 bytes --] diff --git a/lisp/org-clock.el b/lisp/org-clock.el index ceb1fc833..81be37448 100644 --- a/lisp/org-clock.el +++ b/lisp/org-clock.el @@ -453,6 +453,15 @@ https://orgmode.org/worg/code/scripts/x11idle.c" :package-version '(Org . "9.7") :type 'string) +(defcustom org-clock-pgtkidle-program-name + (if (executable-find "jc-idle-time") + "jc-idle-time") + "Name of the program which prints idle time in milliseconds. +Case of a pgtk Emacs instance." + :group 'org-clock + :package-version '(Org . "9.7") + :type 'string) + (defcustom org-clock-goto-before-context 2 "Number of lines of context to display before currently clocked-in entry. This applies when using `org-clock-goto'." @@ -1199,6 +1208,17 @@ If `only-dangling-p' is non-nil, only ask to resolve dangling "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}'"))) +(defvar org-pgtkidle-exists-p + ;; Check that org-clock-pgtkidle-program-name exists. But don't do that on DOS/Windows, + ;; since the command definitely does NOT exist there, and invoking + ;; COMMAND.COM on MS-Windows is a bad idea -- it hangs. + (and (null (memq system-type '(windows-nt ms-dos))) + (eq 0 (call-process-shell-command + (format "command -v %s" org-clock-pgtkidle-program-name))) + ;; Check that x11idle can retrieve the idle time + ;; FIXME: Why "..-shell-command" rather than just `call-process'? + (eq 0 (call-process-shell-command org-clock-pgtkidle-program-name)))) + (defvar org-x11idle-exists-p ;; Check that x11idle exists. But don't do that on DOS/Windows, ;; since the command definitely does NOT exist there, and invoking @@ -1214,6 +1234,10 @@ 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)) +(defun org-pgtk-idle-seconds () + "Return the current X11 idle time in seconds." + (/ (string-to-number (shell-command-to-string org-clock-pgtkidle-program-name)) 1000)) + (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 +1246,8 @@ 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 (eq window-system 'pgtk) org-pgtkidle-exists-p) + (org-pgtk-idle-seconds)) (t (org-emacs-idle-seconds)))) [-- Attachment #3: Type: text/plain, Size: 219 bytes --] > Please, make sure that the pgtk option works on Wayland as well (or not, > but we will then need to wait until someone tests the patch on Wayland). It's working in Wayland, with a pgtk build. -- Julien Cubizolles ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: org-clock idle time in pgtk Emacs 2023-01-31 16:24 ` Julien Cubizolles @ 2023-02-01 13:15 ` Ihor Radchenko 2023-02-01 15:45 ` Max Nikulin 2023-02-03 5:55 ` Julien Cubizolles 0 siblings, 2 replies; 11+ messages in thread From: Ihor Radchenko @ 2023-02-01 13:15 UTC (permalink / raw) To: Julien Cubizolles; +Cc: emacs-orgmode Julien Cubizolles <j.cubizolles@free.fr> writes: > Ihor Radchenko <yantar92@gmail.com> writes: > >> >> As Tim pointed out, we cannot guarantee that things working on 'x build >> will also work on 'pgtk. Instead of abusing settings for 'x window >> system, can you please introduce a new function org-pgtk-idle-seconds >> using a new variable org-clock-pgtkidle-program-name, similar to >> org-x11-idle-seconds, and then update org-user-idle-seconds? > > Sorry for the delay, here is a patch to that effect. Thanks! > +(defcustom org-clock-pgtkidle-program-name > + (if (executable-find "jc-idle-time") > + "jc-idle-time") > + "Name of the program which prints idle time in milliseconds. May I know where "jc-idle-time" is coming from? Is it a built-in command on wayland? > +(defvar org-pgtkidle-exists-p > + ;; Check that org-clock-pgtkidle-program-name exists. But don't do that on DOS/Windows, > + ;; since the command definitely does NOT exist there, and invoking > + ;; COMMAND.COM on MS-Windows is a bad idea -- it hangs. > + (and (null (memq system-type '(windows-nt ms-dos))) > + (eq 0 (call-process-shell-command > + (format "command -v %s" org-clock-pgtkidle-program-name))) > + ;; Check that x11idle can retrieve the idle time > + ;; FIXME: Why "..-shell-command" rather than just `call-process'? > + (eq 0 (call-process-shell-command org-clock-pgtkidle-program-name)))) We may as well resolve this FIXME since we are at it. Instead of the awkward combination of two `call-process-shell-command' prompts, we can simply use `executable-find' + `call-process'. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at <https://orgmode.org/>. Support Org development at <https://liberapay.com/org-mode>, or support my work at <https://liberapay.com/yantar92> ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: org-clock idle time in pgtk Emacs 2023-02-01 13:15 ` Ihor Radchenko @ 2023-02-01 15:45 ` Max Nikulin 2023-02-02 9:17 ` Ihor Radchenko 2023-02-03 5:55 ` Julien Cubizolles 1 sibling, 1 reply; 11+ messages in thread From: Max Nikulin @ 2023-02-01 15:45 UTC (permalink / raw) To: emacs-orgmode; +Cc: Julien Cubizolles On 01/02/2023 20:15, Ihor Radchenko wrote: >> +(defcustom org-clock-pgtkidle-program-name >> + (if (executable-find "jc-idle-time") >> + "jc-idle-time") >> + "Name of the program which prints idle time in milliseconds. > > May I know where "jc-idle-time" is coming from? Is it a built-in command > on wayland? During discussion in the later thread Julien Cubizolles to emacs-orgmode. org-x11idle-exists-p with emacs --daemon. Fri, 28 Oct 2022 00:31:23 +0200. https://list.orgmode.org/871qqs6gqs.fsf@free.fr I noticed a suggestion to use a d-bus method, unfortunately it is Gnome-specific https://unix.stackexchange.com/questions/396911/how-can-i-tell-if-a-user-is-idle-in-wayland/ dbus-send --print-reply --dest=org.gnome.Mutter.IdleMonitor /org/gnome/Mutter/IdleMonitor/Core org.gnome.Mutter.IdleMonitor.GetIdletime Another interface likely may give not really reliable results: org.freedesktop.ScreenSaver GetSessionIdleTime https://lists.freedesktop.org/archives/xdg/2007-March/009187.html Stephan Kulow. screensaver dbus interfaces. Mon Mar 5 05:16:39 PST 2007 Unsure if some workaround like in xprintidle should be used on this way: https://github.com/g0hl1n/xprintidle/blob/master/xprintidle.c#L150 * Workaround: Check if if XServer is in a dpms state, check the * current timeout for this state and add this value to * the current idle time and return. */ >> +(defvar org-pgtkidle-exists-p >> + ;; Check that org-clock-pgtkidle-program-name exists. But don't do that on DOS/Windows, >> + ;; since the command definitely does NOT exist there, and invoking >> + ;; COMMAND.COM on MS-Windows is a bad idea -- it hangs. >> + (and (null (memq system-type '(windows-nt ms-dos))) >> + (eq 0 (call-process-shell-command >> + (format "command -v %s" org-clock-pgtkidle-program-name))) >> + ;; Check that x11idle can retrieve the idle time >> + ;; FIXME: Why "..-shell-command" rather than just `call-process'? >> + (eq 0 (call-process-shell-command org-clock-pgtkidle-program-name)))) > > We may as well resolve this FIXME since we are at it. > Instead of the awkward combination of two `call-process-shell-command' > prompts, we can simply use `executable-find' + `call-process'. Is there a reasonable way to avoid code duplication? I agree that `executable-find' may be better since `org-clock-pgtkidle-program-name' might contain spaces or shell specials causing issues with current code. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: org-clock idle time in pgtk Emacs 2023-02-01 15:45 ` Max Nikulin @ 2023-02-02 9:17 ` Ihor Radchenko 0 siblings, 0 replies; 11+ messages in thread From: Ihor Radchenko @ 2023-02-02 9:17 UTC (permalink / raw) To: Max Nikulin; +Cc: emacs-orgmode, Julien Cubizolles Max Nikulin <manikulin@gmail.com> writes: >>> +(defvar org-pgtkidle-exists-p >>> + ;; Check that org-clock-pgtkidle-program-name exists. But don't do that on DOS/Windows, >>> + ;; since the command definitely does NOT exist there, and invoking >>> + ;; COMMAND.COM on MS-Windows is a bad idea -- it hangs. >>> + (and (null (memq system-type '(windows-nt ms-dos))) >>> + (eq 0 (call-process-shell-command >>> + (format "command -v %s" org-clock-pgtkidle-program-name))) >>> + ;; Check that x11idle can retrieve the idle time >>> + ;; FIXME: Why "..-shell-command" rather than just `call-process'? >>> + (eq 0 (call-process-shell-command org-clock-pgtkidle-program-name)))) >> >> We may as well resolve this FIXME since we are at it. >> Instead of the awkward combination of two `call-process-shell-command' >> prompts, we can simply use `executable-find' + `call-process'. > > Is there a reasonable way to avoid code duplication? I agree that > `executable-find' may be better since `org-clock-pgtkidle-program-name' > might contain spaces or shell specials causing issues with current code. I do not think that we should avoid code duplication here. pgtk and x11 is principally different. The fact that the same code works for them is rather a co-incidence. It is unlikely that a new window-system is going to use the same code again. And de-duplicating jut two functions is not worth it. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at <https://orgmode.org/>. Support Org development at <https://liberapay.com/org-mode>, or support my work at <https://liberapay.com/yantar92> ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: org-clock idle time in pgtk Emacs 2023-02-01 13:15 ` Ihor Radchenko 2023-02-01 15:45 ` Max Nikulin @ 2023-02-03 5:55 ` Julien Cubizolles 2023-02-03 12:17 ` Ihor Radchenko 1 sibling, 1 reply; 11+ messages in thread From: Julien Cubizolles @ 2023-02-03 5:55 UTC (permalink / raw) To: emacs-orgmode Ihor Radchenko <yantar92@posteo.net> writes: >> +(defcustom org-clock-pgtkidle-program-name >> + (if (executable-find "jc-idle-time") >> + "jc-idle-time") >> + "Name of the program which prints idle time in milliseconds. > > May I know where "jc-idle-time" is coming from? Is it a built-in command > on wayland? Sorry, I forgot to mention. It's a custom python program, working both in X11 and wayland. I didn't find a built-in command. --8<---------------cut here---------------start------------->8--- #!/usr/bin/env python3 from idle_time import IdleMonitor monitor = IdleMonitor.get_monitor() print(f"{1000*monitor.get_idle_time():.0f}") --8<---------------cut here---------------end--------------->8--- -- Julien Cubizolles ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: org-clock idle time in pgtk Emacs 2023-02-03 5:55 ` Julien Cubizolles @ 2023-02-03 12:17 ` Ihor Radchenko 2023-02-03 15:07 ` Max Nikulin 0 siblings, 1 reply; 11+ messages in thread From: Ihor Radchenko @ 2023-02-03 12:17 UTC (permalink / raw) To: Julien Cubizolles; +Cc: emacs-orgmode Julien Cubizolles <j.cubizolles@free.fr> writes: >> May I know where "jc-idle-time" is coming from? Is it a built-in command >> on wayland? > > Sorry, I forgot to mention. It's a custom python program, working both > in X11 and wayland. I didn't find a built-in command. I would prefer something built-in or, at least, available via OS' package manager. > --8<---------------cut here---------------start------------->8--- > #!/usr/bin/env python3 > > from idle_time import IdleMonitor > > monitor = IdleMonitor.get_monitor() > print(f"{1000*monitor.get_idle_time():.0f}") > --8<---------------cut here---------------end--------------->8--- This does not look pgtk-specific. Is it? -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at <https://orgmode.org/>. Support Org development at <https://liberapay.com/org-mode>, or support my work at <https://liberapay.com/yantar92> ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: org-clock idle time in pgtk Emacs 2023-02-03 12:17 ` Ihor Radchenko @ 2023-02-03 15:07 ` Max Nikulin 2023-02-04 11:04 ` Ihor Radchenko 0 siblings, 1 reply; 11+ messages in thread From: Max Nikulin @ 2023-02-03 15:07 UTC (permalink / raw) To: Julien Cubizolles; +Cc: emacs-orgmode On 03/02/2023 19:17, Ihor Radchenko wrote: > Julien Cubizolles writes: > >>> May I know where "jc-idle-time" is coming from? Is it a built-in command >>> on wayland? >> >> Sorry, I forgot to mention. It's a custom python program, working both >> in X11 and wayland. I didn't find a built-in command. > > I would prefer something built-in or, at least, available via OS' > package manager. It seems, one can obtain the python package using pip install idle-time https://pypi.org/project/idle-time/ The issue is that the project has just 2 commits, a pull request for wider support of various environments is ignored by the author. The package already has CLI interface, but output format is not script-friendly: https://github.com/escaped/idle_time/blob/master/idle_time/__main__.py print(f"Idle time: {monitor.get_idle_time()}s") python3 -m idle-time > This does not look pgtk-specific. Is it? I see X11 and Windows in the implementation. xprintidle might be more reliable though. As to Org my opinion is still that a defcustom for user-defined function returning idle may be a better option. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: org-clock idle time in pgtk Emacs 2023-02-03 15:07 ` Max Nikulin @ 2023-02-04 11:04 ` Ihor Radchenko 0 siblings, 0 replies; 11+ messages in thread From: Ihor Radchenko @ 2023-02-04 11:04 UTC (permalink / raw) To: Max Nikulin; +Cc: Julien Cubizolles, emacs-orgmode Max Nikulin <manikulin@gmail.com> writes: > As to Org my opinion is still that a defcustom for user-defined function > returning idle may be a better option. Agree. If pgtk does not have to use something that absolutely needs to be pgtk-specific, we should rather introduce a generic customization. For example, a new `org-clock-idle-function' customization may accept Elisp function of a string (for a shell command), defaulting to `org-emacs-idle-seconds'. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at <https://orgmode.org/>. Support Org development at <https://liberapay.com/org-mode>, or support my work at <https://liberapay.com/yantar92> ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2023-02-04 11:05 UTC | newest] Thread overview: 11+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-05-24 8:32 org-clock idle time in pgtk Emacs Julien Cubizolles 2022-05-24 10:27 ` Tim Cross 2022-05-25 6:38 ` Ihor Radchenko 2023-01-31 16:24 ` Julien Cubizolles 2023-02-01 13:15 ` Ihor Radchenko 2023-02-01 15:45 ` Max Nikulin 2023-02-02 9:17 ` Ihor Radchenko 2023-02-03 5:55 ` Julien Cubizolles 2023-02-03 12:17 ` Ihor Radchenko 2023-02-03 15:07 ` Max Nikulin 2023-02-04 11:04 ` Ihor Radchenko
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.