[gnome-flashback] backends: centralize panel autorotation in a DisplayConfig property



commit 7ee220cc3b367e25a0f29d32852cbd9a12c37130
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sat Sep 5 17:28:09 2020 +0300

    backends: centralize panel autorotation in a DisplayConfig property
    
    Instead of having everyone check net.hadess.SensorProxy themselves, have
    this all controlled by the MetaOrientationManager, and proxied everywhere
    else via a readonly property in org.gnome.Mutter.DisplayConfig.
    
    We want to attach more complex policies here, and it seems better to
    centralize the handling of the autorotation feature rather than
    implementing policy changes all over the place.
    
    Based on mutter commit:
    https://gitlab.gnome.org/GNOME/mutter/-/commit/1acf7444731d1fec90ae

 backends/gf-monitor-manager-private.h       |  2 ++
 backends/gf-monitor-manager.c               | 54 +++++++++++++++++++++++++++++
 backends/gf-monitor-manager.h               |  2 ++
 backends/org.gnome.Mutter.DisplayConfig.xml |  8 +++++
 4 files changed, 66 insertions(+)
---
diff --git a/backends/gf-monitor-manager-private.h b/backends/gf-monitor-manager-private.h
index 4dbe2279..1592e06c 100644
--- a/backends/gf-monitor-manager-private.h
+++ b/backends/gf-monitor-manager-private.h
@@ -65,6 +65,8 @@ struct _GfMonitorManager
   GList                       *logical_monitors;
   GfLogicalMonitor            *primary_logical_monitor;
 
+  gboolean                     panel_orientation_managed;
+
   GfMonitorConfigManager      *config_manager;
 
   GnomePnpIds                 *pnp_ids;
diff --git a/backends/gf-monitor-manager.c b/backends/gf-monitor-manager.c
index 5b452af8..ad947b48 100644
--- a/backends/gf-monitor-manager.c
+++ b/backends/gf-monitor-manager.c
@@ -64,6 +64,8 @@ enum
 
   PROP_BACKEND,
 
+  PROP_PANEL_ORIENTATION_MANAGED,
+
   LAST_PROP
 };
 
@@ -541,6 +543,30 @@ orientation_changed (GfOrientationManager *orientation_manager,
   g_object_unref (config);
 }
 
+static void
+update_panel_orientation_managed (GfMonitorManager *self)
+{
+  GfMonitorManagerPrivate *priv;
+  GfOrientationManager *orientation_manager;
+  gboolean panel_orientation_managed;
+
+  priv = gf_monitor_manager_get_instance_private (self);
+
+  orientation_manager = gf_backend_get_orientation_manager (priv->backend);
+  panel_orientation_managed = gf_orientation_manager_has_accelerometer (orientation_manager);
+
+  if (self->panel_orientation_managed == panel_orientation_managed)
+    return;
+
+  self->panel_orientation_managed = panel_orientation_managed;
+
+  g_object_notify_by_pspec (G_OBJECT (self),
+                            manager_properties[PROP_PANEL_ORIENTATION_MANAGED]);
+
+  gf_dbus_display_config_set_panel_orientation_managed (self->display_config,
+                                                        panel_orientation_managed);
+}
+
 static void
 restore_previous_config (GfMonitorManager *manager)
 {
@@ -2069,6 +2095,12 @@ gf_monitor_manager_constructed (GObject *object)
   g_signal_connect_object (orientation_manager, "orientation-changed",
                            G_CALLBACK (orientation_changed), manager, 0);
 
+  g_signal_connect_object (orientation_manager,
+                           "notify::has-accelerometer",
+                           G_CALLBACK (update_panel_orientation_managed),
+                           manager,
+                           G_CONNECT_SWAPPED);
+
   manager->current_switch_config = GF_MONITOR_SWITCH_CONFIG_UNKNOWN;
 
   priv->bus_name_id = g_bus_own_name (G_BUS_TYPE_SESSION,
@@ -2136,6 +2168,10 @@ gf_monitor_manager_get_property (GObject    *object,
         g_value_set_object (value, priv->backend);
         break;
 
+      case PROP_PANEL_ORIENTATION_MANAGED:
+        g_value_set_boolean (value, manager->panel_orientation_managed);
+        break;
+
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
         break;
@@ -2160,6 +2196,9 @@ gf_monitor_manager_set_property (GObject      *object,
         priv->backend = g_value_get_object (value);
         break;
 
+      case PROP_PANEL_ORIENTATION_MANAGED:
+        break;
+
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
         break;
@@ -2178,6 +2217,15 @@ gf_monitor_manager_install_properties (GObjectClass *object_class)
                          G_PARAM_CONSTRUCT_ONLY |
                          G_PARAM_STATIC_STRINGS);
 
+ manager_properties[PROP_PANEL_ORIENTATION_MANAGED] =
+    g_param_spec_boolean ("panel-orientation-managed",
+                          "Panel orientation managed",
+                          "Panel orientation is managed",
+                          FALSE,
+                          G_PARAM_READABLE |
+                          G_PARAM_EXPLICIT_NOTIFY |
+                          G_PARAM_STATIC_STRINGS);
+
   g_object_class_install_properties (object_class, LAST_PROP,
                                      manager_properties);
 }
@@ -2790,6 +2838,12 @@ gf_monitor_manager_get_display_configuration_timeout (void)
   return DEFAULT_DISPLAY_CONFIGURATION_TIMEOUT;
 }
 
+gboolean
+gf_monitor_manager_get_panel_orientation_managed (GfMonitorManager *self)
+{
+  return self->panel_orientation_managed;
+}
+
 void
 gf_monitor_manager_confirm_configuration (GfMonitorManager *manager,
                                           gboolean          ok)
diff --git a/backends/gf-monitor-manager.h b/backends/gf-monitor-manager.h
index ae93faef..b476086c 100644
--- a/backends/gf-monitor-manager.h
+++ b/backends/gf-monitor-manager.h
@@ -51,6 +51,8 @@ void                      gf_monitor_manager_switch_config                     (
 
 gint                      gf_monitor_manager_get_display_configuration_timeout (void);
 
+gboolean                  gf_monitor_manager_get_panel_orientation_managed     (GfMonitorManager          
*self);
+
 void                      gf_monitor_manager_confirm_configuration             (GfMonitorManager          
*manager,
                                                                                 gboolean                   
ok);
 
diff --git a/backends/org.gnome.Mutter.DisplayConfig.xml b/backends/org.gnome.Mutter.DisplayConfig.xml
index 3b55e0b8..1c6f05b2 100644
--- a/backends/org.gnome.Mutter.DisplayConfig.xml
+++ b/backends/org.gnome.Mutter.DisplayConfig.xml
@@ -223,6 +223,14 @@
     -->
     <property name="PowerSaveMode" type="i" access="readwrite" />
 
+    <!--
+        PanelOrientationManaged:
+
+        Whether the built-in panel orientation is automatically managed
+        by mutter.
+    -->
+    <property name="PanelOrientationManaged" type="b" access="read" />
+
     <!--
         MonitorsChanged:
 


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