[libadwaita/libadwaita-1-0] adw-view-switcher-title: Clear pending idle callback on unrealize



commit 426bfdeff43a46063740ae14bfa53b4a6a9ae81d
Author: Philip Withnall <pwithnall endlessos org>
Date:   Thu Mar 31 17:54:53 2022 +0100

    adw-view-switcher-title: Clear pending idle callback on unrealize
    
    It’s possible (but quite unlikely) for the widget to be unrealized and
    destroyed while `check_window_width()` is pending in an idle callback.
    
    If that happens, `check_window_width()` will be called on a disposed
    `AdwViewSwitcherTitle` instance, and will crash.
    
    Avoid that by explicitly removing the idle source when the widget is
    unrealized.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    
    (cherry picked from commit 646d89d4e3bce25c77a24230c70948628f0d3386)
    
    (cherry picked from commit 7ad2d54b747746c1538bcea1d1d24379bdf18bf4)

 src/adw-view-switcher-title.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
---
diff --git a/src/adw-view-switcher-title.c b/src/adw-view-switcher-title.c
index d4334496..fdfd1018 100644
--- a/src/adw-view-switcher-title.c
+++ b/src/adw-view-switcher-title.c
@@ -102,6 +102,8 @@ struct _AdwViewSwitcherTitle
   gboolean is_window_narrow;
 
   GtkSelectionModel *pages;
+
+  guint check_window_width_id;
 };
 
 static GParamSpec *props[LAST_PROP];
@@ -224,13 +226,15 @@ check_window_width (AdwViewSwitcherTitle *self)
   self->is_window_narrow = width <= 360;
   update_view_switcher_visible (self);
 
+  self->check_window_width_id = 0;
   return G_SOURCE_REMOVE;
 }
 
 static void
 notify_surface_width_cb (AdwViewSwitcherTitle *self)
 {
-  g_idle_add (G_SOURCE_FUNC (check_window_width), self);
+  if (self->check_window_width_id == 0)
+    self->check_window_width_id = g_idle_add (G_SOURCE_FUNC (check_window_width), self);
 }
 
 static void
@@ -258,6 +262,8 @@ adw_view_switcher_title_unrealize (GtkWidget *widget)
 
   g_signal_handlers_disconnect_by_func (surface, notify_surface_width_cb, self);
 
+  g_clear_handle_id (&self->check_window_width_id, g_source_remove);
+
   GTK_WIDGET_CLASS (adw_view_switcher_title_parent_class)->unrealize (widget);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]