Subject: Re: bug#75056: 31.0.50; tty-child-frames with server / multiple clients possible hangs

From: Eli Zaretskii <[email-masked]>
Date: Fri, 31 Jan 2025 14:03:02 +0200

> From: Gerd Möllmann <[email-masked]>
> Cc: Eli Zaretskii <[email-masked]>,  [email-masked],  [email-masked]
> Date: Fri, 31 Jan 2025 11:28:19 +0100
> 
> martin rudalics <[email-masked]> writes:
> 
> >> Just came to my mind that one could re-implemented tty menus in Lisp
> >> using child frames.
> >
> > I have never looked into the menu bar drawing code.  Does it use a
> > painter's algorithm?
> 
> The menu bar itself, the stripe at the top of a frame is pretty special.
> On GUIs without external, i.e. toolkit, menu bar, a window is used to
> display it, on ttys not IIRC.

It's not a window on TTY frames, indeed.  See the commentary to
display_menu_bar:

  /* Redisplay the menu bar in the frame for window W.

     The menu bar of X frames that don't have X toolkit support is
     displayed in a special window W->frame->menu_bar_window.

     The menu bar of terminal frames is treated specially as far as
     glyph matrices are concerned.  Menu bar lines are not part of
     windows, so the update is done directly on the frame matrix rows
     for the menu bar.  */

And the corresponding code:

    else
  #endif /* not USE_X_TOOLKIT and not USE_GTK */
      {
	/* This is a TTY frame, i.e. character hpos/vpos are used as
	   pixel x/y.  */
	init_iterator (&it, w, -1, -1, f->desired_matrix->rows,
		       MENU_FACE_ID);
	it.first_visible_x = 0;
	it.last_visible_x = FRAME_COLS (f);
      }

> The menus themselves are drawn, simplifying, in these steps
> 
> 1. Save away the frame's whole current matrix
> 
> 2. Produce a desired matrix that contains the menu
> 
> 3. Update the display. Maybe loop for highlighting item.
> 
> 4. In the end, restore the display from the current matrix saved in the
>    first step.
> 
> That's save_and_enable_current_matrix, tty_menu_display,
> restore_desired_matrix and alike. The event loop is somewhere in
> tty_menu_activate IIRC.

Right.