summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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}