From 135d178d088800992e3526fafb659788bb42ba34 Mon Sep 17 00:00:00 2001 From: Robert Mader Date: Thu, 21 Nov 2019 23:00:53 +0100 Subject: [PATCH] cleanup: Use g_clear_signal_handler() where possible `g_clear_signal_handler()` is usually cleaner and saver than `g_signal_handler_disconnect()`. We use it new code, lets also adopt the existing one. See also https://gitlab.gnome.org/GNOME/mutter/merge_requests/868 and https://gitlab.gnome.org/GNOME/mutter/merge_requests/940 https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/842 --- src/calendar-server/calendar-sources.c | 14 ++++++------- .../gnome-shell-calendar-server.c | 3 +-- src/gtkactionmuxer.c | 2 +- src/shell-app.c | 4 ++-- src/shell-gtk-embed.c | 21 +++++++------------ src/st/st-adjustment.c | 2 +- src/st/st-icon.c | 5 ++--- src/st/st-texture-cache.c | 4 ++-- src/st/st-theme-node-transition.c | 12 ++++------- src/st/st-widget.c | 7 ++----- 10 files changed, 29 insertions(+), 45 deletions(-) diff --git a/src/calendar-server/calendar-sources.c b/src/calendar-server/calendar-sources.c index ed76c015c..7e4c7f52e 100644 --- a/src/calendar-server/calendar-sources.c +++ b/src/calendar-server/calendar-sources.c @@ -112,7 +112,7 @@ static CalendarSources *calendar_sources_singleton = NULL; static void client_data_free (ClientData *data) { - g_signal_handler_disconnect (data->client, data->backend_died_id); + g_clear_signal_handler (&data->backend_died_id, data->client); g_object_unref (data->client); g_slice_free (ClientData, data); } @@ -259,12 +259,12 @@ calendar_sources_finalize (GObject *object) if (sources->priv->registry) { - g_signal_handler_disconnect (sources->priv->registry, - sources->priv->source_added_id); - g_signal_handler_disconnect (sources->priv->registry, - sources->priv->source_changed_id); - g_signal_handler_disconnect (sources->priv->registry, - sources->priv->source_removed_id); + g_clear_signal_handler (&sources->priv->source_added_id, + sources->priv->registry); + g_clear_signal_handler (&sources->priv->source_changed_id, + sources->priv->registry); + g_clear_signal_handler (&sources->priv->source_removed_id, + sources->priv->registry); g_object_unref (sources->priv->registry); } sources->priv->registry = NULL; diff --git a/src/calendar-server/gnome-shell-calendar-server.c b/src/calendar-server/gnome-shell-calendar-server.c index 9c88a2f9e..d04f0019c 100644 --- a/src/calendar-server/gnome-shell-calendar-server.c +++ b/src/calendar-server/gnome-shell-calendar-server.c @@ -789,8 +789,7 @@ app_free (App *app) g_hash_table_unref (app->appointments); g_object_unref (app->connection); - g_signal_handler_disconnect (app->sources, - app->sources_signal_id); + g_clear_signal_handler (&app->sources_signal_id, app->sources); g_object_unref (app->sources); if (app->changed_timeout_id != 0) diff --git a/src/gtkactionmuxer.c b/src/gtkactionmuxer.c index 1cdf2940a..bbd26d27b 100644 --- a/src/gtkactionmuxer.c +++ b/src/gtkactionmuxer.c @@ -540,7 +540,7 @@ gtk_action_muxer_free_group (gpointer data) /* 'for loop' or 'four loop'? */ for (i = 0; i < 4; i++) - g_signal_handler_disconnect (group->group, group->handler_ids[i]); + g_clear_signal_handler (&group->handler_ids[i], group->group); g_object_unref (group->group); g_free (group->prefix); diff --git a/src/shell-app.c b/src/shell-app.c index 14ebfc40d..c237a225e 100644 --- a/src/shell-app.c +++ b/src/shell-app.c @@ -35,7 +35,7 @@ typedef struct { guint refcount; /* Signal connection to dirty window sort list on workspace changes */ - guint workspace_switch_id; + gulong workspace_switch_id; GSList *windows; @@ -1445,7 +1445,7 @@ unref_running_state (ShellAppRunningState *state) if (state->refcount > 0) return; - g_signal_handler_disconnect (workspace_manager, state->workspace_switch_id); + g_clear_signal_handler (&state->workspace_switch_id, workspace_manager); g_clear_object (&state->application_proxy); diff --git a/src/shell-gtk-embed.c b/src/shell-gtk-embed.c index 6d3a66466..8a3fbac06 100644 --- a/src/shell-gtk-embed.c +++ b/src/shell-gtk-embed.c @@ -23,9 +23,9 @@ struct _ShellGtkEmbedPrivate ShellEmbeddedWindow *window; ClutterActor *window_actor; - guint window_actor_destroyed_handler; + gulong window_actor_destroyed_handler; - guint window_created_handler; + gulong window_created_handler; }; G_DEFINE_TYPE_WITH_PRIVATE (ShellGtkEmbed, shell_gtk_embed, CLUTTER_TYPE_CLONE); @@ -47,9 +47,8 @@ shell_gtk_embed_remove_window_actor (ShellGtkEmbed *embed) if (priv->window_actor) { - g_signal_handler_disconnect (priv->window_actor, - priv->window_actor_destroyed_handler); - priv->window_actor_destroyed_handler = 0; + g_clear_signal_handler (&priv->window_actor_destroyed_handler, + priv->window_actor); g_object_unref (priv->window_actor); priv->window_actor = NULL; @@ -116,9 +115,8 @@ shell_gtk_embed_window_created_cb (MetaDisplay *display, /* Now that we've found the window we don't need to listen for new windows anymore */ - g_signal_handler_disconnect (display, - priv->window_created_handler); - priv->window_created_handler = 0; + g_clear_signal_handler (&priv->window_created_handler, + display); } } @@ -148,12 +146,7 @@ shell_gtk_embed_set_window (ShellGtkEmbed *embed, if (priv->window) { - if (priv->window_created_handler) - { - g_signal_handler_disconnect (display, - priv->window_created_handler); - priv->window_created_handler = 0; - } + g_clear_signal_handler (&priv->window_created_handler, display); shell_gtk_embed_remove_window_actor (embed); diff --git a/src/st/st-adjustment.c b/src/st/st-adjustment.c index 890c69903..dfd1efe67 100644 --- a/src/st/st-adjustment.c +++ b/src/st/st-adjustment.c @@ -623,7 +623,7 @@ transition_closure_free (gpointer data) clos = data; timeline = CLUTTER_TIMELINE (clos->transition); - g_signal_handler_disconnect (clos->transition, clos->completed_id); + g_clear_signal_handler (&clos->completed_id, clos->transition); if (clutter_timeline_is_playing (timeline)) clutter_timeline_stop (timeline); diff --git a/src/st/st-icon.c b/src/st/st-icon.c index 71a6b8980..4ef287620 100644 --- a/src/st/st-icon.c +++ b/src/st/st-icon.c @@ -50,7 +50,7 @@ struct _StIconPrivate { ClutterActor *icon_texture; ClutterActor *pending_texture; - guint opacity_handler_id; + gulong opacity_handler_id; GIcon *gicon; gint prop_icon_size; /* icon size set as property */ @@ -369,8 +369,7 @@ opacity_changed_cb (GObject *object, StIcon *icon = user_data; StIconPrivate *priv = icon->priv; - g_signal_handler_disconnect (priv->pending_texture, priv->opacity_handler_id); - priv->opacity_handler_id = 0; + g_clear_signal_handler (&priv->opacity_handler_id, priv->pending_texture); st_icon_finish_update (icon); } diff --git a/src/st/st-texture-cache.c b/src/st/st-texture-cache.c index 53df7195b..d5f204ba2 100644 --- a/src/st/st-texture-cache.c +++ b/src/st/st-texture-cache.c @@ -707,7 +707,7 @@ typedef struct { ClutterActor *actor; gint size; GObject *source; - guint notify_signal_id; + gulong notify_signal_id; gboolean weakref_active; } StTextureCachePropertyBind; @@ -772,7 +772,7 @@ st_texture_cache_bind_weak_notify (gpointer data, { StTextureCachePropertyBind *bind = data; bind->weakref_active = FALSE; - g_signal_handler_disconnect (bind->source, bind->notify_signal_id); + g_clear_signal_handler (&bind->notify_signal_id, bind->source); } static void diff --git a/src/st/st-theme-node-transition.c b/src/st/st-theme-node-transition.c index f35977a18..42232bd2d 100644 --- a/src/st/st-theme-node-transition.c +++ b/src/st/st-theme-node-transition.c @@ -54,8 +54,8 @@ struct _StThemeNodeTransitionPrivate { ClutterTimeline *timeline; - guint timeline_completed_id; - guint timeline_new_frame_id; + gulong timeline_completed_id; + gulong timeline_new_frame_id; ClutterActorBox last_allocation; ClutterActorBox offscreen_box; @@ -410,12 +410,8 @@ st_theme_node_transition_dispose (GObject *object) if (priv->timeline) { - if (priv->timeline_completed_id != 0) - g_signal_handler_disconnect (priv->timeline, - priv->timeline_completed_id); - if (priv->timeline_new_frame_id != 0) - g_signal_handler_disconnect (priv->timeline, - priv->timeline_new_frame_id); + g_clear_signal_handler (&priv->timeline_completed_id, priv->timeline); + g_clear_signal_handler (&priv->timeline_new_frame_id, priv->timeline); g_clear_object (&priv->timeline); } diff --git a/src/st/st-widget.c b/src/st/st-widget.c index fd0f19b22..23787073d 100644 --- a/src/st/st-widget.c +++ b/src/st/st-widget.c @@ -308,11 +308,8 @@ st_widget_dispose (GObject *gobject) g_clear_pointer (&priv->label_actor, g_object_unref); - if (priv->texture_file_changed_id != 0) - { - g_signal_handler_disconnect (st_texture_cache_get_default (), priv->texture_file_changed_id); - priv->texture_file_changed_id = 0; - } + g_clear_signal_handler (&priv->texture_file_changed_id, + st_texture_cache_get_default ()); g_clear_object (&priv->first_visible_child); g_clear_object (&priv->last_visible_child);