From 6d65871c4d0f636307fdd12f062c2bfe48254972 Mon Sep 17 00:00:00 2001 From: deepend-tildeclub Date: Mon, 11 May 2026 13:32:11 -0600 Subject: [PATCH] Fix xtext resize paint clipping --- src/fe-gtk/xtext.c | 55 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/src/fe-gtk/xtext.c b/src/fe-gtk/xtext.c index 01373725..015177ab 100644 --- a/src/fe-gtk/xtext.c +++ b/src/fe-gtk/xtext.c @@ -1283,13 +1283,25 @@ gtk_xtext_get_preferred_height_for_width (GtkWidget *widget, gint width, *natural = requisition.height; } +static void +gtk_xtext_invalidate_resize (GtkXText *xtext, xtext_buffer *buf) +{ + buf->pagetop_ent = NULL; + dontscroll (buf); + xtext->force_render = TRUE; +} + static void gtk_xtext_size_allocate (GtkWidget * widget, GtkAllocation * allocation) { GtkXText *xtext = GTK_XTEXT (widget); int height_only = FALSE; + gboolean resized; GdkWindow *window; + resized = allocation->width != xtext->buffer->window_width || + allocation->height != xtext->buffer->window_height; + if (allocation->width == xtext->buffer->window_width) height_only = TRUE; @@ -1315,6 +1327,11 @@ gtk_xtext_size_allocate (GtkWidget * widget, GtkAllocation * allocation) xtext_adj_set_value (xtext->adj, xtext_adj_get_upper (xtext->adj) - xtext_adj_get_page_size (xtext->adj)); + if (resized) + { + gtk_xtext_invalidate_resize (xtext, xtext->buffer); + gtk_widget_queue_draw (widget); + } } } @@ -1587,6 +1604,17 @@ gtk_xtext_render (GtkWidget *widget, GdkRectangle *area, cairo_t *cr) gtk_widget_get_allocation (widget, &allocation); + if (xtext->force_render && area->x == 0 && area->y == 0 && + area->height == allocation.height && + area->width == allocation.width) + { + xtext->force_render = FALSE; + } + else if (xtext->force_render) + { + gtk_widget_queue_draw (widget); + } + if (area->x == 0 && area->y == 0 && area->height == allocation.height && area->width == allocation.width) @@ -4302,13 +4330,9 @@ gtk_xtext_calc_lines (xtext_buffer *buf, int fire_signal) int width; int height; int lines; - GdkWindow *window; - window = gtk_widget_get_window (GTK_WIDGET (buf->xtext)); - if (!window) - return; - height = gdk_window_get_height (window); - width = gdk_window_get_width (window); + height = buf->window_height; + width = buf->window_width; width -= MARGIN; if (width < 30 || height < buf->xtext->fontsize || width < buf->indent + 30) @@ -4520,6 +4544,7 @@ gtk_xtext_render_page (GtkXText * xtext) int startline = adj_value; int pos, overlap; GdkWindow *window; + GtkAllocation allocation; if(!gtk_widget_get_realized(GTK_WIDGET(xtext))) return; @@ -4530,8 +4555,9 @@ gtk_xtext_render_page (GtkXText * xtext) window = gtk_widget_get_window (GTK_WIDGET (xtext)); if (!window) return; - width = gdk_window_get_width (window); - height = gdk_window_get_height (window); + gtk_widget_get_allocation (GTK_WIDGET (xtext), &allocation); + width = allocation.width; + height = allocation.height; if (width < 34 || height < xtext->fontsize || width < xtext->buffer->indent + 32) return; @@ -5742,6 +5768,7 @@ gtk_xtext_buffer_show (GtkXText *xtext, xtext_buffer *buf, int render) { int w, h; GdkWindow *window; + GtkAllocation allocation; buf->xtext = xtext; @@ -5768,8 +5795,9 @@ gtk_xtext_buffer_show (GtkXText *xtext, xtext_buffer *buf, int render) window = gtk_widget_get_window (GTK_WIDGET (xtext)); if (!window) return; - h = gdk_window_get_height (window); - w = gdk_window_get_width (window); + gtk_widget_get_allocation (GTK_WIDGET (xtext), &allocation); + h = allocation.height; + w = allocation.width; /* after a font change */ if (buf->needs_recalc) @@ -5807,6 +5835,10 @@ gtk_xtext_buffer_show (GtkXText *xtext, xtext_buffer *buf, int render) if (render) { + gboolean resized; + + resized = buf->window_width != w || buf->window_height != h; + /* did the window change size since this buffer was last shown? */ if (buf->window_width != w) { @@ -5827,6 +5859,9 @@ gtk_xtext_buffer_show (GtkXText *xtext, xtext_buffer *buf, int render) gtk_xtext_adjustment_set (buf, FALSE); } + if (resized) + gtk_xtext_invalidate_resize (xtext, buf); + gtk_xtext_render_page (xtext); { GtkAllocation allocation;