From bc951557e81c678ca28222092988fd9e8c470456 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Sat, 17 Dec 2016 22:34:26 +0800 Subject: [PATCH] monitor: Add monitor spec object A monitor spec object is meant to be used to identify a certain monitor on a certain output. The spec is unique per actual monitor and connector, meaning that a monitor that changes from one connector from another (e.g. HDMI1 to HDMI2) will not be identified as the same. It is meant to associate for example a configuration entry with an actual monitor. https://bugzilla.gnome.org/show_bug.cgi?id=777732 --- src/backends/meta-monitor.c | 77 +++++++++++++++++++++++++++++++++++-- src/backends/meta-monitor.h | 17 ++++++++ 2 files changed, 90 insertions(+), 4 deletions(-) diff --git a/src/backends/meta-monitor.c b/src/backends/meta-monitor.c index a3fd155e8..14b188047 100644 --- a/src/backends/meta-monitor.c +++ b/src/backends/meta-monitor.c @@ -39,6 +39,8 @@ typedef struct _MetaMonitorPrivate MetaMonitorMode *preferred_mode; + MetaMonitorSpec *spec; + /* * The primary or first output for this monitor, 0 if we can't figure out. * It can be matched to a winsys_id of a MetaOutput. @@ -74,6 +76,60 @@ G_DEFINE_TYPE (MetaMonitorTiled, meta_monitor_tiled, META_TYPE_MONITOR) static void meta_monitor_mode_free (MetaMonitorMode *mode); +MetaMonitorSpec * +meta_monitor_spec_clone (MetaMonitorSpec *monitor_spec) +{ + MetaMonitorSpec *new_monitor_spec; + + new_monitor_spec = g_new0 (MetaMonitorSpec, 1); + *new_monitor_spec = (MetaMonitorSpec) { + .connector = g_strdup (monitor_spec->connector), + .vendor = g_strdup (monitor_spec->vendor), + .product = g_strdup (monitor_spec->product), + .serial = g_strdup (monitor_spec->serial), + }; + + return new_monitor_spec; +} + +gboolean +meta_monitor_spec_equals (MetaMonitorSpec *monitor_spec, + MetaMonitorSpec *other_monitor_spec) +{ + return (g_str_equal (monitor_spec->connector, other_monitor_spec->connector) && + g_str_equal (monitor_spec->vendor, other_monitor_spec->vendor) && + g_str_equal (monitor_spec->product, other_monitor_spec->product) && + g_str_equal (monitor_spec->serial, other_monitor_spec->serial)); +} + +void +meta_monitor_spec_free (MetaMonitorSpec *monitor_spec) +{ + g_free (monitor_spec->connector); + g_free (monitor_spec->vendor); + g_free (monitor_spec->product); + g_free (monitor_spec->serial); + g_free (monitor_spec); +} + +static void +meta_monitor_generate_id (MetaMonitor *monitor) +{ + MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor); + MetaOutput *output = meta_monitor_get_main_output (monitor); + MetaMonitorSpec *monitor_spec; + + monitor_spec = g_new0 (MetaMonitorSpec, 1); + *monitor_spec = (MetaMonitorSpec) { + .connector = g_strdup (output->name), + .vendor = g_strdup (output->vendor), + .product = g_strdup (output->product), + .serial = g_strdup (output->serial), + }; + + priv->spec = monitor_spec; +} + GList * meta_monitor_get_outputs (MetaMonitor *monitor) { @@ -145,6 +201,7 @@ meta_monitor_finalize (GObject *object) g_list_free_full (priv->modes, (GDestroyNotify) meta_monitor_mode_free); g_clear_pointer (&priv->outputs, g_list_free); + meta_monitor_spec_free (priv->spec); } static void @@ -200,16 +257,18 @@ MetaMonitorNormal * meta_monitor_normal_new (MetaOutput *output) { MetaMonitorNormal *monitor_normal; + MetaMonitor *monitor; MetaMonitorPrivate *monitor_priv; monitor_normal = g_object_new (META_TYPE_MONITOR_NORMAL, NULL); - monitor_priv = - meta_monitor_get_instance_private (META_MONITOR (monitor_normal)); + monitor = META_MONITOR (monitor_normal); + monitor_priv = meta_monitor_get_instance_private (monitor); monitor_priv->outputs = g_list_append (NULL, output); monitor_priv->winsys_id = output->winsys_id; meta_monitor_normal_generate_modes (monitor_normal); + meta_monitor_generate_id (monitor); return monitor_normal; } @@ -380,11 +439,12 @@ meta_monitor_tiled_new (MetaMonitorManager *monitor_manager, MetaOutput *output) { MetaMonitorTiled *monitor_tiled; + MetaMonitor *monitor; MetaMonitorPrivate *monitor_priv; monitor_tiled = g_object_new (META_TYPE_MONITOR_TILED, NULL); - monitor_priv = - meta_monitor_get_instance_private (META_MONITOR (monitor_tiled)); + monitor = META_MONITOR (monitor_tiled); + monitor_priv = meta_monitor_get_instance_private (monitor); monitor_tiled->tile_group_id = output->tile_info.group_id; monitor_priv->winsys_id = output->winsys_id; @@ -396,6 +456,7 @@ meta_monitor_tiled_new (MetaMonitorManager *monitor_manager, META_MONITOR (monitor_tiled)); meta_monitor_tiled_generate_modes (monitor_tiled); + meta_monitor_generate_id (monitor); return monitor_tiled; } @@ -452,6 +513,14 @@ meta_monitor_mode_free (MetaMonitorMode *monitor_mode) g_free (monitor_mode); } +MetaMonitorSpec * +meta_monitor_get_spec (MetaMonitor *monitor) +{ + MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor); + + return priv->spec; +} + MetaMonitorMode * meta_monitor_get_preferred_mode (MetaMonitor *monitor) { diff --git a/src/backends/meta-monitor.h b/src/backends/meta-monitor.h index 3bab0a3cf..72775e0fc 100644 --- a/src/backends/meta-monitor.h +++ b/src/backends/meta-monitor.h @@ -28,6 +28,14 @@ typedef struct _MetaMonitorMode MetaMonitorMode; +typedef struct _MetaMonitorSpec +{ + char *connector; + char *vendor; + char *product; + char *serial; +} MetaMonitorSpec; + typedef struct _MetaMonitorModeSpec { int width; @@ -76,6 +84,8 @@ MetaMonitorTiled * meta_monitor_tiled_new (MetaMonitorManager *monitor_manager, MetaMonitorNormal * meta_monitor_normal_new (MetaOutput *output); +MetaMonitorSpec * meta_monitor_get_spec (MetaMonitor *monitor); + gboolean meta_monitor_is_active (MetaMonitor *monitor); MetaOutput * meta_monitor_get_main_output (MetaMonitor *monitor); @@ -113,4 +123,11 @@ void meta_monitor_mode_foreach_crtc (MetaMonitor *monitor, MetaMonitorModeFunc func, gpointer user_data); +MetaMonitorSpec * meta_monitor_spec_clone (MetaMonitorSpec *monitor_id); + +gboolean meta_monitor_spec_equals (MetaMonitorSpec *monitor_id, + MetaMonitorSpec *other_monitor_id); + +void meta_monitor_spec_free (MetaMonitorSpec *monitor_id); + #endif /* META_MONITOR_H */