summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2019-03-03 23:35:45 +0100
committerFlorian Pritz <bluewind@xinu.at>2019-03-27 15:23:02 +0100
commitf7fddaad6c34f01996a2bb93d16f3b1e44fadb9f (patch)
tree08be016bc07915ca0894577aa86a60f096951942
parent0d9c59ce32185aab62dd41200d34c27f01c86237 (diff)
downloaddotfiles-f7fddaad6c34f01996a2bb93d16f3b1e44fadb9f.tar.gz
dotfiles-f7fddaad6c34f01996a2bb93d16f3b1e44fadb9f.tar.xz
Handle battery stats on T480
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rwxr-xr-x.i3/conky-wrapper.pl31
-rw-r--r--.i3/conkyrc-perl5
2 files changed, 35 insertions, 1 deletions
diff --git a/.i3/conky-wrapper.pl b/.i3/conky-wrapper.pl
index da02291..7e3dedd 100755
--- a/.i3/conky-wrapper.pl
+++ b/.i3/conky-wrapper.pl
@@ -29,6 +29,10 @@ my %simple_mappings = (
"SHORTTEXT" => "shorttext",
);
+my %commands = (
+ battery => \&get_bat_stats,
+);
+
LINE: while (<$conky>) {
chomp($_);
@@ -60,6 +64,33 @@ LINE: while (<$conky>) {
next;
}
+
+ if (m/^COMMAND: (.*) (.*)$/) {
+ my $command = $1;
+ my @args = split / /, $2;
+ die "Unknown command requested: $command" unless defined $commands{$command};
+ $in_progress{full_text} = $commands{$command}->(@args);
+ push @data, clone \%in_progress;
+ undef %in_progress;
+ next;
+ }
+
printf STDERR "Got unexpected data: %s\n", $_;
}
+
+sub get_bat_stats {
+ my $bat = shift // "BAT0";
+
+ open my $fh, "<", "/sys/class/power_supply/$bat/uevent";
+ my %values;
+ while (my $line = <$fh>) {
+ my ($key, $value) = split /=/, $line;
+ $key =~ s/^POWER_SUPPLY_//;
+ chomp $value;
+ $values{$key} = $value;
+ }
+ close $fh;
+
+ return sprintf("%s %s%%, %sW", $bat, $values{CAPACITY}, $values{POWER_NOW} / 1e6);
+}
diff --git a/.i3/conkyrc-perl b/.i3/conkyrc-perl
index c5ee726..e41e6c4 100644
--- a/.i3/conkyrc-perl
+++ b/.i3/conkyrc-perl
@@ -65,7 +65,10 @@ FULLTEXT: SWAP ${swap}/${swapmax} (${swapperc}%)
${endif}
COLOR: \#5555FF
-FULLTEXT: ${smapi_bat_perc 0}%, ${battery_time}, ${smapi_bat_power 0}W ${smapi_bat_temp 0}°
+COMMAND: battery BAT0
+
+COLOR: \#5555FF
+COMMAND: battery BAT1
FULLTEXT: ${loadavg}