diff --git a/data/Indicator.css b/data/Indicator.css new file mode 100644 index 00000000..3d811acb --- /dev/null +++ b/data/Indicator.css @@ -0,0 +1,20 @@ +.battery-indicator label { + margin-left: -4px; + margin-right: 3px; + text-shadow: none; +} + +panel.color-dark .battery-indicator label, +panel.maximized .battery-indicator label { + color: #333; +} + +panel.color-light .battery-indicator label { + color: white; +} + +/*Workaround shadow clip, replace with overflow in GTK4*/ +.battery-indicator image { + margin-right: 1px; + margin-left: 1px; +} diff --git a/data/icons.gresource.xml b/data/icons.gresource.xml index 4e55c81b..746abe72 100644 --- a/data/icons.gresource.xml +++ b/data/icons.gresource.xml @@ -1,10 +1,17 @@ + Indicator.css + icons/balanced.svg icons/performance.svg icons/powersaver.svg + icons/battery-labeled.svg + icons/battery-labeled-charging.svg + icons/battery-labeled-critical.svg + icons/battery-labeled-full-charging.svg + icons/battery-100.svg icons/battery-95.svg icons/battery-90.svg diff --git a/data/icons/battery-labeled-charging.svg b/data/icons/battery-labeled-charging.svg new file mode 100644 index 00000000..83184150 --- /dev/null +++ b/data/icons/battery-labeled-charging.svg @@ -0,0 +1,3 @@ + +image/svg+xml diff --git a/data/icons/battery-labeled-critical.svg b/data/icons/battery-labeled-critical.svg new file mode 100644 index 00000000..1c40b4ed --- /dev/null +++ b/data/icons/battery-labeled-critical.svg @@ -0,0 +1,2 @@ + +image/svg+xml diff --git a/data/icons/battery-labeled-full-charging.svg b/data/icons/battery-labeled-full-charging.svg new file mode 100644 index 00000000..1057f6e1 --- /dev/null +++ b/data/icons/battery-labeled-full-charging.svg @@ -0,0 +1,3 @@ + +image/svg+xml diff --git a/data/icons/battery-labeled.svg b/data/icons/battery-labeled.svg new file mode 100644 index 00000000..27b4c90e --- /dev/null +++ b/data/icons/battery-labeled.svg @@ -0,0 +1,45 @@ + +image/svg+xml diff --git a/src/Indicator.vala b/src/Indicator.vala index f007817f..e07e28b1 100644 --- a/src/Indicator.vala +++ b/src/Indicator.vala @@ -57,6 +57,15 @@ public class Power.Indicator : Wingpanel.Indicator { public override Gtk.Widget get_display_widget () { if (display_widget == null) { + var provider = new Gtk.CssProvider (); + provider.load_from_resource ("io/elementary/desktop/wingpanel/power/Indicator.css"); + + Gtk.StyleContext.add_provider_for_screen ( + Gdk.Screen.get_default (), + provider, + Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION + ); + display_widget = new Widgets.DisplayWidget (); /* No need to display the indicator when the device is completely in AC mode */ diff --git a/src/Services/Device.vala b/src/Services/Device.vala index 810e723b..5600cf64 100644 --- a/src/Services/Device.vala +++ b/src/Services/Device.vala @@ -237,6 +237,11 @@ public class Power.Services.Device : Object { return "preferences-system-power-symbolic"; } + var settings = new GLib.Settings ("io.elementary.desktop.wingpanel.power"); + if (settings.get_boolean ("show-percentage")) { + return get_icon_name_labeled (); + } + var icon_name = "battery"; if (percentage > 10) { @@ -263,6 +268,22 @@ public class Power.Services.Device : Object { return icon_name += "-symbolic"; } + private string get_icon_name_labeled () { + var icon_name = "battery-labeled"; + + if (is_charging) { + if (percentage == 100) { + icon_name += "-full"; + } + + icon_name += "-charging"; + } else if (time_to_empty >= 0 && time_to_empty < 15 * 60 && percentage > 0) { + icon_name += "-critical"; + } + + return icon_name += "-symbolic"; + } + public string get_icon_name_for_battery () { if (!is_a_battery) { return "preferences-system-power-symbolic"; diff --git a/src/Widgets/DisplayWidget.vala b/src/Widgets/DisplayWidget.vala index 0e6f15c8..5892d374 100644 --- a/src/Widgets/DisplayWidget.vala +++ b/src/Widgets/DisplayWidget.vala @@ -17,7 +17,7 @@ * Boston, MA 02110-1301, USA. */ -public class Power.Widgets.DisplayWidget : Gtk.Box { +public class Power.Widgets.DisplayWidget : Gtk.Bin { private Gtk.Revealer percent_revealer; public string icon_name { set { @@ -28,8 +28,7 @@ public class Power.Widgets.DisplayWidget : Gtk.Box { public bool allow_percent { get; set; default = false; } public int percentage { set { - ///Translators: This represents battery charge precentage with `%i` representing the number and `%%` representing the percent symbol - percent_label.label = _("%i%%").printf (value); + percent_label.label = "%i".printf (value); } } @@ -47,12 +46,18 @@ public class Power.Widgets.DisplayWidget : Gtk.Box { percent_label = new Gtk.Label (null); percent_revealer = new Gtk.Revealer () { - transition_type = Gtk.RevealerTransitionType.SLIDE_RIGHT + child = percent_label, + hexpand = true, + transition_type = CROSSFADE }; - percent_revealer.add (percent_label); - add (image); - add (percent_revealer); + var percent_overlay = new Gtk.Overlay () { + child = image + }; + percent_overlay.add_overlay (percent_revealer); + + get_style_context ().add_class ("battery-indicator"); + child = percent_overlay; var settings = new GLib.Settings ("io.elementary.desktop.wingpanel.power"); settings.bind ("show-percentage", percent_revealer, "reveal-child", GLib.SettingsBindFlags.GET);