cleanup: Use g_clear_signal_handler() where possible

This is inspired by 98892391d7 where the usage of
`g_signal_handler_disconnect()` without resetting the corresponding
handler id later resulted in a bug. Using `g_clear_signal_handler()`
makes sure we avoid similar bugs and is almost always the better
alternative. We use it for new code, let's clean up the old code to
also use it.

A further benefit is that it can get called even if the passed id is
0, allowing us to remove a lot of now unnessecary checks, and the fact
that `g_clear_signal_handler()` checks for the right type size, forcing us
to clean up all places where we used `guint` instead of `gulong`.

No functional changes intended here and all changes should be trivial,
thus bundled in one big commit.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/940
This commit is contained in:
Robert Mader
2019-11-16 01:25:52 +01:00
committed by Florian Müllner
parent 22d1febf3c
commit 92375c75f8
45 changed files with 168 additions and 303 deletions

View File

@ -50,7 +50,7 @@ struct _CurrentToolInfo
ClutterInputDevice *device;
ClutterInputDeviceTool *tool;
GSettings *settings;
guint changed_id;
gulong changed_id;
};
struct _DeviceMappingInfo
@ -58,7 +58,7 @@ struct _DeviceMappingInfo
MetaInputSettings *input_settings;
ClutterInputDevice *device;
GSettings *settings;
guint changed_id;
gulong changed_id;
#ifdef HAVE_LIBWACOM
WacomDevice *wacom_device;
#endif
@ -69,7 +69,7 @@ struct _MetaInputSettingsPrivate
{
ClutterDeviceManager *device_manager;
MetaMonitorManager *monitor_manager;
guint monitors_changed_id;
gulong monitors_changed_id;
GSettings *mouse_settings;
GSettings *touchpad_settings;
@ -168,12 +168,8 @@ meta_input_settings_dispose (GObject *object)
g_clear_pointer (&priv->mappable_devices, g_hash_table_unref);
g_clear_pointer (&priv->current_tools, g_hash_table_unref);
if (priv->monitors_changed_id && priv->monitor_manager)
{
g_signal_handler_disconnect (priv->monitor_manager,
priv->monitors_changed_id);
priv->monitors_changed_id = 0;
}
if (priv->monitor_manager)
g_clear_signal_handler (&priv->monitors_changed_id, priv->monitor_manager);
g_clear_object (&priv->monitor_manager);
@ -1555,7 +1551,7 @@ device_mapping_info_free (DeviceMappingInfo *info)
if (info->wacom_device)
libwacom_destroy (info->wacom_device);
#endif
g_signal_handler_disconnect (info->settings, info->changed_id);
g_clear_signal_handler (&info->changed_id, info->settings);
g_object_unref (info->settings);
g_free (info->group_modes);
g_slice_free (DeviceMappingInfo, info);
@ -1812,7 +1808,7 @@ current_tool_info_new (MetaInputSettings *input_settings,
static void
current_tool_info_free (CurrentToolInfo *info)
{
g_signal_handler_disconnect (info->settings, info->changed_id);
g_clear_signal_handler (&info->changed_id, info->settings);
g_free (info);
}