Subject: Re: bug#47731: 28.0.50; Switching frame via keyboard does not fire focus change event

From: Alan Third <[email-masked]>
Date: Sun, 29 Aug 2021 10:38:38 +0100

On Sat, Aug 28, 2021 at 10:23:35PM -0500, Sean Farley via Bug reports for GNU Emacs, the Swiss army knife of text editors wrote:
> 
> Alan Third <[email-masked]> writes:
> 
> > On Thu, May 06, 2021 at 11:54:10AM +0200, Lars Ingebrigtsen wrote:
> >> Sean Farley <[email-masked]> writes:
> >>
> >> > Here is some testing code:
> >> > (defun test--focus-out ()
> >> >   (message "FOCUS TEST"))
> >> >
> >> > (add-function :after after-focus-change-function #'test--focus-out)
> >> > (make-frame)
> >> >
> >> > On macOS, this code runs fine if you click on the other frame. But if
> >> > using the keyboard shortcut Command-` the event doesn't fire. It seems
> >> > to be some interaction in the keydown event function where emacs_event
> >> > is cleared before the call to windowDidBecomeKey.
> >>
> >> I haven't tested the recipe, but perhaps Alan has some comments here
> >> (added to the CCs).
> >
> > Interestingly the NS port only generates Emacs events for things that
> > happen within the NS run loop, which excludes many things that are
> > initiated by Emacs itself.
> >
> > I'm not sure how to fix this as I'm not sure why it's set up this way.
> 
> Is there anything I can do to help?

Probably not at the moment. I think we need to rewrite the NS event
code so it will create events any time, and then test it to see if it
causes problems. I can't see any way it will, but I don't know why
it's written this way, so maybe I'm missing something.
-- 
Alan Third