[gnome-control-center/wip/hadess/degraded-power-profile: 84/84] power: Handle new power-profiles-daemon API




commit 3370ecacfa395f020280b730d1b75ae1fa409ad3
Author: Bastien Nocera <hadess hadess net>
Date:   Fri Apr 2 13:10:19 2021 +0200

    power: Handle new power-profiles-daemon API
    
    Handle the new PerformanceDegraded property to replace
    PerformanceInhibited.

 panels/power/cc-power-panel.c | 36 +++++++++++++++++++++++++++++++-----
 1 file changed, 31 insertions(+), 5 deletions(-)
---
diff --git a/panels/power/cc-power-panel.c b/panels/power/cc-power-panel.c
index 96558c778..1320db7e9 100644
--- a/panels/power/cc-power-panel.c
+++ b/panels/power/cc-power-panel.c
@@ -118,6 +118,7 @@ struct _CcPowerPanel
   guint          power_profiles_prop_id;
   CcPowerProfileRow *power_profiles_row[NUM_CC_POWER_PROFILES];
   gboolean       power_profiles_in_update;
+  gboolean       has_performance_degraded;
 
 #ifdef HAVE_NETWORK_MANAGER
   NMClient      *nm_client;
@@ -1360,6 +1361,18 @@ performance_profile_set_inhibited (CcPowerPanel  *self,
   cc_power_profile_row_set_performance_inhibited (row, performance_inhibited);
 }
 
+static void
+performance_profile_set_degraded (CcPowerPanel  *self,
+                                  const char    *performance_degraded)
+{
+  CcPowerProfileRow *row;
+
+  row = self->power_profiles_row[CC_POWER_PROFILE_PERFORMANCE];
+  if (!row)
+      return;
+  cc_power_profile_row_set_performance_degraded (row, performance_degraded);
+}
+
 static void
 power_profiles_row_activated_cb (GtkListBox    *box,
                                  GtkListBoxRow *box_row,
@@ -1415,8 +1428,14 @@ power_profiles_properties_changed_cb (CcPowerPanel *self,
     {
       if (g_strcmp0 (key, "PerformanceInhibited") == 0)
         {
-          performance_profile_set_inhibited (self,
-                                             g_variant_get_string (value, NULL));
+          if (!self->has_performance_degraded)
+            performance_profile_set_inhibited (self,
+                                               g_variant_get_string (value, NULL));
+        }
+      else if (g_strcmp0 (key, "PerformanceDegraded") == 0)
+        {
+          performance_profile_set_degraded (self,
+                                            g_variant_get_string (value, NULL));
         }
       else if (g_strcmp0 (key, "ActiveProfile") == 0)
         {
@@ -1499,7 +1518,8 @@ setup_power_profiles (CcPowerPanel *self)
   g_autoptr(GVariant) props = NULL;
   guint i, num_children;
   g_autoptr(GError) error = NULL;
-  const char *performance_inhibited;
+  const char *performance_inhibited = NULL;
+  const char *performance_degraded;
   const char *active_profile;
   g_autoptr(GVariant) profiles = NULL;
   GtkRadioButton *last_button;
@@ -1552,7 +1572,10 @@ setup_power_profiles (CcPowerPanel *self)
   gtk_widget_show (GTK_WIDGET (self->power_profile_section));
 
   props = g_variant_get_child_value (variant, 0);
-  performance_inhibited = variant_lookup_string (props, "PerformanceInhibited");
+  performance_degraded = variant_lookup_string (props, "PerformanceDegraded");
+  self->has_performance_degraded = performance_degraded != NULL;
+  if (performance_degraded == NULL)
+    performance_inhibited = variant_lookup_string (props, "PerformanceInhibited");
   active_profile = variant_lookup_string (props, "ActiveProfile");
 
   last_button = NULL;
@@ -1579,7 +1602,10 @@ setup_power_profiles (CcPowerPanel *self)
 
       profile = cc_power_profile_from_str (name);
       row = cc_power_profile_row_new (cc_power_profile_from_str (name));
-      cc_power_profile_row_set_performance_inhibited (row, performance_inhibited);
+      if (performance_degraded)
+        cc_power_profile_row_set_performance_degraded (row, performance_degraded);
+      else
+        cc_power_profile_row_set_performance_inhibited (row, performance_inhibited);
       g_signal_connect_object (G_OBJECT (row), "button-toggled",
                                G_CALLBACK (power_profile_button_toggled_cb), self,
                                0);


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