From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id iKA9JlHZbWVsRwAAauVa8A:P1 (envelope-from ) for ; Mon, 04 Dec 2023 14:51:13 +0100 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id iKA9JlHZbWVsRwAAauVa8A (envelope-from ) for ; Mon, 04 Dec 2023 14:51:13 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 4FE4244A7D for ; Mon, 4 Dec 2023 14:51:13 +0100 (CET) Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=cK3NHW3M; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1701697873; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=Pi0wXRq9lVfnkOMct9TP/c16pYTVSH9SfohbeRyplfE=; b=Pg96mRcyQUYX3Hq4tlzhmbuVLgXTdUUUSgLJwVFiuCRqCZH89YZnovyVBwEnVbWVrIh0Pt /WEttMdQhoqT0g42La6eV6lMonEPHwCet2Vvo5YfubflUAmrc81BVrzxsdcjZlNe2q5m8M ob/l5wvP/64EEtyUhzafkBZJwLBE6CXZo+6CwduHrAD3s4RcDMKSmip1sbdivaHKt8d9ie rPJnrQ9BwywDJLP+M1UyNBdE+8L/aEK1zQZubj0pbS/sTgQShRJTB8OBJZuf4nf8Dh2Ivw Q8xZAinzuQoIpXQ2aHr0nDPvFnG6UPzeAdFkDWyfKAhwFsgn1a2bxkkCYWUerg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1701697873; a=rsa-sha256; cv=none; b=u2ogSCRLTLzmHPTa+UT3+5fAhBcNyeO/UWyG//YpAHalRur5GZQjTAiqsfVudeFy4If8JP rI0nDJxXOL98RTWrkV4qI2J+SnR/Ye5EutYQu/r53TmADcbx+echZ2P7+Pjoyombzqfxqv ChLCgPrhzWi0Q+/fL6hsNINduSvKyPGeZnq9ZY83WSpEiEwVnECG+QcQ+YO6jaGDNq1Q4D OQNvrye26BJ/kKWEL6I0znD9Kn+LsxvBQ1+vZWIVed8+dzHzq0pdccViz7Evx4VpPmPc2s HEkI2uwSKH9HwnEWv0QYhsl8IHGhQ+vWJRti9vd0l9S+pqyHwlPPBNzhcrtSrA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=cK3NHW3M; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rA9LB-0006yy-NM; Mon, 04 Dec 2023 08:50:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rA9L8-0006yW-SV for emacs-orgmode@gnu.org; Mon, 04 Dec 2023 08:50:26 -0500 Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rA9L6-0004Ti-97 for emacs-orgmode@gnu.org; Mon, 04 Dec 2023 08:50:26 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 4C6C2240101 for ; Mon, 4 Dec 2023 14:50:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1701697821; bh=kE14UcnOh+FlrnTZttjBu7yCOY19sW2NKcOQqdeL8Vg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:From; b=cK3NHW3MERewxuhNZFZcSx5TOtDcUqGhHGjd1I5PxcD0sdjvTu2vtw50Xpv0RiJAo c3pTAoQc/YUfYBfuO+1AfZqtiPTWJsefhz3h0BX+2ZUbp50Oi2HHm7TXJuq8esRPyr 3lENMJMFFjWCgwHtVHkJKJkqPKCHBxvul8d4++We/8qOXoWnd9SqqaBGrhGsheMi1G Z7xCSIIjgDAPkCc7KCSn9uQjp0bhye7FWjNox9EjbFs38SInGXbzJJeG+JxhG2mOBj hDB8SZ0J73np0Iel0zOVQC8aLR0UJAAuLCj5pHRJ+iQl4l3cjAq2nCQB0N3400meuq TdidPPG3ANysA== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4SkQ644Cmgz6txg; Mon, 4 Dec 2023 14:50:20 +0100 (CET) From: Ihor Radchenko To: Vladimir Nikishkin Cc: emacs-orgmode@gnu.org Subject: Re: [BUG] org-clock-auto-clockout does not actually use x11idle on X11 [9.6.8 (release_9.6.8-3-g21171d @ /usr/share/emacs/30.0.50/lisp/org/)] In-Reply-To: <875y38b8ay.fsf@localhost> References: <87ttqv6l2g.fsf@laptop.lockywolf.net> <875y38b8ay.fsf@localhost> Date: Mon, 04 Dec 2023 13:53:19 +0000 Message-ID: <87il5em5v4.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.66; envelope-from=yantar92@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Scanner: mx11.migadu.com X-Migadu-Spam-Score: -9.35 X-Spam-Score: -9.35 X-Migadu-Queue-Id: 4FE4244A7D X-TUID: mBzWS8diOKt4 --=-=-= Content-Type: text/plain Ihor Radchenko writes: > Vladimir Nikishkin writes: > >> For some time I have been wondering why auto-clockout does not use >> x11idle on my machine. >> ... Attaching a tentative fix. It would help if someone can test it on other machine. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-org-clock-auto-clockout-Honor-system-idle-time.-Do-n.patch >From d655c095fda6d1789a20aa93d4ac3a5f269dadc9 Mon Sep 17 00:00:00 2001 Message-ID: From: Ihor Radchenko Date: Mon, 4 Dec 2023 14:47:53 +0100 Subject: [PATCH] org-clock-auto-clockout: Honor system idle time. Do not spawn multiple timers * lisp/org-clock.el (org-clock--auto-clockout-timer-obj): New internal variable holding the auto-clockout timer. (org-clock--auto-clockout-maybe): New function to be used in timer. Use `org-user-idle-seconds' to check for idleness. Make sure that we correctly handle system idle time, which may be lesser than Emacs idle time. (org-clock-auto-clockout): Do not create duplicate timers. Use the new internal helper function. Reported-by: Vladimir Nikishkin Link: https://orgmode.org/list/87ttqv6l2g.fsf@laptop.lockywolf.net --- lisp/org-clock.el | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/lisp/org-clock.el b/lisp/org-clock.el index eda312d74..a042af4f3 100644 --- a/lisp/org-clock.el +++ b/lisp/org-clock.el @@ -1493,6 +1493,33 @@ (defun org-clock-in (&optional select start-time) (message "Clock starts at %s - %s" ts org--msg-extra) (run-hooks 'org-clock-in-hook)))))) +(defvar org-clock--auto-clockout-timer-obj nil + "Timer object holding the existing clockout timer.") +(defun org-clock--auto-clockout-maybe () + "Clock out the currently clocked in task when idle. +See `org-clock-auto-clockout-timer' to set the idle time span. + +This function is to be called by a timer." + (when (and (numberp org-clock-auto-clockout-timer) + org-clock-current-task) + (let ((user-idle-seconds (org-user-idle-seconds))) + (cond + ;; Already idle. Clock out. + ((>= user-idle-seconds org-clock-auto-clockout-timer) + (setq org-clock--auto-clockout-timer-obj nil) + (org-clock-out)) + ;; Emacs is idle but system is not. Retry assuming that system will remain idle. + ((>= (org-emacs-idle-seconds) org-clock-auto-clockout-timer) + (setq org-clock--auto-clockout-timer-obj + (run-with-timer + (- org-clock-auto-clockout-timer user-idle-seconds) + nil #'org-clock--auto-clockout-maybe))) + ;; Emacs is not idle. Check again next time we are idle. + (t + (setq org-clock--auto-clockout-timer-obj + (run-with-idle-timer + org-clock-auto-clockout-timer nil #'org-clock--auto-clockout-maybe))))))) + (defun org-clock-auto-clockout () "Clock out the currently clocked in task if Emacs is idle. See `org-clock-auto-clockout-timer' to set the idle time span. @@ -1500,9 +1527,11 @@ (defun org-clock-auto-clockout () This is only effective when `org-clock-auto-clockout-insinuate' is present in the user configuration." (when (and (numberp org-clock-auto-clockout-timer) - org-clock-current-task) - (run-with-idle-timer - org-clock-auto-clockout-timer nil #'org-clock-out))) + org-clock-current-task + (not (timerp org-clock--auto-clockout-timer-obj))) + (setq org-clock--auto-clockout-timer-obj + (run-with-idle-timer + org-clock-auto-clockout-timer nil #'org-clock--auto-clockout-maybe)))) ;;;###autoload (defun org-clock-toggle-auto-clockout () -- 2.42.0 --=-=-= Content-Type: text/plain -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at --=-=-=--