On September 18, 2025 10:32:57 AM GMT+02:00, Maximilian Immanuel Brandtner 
<[email protected]> wrote:
> On Fri, 2025-09-12 at 05:39 +0200, Filip Hejsek wrote:
> > From: Szymon Lukasz <[email protected]>
> > 
> > The terminal size of a mux chardev should be the same as the real
> > chardev, so listen for CHR_EVENT_RESIZE to be up to date.
> > 
> > We forward CHR_EVENT_RESIZE only to the focused frontend. This means
> > frontends should probably update their view of the terminal size on
> > receiving CHR_EVENT_MUX_IN.
> > 
> > Signed-off-by: Szymon Lukasz <[email protected]>
> > Signed-off-by: Filip Hejsek <[email protected]>
> > ---
> >  chardev/char-mux.c | 18 +++++++++++++++++-
> >  1 file changed, 17 insertions(+), 1 deletion(-)
> > 
> > diff --git a/chardev/char-mux.c b/chardev/char-mux.c
> > index
> > 6b36290e2c49f579580d2abb5aa552806f019d4a..4d3d05b82f13e002c766142f9d9
> > c24977b8b9bd2 100644
> > --- a/chardev/char-mux.c
> > +++ b/chardev/char-mux.c
> > @@ -264,9 +264,24 @@ void mux_chr_send_all_event(Chardev *chr,
> > QEMUChrEvent event)
> >      }
> >  }
> >  
> > +static void mux_update_winsize(Chardev *chr)
> > +{
> > +    MuxChardev *d = MUX_CHARDEV(chr);
> > +    uint16_t cols, rows;
> > +
> > +    qemu_chr_fe_get_winsize(&d->chr, &cols, &rows);
> > +    qemu_chr_resize(chr, cols, rows);
> > +}
> > +
> >  static void mux_chr_event(void *opaque, QEMUChrEvent event)
> >  {
> > -    mux_chr_send_all_event(CHARDEV(opaque), event);
> > +    Chardev *chr = CHARDEV(opaque);
> > +
> > +    if (event == CHR_EVENT_RESIZE) {
> > +        mux_update_winsize(chr);
> > +    } else {
> > +        mux_chr_send_all_event(chr, event);
> > +    }
> >  }
> >  
> >  static GSource *mux_chr_add_watch(Chardev *s, GIOCondition cond)
> > @@ -382,6 +397,7 @@ static void qemu_chr_open_mux(Chardev *chr,
> >       */
> >      *be_opened = muxes_opened;
> >      qemu_chr_fe_init(&d->chr, drv, errp);
> > +    mux_update_winsize(chr);
> >  }
> >  
> >  static void qemu_chr_parse_mux(QemuOpts *opts, ChardevBackend
> > *backend,
> > 
> 
> When changing the focussed chardev, the MuxChardev should send a resize
> event to the newly focussed chardev. Otherwise the size information of
> the focussed chardev might be outdated if it wasn't the focussed
> chardev at the time of the resize event.
> 
> Theoretically, the resize event could also just be sent to all
> character devices focussed or not, however as this causes a lot of
> needless redrawing I prefer the approach of only resizing the focussed
> chardev.
> 
> Kind regards,
> Max Brandtner
> 

Right now, this is handled by frontends also updating the size
on CHR_EVENT_MUX_IN, as mentioned in the commit message.
I could make it so that CHR_EVENT_MUX_IN is always followed
by CHR_EVENT_RESIZE, if that is preferred. A more complicated
option is to remember for each frontend if it missed a resize event,
and only send it then, but that seems like needless complexity.

Kind regards,
Filip

Reply via email to