[libadwaita/wip/exalm/message-weak] message-dialog: Keep a weak pointer to the parent
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libadwaita/wip/exalm/message-weak] message-dialog: Keep a weak pointer to the parent
- Date: Tue, 26 Jul 2022 11:43:47 +0000 (UTC)
commit b8acdc01b625c7e6d2ca525983858e6f80269832
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Tue Jul 26 15:43:09 2022 +0400
message-dialog: Keep a weak pointer to the parent
Don't crash if the parent gets destroyed first.
src/adw-message-dialog.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
---
diff --git a/src/adw-message-dialog.c b/src/adw-message-dialog.c
index 4788746a..f6c3ea09 100644
--- a/src/adw-message-dialog.c
+++ b/src/adw-message-dialog.c
@@ -264,6 +264,16 @@ parent_unrealize_cb (AdwMessageDialog *self)
priv->parent_height = -1;
}
+static void
+parent_window_notify_cb (AdwMessageDialog *self)
+{
+ AdwMessageDialogPrivate *priv = adw_message_dialog_get_instance_private (self);
+
+ priv->parent_window = NULL;
+ priv->parent_width = -1;
+ priv->parent_height = -1;
+}
+
static void
set_parent (AdwMessageDialog *self,
GtkWindow *parent)
@@ -283,11 +293,19 @@ set_parent (AdwMessageDialog *self,
if (gtk_widget_get_realized (GTK_WIDGET (priv->parent_window)))
parent_unrealize_cb (self);
+
+ g_object_weak_unref (G_OBJECT (priv->parent_window),
+ (GWeakNotify) parent_window_notify_cb,
+ self);
}
priv->parent_window = parent;
if (priv->parent_window) {
+ g_object_weak_ref (G_OBJECT (priv->parent_window),
+ (GWeakNotify) parent_window_notify_cb,
+ self);
+
if (gtk_widget_get_realized (GTK_WIDGET (priv->parent_window)))
parent_realize_cb (self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]