--- trunk/dwm-status.pl 2008/04/03 18:39:38 74 +++ trunk/dwm-status.pl 2010/03/29 21:34:11 134 @@ -16,7 +16,7 @@ my $disk_blk_size = 512; my $debug = shift @ARGV; -my $awesome = 1; +my $awesome = 0; $|=1; @@ -28,7 +28,7 @@ while(<$fh>) { chomp; my ( $key, $value ) = split(/:\s+/, $_, 2); - $value =~ s/ m[VW]h*$//; + $value =~ s/ m[AVW]h*$//; $h->{$key} = $value; } warn "$f ",dump( $h ) if ( $debug ); @@ -91,41 +91,48 @@ my ( $lrx, $ltx ) = ( 0, 0 ); my ( $ld_r, $ld_w ) = ( 0, 0 ); -my $bat; +my $bat = ''; my $i = 0; - +my $sys_fs = '/sys/class/power_supply/BAT0'; while ( 1 ) { my $s = strftime("%Y-%m-%d %H:%M:%S", localtime()); - if ( $i % $acpi_every == 0 && $proc_acpi_battery ) { + if ( $i % $acpi_every == 0 ) { + my $sysfs_path = glob "$sys_fs/*_full"; + if ( $sysfs_path ) { + + my $full = read_file( $sysfs_path ); + $sysfs_path =~ s/_full/_now/; + my $now = read_file( $sysfs_path ); + $bat = sprintf("%2d%% | ", $now * 100 / $full ); - my $state = proc2hash( "$proc_acpi_battery/state" ); + } elsif ( $proc_acpi_battery ) { - if ( $state->{'present rate'} != 0 ) { - my $info = proc2hash( "$proc_acpi_battery/info" ); + my $state = proc2hash( "$proc_acpi_battery/state" ); - my $pcnt = $state->{'remaining capacity'} / $info->{'design capacity'}; + if ( $state->{'present rate'} =~ m/^\d+$/ && $state->{'present rate'} != 0 ) { + my $info = proc2hash( "$proc_acpi_battery/info" ); - my $time = $state->{'remaining capacity'} / ( $state->{'present rate'} ); - $time = ( $info->{'design capacity'} - $state->{'remaining capacity'} ) / $state->{'present rate'} if ( $state->{'charging state'} eq 'charging' ); + my $pcnt = $state->{'remaining capacity'} / $info->{'design capacity'}; - warn "time = $time\n" if ($debug); + my $time = $state->{'remaining capacity'} / ( $state->{'present rate'} ); + $time = ( $info->{'design capacity'} - $state->{'remaining capacity'} ) / $state->{'present rate'} if ( $state->{'charging state'} eq 'charging' ); - my $hh = int( $time ); - my $mm = int( ( $time - $hh ) * 60 ); - my $ss = ( $time * 3600 ) % 60; + warn "time = $time\n" if ($debug); - $bat = sprintf("%s %2d%% %02d:%02d:%02d %3.1fW!| ", - substr($state->{'charging state'},0,1), - $pcnt * 100, $hh, $mm, $ss, - $state->{'present rate'} / 1000 - ); + my $hh = int( $time ); + my $mm = int( ( $time - $hh ) * 60 ); + my $ss = ( $time * 3600 ) % 60; - } else { - $bat = ''; + $bat = sprintf("%s %2d%% %02d:%02d:%02d %3.1fW!| ", + substr($state->{'charging state'},0,1), + $pcnt * 100, $hh, $mm, $ss, + $state->{'present rate'} / 1000 + ); } + } } else { $bat =~ s/!(\|\s)$/ $1/; } @@ -147,13 +154,14 @@ foreach ( split(/\n/, $net) ) { s/^\s+//; - s/:\s+/:/; + s/:\s*/ /; my @n = split(/\s+/, $_, 17); - next unless ( $n[0] =~ s!(eth\d|ath\d):!! ); + #next unless ( $n[0] =~ s!(eth\d|ath\d):!! ); + next unless $n[1] =~ m{^\d+$}; warn dump( @n ) if ($debug); - $rx += $n[0]; - $tx += $n[8]; + $rx += $n[1]; + $tx += $n[9]; } warn "rx: $rx tx: $tx\n" if ($debug); @@ -179,18 +187,21 @@ my $d_write = ( $d_w - $ld_w ) / $dt; ( $ld_r, $ld_w ) = ( $d_r, $d_w ); - my $out = sprintf("%s | %s |%5s D %-5s|%5s > %-5s| %s%s\n", - $s, + my $out = sprintf("%s |%5s D %-5s|%5s > %-5s| %s%s | %s", $load, unit( $d_read ), unit( $d_write ), unit( $net_rx ), unit( $net_tx ), $bat, $temp, + $s, ); - print $out; + print "$out\n"; if ( $awesome ) { open(my $fh, '|-', 'awesome-client') || die "can't pipe to awesome-client: $!"; - print $fh "0 widget_tell mystatusbar dwm-status text $out\n"; + print $fh + $awesome == 3 ? qq{mytextbox.text="$out"\n} + : "0 widget_tell mystatusbar dwm-status text $out\n" + ; close($fh); }