From 3dfeb2fd3736ccea4fa224396d192b3501d1ade6 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 2 Feb 2023 12:14:49 +0100 Subject: [PATCH 1/4] monitor: Document connector names better --- gdk/gdkmonitor.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gdk/gdkmonitor.c b/gdk/gdkmonitor.c index ccf1d4b8bc..2d6cbb4fde 100644 --- a/gdk/gdkmonitor.c +++ b/gdk/gdkmonitor.c @@ -377,6 +377,10 @@ gdk_monitor_get_height_mm (GdkMonitor *monitor) * * Gets the name of the monitor's connector, if available. * + * These are strings such as "eDP-1", or "HDMI-2". They depend + * on software and hardware configuration, and should not be + * relied on as stable identifiers of a specific monitor. + * * Returns: (transfer none) (nullable): the name of the connector */ const char * From 2c883a70e22eeaeb43b6c67b9f553adb24371797 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 2 Feb 2023 12:30:46 +0100 Subject: [PATCH 2/4] Add GdkMonitor::description This is the right string to when showing monitors in the UI. --- gdk/gdkmonitor.c | 48 +++++++++++++++++++++++++++++++++++++++++ gdk/gdkmonitor.h | 2 ++ gdk/gdkmonitorprivate.h | 3 +++ 3 files changed, 53 insertions(+) diff --git a/gdk/gdkmonitor.c b/gdk/gdkmonitor.c index 2d6cbb4fde..96d7fe4416 100644 --- a/gdk/gdkmonitor.c +++ b/gdk/gdkmonitor.c @@ -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]); +} + diff --git a/gdk/gdkmonitor.h b/gdk/gdkmonitor.h index f42c999c95..11f91640c6 100644 --- a/gdk/gdkmonitor.h +++ b/gdk/gdkmonitor.h @@ -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) diff --git a/gdk/gdkmonitorprivate.h b/gdk/gdkmonitorprivate.h index 36c591a8f2..275ae91391 100644 --- a/gdk/gdkmonitorprivate.h +++ b/gdk/gdkmonitorprivate.h @@ -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 From 4e62350232dfb639343c07be605001129d864648 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 2 Feb 2023 12:31:38 +0100 Subject: [PATCH 3/4] wayland: Set up monitor descriptions We get this information in the xdg_output protocol. --- gdk/wayland/gdkdisplay-wayland.c | 10 +++++++--- gdk/wayland/gdkmonitor-wayland.c | 1 + gdk/wayland/gdkmonitor-wayland.h | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/gdk/wayland/gdkdisplay-wayland.c b/gdk/wayland/gdkdisplay-wayland.c index 0f745c28dc..e04387df27 100644 --- a/gdk/wayland/gdkdisplay-wayland.c +++ b/gdk/wayland/gdkdisplay-wayland.c @@ -2326,6 +2326,7 @@ apply_monitor_change (GdkWaylandMonitor *monitor) monitor->x, monitor->y, monitor->width, monitor->height }); gdk_monitor_set_connector (GDK_MONITOR (monitor), monitor->name); + gdk_monitor_set_description (GDK_MONITOR (monitor), monitor->description); monitor->wl_output_done = FALSE; monitor->xdg_output_done = FALSE; @@ -2382,7 +2383,7 @@ xdg_output_handle_name (void *data, { GdkWaylandMonitor *monitor = (GdkWaylandMonitor *) data; - GDK_DEBUG (MISC, "handle name xdg-output %d", monitor->id); + GDK_DEBUG (MISC, "handle name xdg-output %d: %s", monitor->id, name); monitor->name = g_strdup (name); } @@ -2392,8 +2393,11 @@ xdg_output_handle_description (void *data, struct zxdg_output_v1 *xdg_output, const char *description) { - GDK_DEBUG (MISC, "handle description xdg-output %d", - ((GdkWaylandMonitor *)data)->id); + GdkWaylandMonitor *monitor = (GdkWaylandMonitor *) data; + + GDK_DEBUG (MISC, "handle description xdg-output %d: %s", monitor->id, description); + + monitor->description = g_strdup (description); } static const struct zxdg_output_v1_listener xdg_output_listener = { diff --git a/gdk/wayland/gdkmonitor-wayland.c b/gdk/wayland/gdkmonitor-wayland.c index 3db7810f26..17406ad6cd 100644 --- a/gdk/wayland/gdkmonitor-wayland.c +++ b/gdk/wayland/gdkmonitor-wayland.c @@ -46,6 +46,7 @@ gdk_wayland_monitor_finalize (GObject *object) GdkWaylandMonitor *monitor = (GdkWaylandMonitor *)object; g_free (monitor->name); + g_free (monitor->description); g_clear_pointer (&monitor->xdg_output, zxdg_output_v1_destroy); diff --git a/gdk/wayland/gdkmonitor-wayland.h b/gdk/wayland/gdkmonitor-wayland.h index 69592bd28a..4397075407 100644 --- a/gdk/wayland/gdkmonitor-wayland.h +++ b/gdk/wayland/gdkmonitor-wayland.h @@ -38,6 +38,7 @@ struct _GdkWaylandMonitor { int32_t width; int32_t height; char *name; + char *description; gboolean wl_output_done; gboolean xdg_output_done; }; From e7bd6915322fe2fdb7b0679f4d60c5e9dd289a0b Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 2 Feb 2023 12:32:05 +0100 Subject: [PATCH 4/4] inspector: Show monitor descriptions --- gtk/inspector/general.c | 1 + 1 file changed, 1 insertion(+) diff --git a/gtk/inspector/general.c b/gtk/inspector/general.c index 288ebbb1fb..569622108a 100644 --- a/gtk/inspector/general.c +++ b/gtk/inspector/general.c @@ -650,6 +650,7 @@ add_monitor (GtkInspectorGeneral *gen, g_free (value); g_free (name); + add_label_row (gen, list, "Description", gdk_monitor_get_description (monitor), 10); add_label_row (gen, list, "Connector", gdk_monitor_get_connector (monitor), 10); gdk_monitor_get_geometry (monitor, &rect);