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

From: Eli Zaretskii <[email-masked]>
Date: Sun, 26 Jan 2025 11:00:41 +0200

> Cc: [email-masked], [email-masked]
> Date: Sun, 26 Jan 2025 10:11:50 +0200
> From: Eli Zaretskii <[email-masked]>
> 
> > From: Gerd Möllmann <[email-masked]>
> > Cc: [email-masked],  [email-masked]
> > Date: Sun, 26 Jan 2025 08:50:14 +0100
> > 
> > Eli Zaretskii <[email-masked]> writes:
> > 
> > > What happens in this case is that F2 cannot be communicated with:
> > > typing anything there gets no response, until we exit the minibuffer
> > > on F1.  Then everything you typed on F2 gets processed.
> > >
> > >> Find in the code what actually happens when switching from F1 to F2 and
> > >> compare that with admin/notes/multi-tty has to say about that. Does that
> > >> document say something about what we've seen the code doing? Open issues
> > >> maybe? Or general considerations?
> > >
> > > What the code does when Emacs enters a minibuffer is switch to a
> > > "single-keyboard mode", whereby it only processes keyboard input from
> > > the frame which entered the minibuffer.  This is because Emacs has
> > > only one input queue.
> > 
> > I would perhaps check how that switching to single-kboard is done. That
> > is, which C functions do that, what does do_switch_frame do and so on.
> 
> See temporarily_switch_to_single_kboard in keyboard.c.

Btw, when I do that on the current master branch, I see some
unexplained cursor movements.  Recipe:

  $ emacs -Q -nw
  M-x server-start RET

Now on another TTY display:

  $ ./lib/src/emacsclient -t ./src/dispnew.c

Now observe how the cursor on the first display (where we started
"emacs -Q -nw") is positioned at the left edge of the mode line,
instead of keeping its previous position.

Now switch back to the fist TTY display and press some key.  The
cursor is moved to its correct position, but now the cursor on the
second TTY display is a the beginning of the mini-window!

Now switch to the second TTY display and press down-arrow: the cursor
on that display is now correct, but the cursor on the first display is
now at the beginning of the mini-window.

Here's another problem with cursor movement, which doesn't involve
multy-tty at all:

  $ emacs -Q -nw
  C-x 5 b RET
  M-: (frame-visible-p (next-frame))

After typing the last line above into the minibuffer, don't press RET.
Instead, move the cursor left one character with C-b and type "C-x
C-e".  This should evaluate the (next-frame) part and show the result
in the echo-area.  But note that, while showing the result of the
evaluation, the cursor is not at the end of the value returned by
next-frame, but several places to the right, after some empty space.
This doesn't happen in Emacs 30.