[gnome-control-center/wip/carlosg/centralized-panel-auto-orientation: 3/4] display: Add panel-orientation-managed signal to CcDisplayConfig



commit 34bdbd1dc897fef29ee56c80a275983eb69fa506
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Jun 11 16:11:55 2020 +0200

    display: Add panel-orientation-managed signal to CcDisplayConfig
    
    So we can track changes on this property.

 panels/display/cc-display-config-dbus.c | 53 ++++++++++++++++++++++++++-------
 panels/display/cc-display-config.c      |  5 ++++
 2 files changed, 48 insertions(+), 10 deletions(-)
---
diff --git a/panels/display/cc-display-config-dbus.c b/panels/display/cc-display-config-dbus.c
index 43b0ab2fc..cdc8f8aef 100644
--- a/panels/display/cc-display-config-dbus.c
+++ b/panels/display/cc-display-config-dbus.c
@@ -882,6 +882,8 @@ struct _CcDisplayConfigDBus
   int min_width;
   int min_height;
 
+  guint panel_orientation_managed;
+
   guint32 serial;
   gboolean supports_mirroring;
   gboolean supports_changing_layout_mode;
@@ -1273,17 +1275,8 @@ static gboolean
 cc_display_config_dbus_get_panel_orientation_managed (CcDisplayConfig *pself)
 {
   CcDisplayConfigDBus *self = CC_DISPLAY_CONFIG_DBUS (pself);
-  gboolean retval;
-  GVariant *v;
-
-  v = g_dbus_proxy_get_cached_property (self->proxy, "PanelOrientationManaged");
-  if (!v)
-    return FALSE;
 
-  retval = g_variant_get_boolean (v);
-  g_variant_unref (v);
-
-  return retval;
+  return self->panel_orientation_managed;
 }
 
 static void
@@ -1439,6 +1432,42 @@ construct_monitors (CcDisplayConfigDBus *self,
   gather_clone_modes (self);
 }
 
+static void
+update_panel_orientation_managed (CcDisplayConfigDBus *self)
+{
+  g_autoptr(GVariant) v = NULL;
+  gboolean panel_orientation_managed = FALSE;
+
+  if (self->proxy != NULL)
+    {
+      v = g_dbus_proxy_get_cached_property (self->proxy, "PanelOrientationManaged");
+      if (v)
+        {
+          panel_orientation_managed = g_variant_get_boolean (v);
+        }
+    }
+
+  if (panel_orientation_managed == self->panel_orientation_managed)
+    return;
+
+  self->panel_orientation_managed = panel_orientation_managed;
+  g_signal_emit_by_name (self, "panel-orientation-managed", self->panel_orientation_managed);
+}
+
+static void
+proxy_properties_changed_cb (GDBusProxy          *proxy,
+                             GVariant            *changed_properties,
+                             GStrv                invalidated_properties,
+                             CcDisplayConfigDBus *self)
+{
+  GVariantDict dict;
+
+  g_variant_dict_init (&dict, changed_properties);
+
+  if (g_variant_dict_contains (&dict, "PanelOrientationManaged"))
+    update_panel_orientation_managed (self);
+}
+
 static void
 cc_display_config_dbus_constructed (GObject *object)
 {
@@ -1498,6 +1527,10 @@ cc_display_config_dbus_constructed (GObject *object)
   if (error)
     g_warning ("Could not create DisplayConfig proxy: %s", error->message);
 
+  g_signal_connect (self->proxy, "g-properties-changed",
+                    G_CALLBACK (proxy_properties_changed_cb), self);
+  update_panel_orientation_managed (self);
+
   G_OBJECT_CLASS (cc_display_config_dbus_parent_class)->constructed (object);
 }
 
diff --git a/panels/display/cc-display-config.c b/panels/display/cc-display-config.c
index 4cacdbff6..08b4c4877 100644
--- a/panels/display/cc-display-config.c
+++ b/panels/display/cc-display-config.c
@@ -486,6 +486,11 @@ cc_display_config_class_init (CcDisplayConfigClass *klass)
                 G_SIGNAL_RUN_LAST,
                 0, NULL, NULL, NULL,
                 G_TYPE_NONE, 0);
+  g_signal_new ("panel-orientation-managed",
+                CC_TYPE_DISPLAY_CONFIG,
+                G_SIGNAL_RUN_LAST,
+                0, NULL, NULL, NULL,
+                G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
 
   gobject_class->constructed = cc_display_config_constructed;
   gobject_class->finalize = cc_display_config_finalize;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]