Add GdkMonitor::description
authorMatthias Clasen <mclasen@redhat.com>
Thu, 2 Feb 2023 11:30:46 +0000 (12:30 +0100)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 2 Feb 2023 11:32:28 +0000 (12:32 +0100)
This is the right string to when showing
monitors in the UI.

gdk/gdkmonitor.c
gdk/gdkmonitor.h
gdk/gdkmonitorprivate.h

index 2d6cbb4fdeb55ce061e19aab55d8b92f4ba9cb72..96d7fe4416956bd6c622b6aaac300df26b3e0c9f 100644 (file)
@@ -39,6 +39,7 @@
 
 enum {
   PROP_0,
+  PROP_DESCRIPTION,
   PROP_DISPLAY,
   PROP_MANUFACTURER,
   PROP_MODEL,
@@ -81,6 +82,10 @@ gdk_monitor_get_property (GObject    *object,
 
   switch (prop_id)
     {
+    case PROP_DESCRIPTION:
+      g_value_set_string (value, monitor->description);
+      break;
+
     case PROP_DISPLAY:
       g_value_set_object (value, monitor->display);
       break;
@@ -154,6 +159,7 @@ gdk_monitor_finalize (GObject *object)
 {
   GdkMonitor *monitor = GDK_MONITOR (object);
 
+  g_free (monitor->description);
   g_free (monitor->connector);
   g_free (monitor->manufacturer);
   g_free (monitor->model);
@@ -170,6 +176,18 @@ gdk_monitor_class_init (GdkMonitorClass *class)
   object_class->get_property = gdk_monitor_get_property;
   object_class->set_property = gdk_monitor_set_property;
 
+  /**
+   * GdkMonitor:description: (attributes org.gtk.Property.get=gdk_monitor_get_description)
+   *
+   * A short description of the monitor, meant for display to the user.
+   *
+   * Since: 4.10
+   */
+  props[PROP_DESCRIPTION] =
+    g_param_spec_string ("description", NULL, NULL,
+                         NULL,
+                         G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
   /**
    * GdkMonitor:display: (attributes org.gtk.Property.get=gdk_monitor_get_display)
    *
@@ -623,3 +641,33 @@ gdk_monitor_is_valid (GdkMonitor *monitor)
 
   return monitor->valid;
 }
+
+/**
+ * gdk_monitor_get_description: (attributes org.gtk.Method.get_property=description)
+ * @monitor: a `GdkMonitor`
+ *
+ * Gets a string describing the monitor, if available.
+ *
+ * This can be used to identify a monitor in the UI.
+ *
+ * Returns: (transfer none) (nullable): the monitor description
+ *
+ * Since: 4.10
+ */
+const char *
+gdk_monitor_get_description (GdkMonitor *monitor)
+{
+  g_return_val_if_fail (GDK_IS_MONITOR (monitor), NULL);
+
+  return monitor->description;
+}
+
+void
+gdk_monitor_set_description (GdkMonitor *monitor,
+                             const char *description)
+{
+  g_free (monitor->description);
+  monitor->description = g_strdup (description);
+  g_object_notify_by_pspec (G_OBJECT (monitor), props[PROP_DESCRIPTION]);
+}
+
index f42c999c959da3ec00d6e1503733c4d95e84e8d0..11f91640c61726a5f6f2c1755c1d6bfeeee1285c 100644 (file)
@@ -86,6 +86,8 @@ GDK_AVAILABLE_IN_ALL
 GdkSubpixelLayout gdk_monitor_get_subpixel_layout (GdkMonitor   *monitor);
 GDK_AVAILABLE_IN_ALL
 gboolean          gdk_monitor_is_valid            (GdkMonitor   *monitor);
+GDK_AVAILABLE_IN_4_10
+const char *      gdk_monitor_get_description     (GdkMonitor   *monitor);
 
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkMonitor, g_object_unref)
 
index 36c591a8f2c6845d2dba206a8cc63d3eb06da74a..275ae91391e59ebea3cb5d8e6f4df5cc7ef70f82 100644 (file)
@@ -37,6 +37,7 @@ struct _GdkMonitor {
   char *manufacturer;
   char *model;
   char *connector;
+  char *description;
   GdkRectangle geometry;
   int width_mm;
   int height_mm;
@@ -70,6 +71,8 @@ void            gdk_monitor_set_refresh_rate    (GdkMonitor *monitor,
 void            gdk_monitor_set_subpixel_layout (GdkMonitor        *monitor,
                                                  GdkSubpixelLayout  subpixel);
 void            gdk_monitor_invalidate          (GdkMonitor *monitor);
+void            gdk_monitor_set_description     (GdkMonitor *monitor,
+                                                 const char *description);
 
 G_END_DECLS