monitor: Add hash function

Will be used to keep a monitor spec as a hash table key.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1712>
This commit is contained in:
Jonas Ådahl 2021-02-05 17:21:55 +01:00 committed by Marge Bot
parent fcbeae5f60
commit 4615da2122
2 changed files with 13 additions and 0 deletions

View File

@ -127,6 +127,17 @@ meta_monitor_spec_clone (MetaMonitorSpec *monitor_spec)
return new_monitor_spec; return new_monitor_spec;
} }
guint
meta_monitor_spec_hash (gconstpointer key)
{
const MetaMonitorSpec *monitor_spec = key;
return (g_str_hash (monitor_spec->connector) +
g_str_hash (monitor_spec->vendor) +
g_str_hash (monitor_spec->product) +
g_str_hash (monitor_spec->serial));
}
gboolean gboolean
meta_monitor_spec_equals (MetaMonitorSpec *monitor_spec, meta_monitor_spec_equals (MetaMonitorSpec *monitor_spec,
MetaMonitorSpec *other_monitor_spec) MetaMonitorSpec *other_monitor_spec)

View File

@ -262,6 +262,8 @@ gboolean meta_monitor_mode_should_be_advertised (MetaMonitorMode *monitor_mode);
META_EXPORT_TEST META_EXPORT_TEST
MetaMonitorSpec * meta_monitor_spec_clone (MetaMonitorSpec *monitor_id); MetaMonitorSpec * meta_monitor_spec_clone (MetaMonitorSpec *monitor_id);
guint meta_monitor_spec_hash (gconstpointer key);
META_EXPORT_TEST META_EXPORT_TEST
gboolean meta_monitor_spec_equals (MetaMonitorSpec *monitor_id, gboolean meta_monitor_spec_equals (MetaMonitorSpec *monitor_id,
MetaMonitorSpec *other_monitor_id); MetaMonitorSpec *other_monitor_id);