[mutter] wayland/inhibit-shortcuts-dialog: Make the dialog ownership clearer



commit c1439e141e7a4b02c073b9ce1b659fc3d06b00d1
Author: Jonas Ådahl <jadahl gmail com>
Date:   Sat Aug 19 00:22:08 2017 +0800

    wayland/inhibit-shortcuts-dialog: Make the dialog ownership clearer
    
    Make it clear that the data object is the owner of the dialog; it
    creates it, and eventually destroys it.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=786385

 .../meta-wayland-inhibit-shortcuts-dialog.c        |   29 +++++++++----------
 1 files changed, 14 insertions(+), 15 deletions(-)
---
diff --git a/src/wayland/meta-wayland-inhibit-shortcuts-dialog.c 
b/src/wayland/meta-wayland-inhibit-shortcuts-dialog.c
index 6ae1eb8..aff067a 100644
--- a/src/wayland/meta-wayland-inhibit-shortcuts-dialog.c
+++ b/src/wayland/meta-wayland-inhibit-shortcuts-dialog.c
@@ -30,6 +30,7 @@ typedef struct _InhibitShortcutsData
   MetaWaylandSurface                *surface;
   MetaWaylandSeat                   *seat;
   MetaInhibitShortcutsDialog        *dialog;
+  gulong                             response_handler_id;
   gboolean                           has_last_response;
   MetaInhibitShortcutsDialogResponse last_response;
 } InhibitShortcutsData;
@@ -51,10 +52,18 @@ surface_inhibit_shortcuts_data_set (MetaWaylandSurface   *surface,
 }
 
 static void
-surface_inhibit_shortcuts_data_free (InhibitShortcutsData *data)
+surface_inhibit_shortcuts_data_destroy_dialog (InhibitShortcutsData *data)
 {
+  g_signal_handler_disconnect (data->dialog, data->response_handler_id);
   meta_inhibit_shortcuts_dialog_hide (data->dialog);
+  g_clear_object (&data->dialog);
+}
 
+static void
+surface_inhibit_shortcuts_data_free (InhibitShortcutsData *data)
+{
+  if (data->dialog)
+    surface_inhibit_shortcuts_data_destroy_dialog (data);
   g_free (data);
 }
 
@@ -69,15 +78,6 @@ on_surface_destroyed (MetaWaylandSurface   *surface,
 }
 
 static void
-surface_inhibit_shortcuts_dialog_free (gpointer  ptr,
-                                       GClosure *closure)
-{
-  InhibitShortcutsData *data = ptr;
-
-  meta_wayland_surface_hide_inhibit_shortcuts_dialog (data->surface);
-}
-
-static void
 inhibit_shortcuts_dialog_response_apply (InhibitShortcutsData *data)
 {
   if (data->last_response == META_INHIBIT_SHORTCUTS_DIALOG_RESPONSE_ALLOW)
@@ -125,11 +125,10 @@ meta_wayland_surface_ensure_inhibit_shortcuts_dialog (MetaWaylandSurface *surfac
   data->surface = surface;
   data->seat = seat;
   data->dialog = dialog;
-
-  g_signal_connect_data (dialog, "response",
-                         G_CALLBACK (inhibit_shortcuts_dialog_response_cb),
-                         data, surface_inhibit_shortcuts_dialog_free,
-                         0);
+  data->response_handler_id =
+    g_signal_connect (dialog, "response",
+                      G_CALLBACK (inhibit_shortcuts_dialog_response_cb),
+                      data);
 
   return data;
 }


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