fix(overlay): enforce text wrap width to prevent overflow beyond screen

Add `gtk_label_set_width_chars` to set a concrete width for label allocation,
ensuring long sentences wrap within the configured max-chars bubble width
instead of extending off-screen.
This commit is contained in:
2026-07-16 18:06:00 +03:00
parent bd2fc175a8
commit 192666dd43
2 changed files with 4 additions and 1 deletions
+1 -1
View File
@@ -64,7 +64,7 @@ Use `--output=both` to keep terminal output as well:
./scripts/distrobox/run.sh --mode=vad --output=both
```
In VAD mode, a 500 ms pause finalizes the current caption and starts the next line. The overlay keeps up to six completed lines above the active provisional caption; each completed line remains visible for at least three seconds and gradually fades from white to a restrained gray as it ages. If a seventh line arrives sooner, the hard six-line cap removes the oldest. Text is left-aligned inside the centered, fixed-width dark bubble. Pointer input passes through the window by default. Empty completed captions hide the overlay.
In VAD mode, a 500 ms pause finalizes the current caption and starts the next line. The overlay keeps up to six completed lines above the active provisional caption; each completed line remains visible for at least three seconds and gradually fades from white to a restrained gray as it ages. If a seventh line arrives sooner, the hard six-line cap removes the oldest. Text is left-aligned inside the centered, fixed-width dark bubble and wraps at its configured width instead of extending off-screen. Pointer input passes through the window by default. Empty completed captions hide the overlay.
To build outside the helper script, install GTK4 and GTK4 Layer Shell development packages, then run:
+3
View File
@@ -354,6 +354,9 @@ static CaptioneerOverlay *captioneer_overlay_new(
gtk_label_set_xalign(GTK_LABEL(labels[i]), 0.0f);
gtk_label_set_wrap(GTK_LABEL(labels[i]), TRUE);
gtk_label_set_wrap_mode(GTK_LABEL(labels[i]), PANGO_WRAP_WORD_CHAR);
// width-chars gives GTK a concrete allocation width, so wrapping happens
// before a long sentence can widen the bubble beyond the screen.
gtk_label_set_width_chars(GTK_LABEL(labels[i]), max_chars);
gtk_label_set_max_width_chars(GTK_LABEL(labels[i]), max_chars);
gtk_widget_set_halign(labels[i], GTK_ALIGN_FILL);
gtk_box_append(GTK_BOX(box), labels[i]);