[gnome-control-center/wip/hadess/power-saver-on-low-battery: 2/2] power: Add UI for "power-saver profile when battery is low"
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/hadess/power-saver-on-low-battery: 2/2] power: Add UI for "power-saver profile when battery is low"
- Date: Thu, 22 Jul 2021 19:45:28 +0000 (UTC)
commit 3892c85f39fabd70769e6d1c488e4a0926cf0b22
Author: Bastien Nocera <hadess hadess net>
Date: Wed Jul 21 12:29:55 2021 +0200
power: Add UI for "power-saver profile when battery is low"
See https://gitlab.gnome.org/GNOME/gnome-settings-daemon/-/merge_requests/247
panels/power/cc-power-panel.c | 29 +++++++++++++++++++++++++++++
panels/power/cc-power-panel.ui | 15 +++++++++++++++
2 files changed, 44 insertions(+)
---
diff --git a/panels/power/cc-power-panel.c b/panels/power/cc-power-panel.c
index 21183f39c..b2729d3c4 100644
--- a/panels/power/cc-power-panel.c
+++ b/panels/power/cc-power-panel.c
@@ -92,6 +92,8 @@ struct _CcPowerPanel
GtkListBox *power_profile_listbox;
GtkListBox *power_profile_info_listbox;
HdyPreferencesGroup *power_profile_section;
+ HdyActionRow *power_saver_low_battery_row;
+ GtkSwitch *power_saver_low_battery_switch;
GtkSizeGroup *row_sizegroup;
GtkComboBox *suspend_on_battery_delay_combo;
GtkLabel *suspend_on_battery_delay_label;
@@ -257,6 +259,24 @@ empty_listbox (GtkListBox *listbox)
gtk_container_remove (GTK_CONTAINER (listbox), l->data);
}
+static void
+update_power_saver_low_battery_row_visibility (CcPowerPanel *self)
+{
+ g_autoptr(UpDevice) composite = NULL;
+ UpDeviceKind kind;
+
+ composite = up_client_get_display_device (self->up_client);
+ g_object_get (composite, "kind", &kind, NULL);
+ if (kind != UP_DEVICE_KIND_BATTERY ||
+ !self->power_profiles_proxy)
+ {
+ gtk_widget_hide (GTK_WIDGET (self->power_saver_low_battery_row));
+ return;
+ }
+
+ gtk_widget_show (GTK_WIDGET (self->power_saver_low_battery_row));
+}
+
static void
up_client_changed (CcPowerPanel *self)
{
@@ -427,6 +447,8 @@ up_client_changed (CcPowerPanel *self)
add_device (self, device);
}
}
+
+ update_power_saver_low_battery_row_visibility (self);
}
static void
@@ -1727,6 +1749,8 @@ setup_power_profiles (CcPowerPanel *self)
if (self->has_performance_degraded)
power_profile_update_info_boxes (self);
+
+ update_power_saver_low_battery_row_visibility (self);
}
static void
@@ -1839,6 +1863,8 @@ cc_power_panel_class_init (CcPowerPanelClass *klass)
gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, power_profile_listbox);
gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, power_profile_info_listbox);
gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, power_profile_section);
+ gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, power_saver_low_battery_row);
+ gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, power_saver_low_battery_switch);
gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, row_sizegroup);
gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, suspend_on_battery_delay_combo);
gtk_widget_class_bind_template_child (widget_class, CcPowerPanel, suspend_on_battery_delay_label);
@@ -1895,6 +1921,9 @@ cc_power_panel_init (CcPowerPanel *self)
setup_power_profiles (self);
setup_power_saving (self);
+ g_settings_bind (self->gsd_settings, "power-saver-profile-on-low-battery",
+ self->power_saver_low_battery_switch, "active",
+ G_SETTINGS_BIND_DEFAULT);
setup_general_section (self);
diff --git a/panels/power/cc-power-panel.ui b/panels/power/cc-power-panel.ui
index d8283c556..bc58e7462 100644
--- a/panels/power/cc-power-panel.ui
+++ b/panels/power/cc-power-panel.ui
@@ -206,6 +206,21 @@
<signal name="notify::selected-index" handler="blank_screen_row_changed_cb"
object="CcPowerPanel" swapped="yes"/>
</object>
</child>
+ <child>
+ <object class="HdyActionRow" id="power_saver_low_battery_row">
+ <property name="visible">False</property>
+ <property name="title" translatable="yes">Automatic Power Saver</property>
+ <property name="subtitle" translatable="yes">Enables power saver mode when battery is
low.</property>
+ <property name="use_underline">True</property>
+ <property name="activatable_widget">power_saver_low_battery_switch</property>
+ <child>
+ <object class="GtkSwitch" id="power_saver_low_battery_switch">
+ <property name="visible">True</property>
+ <property name="valign">center</property>
+ </object>
+ </child>
+ </object>
+ </child>
<child>
<object class="HdyActionRow" id="automatic_suspend_row">
<property name="visible">False</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]