[mutter] wayland/inhibit-shortcuts-dialog: Make data life cycle a bit clearer
- From: Jonas Ådahl <jadahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] wayland/inhibit-shortcuts-dialog: Make data life cycle a bit clearer
- Date: Sat, 19 Aug 2017 09:26:59 +0000 (UTC)
commit dceb0f1f1f35f9d330a0ecfc2519aa3892740201
Author: Jonas Ådahl <jadahl gmail com>
Date: Sat Aug 19 00:17:48 2017 +0800
wayland/inhibit-shortcuts-dialog: Make data life cycle a bit clearer
The 'data' object is attached to the MetaWaylandSurface as a GObject
qdata. It is created once, and stays allocated until the surface is
destroyed. To make things clearer, connect to the "destroy" signal just
after creating, and from a on_surface_destroyed() callback call the
.._free() function.
https://bugzilla.gnome.org/show_bug.cgi?id=786385
.../meta-wayland-inhibit-shortcuts-dialog.c | 31 +++++++++++--------
1 files changed, 18 insertions(+), 13 deletions(-)
---
diff --git a/src/wayland/meta-wayland-inhibit-shortcuts-dialog.c
b/src/wayland/meta-wayland-inhibit-shortcuts-dialog.c
index 207c6b1..6ae1eb8 100644
--- a/src/wayland/meta-wayland-inhibit-shortcuts-dialog.c
+++ b/src/wayland/meta-wayland-inhibit-shortcuts-dialog.c
@@ -51,8 +51,7 @@ surface_inhibit_shortcuts_data_set (MetaWaylandSurface *surface,
}
static void
-surface_inhibit_shortcuts_data_free (MetaWaylandSurface *surface,
- InhibitShortcutsData *data)
+surface_inhibit_shortcuts_data_free (InhibitShortcutsData *data)
{
meta_inhibit_shortcuts_dialog_hide (data->dialog);
@@ -60,6 +59,16 @@ surface_inhibit_shortcuts_data_free (MetaWaylandSurface *surface,
}
static void
+on_surface_destroyed (MetaWaylandSurface *surface,
+ InhibitShortcutsData *data)
+{
+ surface_inhibit_shortcuts_data_free (data);
+ g_object_set_qdata (G_OBJECT (surface),
+ quark_surface_inhibit_shortcuts_data,
+ NULL);
+}
+
+static void
surface_inhibit_shortcuts_dialog_free (gpointer ptr,
GClosure *closure)
{
@@ -98,15 +107,15 @@ meta_wayland_surface_ensure_inhibit_shortcuts_dialog (MetaWaylandSurface *surfac
MetaInhibitShortcutsDialog *dialog;
data = surface_inhibit_shortcuts_data_get (surface);
- if (data == NULL)
- {
- data = g_new (InhibitShortcutsData, 1);
- surface_inhibit_shortcuts_data_set (surface, data);
- }
- else if (data->dialog != NULL)
- /* There is a dialog already created, nothing to do */
+ if (data)
return data;
+ data = g_new (InhibitShortcutsData, 1);
+ surface_inhibit_shortcuts_data_set (surface, data);
+ g_signal_connect (surface, "destroy",
+ G_CALLBACK (on_surface_destroyed),
+ data);
+
window = meta_wayland_surface_get_toplevel_window (surface);
display = window->display;
dialog =
@@ -122,10 +131,6 @@ meta_wayland_surface_ensure_inhibit_shortcuts_dialog (MetaWaylandSurface *surfac
data, surface_inhibit_shortcuts_dialog_free,
0);
- g_signal_connect (surface, "destroy",
- G_CALLBACK (surface_inhibit_shortcuts_data_free),
- data);
-
return data;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]