Subject: bug#78980: 31.0.50; C-z crashes emacsclient -nw

From: martin rudalics <[email-masked]>
Date: Thu, 10 Jul 2025 16:55:53 +0200

> The functionality on GUIs sounds like we should have something like
 >
 >    bool is_displayed(struct frame *f) {
 >        // Öeave window system frames alone
 >        if (!is_tty_frame(f))
 >            return true;
 >        // Don't display if not marked visible.
 >        if (!FRAME_VISIBLE_P(f))
 >            return false;
 >        // If marked visible but parent isn't displayed
 >        const struct frame *oarent = FRAME_PARENT_FRAME(f);
 >        return parent ? is_displayed(parent) : true;
 >    }
 >
 > WDYT?

But that's precisely what frame_redisplay_p is supposed to accomplish.
Look at the patch below which further simplifies what Pip Cet proposed
earlier.

martin

diff --git a/src/frame.c b/src/frame.c
index 70e200d9219..2d88ad94114 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -358,36 +358,27 @@ DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
  }

  /** Return true if F can be redisplayed, that is if F is visible and, if
-    F is a tty frame, all its ancestors are visible too.  */
+    F is a tty frame, all its ancestors are visible too and F's root
+    frame is its terminal's top frame..  */
  bool
  frame_redisplay_p (struct frame *f)
  {
    if (is_tty_frame (f))
      {
-      struct frame *p = FRAME_PARENT_FRAME (f);
-      struct frame *q = NULL;
+      struct tty_display_info *tty = FRAME_TTY (f);
+      struct frame *r = XFRAME (tty->top_frame);

-      while (p)
+      while (f)
  	{
-	  if (!p->visible)
+	  if (!f->visible)
  	    /* A tty child frame cannot be redisplayed if one of its
  	       ancestors is invisible.  */
  	    return false;
  	  else
-	    {
-	      q = p;
-	      p = FRAME_PARENT_FRAME (p);
-	    }
+	    f = FRAME_PARENT_FRAME (f);
  	}

-      struct tty_display_info *tty = FRAME_TTY (f);
-      struct frame *r = XFRAME (tty->top_frame);
-
-      /* A tty child frame can be redisplayed iff its root is the top
-	 frame of its terminal.  Any other tty frame can be redisplayed
-	 iff it is the top frame of its terminal itself which must be
-	 always visible.  */
-      return (q ? q == r : f == r);
+      return f == r;
      }
    else
  #ifndef HAVE_X_WINDOWS