/[scripts]/trunk/dwm-status.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/dwm-status.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 67 by dpavlin, Fri Feb 15 22:01:01 2008 UTC revision 81 by dpavlin, Tue Jul 22 01:16:52 2008 UTC
# Line 91  sub unit { Line 91  sub unit {
91    
92  my ( $lrx, $ltx ) = ( 0, 0 );  my ( $lrx, $ltx ) = ( 0, 0 );
93  my ( $ld_r, $ld_w ) = ( 0, 0 );  my ( $ld_r, $ld_w ) = ( 0, 0 );
94  my $bat;  my $bat = '';
95    
96  my $i = 0;  my $i = 0;
97    my $sys_fs = '/sys/class/power_supply/BAT0';
98    
99  while ( 1 ) {  while ( 1 ) {
100          my $s = strftime("%Y-%m-%d %H:%M:%S", localtime());          my $s = strftime("%Y-%m-%d %H:%M:%S", localtime());
101    
102          if ( $i % $acpi_every == 0 && $proc_acpi_battery ) {          if ( $i % $acpi_every == 0 ) {
103                    if ( $proc_acpi_battery ) {
                 my $state = proc2hash( "$proc_acpi_battery/state" );  
104    
105                  if ( $state->{'present rate'} != 0 ) {                          my $state = proc2hash( "$proc_acpi_battery/state" );
                         my $info = proc2hash( "$proc_acpi_battery/info" );  
106    
107                          my $pcnt = $state->{'remaining capacity'} / $info->{'design capacity'};                          if ( $state->{'present rate'} =~ m/^\d+$/ && $state->{'present rate'} != 0 ) {
108                                    my $info = proc2hash( "$proc_acpi_battery/info" );
109    
110                          my $time = $state->{'remaining capacity'} / ( $state->{'present rate'} );                                  my $pcnt = $state->{'remaining capacity'} / $info->{'design capacity'};
                         $time = ( $info->{'design capacity'} - $state->{'remaining capacity'} ) / $state->{'present rate'} if ( $state->{'charging state'} eq 'charging' );  
111    
112                          warn "time = $time\n" if ($debug);                                  my $time = $state->{'remaining capacity'} / ( $state->{'present rate'} );
113                                    $time = ( $info->{'design capacity'} - $state->{'remaining capacity'} ) / $state->{'present rate'} if ( $state->{'charging state'} eq 'charging' );
114    
115                          my $hh = int( $time );                                  warn "time = $time\n" if ($debug);
                         my $mm = int( ( $time - $hh ) * 60 );  
                         my $ss = ( $time * 3600 ) % 60;  
116    
117                          $bat = sprintf("%s %2d%% %02d:%02d:%02d %3.1fW!| ",                                  my $hh = int( $time );
118                                  substr($state->{'charging state'},0,1),                                  my $mm = int( ( $time - $hh ) * 60 );
119                                  $pcnt * 100, $hh, $mm, $ss,                                  my $ss = ( $time * 3600 ) % 60;
                                 $state->{'present rate'} / 1000  
                         );  
120    
121                          } else {                                  $bat = sprintf("%s %2d%% %02d:%02d:%02d %3.1fW!| ",
122                                  $bat = '';                                          substr($state->{'charging state'},0,1),
123                                            $pcnt * 100, $hh, $mm, $ss,
124                                            $state->{'present rate'} / 1000
125                                    );
126                          }                          }
127                    } elsif ( -e $sys_fs ) {
128                            my $full = read_file( "$sys_fs/charge_full" );
129                            my $now = read_file( "$sys_fs/charge_now" );
130                            $bat = sprintf("%2d%% | ", $now * 100 / $full );
131                    }
132          } else {          } else {
133                  $bat =~ s/!(\|\s)$/ $1/;                  $bat =~ s/!(\|\s)$/ $1/;
134          }          }
# Line 190  while ( 1 ) { Line 193  while ( 1 ) {
193          print $out;          print $out;
194          if ( $awesome ) {          if ( $awesome ) {
195                  open(my $fh, '|-', 'awesome-client') || die "can't pipe to awesome-client: $!";                  open(my $fh, '|-', 'awesome-client') || die "can't pipe to awesome-client: $!";
196                  print $fh "0 widget_tell dwm-status $out\n";                  print $fh "0 widget_tell mystatusbar dwm-status text $out\n";
197                  close($fh);                  close($fh);
198          }          }
199    

Legend:
Removed from v.67  
changed lines
  Added in v.81

  ViewVC Help
Powered by ViewVC 1.1.26