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

From: Po Lu <[email-masked]>
Date: Sat, 15 Jul 2023 08:02:36 +0800

Andrey Listopadov <[email-masked]> writes:

> Hello.
>
> I've tried making a mode that creates an alternative window manager
> within emacs that uses child frames on an infinite pannable desktop
> instead of window splits.  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.
>
> Am I supposed to delete focused child-frames in a different way or is it
> a bug?  I've tried using `handle-delete-frame' by passing it the list
> that resembles the event the function expects, but no luck.  I've also
> tried calling `select-frame' and `select-window' to change focus to the
> root window, but it doesn't help either.
>
>
> In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
>  3.24.38, cairo version 1.17.8) of 2023-07-07 built on toolbox
> Repository revision: 37101780243d083e8773c255242aa26614f22a14
> Repository branch: master
> System Description: Fedora Linux 38 (Container Image)
>
> Configured using:
>  'configure --without-compress-install --with-native-compilation=aot
>  --with-pgtk --with-mailutils --with-xwidgets
>  --prefix=/var/home/alist/.local'

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;

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.