[mutter/wip/carlosg/centralized-panel-auto-orientation: 2/3] backends: Centralize panel autorotation in a DisplayConfig property



commit 89d9be432c2a4fc6220ea7186420ac9627a247c5
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Jun 11 18:15:22 2020 +0200

    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.

 src/backends/meta-monitor-manager-private.h |  2 ++
 src/backends/meta-monitor-manager.c         | 51 +++++++++++++++++++++++++++++
 src/meta/meta-monitor-manager.h             |  3 ++
 src/org.gnome.Mutter.DisplayConfig.xml      |  8 +++++
 4 files changed, 64 insertions(+)
---
diff --git a/src/backends/meta-monitor-manager-private.h b/src/backends/meta-monitor-manager-private.h
index 1b7efd261b..7df72f7162 100644
--- a/src/backends/meta-monitor-manager-private.h
+++ b/src/backends/meta-monitor-manager-private.h
@@ -129,6 +129,8 @@ struct _MetaMonitorManager
 
   int persistent_timeout_id;
 
+  guint panel_orientation_managed : 1;
+
   MetaMonitorConfigManager *config_manager;
 
   GnomePnpIds *pnp_ids;
diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c
index e2d16b7d0f..39dd110c3e 100644
--- a/src/backends/meta-monitor-manager.c
+++ b/src/backends/meta-monitor-manager.c
@@ -67,6 +67,7 @@ enum
   PROP_0,
 
   PROP_BACKEND,
+  PROP_PANEL_ORIENTATION_MANAGED,
 
   PROP_LAST
 };
@@ -684,6 +685,9 @@ orientation_changed (MetaOrientationManager *orientation_manager,
   GError *error = NULL;
   MetaMonitorsConfig *config;
 
+  if (!manager->panel_orientation_managed)
+    return;
+
   switch (meta_orientation_manager_get_orientation (orientation_manager))
     {
     case META_ORIENTATION_NORMAL:
@@ -748,6 +752,27 @@ experimental_features_changed (MetaSettings           *settings,
   meta_settings_update_ui_scaling_factor (settings);
 }
 
+static void
+update_panel_orientation_managed (MetaMonitorManager *manager)
+{
+  MetaOrientationManager *orientation_manager;
+  gboolean panel_orientation_managed;
+
+  orientation_manager = meta_backend_get_orientation_manager (manager->backend);
+
+  panel_orientation_managed =
+    meta_orientation_manager_has_accelerometer (orientation_manager);
+
+  if (manager->panel_orientation_managed == panel_orientation_managed)
+    return;
+
+  manager->panel_orientation_managed = panel_orientation_managed;
+  g_object_notify (G_OBJECT (manager), "panel-orientation-managed");
+
+  meta_dbus_display_config_set_panel_orientation_managed (manager->display_config,
+                                                          manager->panel_orientation_managed);
+}
+
 void
 meta_monitor_manager_setup (MetaMonitorManager *manager)
 {
@@ -788,6 +813,11 @@ meta_monitor_manager_constructed (GObject *object)
                            G_CALLBACK (orientation_changed),
                            manager, 0);
 
+  g_signal_connect_object (meta_backend_get_orientation_manager (backend),
+                           "notify::has-accelerometer",
+                           G_CALLBACK (update_panel_orientation_managed), manager,
+                           G_CONNECT_SWAPPED);
+
   g_signal_connect_object (backend,
                            "lid-is-closed-changed",
                            G_CALLBACK (lid_is_closed_changed),
@@ -848,6 +878,7 @@ meta_monitor_manager_set_property (GObject      *object,
     case PROP_BACKEND:
       manager->backend = g_value_get_object (value);
       break;
+    case PROP_PANEL_ORIENTATION_MANAGED:
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -866,6 +897,9 @@ meta_monitor_manager_get_property (GObject    *object,
     case PROP_BACKEND:
       g_value_set_object (value, manager->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, prop_id, pspec);
     }
@@ -925,6 +959,15 @@ meta_monitor_manager_class_init (MetaMonitorManagerClass *klass)
                          G_PARAM_READWRITE |
                          G_PARAM_CONSTRUCT_ONLY |
                          G_PARAM_STATIC_STRINGS);
+
+  obj_props[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, PROP_LAST, obj_props);
 }
 
@@ -3175,3 +3218,11 @@ meta_monitor_manager_get_vendor_name (MetaMonitorManager *manager,
 
   return gnome_pnp_ids_get_pnp_id (manager->pnp_ids, vendor);
 }
+
+gboolean
+meta_monitor_manager_get_panel_orientation_managed (MetaMonitorManager *manager)
+{
+  g_return_val_if_fail (META_IS_MONITOR_MANAGER (manager), FALSE);
+
+  return manager->panel_orientation_managed;
+}
diff --git a/src/meta/meta-monitor-manager.h b/src/meta/meta-monitor-manager.h
index 033309cc8a..ce57156be5 100644
--- a/src/meta/meta-monitor-manager.h
+++ b/src/meta/meta-monitor-manager.h
@@ -62,4 +62,7 @@ MetaMonitorSwitchConfigType meta_monitor_manager_get_switch_config (MetaMonitorM
 META_EXPORT
 gint meta_monitor_manager_get_display_configuration_timeout (void);
 
+META_EXPORT
+gboolean meta_monitor_manager_get_panel_orientation_managed (MetaMonitorManager *manager);
+
 #endif /* META_MONITOR_MANAGER_H */
diff --git a/src/org.gnome.Mutter.DisplayConfig.xml b/src/org.gnome.Mutter.DisplayConfig.xml
index ec04649fa0..2826370c44 100644
--- a/src/org.gnome.Mutter.DisplayConfig.xml
+++ b/src/org.gnome.Mutter.DisplayConfig.xml
@@ -282,6 +282,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]