From: Raffael Stocker <r.stocker@mnet-mail.de>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 69083@debbugs.gnu.org
Subject: bug#69083: Emacs's keyboard hook state is not reset on session lock (Windows)
Date: Tue, 20 Feb 2024 19:51:21 +0100 [thread overview]
Message-ID: <yplmbk8brl20.fsf@mnet-mail.de> (raw)
In-Reply-To: <861q9exmhe.fsf@gnu.org>
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Raffael Stocker <r.stocker@mnet-mail.de>
>> Cc: 69083@debbugs.gnu.org
>> Date: Wed, 14 Feb 2024 21:20:35 +0100
>>
>> > So we need to load that DLL at run time via LoadLibrary, ...
>>
>> I have added that.
>
> Thanks. I suggest one optimization: instead of probing whether
> LoadLibrary succeeds in two places, do it only once, where you call
> WTSRegisterSessionNotification, and at that time also record the
> function pointer for WTSUnRegisterSessionNotification; then use the
> 2nd function pointer, if non-NULL, to call the unregister API.
Yes, I can do that. I will leave the initialisation in the
setup_w32_kbdhook function as the branch with the call to LoadLibrary
should be executed only once.
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? Or should we just not care?
> 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.
>> 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.
Regards,
Raffael
next prev parent reply other threads:[~2024-02-20 18:51 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-12 19:04 bug#69083: Emacs's keyboard hook state is not reset on session lock (Windows) Raffael Stocker
2024-02-12 20:23 ` Eli Zaretskii
2024-02-14 20:20 ` Raffael Stocker
2024-02-15 6:36 ` Eli Zaretskii
2024-02-20 18:51 ` Raffael Stocker [this message]
2024-02-21 12:37 ` Eli Zaretskii
2024-02-21 14:13 ` Raffael Stocker
2024-02-21 15:03 ` Eli Zaretskii
2024-02-26 20:50 ` Raffael Stocker
2024-02-27 7:42 ` Eli Zaretskii
2024-02-29 20:22 ` Raffael Stocker
2024-03-01 6:41 ` Eli Zaretskii
2024-03-03 16:43 ` Raffael Stocker
2024-03-03 17:23 ` Eli Zaretskii
2024-03-03 17:39 ` Eli Zaretskii
2024-03-04 18:10 ` Raffael Stocker
2024-03-14 8:25 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=yplmbk8brl20.fsf@mnet-mail.de \
--to=r.stocker@mnet-mail.de \
--cc=69083@debbugs.gnu.org \
--cc=eliz@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.