unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Daniel Colascione <dancol@dancol.org>
Cc: luangruo@yahoo.com, 73559@debbugs.gnu.org
Subject: bug#73559: [PATCH] fix NS build focus-in event processing
Date: Mon, 30 Sep 2024 19:29:09 +0300	[thread overview]
Message-ID: <86ed512jhm.fsf@gnu.org> (raw)
In-Reply-To: <C01B6126-3461-4EE6-92E1-C0637B406EAA@dancol.org> (message from Daniel Colascione on Mon, 30 Sep 2024 08:51:27 -0700)

> Date: Mon, 30 Sep 2024 08:51:27 -0700
> From: Daniel Colascione <dancol@dancol.org>
> CC: luangruo@yahoo.com, 73559@debbugs.gnu.org
> 
> >That's not what I meant.  kbd_buffer_store_event doesn't trigger
> >reading from the queue, AFAIU.  Emacs does that itself, when it
> >becomes idle: it calls read_char as part of its main loop, and that
> >reads from the input queue.
> 
> Yes. So now imagine that Emacs is idle and not the focused window. I command-tab to it. Now Emacs is the focused window. I would expect Emacs to have run the functions in focus-in-hook by now, but it didn't, because when we got focus, we queued the focus event but didn't wake up the main thread to process it. Now I hit a key. Emacs wakes up, drains its event loop (firing off focus-in-hook functions), and processes my keystroke. Isn't it correct for Emacs to run that hook immediately when it gets focus, not some time after?

Yes, of course it is.

What happens on MS-Windows in this case is that when the Emacs frame
gets focus, we are sent the WM_SETFOCUS message.  That causes us to
add to the input queue (by using kbd_buffer_store_event) an input
event whose event->kind is FOCUS_IN_EVENT.  Immediately after that, I
see read_char call kbd_buffer_get_event (via several intermediate
calls), and the FOCUS_IN_EVENT is read and processed

I wonder why this doesn't happen for NS.  (But I know that the NS port
uses some tricky code to process events, so I'm hardly surprised.)

> In general, I don't see why we'd wire it up such that the event queue can be non-empty and the main thread asleep indefinitely. If we have an event to process, then in all circumstances, we should process it, yes?

Yes, definitely.  And AFAIU that should happen because we call
read_char whenever we are idle.  Maybe the NS version of pselect
sleeps indefinitely or for too long if no keyboard keys are pressed?
On other systems, any message from the window-system exits pselect,
but maybe that doesn't happen on NS?

Does having a frequently-expiring timer cause the focus-in events to
be processed more timely, without your patch?





  reply	other threads:[~2024-09-30 16:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-30  2:47 bug#73559: [PATCH] fix NS build focus-in event processing Daniel Colascione
2024-09-30  6:55 ` Stefan Kangas
2024-09-30 11:41 ` Eli Zaretskii
2024-09-30 14:20   ` Daniel Colascione
2024-09-30 15:38     ` Eli Zaretskii
2024-09-30 15:51       ` Daniel Colascione
2024-09-30 16:29         ` Eli Zaretskii [this message]
2024-09-30 17:05           ` Daniel Colascione
2024-09-30 17:40             ` Eli Zaretskii
2024-09-30 17:50               ` Daniel Colascione
2024-10-05 10:37                 ` 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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86ed512jhm.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=73559@debbugs.gnu.org \
    --cc=dancol@dancol.org \
    --cc=luangruo@yahoo.com \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).