[gnome-control-center/wip/hadess/power-fixes: 9/9] power: Use correct colour for battery level bars
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/hadess/power-fixes: 9/9] power: Use correct colour for battery level bars
- Date: Mon, 6 Jul 2020 15:28:43 +0000 (UTC)
commit 2397d0c082a12f27eabc1f8a84cea29033d4b999
Author: Bastien Nocera <hadess hadess net>
Date: Mon Jul 6 17:19:24 2020 +0200
power: Use correct colour for battery level bars
Use 3 symbolic colours to paint the levels in the battery bars, with a
red "error" colour used for the lowest level of battery, an orange
"warning" colour for the pre-error level, and a green "success" colour
used for levels above that.
There's no yellow intermediate colour as this is usually too anxiety
inducing and there's no real need to press users into a "warning"
behaviour when the level will still be comfortable for a long enough
time.
Closes: #725
panels/power/battery-levels.css | 14 ++++++++++++++
panels/power/cc-power-panel.c | 32 +++++++++++++++++++++++---------
panels/power/power.gresource.xml | 1 +
3 files changed, 38 insertions(+), 9 deletions(-)
---
diff --git a/panels/power/battery-levels.css b/panels/power/battery-levels.css
new file mode 100644
index 000000000..f8c73300b
--- /dev/null
+++ b/panels/power/battery-levels.css
@@ -0,0 +1,14 @@
+levelbar block.warning-battery-offset {
+ background-color: @error_color;
+ border-color: @error_color;
+}
+
+levelbar block.low-battery-offset {
+ background-color: @warning_color;
+ border-color: @warning_color;
+}
+
+levelbar block.high-battery-offset {
+ background-color: @success_color;
+ border-color: @success_color;
+}
diff --git a/panels/power/cc-power-panel.c b/panels/power/cc-power-panel.c
index be482f8e5..d4f305132 100644
--- a/panels/power/cc-power-panel.c
+++ b/panels/power/cc-power-panel.c
@@ -446,6 +446,19 @@ get_details_string (gdouble percentage, UpDeviceState state, guint64 time)
return details;
}
+static void
+load_custom_css (CcPowerPanel *self)
+{
+ g_autoptr(GtkCssProvider) provider = NULL;
+
+ /* use custom CSS */
+ provider = gtk_css_provider_new ();
+ gtk_css_provider_load_from_resource (provider, "/org/gnome/control-center/power/battery-levels.css");
+ gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
+ GTK_STYLE_PROVIDER (provider),
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+}
+
static void
set_primary (CcPowerPanel *panel, UpDevice *device)
{
@@ -492,9 +505,9 @@ set_primary (CcPowerPanel *panel, UpDevice *device)
levelbar = gtk_level_bar_new ();
gtk_widget_show (levelbar);
gtk_level_bar_set_value (GTK_LEVEL_BAR (levelbar), percentage / 100.0);
- gtk_level_bar_add_offset_value (GTK_LEVEL_BAR (levelbar), GTK_LEVEL_BAR_OFFSET_LOW, 0.03);
- gtk_level_bar_add_offset_value (GTK_LEVEL_BAR (levelbar), GTK_LEVEL_BAR_OFFSET_HIGH, 0.1);
- gtk_level_bar_add_offset_value (GTK_LEVEL_BAR (levelbar), GTK_LEVEL_BAR_OFFSET_FULL, 0.8);
+ gtk_level_bar_add_offset_value (GTK_LEVEL_BAR (levelbar), "warning-battery-offset", 0.03);
+ gtk_level_bar_add_offset_value (GTK_LEVEL_BAR (levelbar), "low-battery-offset", 0.1);
+ gtk_level_bar_add_offset_value (GTK_LEVEL_BAR (levelbar), "high-battery-offset", 1.0);
gtk_widget_set_hexpand (levelbar, TRUE);
gtk_widget_set_halign (levelbar, GTK_ALIGN_FILL);
gtk_widget_set_valign (levelbar, GTK_ALIGN_CENTER);
@@ -603,9 +616,9 @@ add_battery (CcPowerPanel *panel, UpDevice *device)
levelbar = gtk_level_bar_new ();
gtk_widget_show (levelbar);
gtk_level_bar_set_value (GTK_LEVEL_BAR (levelbar), percentage / 100.0);
- gtk_level_bar_add_offset_value (GTK_LEVEL_BAR (levelbar), GTK_LEVEL_BAR_OFFSET_LOW, 0.05);
- gtk_level_bar_add_offset_value (GTK_LEVEL_BAR (levelbar), GTK_LEVEL_BAR_OFFSET_HIGH, 0.1);
- gtk_level_bar_add_offset_value (GTK_LEVEL_BAR (levelbar), GTK_LEVEL_BAR_OFFSET_FULL, 0.8);
+ gtk_level_bar_add_offset_value (GTK_LEVEL_BAR (levelbar), "warning-battery-offset", 0.05);
+ gtk_level_bar_add_offset_value (GTK_LEVEL_BAR (levelbar), "low-battery-offset", 0.1);
+ gtk_level_bar_add_offset_value (GTK_LEVEL_BAR (levelbar), "high-battery-offset", 1.0);
gtk_widget_set_hexpand (levelbar, TRUE);
gtk_widget_set_halign (levelbar, GTK_ALIGN_FILL);
gtk_widget_set_valign (levelbar, GTK_ALIGN_CENTER);
@@ -793,9 +806,9 @@ add_device (CcPowerPanel *panel, UpDevice *device)
gtk_widget_set_halign (widget, GTK_ALIGN_FILL);
gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
gtk_level_bar_set_value (GTK_LEVEL_BAR (widget), percentage / 100.0f);
- gtk_level_bar_add_offset_value (GTK_LEVEL_BAR (widget), GTK_LEVEL_BAR_OFFSET_LOW, 0.03);
- gtk_level_bar_add_offset_value (GTK_LEVEL_BAR (widget), GTK_LEVEL_BAR_OFFSET_HIGH, 0.1);
- gtk_level_bar_add_offset_value (GTK_LEVEL_BAR (widget), GTK_LEVEL_BAR_OFFSET_FULL, 0.8);
+ gtk_level_bar_add_offset_value (GTK_LEVEL_BAR (widget), "warning-battery-offset", 0.03);
+ gtk_level_bar_add_offset_value (GTK_LEVEL_BAR (widget), "low-battery-offset", 0.1);
+ gtk_level_bar_add_offset_value (GTK_LEVEL_BAR (widget), "high-battery-offset", 1.0);
gtk_box_pack_start (GTK_BOX (box2), widget, TRUE, TRUE, 0);
gtk_size_group_add_widget (panel->level_sizegroup, widget);
gtk_box_pack_start (GTK_BOX (hbox), box2, TRUE, TRUE, 0);
@@ -2533,6 +2546,7 @@ cc_power_panel_init (CcPowerPanel *self)
g_resources_register (cc_power_get_resource ());
gtk_widget_init_template (GTK_WIDGET (self));
+ load_custom_css (self);
cc_object_storage_create_dbus_proxy (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE,
diff --git a/panels/power/power.gresource.xml b/panels/power/power.gresource.xml
index bc08d697f..f0bcb1a62 100644
--- a/panels/power/power.gresource.xml
+++ b/panels/power/power.gresource.xml
@@ -2,5 +2,6 @@
<gresources>
<gresource prefix="/org/gnome/control-center/power">
<file preprocess="xml-stripblanks">cc-power-panel.ui</file>
+ <file>battery-levels.css</file>
</gresource>
</gresources>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]