Subject: 28.0.50; Switching frame via keyboard does not fire focus change event

From: Sean Farley <[email-masked]>
Date: Mon, 12 Apr 2021 11:17:15 -0500

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.

In GNU Emacs 28.0.50 (build 2, x86_64-apple-darwin20.3.0, NS appkit-2022.30 Version 11.2.2 (Build 20D80))
 of 2021-03-09 built on laptop
Windowing system distributor 'Apple', version 10.3.2022
System Description:  macOS 11.2.3

Configured using:
 'configure --disable-dependency-tracking --disable-silent-rules
 --enable-locallisppath=/usr/local/share/emacs/site-lisp
 --infodir=/usr/local/Cellar/emacs-plus@28/28.0.50/share/info/emacs
 --prefix=/usr/local/Cellar/emacs-plus@28/28.0.50 --with-xml2
 --with-gnutls --with-native-compilation --with-dbus --with-imagemagick
 --with-modules --with-rsvg --with-ns --disable-ns-self-contained
 'CFLAGS=-I/usr/local/opt/gcc/include -I/usr/local/opt/libgccjit/include
 -I/usr/local/opt/gmp/include -I/usr/local/opt/jpeg/include'
 'LDFLAGS=-L/usr/local/lib/gcc/10 -I/usr/local/opt/gcc/include
 -I/usr/local/opt/libgccjit/include -I/usr/local/opt/gmp/include
 -I/usr/local/opt/jpeg/include''

Configured features:
ACL DBUS GIF GLIB GMP GNUTLS IMAGEMAGICK JPEG JSON LCMS2 LIBXML2 MODULES
NATIVE_COMP NOTIFY KQUEUE NS PDUMPER PNG RSVG THREADS TIFF
TOOLKIT_SCROLL_BARS XIM ZLIB

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: ObjC//l

Minor modes in effect:
  org-roam-mode: t
  treemacs-filewatch-mode: t
  treemacs-git-mode: simple
  treemacs-fringe-indicator-mode: t
  lsp-diagnostics-mode: t
  lsp-modeline-workspace-status-mode: t
  lsp-modeline-diagnostics-mode: t
  lsp-modeline-code-actions-mode: t
  lsp-ui-mode: t
  lsp-ui-imenu-buffer-mode: t
  lsp-ui-sideline-mode: t
  lsp-completion-mode: t
  lsp-managed-mode: t
  lsp-mode: t
  bug-reference-prog-mode: t
  rainbow-delimiters-mode: t
  highlight-numbers-mode: t
  hl-todo-mode: t
  git-gutter-mode: t
  whitespace-mode: t
  display-fill-column-indicator-mode: t
  vi-tilde-fringe-mode: t
  display-line-numbers-mode: t
  highlight-indent-guides-mode: t
  flycheck-posframe-mode: t
  yas-minor-mode: t
  gcmh-mode: t
  winner-mode: t
  show-paren-mode: t
  smartparens-global-mode: t
  smartparens-mode: t
  global-undo-fu-session-mode: t
  undo-fu-session-mode: t
  undo-fu-mode: t
  global-flycheck-mode: t
  flycheck-mode: t
  ws-butler-global-mode: t
  editorconfig-mode: t
  recentf-mode: t
  save-place-mode: t
  global-so-long-mode: t
  global-git-commit-mode: t
  shell-dirtrack-mode: t
  which-key-mode: t
  savehist-mode: t
  better-jumper-mode: t
  better-jumper-local-mode: t
  company-box-mode: t
  global-company-mode: t
  company-mode: t
  ivy-posframe-mode: t
  ivy-prescient-mode: t
  prescient-persist-mode: t
  ivy-rich-project-root-cache-mode: t
  ivy-rich-mode: t
  ivy-mode: t
  volatile-highlights-mode: t
  global-hl-line-mode: t
  hl-line-mode: t
  dtrt-indent-mode: t
  doom-modeline-mode: t
  global-page-break-lines-mode: t
  whole-line-or-region-global-mode: t
  whole-line-or-region-local-mode: t
  global-dot-mode: t
  dot-mode: t
  fancy-narrow-mode: t
  global-tree-sitter-mode: t
  solaire-global-mode: t
  solaire-mode: t
  persp-mode: t
  delete-selection-mode: t
  projectile-mode: t
  ns-auto-titlebar-mode: t
  +lsp-optimization-mode: t
  +popup-mode: t
  general-override-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  window-divider-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  size-indication-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t
  abbrev-mode: t
  hs-minor-mode: t

Load-path shadows:
/Users/sean/projects/doom-emacs/.local/straight/build-28.0.50/ht/ht hides /Users/sean/projects/doom-emacs/.local/elpa/ht-20210119.141/ht
/Users/sean/projects/doom-emacs/.local/straight/build-28.0.50/esxml/esxml-query hides /Users/sean/projects/doom-emacs/.local/elpa/esxml-20201226.1546/esxml-query
/Users/sean/projects/doom-emacs/.local/straight/build-28.0.50/esxml/esxml hides /Users/sean/projects/doom-emacs/.local/elpa/esxml-20201226.1546/esxml
/Users/sean/projects/doom-emacs/.local/straight/build-28.0.50/esxml/esxml-pkg hides /Users/sean/projects/doom-emacs/.local/elpa/esxml-20201226.1546/esxml-pkg
/Users/sean/projects/doom-emacs/.local/straight/build-28.0.50/a/a hides /Users/sean/projects/doom-emacs/.local/elpa/a-20201203.1327/a
/Users/sean/projects/doom-emacs/.local/straight/build-28.0.50/f/f hides /Users/sean/projects/doom-emacs/.local/elpa/f-20210113.118/f
/Users/sean/projects/doom-emacs/.local/straight/build-28.0.50/dash-functional/dash-functional hides /Users/sean/projects/doom-emacs/.local/elpa/dash-functional-20210210.849/dash-functional
/Users/sean/projects/doom-emacs/.local/straight/build-28.0.50/dash/dash hides /Users/sean/projects/doom-emacs/.local/elpa/dash-20210210.849/dash
/Users/sean/projects/doom-emacs/.local/straight/build-28.0.50/dash/dash-autoloads hides /Users/sean/projects/doom-emacs/.local/elpa/dash-20210210.849/dash-autoloads
/Users/sean/projects/doom-emacs/.local/straight/build-28.0.50/ov/ov-autoloads hides /Users/sean/projects/doom-emacs/.local/elpa/ov-20200326.542/ov-autoloads
/Users/sean/projects/doom-emacs/.local/straight/build-28.0.50/ov/ov hides /Users/sean/projects/doom-emacs/.local/elpa/ov-20200326.542/ov
/Users/sean/projects/doom-emacs/.local/straight/build-28.0.50/request/request hides /Users/sean/projects/doom-emacs/.local/elpa/request-20210213.1837/request
/Users/sean/projects/doom-emacs/.local/straight/build-28.0.50/s/s hides /Users/sean/projects/doom-emacs/.local/elpa/s-20200330.1554/s
/Users/sean/projects/doom-emacs/.local/straight/build-28.0.50/cmake-mode/cmake-mode hides /usr/local/share/emacs/site-lisp/cmake/cmake-mode
/Users/sean/projects/doom-emacs/.local/straight/build-28.0.50/map/map hides /usr/local/Cellar/emacs-plus@28/28.0.50/share/emacs/28.0.50/lisp/emacs-lisp/map

Features:
(magit-extras forge-list forge-commands forge-semi forge-bitbucket buck
forge-gogs gogs forge-gitea gtea forge-gitlab glab forge-github
forge-notify forge-revnote forge-pullreq forge-issue forge-topic
forge-post forge-repo forge forge-core forge-db closql emacsql-sqlite
shadow emacsbug magit-gitflow org-eldoc toc-org org-indent ol-bibtex
bibtex windmove vterm term ehelp vterm-module term/xterm xterm
mu4e-patch mu4e-alert time alert log4e notifications gntp org-mu4e mu4e
mu4e-org mu4e-main mu4e-view mu4e-headers mu4e-compose mu4e-context
mu4e-draft mu4e-actions ido rfc2368 smtpmail sendmail mu4e-mark
mu4e-proc mu4e-utils doc-view image-mode exif mu4e-lists mu4e-message
shr kinsoku svg flow-fill mu4e-vars macrostep-c cmacexp macrostep amx
hide-mode-line tramp-archive tramp-gvfs dbus docker-tramp tramp-cache
tramp tramp-loaddefs trampver tramp-integration files-x tramp-compat
parse-time iso8601 ls-lisp jka-compr flycheck-cask flycheck-package
package-lint finder finder-inf lisp-mnt elisp-slime-nav highlight-quoted
org-agenda orgit magit-todos pcre2el rxt re-builder async github-review
ghub-graphql treepy gsexp ghub url-http url-gw url-auth deferred a
treemacs-magit magit-autoloads magit-submodule magit-obsolete
magit-popup magit-blame magit-stash magit-reflog magit-bisect magit-push
magit-pull magit-fetch magit-clone magit-remote magit-commit
magit-sequence magit-notes magit-worktree magit-tag magit-merge
magit-branch magit-reset magit-files magit-refs magit-status magit
magit-repos magit-apply magit-wip magit-log which-func magit-diff
smerge-mode diff magit-core magit-autorevert magit-margin
magit-transient magit-process magit-mode org-roam org-roam-link
org-roam-graph xml org-roam-doctor org-roam-dailies org-roam-capture
org-roam-db emacsql-sqlite3 emacsql emacsql-compiler org-capture
org-roam-completion org-roam-buffer org-roam-faces org-roam-macs
org-roam-compat org-id org-refile smartparens-org org-yt org-element
avl-tree org org-pcomplete org-version ob-emacs-lisp org-table
org-loaddefs ob ob-tangle ol ob-ref ob-lob ob-table ob-exp org-macro
org-footnote org-src org-keys ob-comint ob-core ob-eval lsp-treemacs
lsp-treemacs-themes treemacs-persp treemacs-projectile treemacs
treemacs-header-line treemacs-compatibility treemacs-mode
treemacs-interface treemacs-extensions treemacs-mouse-interface
treemacs-tags treemacs-persistence treemacs-filewatch-mode
treemacs-follow-mode treemacs-rendering treemacs-async
treemacs-workspaces treemacs-dom treemacs-visuals
treemacs-fringe-indicator treemacs-scope treemacs-faces treemacs-icons
treemacs-themes treemacs-core-utils pfuture treemacs-logging
treemacs-customization treemacs-macros company-yasnippet lsp-diagnostics
lsp-modeline lsp-ui lsp-ui-flycheck lsp-ui-doc goto-addr lsp-ui-imenu
lsp-ui-peek lsp-ui-sideline lsp-ui-util view lsp-zig lsp-steep
lsp-svelte lsp-sqls lsp-yaml lsp-xml lsp-vimscript lsp-vhdl lsp-vetur
lsp-html lsp-verilog lsp-vala lsp-terraform lsp-tex lsp-sorbet
lsp-solargraph lsp-rust lsp-rf lsp-r lsp-purescript lsp-pyls lsp-pwsh
lsp-php lsp-perl lsp-ocaml lsp-nix lsp-nim lsp-lua lsp-kotlin lsp-json
lsp-javascript lsp-haxe lsp-groovy lsp-hack lsp-go lsp-completion
lsp-gdscript lsp-fsharp lsp-fortran lsp-eslint lsp-erlang lsp-elixir
lsp-elm lsp-dockerfile lsp-dhall lsp-d lsp-css lsp-csharp gnutls
lsp-crystal lsp-cmake lsp-clojure lsp-clangd dom lsp-bash lsp-angular
lsp-ada lsp-actionscript lsp-python-ms ccls ccls-member-hierarchy
ccls-inheritance-hierarchy ccls-call-hierarchy ccls-tree ccls-code-lens
ccls-semantic-highlight ccls-common lsp-mode lsp-protocol spinner
network-stream nsm lv imenu ht inline ewoc vc bug-reference
rainbow-delimiters highlight-numbers parent-mode hl-todo hideshow
smartparens-c cc-mode cc-fonts cc-guess cc-menus cc-cmds cc-styles
cc-align cc-engine cc-vars cc-defs octave smie pyvenv eshell esh-cmd
esh-ext esh-opt esh-proc esh-io esh-arg esh-module esh-groups esh-util
org-list org-entities org-faces org-compat org-macs cal-menu calendar
cal-loaddefs core-packages package browse-url url url-proxy url-privacy
url-expand url-methods url-history url-cookie url-domsuf mailcap
url-handlers git-gutter-fringe fringe-helper git-gutter vc-git diff-mode
vc-dispatcher url-util auto-minor-mode disp-table whitespace
display-fill-column-indicator vi-tilde-fringe display-line-numbers
highlight-indent-guides doom-snippets doom-snippets-lib yasnippet
flycheck-posframe elisp-mode adaptive-wrap spell-fu ispell
smartparens-markdown markdown-mode edit-indirect url-parse url-vars
noutline outline editorconfig-core editorconfig-core-handle
editorconfig-fnmatch gcmh winner paren smartparens-config
smartparens-text smartparens undo-fu-session undo-fu flycheck-clj-kondo
flycheck find-func ws-butler editorconfig recentf saveplace so-long
git-commit with-editor shell pcomplete transient format-spec log-edit
message rmc puny rfc822 mml mml-sec epa epg epg-config gnus-util rmail
rmail-loaddefs time-date mm-decode mm-bodies mm-encode mail-parse
rfc2231 rfc2047 rfc2045 mm-util ietf-drums mail-prsvr mailabbrev
mail-utils gmm-utils mailheader pcvs-util add-log magit-git
magit-section magit-utils crm char-fold nav-flash pulse cursor-sensor
counsel-projectile which-key savehist better-jumper company-box
company-box-doc frame-local company-box-icons dash-functional
company-capf company ivy-posframe posframe ivy-prescient prescient etags
fileloop generator ivy-xref ivy-avy avy autorevert filenotify
all-the-icons-ivy ivy-rich counsel xdg swiper ivy ivy-faces ivy-overlay
colir color xref project volatile-highlights server objed objed-objects
hl-line cap-words superword subword face-remap bitwarden tree-widget
wid-edit auth-source eieio eieio-core eieio-loaddefs password-cache json
dtrt-indent doom-modeline doom-modeline-segments doom-modeline-env
doom-modeline-core shrink-path f all-the-icons all-the-icons-faces
data-material data-weathericons data-octicons data-fileicons
data-faicons data-alltheicons dash page-break-lines whole-line-or-region
dot-mode fancy-narrow advice simple-mpc simple-mpc-query
simple-mpc-current-playlist simple-mpc-utils simple-mpc-vars
simple-mpc-mode s tree-sitter tree-sitter-load tree-sitter-cli map tsc
tsc-dyn tsc-dyn-get dired-aux dired dired-loaddefs tsc-obsolete
doom-themes-ext-org doom-themes-ext-treemacs solaire-mode
doom-nord-theme doom-themes doom-themes-base persp-mode delsel
projectile grep compile text-property-search comint ansi-color ring
ibuffer-vc ibuf-ext ibuffer ibuffer-loaddefs thingatpt mu4e-meta
html2text let-alist smartparens-lua ns-auto-titlebar ibuf-macs derived
core-editor core-projects core-ui edmacro kmacro easy-mmode comp
comp-cstr warnings core-keybinds pp general cl-extra help-mode seq
byte-opt cl-seq use-package-core bytecomp byte-compile cconv
core-modules cl tex-site rx realgud-recursive-autoloads core core-lib
cl-macs gv cl-loaddefs cl-lib subr-x iso-transl tooltip eldoc electric
uniquify ediff-hook vc-hooks lisp-float-type mwheel term/ns-win ns-win
ucs-normalize mule-util term/common-win tool-bar dnd fontset image
regexp-opt fringe tabulated-list replace newcomment text-mode lisp-mode
prog-mode register page tab-bar menu-bar rfn-eshadow isearch easymenu
timer select scroll-bar mouse jit-lock font-lock syntax facemenu
font-core term/tty-colors frame minibuffer cl-generic cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese composite charscript charprop
case-table epa-hook jka-cmpr-hook help simple abbrev obarray
cl-preloaded nadvice button loaddefs faces cus-face pcase macroexp files
window text-properties overlay sha1 md5 base64 format env code-pages
mule custom widget hashtable-print-readable backquote threads dbusbind
kqueue cocoa ns lcms2 multi-tty make-network-process nativecomp emacs)

Memory information:
((conses 16 1874513 799203)
 (symbols 48 82098 111)
 (strings 32 470148 35028)
 (string-bytes 1 11748287)
 (vectors 16 152617)
 (vector-slots 8 4289570 458845)
 (floats 8 2762 2729)
 (intervals 56 96788 26251)
 (buffers 992 39))