From f2655b055d6d1e7b81293aad7ecbcc0956857164 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 1 Nov 2017 14:02:08 -0400 Subject: [PATCH] monitor: Add a ::valid property This is slightly more useful than the existing ::invalidate signal, since it can be queried at any time. --- docs/reference/gdk/gdk4-sections.txt | 1 + gdk/gdkmonitor.c | 34 ++++++++++++++++++++++++++++ gdk/gdkmonitor.h | 2 ++ gdk/gdkmonitorprivate.h | 1 + 4 files changed, 38 insertions(+) diff --git a/docs/reference/gdk/gdk4-sections.txt b/docs/reference/gdk/gdk4-sections.txt index a39abe6136..797bb27290 100644 --- a/docs/reference/gdk/gdk4-sections.txt +++ b/docs/reference/gdk/gdk4-sections.txt @@ -1271,6 +1271,7 @@ gdk_monitor_get_refresh_rate GdkSubpixelLayout gdk_monitor_get_subpixel_layout gdk_monitor_is_primary +gdk_monitor_is_valid gdk_monitor_get_type diff --git a/gdk/gdkmonitor.c b/gdk/gdkmonitor.c index fb721481db..3e8ec272b5 100644 --- a/gdk/gdkmonitor.c +++ b/gdk/gdkmonitor.c @@ -49,6 +49,7 @@ enum { PROP_HEIGHT_MM, PROP_REFRESH_RATE, PROP_SUBPIXEL_LAYOUT, + PROP_VALID, LAST_PROP }; @@ -67,6 +68,7 @@ static void gdk_monitor_init (GdkMonitor *monitor) { monitor->scale_factor = 1; + monitor->valid = TRUE; } static void @@ -123,6 +125,10 @@ gdk_monitor_get_property (GObject *object, g_value_set_enum (value, monitor->subpixel_layout); break; + case PROP_VALID: + g_value_set_boolean (value, monitor->valid); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } @@ -232,6 +238,12 @@ gdk_monitor_class_init (GdkMonitorClass *class) GDK_TYPE_SUBPIXEL_LAYOUT, GDK_SUBPIXEL_LAYOUT_UNKNOWN, G_PARAM_READABLE); + props[PROP_VALID] = + g_param_spec_boolean ("valid", + "Valid", + "Whether the monitor is still valid", + TRUE, + G_PARAM_READABLE); g_object_class_install_properties (object_class, LAST_PROP, props); @@ -595,5 +607,27 @@ gdk_monitor_set_subpixel_layout (GdkMonitor *monitor, void gdk_monitor_invalidate (GdkMonitor *monitor) { + monitor->valid = FALSE; + g_object_notify (G_OBJECT (monitor), "valid"); g_signal_emit (monitor, signals[INVALIDATE], 0); } + +/** + * gdk_monitor_is_valid: + * @monitor: a #GdkMonitor + * + * Returns %TRUE if the @monitor object corresponds to a + * physical monitor. The @monitor becomes invalid when the + * physical monitor is unplugged or removed. + * + * Returns: %TRUE if the object corresponds to a physical monitor + * + * Since: 3.94 + */ +gboolean +gdk_monitor_is_valid (GdkMonitor *monitor) +{ + g_return_val_if_fail (GDK_IS_MONITOR (monitor), FALSE); + + return monitor->valid; +} diff --git a/gdk/gdkmonitor.h b/gdk/gdkmonitor.h index a12bfa8ac0..887bbbd40c 100644 --- a/gdk/gdkmonitor.h +++ b/gdk/gdkmonitor.h @@ -89,6 +89,8 @@ GDK_AVAILABLE_IN_3_22 GdkSubpixelLayout gdk_monitor_get_subpixel_layout (GdkMonitor *monitor); GDK_AVAILABLE_IN_3_22 gboolean gdk_monitor_is_primary (GdkMonitor *monitor); +GDK_AVAILABLE_IN_3_94 +gboolean gdk_monitor_is_valid (GdkMonitor *monitor); G_END_DECLS diff --git a/gdk/gdkmonitorprivate.h b/gdk/gdkmonitorprivate.h index c76b59ce90..a2c7b5c86b 100644 --- a/gdk/gdkmonitorprivate.h +++ b/gdk/gdkmonitorprivate.h @@ -42,6 +42,7 @@ struct _GdkMonitor { int scale_factor; int refresh_rate; GdkSubpixelLayout subpixel_layout; + gboolean valid; }; struct _GdkMonitorClass {