Defer gtk_widget_set_size_request() when size-allocate is in progress

Otherwise, GTK's sizing state may become inconsistent, resulting in later
size-allocate signals not being generated when they should be.
See #22628
This commit is contained in:
Paul Cornett 2022-08-12 10:39:17 -07:00
parent d0e4aa761c
commit f294083c24

View file

@ -227,6 +227,7 @@ int g_lastButtonNumber = 0;
#ifdef __WXGTK3__
static GList* gs_sizeRevalidateList;
static GSList* gs_setSizeRequestList;
#endif
wxRecursionGuardFlag g_inSizeAllocate = 0;
@ -2351,6 +2352,23 @@ static void frame_clock_layout(GdkFrameClock*, wxWindow* win)
static void frame_clock_layout_after(GdkFrameClock*, wxWindowGTK* win)
{
win->GTKSendSizeEventIfNeeded();
if (gs_setSizeRequestList)
{
for (GSList* p = gs_setSizeRequestList; p; p = p->next)
{
if (p->data == NULL)
continue;
wxWindowGTK* w = static_cast<wxWindowGTK*>(p->data);
g_object_remove_weak_pointer(G_OBJECT(w->m_widget), &p->data);
GtkAllocation a;
gtk_widget_get_allocation(w->m_widget, &a);
gtk_widget_set_size_request(w->m_widget, a.width, a.height);
}
g_slist_free(gs_setSizeRequestList);
gs_setSizeRequestList = NULL;
}
}
#endif // GTK_CHECK_VERSION(3,8,0)
@ -3844,7 +3862,6 @@ void wxWindowGTK::DoMoveWindow(int x, int y, int width, int height)
}
}
gtk_widget_set_size_request(m_widget, width, height);
#ifdef __WXGTK3__
// With GTK3, gtk_widget_queue_resize() is ignored while a size-allocate
@ -3865,8 +3882,25 @@ void wxWindowGTK::DoMoveWindow(int x, int y, int width, int height)
GtkAllocation a = { x, y, width, height };
gtk_widget_size_allocate(m_widget, &a);
}
#if GTK_CHECK_VERSION(3,8,0)
if (wx_is_at_least_gtk3(8))
{
// Defer gtk_widget_set_size_request(), as doing it now
// causes GTK's sizing state to become inconsistent
gs_setSizeRequestList = g_slist_prepend(gs_setSizeRequestList, this);
g_object_add_weak_pointer(G_OBJECT(m_widget), &gs_setSizeRequestList->data);
}
else
#endif
{
gtk_widget_set_size_request(m_widget, width, height);
}
}
else
#endif // __WXGTK3__
{
gtk_widget_set_size_request(m_widget, width, height);
}
}
void wxWindowGTK::ConstrainSize()