summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2019-03-27 15:14:35 +0100
committerFlorian Pritz <bluewind@xinu.at>2019-03-27 15:23:20 +0100
commit89ac0867dda151c59dc5a8c4584880e3bab86e66 (patch)
treebd648c0841912c0538d7a81ed32a02ffcd06097a
parent3531f603e6ce5920b22532c34534863d5a145105 (diff)
downloaddotfiles-89ac0867dda151c59dc5a8c4584880e3bab86e66.tar.gz
dotfiles-89ac0867dda151c59dc5a8c4584880e3bab86e66.tar.xz
i3 status: Make battery display more flexible
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rwxr-xr-x.i3/conky-wrapper.pl44
-rw-r--r--.i3/conkyrc-perl5
2 files changed, 28 insertions, 21 deletions
diff --git a/.i3/conky-wrapper.pl b/.i3/conky-wrapper.pl
index 687762b..2e69d29 100755
--- a/.i3/conky-wrapper.pl
+++ b/.i3/conky-wrapper.pl
@@ -65,12 +65,15 @@ LINE: while (<$conky>) {
}
- if (m/^COMMAND: (.*) (.*)$/) {
+ if (m/^COMMAND: ([^\s]*)(?: (.*)?)$/) {
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;
+ my $command_ret = $commands{$command}->(@args);
+ for my $text (@$command_ret) {
+ $in_progress{full_text} = $text;
+ push @data, clone \%in_progress;
+ }
undef %in_progress;
next;
}
@@ -80,20 +83,27 @@ LINE: while (<$conky>) {
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;
+ my $bats = [@_] // ["BAT0"];
+
+ my $ret = [];
- my $time_remaining_hours = 0;
- $time_remaining_hours = $values{ENERGY_NOW} / $values{POWER_NOW} unless $values{POWER_NOW} == 0;
+ for my $bat (@$bats) {
+ next unless -e "/sys/class/power_supply/$bat";
- return sprintf("%s %s%%, %.2fW, %.2fh", $bat, $values{CAPACITY}, $values{POWER_NOW} / 1e6, $time_remaining_hours);
+ 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;
+
+ my $time_remaining_hours = 0;
+ $time_remaining_hours = $values{ENERGY_NOW} / $values{POWER_NOW} unless $values{POWER_NOW} == 0;
+
+ push @$ret, sprintf("%s %s%%, %.2fW, %.2fh", $bat, $values{CAPACITY}, $values{POWER_NOW} / 1e6, $time_remaining_hours);
+ }
+ return $ret;
}
diff --git a/.i3/conkyrc-perl b/.i3/conkyrc-perl
index e41e6c4..e1b6f33 100644
--- a/.i3/conkyrc-perl
+++ b/.i3/conkyrc-perl
@@ -65,10 +65,7 @@ FULLTEXT: SWAP ${swap}/${swapmax} (${swapperc}%)
${endif}
COLOR: \#5555FF
-COMMAND: battery BAT0
-
-COLOR: \#5555FF
-COMMAND: battery BAT1
+COMMAND: battery BAT0 BAT1
FULLTEXT: ${loadavg}