Subject: bug#64625: 30.0.50; deleting a focused child frame causes Emacs to ignore all input

From: Godefroy Vannoye <[email-masked]>
Date: Tue, 20 May 2025 17:24:02 +0200

Hi,

> When I've implemented the button that closes
> the window, I've noticed, that when I'm closing the last input, Emacs
> stops recognizing any keyboard events, and the point in the root window
> disappears.
>
> This can be reproduced with the following steps:
>
> 1. Call (make-frame `((parent-frame . ,(selected-frame))))
> 2. Focus the newly created child-frame (with a mouse or elsehow)
> 3. Call C-x 5 0 to kill the frame.
> 4. Try typing or calling M-x in the original Emacs window.
>
> Weirdly enough, the only thing that Emacs responds to and restores the
> focus are the arrow keys. You can also go to File > New Frame menu and
> it will fix the issue for the new frame, but the old one is still
> broken.

I've been stumbling upon the same issue, on Emacs pretest 30.1.90.

> Thanks. Would you please instrument `pgtk_new_focus_frame' (in
> pgtkterm.c) as follows:
>
> diff --git a/src/pgtkterm.c b/src/pgtkterm.c
> index dc2d6477bb5..d62414f4e50 100644
> --- a/src/pgtkterm.c
> +++ b/src/pgtkterm.c
> @@ -4732,6 +4732,9 @@ pgtk_new_focus_frame (struct pgtk_display_info 
> *dpyinfo,
> struct frame *frame)
> if (frame != dpyinfo->x_focus_frame)
> {
> + fprintf (stderr, "pgtk_new_focus_frame: new frame %p, "
> + "with outer widget %p\n", (void *) frame,
> + (void *) FRAME_GTK_OUTER_WIDGET (frame));
> /* Set this before calling other routines, so that they see
> the correct value of x_focus_frame. */
> dpyinfo->x_focus_frame = frame;

I've also instrumented `pgtk_new_focus_frame' (in pgtkterm.c) in a slightly
different way than suggested, to avoid an Emacs crash:

   if (frame != dpyinfo->x_focus_frame)
     {
+     fprintf (stderr, "pgtk_new_focus_frame: new frame %p", (void *) 
frame);
+     if (frame) {
+       fprintf (stderr, ", with outer widget %p\n", (void *) 
FRAME_GTK_OUTER_WIDGET (frame));
+     }
+     else {
+       fprintf(stderr, "\n");
+     }
       /* Set this before calling other routines, so that they see
          the correct value of x_focus_frame.  */
       dpyinfo->x_focus_frame = frame;

> and show me what is printed when the child frame is initially focused,
> and when you try to focus its parent after it is deleted.
When the child frame is initially focused:

     pgtk_new_focus_frame: new frame (nil)
     pgtk_new_focus_frame: new frame 0x555821d935d0, with outer widget (nil)

When I try to focus the parent after it is deleted, nothing is printed. 
When I do
the arrow key manipulation to make the frame reactive again, the 
following is printed:

     pgtk_new_focus_frame: new frame 0x55e133e383f8, with outer widget 
0x55e133ce6b20

Thanks in advance for any possible progress of this bug,
and I stay at your disposal for any necessary test.

Godefroy Vannoye

In GNU Emacs 30.1.90 (build 14, x86_64-pc-linux-gnu, GTK+ Version
  3.24.49, cairo version 1.18.4) of 2025-05-20 built on gvlaptop
System Description: Arch Linux

Configured using:
  'configure --with-pgtk --with-tree-sitter'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
LCMS2 LIBOTF LIBSYSTEMD LIBXML2 MODULES NATIVE_COMP NOTIFY INOTIFY
PDUMPER PGTK PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS TREE_SITTER WEBP XIM GTK3 ZLIB

Important settings:
   value of $LC_ALL: en_US.UTF-8
   value of $LC_CTYPE: en_US.UTF-8
   value of $LC_MONETARY: fr_FR.UTF-8
   value of $LC_NUMERIC: fr_FR.UTF-8
   value of $LC_TIME: fr_FR.UTF-8
   value of $LANG: en_US.UTF-8
   value of $XMODIFIERS: @im=ibus
   locale-coding-system: utf-8-unix

Major mode: ELisp/d

Minor modes in effect:
   tooltip-mode: t
   global-eldoc-mode: t
   eldoc-mode: t
   show-paren-mode: t
   electric-indent-mode: t
   mouse-wheel-mode: t
   tool-bar-mode: t
   menu-bar-mode: t
   file-name-shadow-mode: t
   global-font-lock-mode: t
   font-lock-mode: t
   blink-cursor-mode: t
   minibuffer-regexp-mode: t
   line-number-mode: t
   indent-tabs-mode: t
   transient-mark-mode: t
   auto-composition-mode: t
   auto-encryption-mode: t
   auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message mailcap yank-media puny dired
dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg rfc6068
epg-config gnus-util text-property-search mm-decode mm-bodies mm-encode
mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047
rfc2045 ietf-drums mm-util mail-prsvr mail-utils time-date subr-x
cl-loaddefs cl-lib rmc iso-transl tooltip cconv eldoc paren electric
uniquify ediff-hook vc-hooks lisp-float-type elisp-mode mwheel
term/pgtk-win pgtk-win term/common-win touch-screen pgtk-dnd 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
font-core term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine 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 emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
theme-loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads dbusbind inotify
dynamic-setting system-font-setting font-render-setting cairo gtk pgtk
lcms2 multi-tty move-toolbar make-network-process native-compile emacs)

Memory information:
((conses 16 49742 11179) (symbols 48 5335 0) (strings 32 13545 1800)
  (string-bytes 1 399073) (vectors 16 9168)
  (vector-slots 8 130097 9328) (floats 8 24 11) (intervals 56 291 30)
  (buffers 992 13))