From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Andrew Cohen Newsgroups: gmane.emacs.bugs Subject: bug#63620: 30.0.50; [Feature Request] run hooks on sleep/wake Date: Mon, 05 Jun 2023 21:06:37 +0800 Organization: Hong Kong University of Science and Technology Message-ID: <87y1ky83du.fsf@ust.hk> References: <87fs7qmw00.fsf@ust.hk> <87lehinlvg.fsf@gmx.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35487"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 63620@debbugs.gnu.org To: Michael Albinus Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jun 05 15:07:24 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q69vf-00093y-9P for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 05 Jun 2023 15:07:24 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q69vR-0007Wk-Ml; Mon, 05 Jun 2023 09:07:09 -0400 Original-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 1q69vK-0007Vu-HB for bug-gnu-emacs@gnu.org; Mon, 05 Jun 2023 09:07:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q69vK-0001SX-7c for bug-gnu-emacs@gnu.org; Mon, 05 Jun 2023 09:07:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q69vJ-0004hs-MP for bug-gnu-emacs@gnu.org; Mon, 05 Jun 2023 09:07:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Andrew Cohen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 05 Jun 2023 13:07:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63620 X-GNU-PR-Package: emacs Original-Received: via spool by 63620-submit@debbugs.gnu.org id=B63620.168597041518077 (code B ref 63620); Mon, 05 Jun 2023 13:07:01 +0000 Original-Received: (at 63620) by debbugs.gnu.org; 5 Jun 2023 13:06:55 +0000 Original-Received: from localhost ([127.0.0.1]:48430 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q69vC-0004hV-NU for submit@debbugs.gnu.org; Mon, 05 Jun 2023 09:06:55 -0400 Original-Received: from mail-os0jpn01on2107.outbound.protection.outlook.com ([40.107.113.107]:5970 helo=JPN01-OS0-obe.outbound.protection.outlook.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q69v9-0004hC-78 for 63620@debbugs.gnu.org; Mon, 05 Jun 2023 09:06:52 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U5sTqryY+cgAgzfq/wkJsVh5RpGOnR9YKIikdfr1b146xGfv2lqa+9wGuDdulCfI3nWO4/xSh+Soi/r5Ogc/QaP5yMKj7KTn4RL6M8nV4TSyAUNPkiasklTiUAttcM2uZYpU3aWUPNkFgFrP7FxfbTAnZm96s9CoGtdEL+MXJ0lrnCPmb7pQ+d4yhfl0OCRVgygP8aUoUOLmNOl8w6PjnufD8IA2iWA0kEZqRwmi+vSi2q8eNTe1TbBAl94pUjIQAr6L1hfvKQLGWTkEUh64sSGX8PH8KaG9OinedcQn09GEh5f94QDGhNmcIBaM9NW0btvfxYim8TgmI5L1KWZ1jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ByPxk3uByxTlt4F0+cZPCPMSKoW9mKYZPS+QUmqCSAw=; b=FCefDBiQ6sY5MnVKv1cVNubWLFIcDgORJrqFzy6vKS8UbGXgsEYFMqGnXFmTtV2xekch3eVj7lLiW3b/gMl6j8qXwFs8CdWI7rvKklP51HTeUC+v5UPcsgEZNEFra59Fc7+DJ/yMdhS102/HCfbAOQzBDTyG2Zny4Iy1o8tJ81hMFarP58yDQho9kJWjD/tN4nRMRt3QW/rDX8u5cV7J1+POdLQovUENhUcF/7KBsqlpPJd/b0S/rUKvEV82FHIi+lNhXGdNxLv5l3yc7n26M5ynzFNpoNZP0zkf7e+VUUJWU149nTBy3t/+7Vk2mlmyEcV6l0O+pKEJnk4JgCCmxw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=ust.hk; dmarc=pass action=none header.from=ust.hk; dkim=pass header.d=ust.hk; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ust.hk; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ByPxk3uByxTlt4F0+cZPCPMSKoW9mKYZPS+QUmqCSAw=; b=eHt3BDSXxKibgihvXOebMtEFDNiknUD/GpUYUL9zn3F5ZgI7cZcLe/XKyioX5s265lLYmrfaB0SKG35SwxoBSVoKEE51+9Y4aAmYkgCRO5P1pR/Pz+hL/+3CpCcud94VerGWFX49vMhvf4cgToWfOphm5AVFK/f++K1XMVpcDYKRcpz8OtmHeAQxzZ1DUNcyIj3ytle9f+/JLTCbhyyT00eOgHwyB9mU+wkOYSXfTosH57xMR+xJxFW+Fqsqhnl57XgPpxXctKHt/rLmbIzZrFdHMl48EcaRk79SpoAzfUPPK+imsjT5NS40yB7yDse8W8pmXVN69qRP8cBetrHKqw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=ust.hk; Original-Received: from OS3P286MB1877.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1bf::11) by TY1P286MB3257.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:2e8::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.33; Mon, 5 Jun 2023 13:06:43 +0000 Original-Received: from OS3P286MB1877.JPNP286.PROD.OUTLOOK.COM ([fe80::873a:53e:955d:c20f]) by OS3P286MB1877.JPNP286.PROD.OUTLOOK.COM ([fe80::873a:53e:955d:c20f%7]) with mapi id 15.20.6455.030; Mon, 5 Jun 2023 13:06:43 +0000 In-Reply-To: <87lehinlvg.fsf@gmx.de> (Michael Albinus's message of "Sun, 21 May 2023 10:12:51 +0200") X-ClientProxiedBy: KU1PR03CA0029.apcprd03.prod.outlook.com (2603:1096:802:19::17) To OS3P286MB1877.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:1bf::11) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OS3P286MB1877:EE_|TY1P286MB3257:EE_ X-MS-Office365-Filtering-Correlation-Id: e665078d-0cc3-41ff-06db-08db65c5b57f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oL0+oPEfyh+4wm2rGxJS63rWV7WTdiiG2zZ1SuiHrtpYDj+F5x/X6SnFGi5XrZq9du6cB0MP444EnESJNEVzOMp3adAdYFgtbzdtoMR3Dc3nyNgVFIXZQKltJCmDnTy8oRDLk9gc/4Gk1LF7HieeMkc0kvE5LMAZk9sIl+TIedeKWncbxywoSW2VloX96eIGUcVqII50TaTKhJCoVKlh8DH5OIMW7MISMMn/3oGBIV4gjuKbuOd79UM9IxD2vonB4aLrMDCEuKXcaKVZnHrvjaCmxOc85Kyy4hUvSPeWc2NJi5ZECT4xH4UOwIzlQBgda1GNcPMpHsrdm9tC9lrbJr6Oh+HBL4JJeBcsM9eqN3zDeENsv2dJDhRfdTER+o68AO+nLG8NSJNaSnliAFo4Z7NmAJfr0atcLSRl+TAKZ2pMmfjesMYOEO90WVdq/KqjHNf1YelelNeLntVMgcGuV+wwAU9nHGgVIs9COrKwDW0CM415HIl8gaF9v7GvKVLQpEGNcoFmlh3UHFn6OPIhgkuAgELkOnVYli+iVzFnZGwMvaCJ91ekgZj53KKZ23Sfd2qfO2WkFFHL1WMQd0Na9JsuzcOhb59VJb0CyqMOaBYsg7CvhXfAfhEYtV6xvHP1 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:OS3P286MB1877.JPNP286.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(13230028)(4636009)(39860400002)(366004)(396003)(136003)(346002)(376002)(451199021)(478600001)(2906002)(36756003)(6486002)(36916002)(6666004)(2616005)(83380400001)(41320700001)(186003)(6512007)(6506007)(26005)(86362001)(38100700002)(786003)(316002)(8676002)(8936002)(66946007)(6916009)(4326008)(66556008)(66476007)(5660300002)(41300700001)(547064002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: zeaYcuFLqYQVcwDIiejP3lr+lw4rNl+KlQ2VLSRAzE5PHulGHzrzufHF1cRfIMPTxMg0jxwfOet+0+fULdSl/b1p/zMts5wAZkX1YMcOl/E4a6Ec93RT2jw/anWxkZJB5xcjjNHX3VmdDHBxhiw9fmAR+T3m0x1rCEzSxx1NLXmTOI7MoZCXLxsPCjVsQ0rtLtVsvdhPpADbuy/WFq1tNjKUwKrLLOoO9BtoZuAWCPhavCirfkSmS1rmDYL50tU6bP4eKJ+WMPKedbIMAzoXuUhWcb9iKM0ilXuBNMr6KZ3Vcv49KJ7FrNtPgGlve96RvjyePoilIV3tPYfPfkNIGitLRnhGJP6sGzf/deXkVIUg9VC1q2//ZHRh5LUxiBrUwlWPvihAPxd7c5z7/K6s3jjd27+3UiQNe9savBOj16T9Qfo/gxOu2q+5hMdao60L2dVa3VHBWWV4IH509494QiVc04tTPH6hqmleOCs8BTSYFdct14/jxKjK/WQCIWwaJ/Sun3mfGRdKcVDm9B1Vk0XpycScVaY+mLcRTnGTLnZyVWpzoNyMa7yk84IhChoY1Ak0+0pKI2eQ+I3qhN87jLBEspEeBnunikpxv/Hz6Khooq2qgVItFJltRibQH5OEqJFirAyYXZuu7yUhrxb1M2TUVvUJ7d6hg1qWHxHbdSoTYApY6G5mCwAwh7/1Yj9iQomMfrGbCrvJbE9UvicMzNb5foUpsd50QHIGaKtZRZRDBWeY5PdWoX1M7+ Glf08XkLwVHrdkwYQBmQShBzdlBPo6FfS9s7qkehnQqEgfgKJo7aYwSWMkScaSfYOkuGCqdllyEqaVixIwmndM050qS1I5Dz6a X-OriginatorOrg: ust.hk X-MS-Exchange-CrossTenant-Network-Message-Id: e665078d-0cc3-41ff-06db-08db65c5b57f X-MS-Exchange-CrossTenant-AuthSource: OS3P286MB1877.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jun 2023 13:06:43.3209 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: c917f3e2-9322-4926-9bb3-daca730413ca X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: PmAbTWXcoPuAOKdVUL9d86ptUTrZjSmhmaoZ4w2mSq9AmRmEo7ba+pzFh5RYDMol X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY1P286MB3257 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:263004 Archived-At: --=-=-= Content-Type: text/plain Dear Michael >>>>> "MA" == Michael Albinus writes: [...] MA> Using D-Bus is just an implementation detail. What you want are MA> handlers, which are invoked when your laptop falls asleep or MA> awakes. Yes, of course you are right! MA> A general package could implement it using D-Bus if available, MA> or using something else if there's no D-Bus. See battery.el, MA> which uses the D-Bus service "org.freedesktop.UPower" only if MA> possible. Your package might be called sleep.el or alike. I am not familiar with other methods for detecting sleep/wake, so I just have dbus at the moment. But if anyone knows of something else (especially on windows) it can then be added. [...] MA> I would make it rather a global minor mode, that you can MA> enable/disable it easily. Yes, that is a better idea. [...] MA> Perhaps, you check also for the service MA> "org.freedesktop.login1", like MA> (member "org.freedesktop.login1" (dbus-list-activatable-names MA> :system)) OK, added. I've now put everything together and modified the gnus code to use the new sleep.el. But I remain unsure if I should remove gnus-dbus.el entirely (everything remains the same for the user: setting gnus-dbus-close-on-sleep to a non-nil value will enable the feature using the global minor mode rather than gnus-dbus). And is sleep.el something worth adding? --=-=-= Content-Type: application/emacs-lisp Content-Disposition: inline; filename=sleep.el Content-Transfer-Encoding: quoted-printable Content-Description: sleep.el ;;; sleep.el --- run hooks on sleep and wake -*- lexical-binding:t -*- ;; Copyright (C) 2023 Free Software Foundation, Inc. ;; Author: Andrew Cohen <> ;; Maintainer: emacs-devel@gnu.org ;; Keywords: ;; This file is part of GNU Emacs. ;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see . ;;; Commentary: ;;; This global minor mode enables evaluating code when the device ;;; running Emacs enters or leaves the sleep state. Two hooks are ;;; used, sleep-sleep-hook and sleep-wake-hook, run when the system ;;; detects that it is going to sleep or waking up. Currently only a ;;; dbus interface to detect sleep state change is implemented. ;;; Code: (require 'dbus) (defgroup sleep nil "Run hooks on entering/leaving the sleep state." :group 'hardware) (defcustom sleep-sleep-hook nil "Hook to run on entering sleep." :group 'sleep :type 'hook) (defcustom sleep-wake-hook nil "Hook to run on leaving sleep." :group 'sleep :type 'hook) (defvar sleep-registration-object nil "Object returned from `dbus-register-signal'. This is used to unregister the signal.") (defun sleep-wake-enable () "Enable detection of sleep/wake state change. Run sleep-sleep-hook and sleep-wake-hook as appropriate." (unless sleep-registration-object (setq sleep-registration-object (dbus-register-signal :system "org.freedesktop.login1" "/org/freedesktop/login1" "org.freedesktop.login1.Manager" "PrepareForSleep" #'sleep-handler)))) (defun sleep-wake-disable () "Disable detection of sleep/wake state change." (condition-case nil (progn (dbus-unregister-object sleep-registration-object) (setq sleep-registration-object nil)) (wrong-type-argument nil))) (defun sleep-handler (sleep-wake) "Handler to execute sleep and wake functions. SLEEP-WAKE is t on sleeping and nil on waking." (ignore-errors (if sleep-wake (run-hooks 'sleep-sleep-hook) (run-hooks 'sleep-wake-hook)))) ;;;###autoload (define-minor-mode sleep-wake-mode "Toggle sleep/wake detection. When sleep-wake-mode is enabled, Emacs will execute the hooks `sleep-sleep-hook' and `sleep-wake-hook' when entering or leaving the sleep state. This is currently only available on systems that support dbus detection of sleep state change." :global t :group 'sleep (when (and (featurep 'dbusbind) (member "org.freedesktop.login1" (dbus-list-activatable-names :system))) (if sleep-wake-mode (sleep-wake-enable) (sleep-wake-disable)))) (provide 'sleep) ;;; sleep.el ends here --=-=-= Content-Type: text/plain -- Andrew Cohen --=-=-=--