Query the terminal size from the vte library when creating the console and every time it might change. Vte doesn't send any signal specifically for terminal size changes, so instead we register callbacks for size-allocate and char-size-changed.
Reviewed-by: Daniel P. Berrangé <[email protected]> Signed-off-by: Filip Hejsek <[email protected]> --- ui/gtk.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/ui/gtk.c b/ui/gtk.c index e83a366625..471528362f 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -2029,6 +2029,28 @@ static gboolean gd_vc_in(VteTerminal *terminal, gchar *text, guint size, return TRUE; } +static void gd_vc_vte_update_size(VirtualConsole *vc) +{ + uint16_t cols, rows; + cols = vte_terminal_get_column_count(VTE_TERMINAL(vc->vte.terminal)); + rows = vte_terminal_get_row_count(VTE_TERMINAL(vc->vte.terminal)); + qemu_chr_resize(vc->vte.chr, cols, rows); +} + +static void gd_vc_size_allocate(VteTerminal *terminal, + GtkAllocation *allocation, gpointer user_data) +{ + VirtualConsole *vc = user_data; + gd_vc_vte_update_size(vc); +} + +static void gd_vc_char_size_changed(VteTerminal *terminal, guint width, + guint height, gpointer user_data) +{ + VirtualConsole *vc = user_data; + gd_vc_vte_update_size(vc); +} + static GSList *gd_vc_vte_init(GtkDisplayState *s, VirtualConsole *vc, Chardev *chr, int idx, GSList *group, GtkWidget *view_menu) @@ -2094,6 +2116,12 @@ static GSList *gd_vc_vte_init(GtkDisplayState *s, VirtualConsole *vc, qemu_chr_be_event(vc->vte.chr, CHR_EVENT_OPENED); + g_signal_connect(vc->vte.terminal, "size-allocate", + G_CALLBACK(gd_vc_size_allocate), vc); + g_signal_connect(vc->vte.terminal, "char-size-changed", + G_CALLBACK(gd_vc_char_size_changed), vc); + gd_vc_vte_update_size(vc); + return group; } -- 2.52.0
