wayland/idle-inhibit: Change to use GObject signals

Fixes: 388b534062 ("wayland: Implement idle inhibit protocol")
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3219>
This commit is contained in:
Jonas Ådahl 2023-08-28 11:52:12 +02:00
parent 45abae7ebb
commit 170ba63dbf

View File

@ -37,7 +37,7 @@ struct _MetaWaylandIdleInhibitor
uint32_t cookie; uint32_t cookie;
gulong is_obscured_changed_handler; gulong is_obscured_changed_handler;
gboolean idle_inhibited; gboolean idle_inhibited;
struct wl_listener surface_destroy_listener; gulong surface_destroy_handler_id;
GCancellable *cancellable; GCancellable *cancellable;
}; };
@ -188,18 +188,20 @@ idle_inhibitor_destructor (struct wl_resource *resource)
uninhibit_completed, uninhibit_completed,
NULL); NULL);
} }
if (inhibitor->surface) if (inhibitor->surface)
wl_list_remove (&inhibitor->surface_destroy_listener.link); {
g_clear_signal_handler (&inhibitor->surface_destroy_handler_id,
inhibitor->surface);
}
g_free (inhibitor); g_free (inhibitor);
} }
static void static void
inhibitor_surface_destroyed (struct wl_listener *listener, on_surface_destroyed (MetaWaylandSurface *surface,
void *data) MetaWaylandIdleInhibitor *inhibitor)
{ {
MetaWaylandIdleInhibitor *inhibitor = wl_container_of (listener,
inhibitor,
surface_destroy_listener);
inhibitor->surface = NULL; inhibitor->surface = NULL;
} }
@ -247,9 +249,10 @@ idle_inhibit_manager_create_inhibitor (struct wl_client *client,
inhibitor, inhibitor,
idle_inhibitor_destructor); idle_inhibitor_destructor);
inhibitor->surface_destroy_listener.notify = inhibitor_surface_destroyed; inhibitor->surface_destroy_handler_id =
wl_resource_add_destroy_listener (surface->resource, g_signal_connect (surface, "destroy",
&inhibitor->surface_destroy_listener); G_CALLBACK (on_surface_destroyed),
inhibitor);
} }