[Libguestfs] [p2v PATCH 5/7] gui.c: fix warning label wrapping regression under GTK3

Laszlo Ersek
2022-09-26T08:18:10Z

(Note that this issue is reproducible with virt-p2v v1.42.2.)

When building virt-p2v with GTK3 (specifically,
gtk3-3.24.34-1.fc35.x86_64), the label that warns about too many VCPUs
and/or too much guest RAM does not wrap, even though we set it to
wrapping.  Instead, the (otherwise fixed size) outer window is resized
with a sudden jump, to accommodate the (now very long) single-line
warning.

This issue does not manifest itself under GTK2, which is why I've not
noticed it thus far.  Under GTK3, we can mitigate the symptom by following
the advice at:

  https://wiki.gnome.org/HowDoI/Labels#Labels_in_non-resizable_windows

Namely, set the "max-width-chars" property of the label, specifying
the
"natural width" of the label, expressed in units of average-width
characters.  The empirical value 50 seems to do what GTK2 does out of the
box.

Signed-off-by: Laszlo Ersek <lersek at redhat.com>
---
 gui.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gui.c b/gui.c
index 1e2cd3f94c62..5d1771266605 100644
--- a/gui.c
+++ b/gui.c
@@ -835,6 +835,7 @@ create_conversion_dialog (struct config *config,
   gtk_label_set_line_wrap (GTK_LABEL (target_warning_label), TRUE);
   gtk_label_set_line_wrap_mode (GTK_LABEL (target_warning_label),
                                 PANGO_WRAP_WORD);
+  gtk_label_set_max_width_chars (GTK_LABEL (target_warning_label), 50);
   gtk_widget_set_size_request (target_warning_label, -1, 7 * 16);
   gtk_box_pack_end (GTK_BOX (target_vbox), target_warning_label, TRUE, TRUE,
0);