[libadwaita] adw-view-switcher-title: Clear pending idle callback on unrealize
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libadwaita] adw-view-switcher-title: Clear pending idle callback on unrealize
- Date: Fri, 1 Apr 2022 11:54:05 +0000 (UTC)
commit 646d89d4e3bce25c77a24230c70948628f0d3386
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>
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 a55d9d45..cc5a5b63 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]