Skip to content

Commit

Permalink
Less aggressive, add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit committed Aug 30, 2024
1 parent 0c3eaf7 commit 93effb7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Services/Device.vala
Original file line number Diff line number Diff line change
Expand Up @@ -233,17 +233,20 @@ public class Power.Services.Device : Object {

var icon_name = "battery";

if (percentage >= 20) {
icon_name += "-%i".printf ((int) (5 * Math.round (percentage / 5)));
} else if (percentage >= 10) {
if (percentage > 10) {
// Round to the nearest 5 percent
// Clamp to 20. There is no 15. Make sure we don't have single px red line until < 10
var rounded_percentage = (int) (5 * Math.round (percentage / 5)).clamp (20, 100);
icon_name += "-%i".printf (rounded_percentage);
} else if (percentage > 0) {
icon_name += "-10";
} else {
icon_name += "-0";
}

if (is_charging) {
icon_name += "-charging";
} else if (time_to_empty > 0 && time_to_empty < 15 * 60) {
} else if (time_to_empty >= 0 && time_to_empty < 15 * 60) {
icon_name = "battery-0";
}

Expand Down

0 comments on commit 93effb7

Please sign in to comment.