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
This commit is contained in:
Jonas Ådahl 2017-08-19 00:17:48 +08:00
parent a7915ff8ae
commit dceb0f1f1f

View File

@ -51,14 +51,23 @@ 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);
g_free (data);
}
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;
}