From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#69083: Emacs's keyboard hook state is not reset on session lock (Windows) Date: Wed, 21 Feb 2024 14:37:46 +0200 Message-ID: <86v86im1r9.fsf@gnu.org> References: <86cyt1qvmt.fsf@gnu.org> <861q9exmhe.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="356"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 69083@debbugs.gnu.org To: Raffael Stocker Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Feb 21 16:25:09 2024 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 1rcoT7-000AGS-Kq for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 21 Feb 2024 16:25:09 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcoNO-0006Yy-3a; Wed, 21 Feb 2024 10:19:14 -0500 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 1rcoK6-0000nB-8y for bug-gnu-emacs@gnu.org; Wed, 21 Feb 2024 10:16:01 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rclrz-0007fH-W5 for bug-gnu-emacs@gnu.org; Wed, 21 Feb 2024 07:38:40 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rclsM-00070X-8h for bug-gnu-emacs@gnu.org; Wed, 21 Feb 2024 07:39:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 21 Feb 2024 12:39:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 69083 X-GNU-PR-Package: emacs Original-Received: via spool by 69083-submit@debbugs.gnu.org id=B69083.170851910526891 (code B ref 69083); Wed, 21 Feb 2024 12:39:02 +0000 Original-Received: (at 69083) by debbugs.gnu.org; 21 Feb 2024 12:38:25 +0000 Original-Received: from localhost ([127.0.0.1]:48004 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rclrl-0006zf-4b for submit@debbugs.gnu.org; Wed, 21 Feb 2024 07:38:25 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:52420) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rclrf-0006zO-E8 for 69083@debbugs.gnu.org; Wed, 21 Feb 2024 07:38:23 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rclrD-0007cS-1Y; Wed, 21 Feb 2024 07:37:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=NCVDmmfyQ0+FK5Q1IfZQFNaCoFSanqGKBQwYFYgIo30=; b=XGy6Hu7NCkR68Mu7qq0U 1CwC0QWKVNcmWerGPCOPKlIFW+WcU9uEh00G3o5ZssI7djg/IPrLAmdIvSO8F1PgR0Mw4pltdfsmz LI1yueH41yZyOlaJa+Xem6AajZJQBJtus6oCsD1em2bhfGC7+A7VC7AfvALC+VwT0V0KScmflOKGi viZaMGk4yvFs0nttuFHQE0AcMR6yVvVXqFKJezmQSR13ak/6h1Nrkdl4mESfphMpWVsHHaaUnf/PX PBp8LW/637xY1ihu3Qqq2nC6cE87NOc5jSg9aQqi2T3LEjQBJyiJYrTVWQJZHOhVMATYLLxlOHJaB gmy24nSVh8vo3Q==; In-Reply-To: (message from Raffael Stocker on Tue, 20 Feb 2024 19:51:21 +0100) 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:280380 Archived-At: > From: Raffael Stocker > Cc: 69083@debbugs.gnu.org > Date: Tue, 20 Feb 2024 19:51:21 +0100 > > I experimented a bit today and found that the remove_w32_kbdhook > function is not actually getting called when Emacs is being killed. It > is only called when the Emacs window receives a WM_DESTROY message. But > we get relevant WM_* messages, when > > - creating second frame with ‘C-x 5 2’ and closing it using ‘C-x 5 0’: > WM_EMACS_DESTROYWINDOW, then WM_DESTROY > - creating second frame with ‘C-x 5 2’ and closing it by clicking ‘X’ > in frame decoration: > WM_CLOSE, then WM_EMACS_DESTROYWINDOW, then WM_DESTROY > - closing the last frame by clicking ‘X’ in frame decoration: WM_CLOSE > - killing Emacs with ‘C-x C-c’: nothing > > At least, if Emacs is not run as daemon. Then, the WM_DESTROY is only > handled when there is still another frame, and in this case > ‘remove_w32_kbdhook’ will not remove the hook as kbdhook.hook_count > 1. > > If Emacs is run as daemon, it cleans up the keyboard hook when closing > the last window. > > Is there a better place where the remove_w32_kbdhook call could go such > that cleanup can always happen? I think that place is term_ntproc. > > This URL: > > > > https://stackoverflow.com/questions/8606300/how-to-detect-windows-is-locked > > > > seems to indicate that WTSRegisterSessionNotification requires > > elevation on Windows 10/11. Did you get the UAC prompt when calling > > that API? Are you running with admin privileges when you test this > > code? Triggering UAC prompts when starting Emacs would be a nuisance > > to our users. > > I have read this post, but it seems to be wrong. I don't have any > elevated privileges and it works without showing any prompt, at least on > Windows 10. I'll try to have my colleague test it as well, she runs > Windows 11. Is your user a member of the local Administrators group? Did you try running this code as a "normal" user, not an admin? > >> Unfortunately, this didn't work for me. I tried calling > >> ‘EnumWindows(find_child_console, ...)’ with a ‘child_process’ instance > >> containing the current process id as returned by ‘GetCurrentProcessId’, > >> but I don't seem to get a useful window handle. > > > > What do you mean? What is the result of using find_child_console? > > does the condition in find_child_console, which looks at the > > process_id of all windows, never match the process ID of the Emacs > > session running with -nw? Or what else goes wrong? > > I'm not quite sure myself what I mean. I will experiment with this > a bit more and try to find out what's happening. Thanks.