From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id gLXPMdsXXmMXggAAbAwnHQ (envelope-from ) for ; Sun, 30 Oct 2022 07:21:15 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id GJmfMdsXXmPoMAAA9RJhRA (envelope-from ) for ; Sun, 30 Oct 2022 07:21:15 +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 952ED39B80 for ; Sun, 30 Oct 2022 07:21:15 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1op1gd-0005G7-Vu; Sun, 30 Oct 2022 02:20:48 -0400 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 1op1gZ-0005Fn-P7 for emacs-orgmode@gnu.org; Sun, 30 Oct 2022 02:20:44 -0400 Received: from ciao.gmane.io ([116.202.254.214]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1op1gY-0006bA-2p for emacs-orgmode@gnu.org; Sun, 30 Oct 2022 02:20:43 -0400 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1op1gV-00006Z-QI for emacs-orgmode@gnu.org; Sun, 30 Oct 2022 07:20:39 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: emacs-orgmode@gnu.org From: Max Nikulin Subject: Re: org-x11idle-exists-p with emacs --daemon Date: Sun, 30 Oct 2022 13:20:31 +0700 Message-ID: References: <871qqs6gqs.fsf@free.fr> <87y1t0lgfo.fsf@localhost> <87mt9egknp.fsf@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Content-Language: en-US In-Reply-To: <87mt9egknp.fsf@localhost> Received-SPF: pass client-ip=116.202.254.214; envelope-from=geo-emacs-orgmode@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: 26 X-Spam_score: 2.6 X-Spam_bar: ++ X-Spam_report: (2.6 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1, FORGED_MUA_MOZILLA=2.309, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, NICE_REPLY_A=-0.001, NML_ADSP_CUSTOM_MED=0.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Sender: "Emacs-orgmode" Errors-To: emacs-orgmode-bounces+larch=yhetil.org+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1667110875; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=RcNNPNxG7EfylHP0yr6pC90PkoJXsyN2GJM7mfNehbg=; b=E1G/bMp0MMeP4DcCO27I9yyLqWMFSESlyV0OGmM67BKT9DSa+SKYK53ROZ/q3iGH0gAPV/ nSMU1j8kIgikEClsfFGk5VYq2ZFW1vVUwVTqkfoA+VHNNzkUqrXr5izms81NXEyb6tXn7A gBBp4HcdcIMGKWzGE6LG16Sb44r92jWYsG30+ZQPyIxATvg57SW+0RVTkZLez/yOc4Jmmf xpiK0HusP2HYAlVSaR6Wf+MabnEt2Y6K67v4h/CZONQnMmQkzm7AkbjtvOdSlExL15U9qr Do2IYyr5G+voPP/7gugVVMMqHCTtkp3JvL0Vj+8Iw7cC9S0ZvZNcj1b9JeSuzw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1667110875; a=rsa-sha256; cv=none; b=phMkNSqoZRg/DG7TMPxsnZNclylNtVLnLysP/sA2nZHL3ZL0n4U110pLkH6zjCmfpSrsrd JHPWnUA8IXYwUMlMtxkpt6k4bQl6LQVKVcC+Dp8HTmQBpoZOc/u4YQOrL/C9q2Ua15uMQY NkN3ePMKAZGyakEy95b9pAspCXZw1uDOUYfTQ5Y1KfVzuVAfcKEArxFl/AG7frLLHQBgsj 1ywx8D6Lzvcz/MkH2LcWGEolX1+XeNBvh18jDgiguusxioK5kvxYyEu6X6i2cwRuKMO0m2 kAiCzKVnT5k6YCRUtNJgipz/WW6borkwZp3W01kIvxUsy9Z+8oPlxLBXX7XMkQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: 2.76 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 952ED39B80 X-Spam-Score: 2.76 X-Migadu-Scanner: scn0.migadu.com X-TUID: DNzTMFVn080g Ihor, what I do not like in your patch is that an external process is unconditionally executed during load time. Earlier there was a (failed) attempt to limit it to X11. - Unsure if Windows builds of Emacs may connect to X servers. - MacOS does not use x11idle, it calls ioreg and perl instead. In above cases, there might be a point to execute x11idle if a user is running remote Emacs session on a Windows or a MacOS machine (e.g. through ssh) from local X server. Unsure if somebody has ever tried it. The reason to try x11idle should be a test if current frame is associated with X. A side note. I am aware that the following comment existed before your commit. > (and (eq 0 (call-process-shell-command > (format "command -v %s" org-clock-x11idle-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-x11idle-program-name)))) `call-process' can not be used here because "command" is a shell built-in, not a real executable. I have another question. Why `locate-file' is not used instead? (locate-file command exec-path exec-suffixes 1)) https://emacs.stackexchange.com/questions/332/how-can-i-find-the-path-to-an-executable-with-emacs-lisp On 30/10/2022 08:33, Ihor Radchenko wrote: > Max Nikulin writes: > >> In server.el I found >> >> (frame-parameter frame 'display) .. > > I do not understand. echo "$DISPLAY" :0 emacs -Q --daemon emacsclient -nw window-system nil (frame-parameter nil 'display) ":0" (call-process "xterm") So formally a tty frame has access to X11 server. > Multiple X connection means non-deterministic idle time. Each individual > X server will have its own idle time. The current approach with running > `org-x11-idle-seconds' in current frame is the most reasonable in such > scenario, IMHO. I would say that minimal value should be used. However such case is rarely used and will be almost untested. From my point of view `org-clock-x11idle-program-name' approach is a bit fragile. I do not like "%s" substitutions while formatting shell commands. On the other hand it allows a complex command instead of executable, e.g. dbus-send --print-reply --dest=org.gnome.Mutter.IdleMonitor /org/gnome/Mutter/IdleMonitor/Core org.gnome.Mutter.IdleMonitor.GetIdletime for Wayland, see https://unix.stackexchange.com/questions/396911/how-can-i-tell-if-a-user-is-idle-in-wayland/492328 Perhaps, using Emacs D-BUS API would be even better. x11idle as `org-clock-x11idle-program-name' default is questionable as well. Debian, Arch, Gentoo have xprintidle packages and this tool have some additional code. My summary: - To be really flexible (e.g. to support Wayland) `org-user-idle-seconds' should have an extension point allowing to specify elisp function. - x11idle availability should be checked when X connection is detected, not at startup time and perhaps `locate-file' is better than "command" shell built-in. - (frame-parameter nil 'display) might be more accurate in addition to `window-system' check. - xprintidle should be either the default or an alternative during the test. - I can not figure out how to detect --display argument of "emacs --daemon", but perhaps there is no point of time logging in the case of a headless process. - There are tricky cases like remote Emacs or multihead Emacs. Custom idle function will allow to postpone their discussion till actual request.