/[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 73 by dpavlin, Mon Mar 24 13:26:30 2008 UTC revision 108 by dpavlin, Tue Feb 24 21:27:17 2009 UTC
# Line 16  my $acpi_every = 10; Line 16  my $acpi_every = 10;
16  my $disk_blk_size = 512;  my $disk_blk_size = 512;
17    
18  my $debug = shift @ARGV;  my $debug = shift @ARGV;
19  my $awesome = 1;  my $awesome = 3;
20    
21  $|=1;  $|=1;
22    
# Line 28  sub proc2hash { Line 28  sub proc2hash {
28          while(<$fh>) {          while(<$fh>) {
29                  chomp;                  chomp;
30                  my ( $key, $value ) = split(/:\s+/, $_, 2);                  my ( $key, $value ) = split(/:\s+/, $_, 2);
31                  $value =~ s/ m[VW]h*$//;                  $value =~ s/ m[AVW]h*$//;
32                  $h->{$key} = $value;                  $h->{$key} = $value;
33          }          }
34          warn "$f ",dump( $h ) if ( $debug );          warn "$f ",dump( $h ) if ( $debug );
# 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                    my $sysfs_path = glob "$sys_fs/*_full";
104                    if ( $sysfs_path ) {
105    
106                            my $full = read_file( $sysfs_path );
107                            $sysfs_path =~ s/_full/_now/;
108                            my $now = read_file( $sysfs_path );
109                            $bat = sprintf("%2d%% | ", $now * 100 / $full );
110    
111                  my $state = proc2hash( "$proc_acpi_battery/state" );                  } elsif ( $proc_acpi_battery ) {
112    
113                  if ( $state->{'present rate'} != 0 ) {                          my $state = proc2hash( "$proc_acpi_battery/state" );
                         my $info = proc2hash( "$proc_acpi_battery/info" );  
114    
115                          my $pcnt = $state->{'remaining capacity'} / $info->{'design capacity'};                          if ( $state->{'present rate'} =~ m/^\d+$/ && $state->{'present rate'} != 0 ) {
116                                    my $info = proc2hash( "$proc_acpi_battery/info" );
117    
118                          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' );  
119    
120                          warn "time = $time\n" if ($debug);                                  my $time = $state->{'remaining capacity'} / ( $state->{'present rate'} );
121                                    $time = ( $info->{'design capacity'} - $state->{'remaining capacity'} ) / $state->{'present rate'} if ( $state->{'charging state'} eq 'charging' );
122    
123                          my $hh = int( $time );                                  warn "time = $time\n" if ($debug);
                         my $mm = int( ( $time - $hh ) * 60 );  
                         my $ss = ( $time * 3600 ) % 60;  
124    
125                          $bat = sprintf("%s %2d%% %02d:%02d:%02d %3.1fW!| ",                                  my $hh = int( $time );
126                                  substr($state->{'charging state'},0,1),                                  my $mm = int( ( $time - $hh ) * 60 );
127                                  $pcnt * 100, $hh, $mm, $ss,                                  my $ss = ( $time * 3600 ) % 60;
                                 $state->{'present rate'} / 1000  
                         );  
128    
129                          } else {                                  $bat = sprintf("%s %2d%% %02d:%02d:%02d %3.1fW!| ",
130                                  $bat = '';                                          substr($state->{'charging state'},0,1),
131                                            $pcnt * 100, $hh, $mm, $ss,
132                                            $state->{'present rate'} / 1000
133                                    );
134                          }                          }
135                    }
136          } else {          } else {
137                  $bat =~ s/!(\|\s)$/ $1/;                  $bat =~ s/!(\|\s)$/ $1/;
138          }          }
# Line 179  while ( 1 ) { Line 186  while ( 1 ) {
186          my $d_write = ( $d_w - $ld_w ) / $dt;          my $d_write = ( $d_w - $ld_w ) / $dt;
187          ( $ld_r, $ld_w ) = ( $d_r, $d_w );          ( $ld_r, $ld_w ) = ( $d_r, $d_w );
188    
189          my $out = sprintf("%s | %s |%5s D %-5s|%5s > %-5s| %s%s\n",          my $out = sprintf("%s | %s |%5s D %-5s|%5s > %-5s| %s%s",
190                  $s,                  $s,
191                  $load,                  $load,
192                  unit( $d_read ), unit( $d_write ),                  unit( $d_read ), unit( $d_write ),
# Line 187  while ( 1 ) { Line 194  while ( 1 ) {
194                  $bat, $temp,                  $bat, $temp,
195          );          );
196    
197          print $out;          print "$out\n";
198          if ( $awesome ) {          if ( $awesome ) {
199                  open(my $fh, '|-', 'awesome-client') || die "can't pipe to awesome-client: $!";                  open(my $fh, '|-', 'awesome-client') || die "can't pipe to awesome-client: $!";
200                  print $fh "0 widget_tell dwm-status text $out\n";                  print $fh
201                            $awesome == 3   ? qq{mytextbox.text="$out"\n}
202                                            : "0 widget_tell mystatusbar dwm-status text $out\n"
203                                            ;
204                  close($fh);                  close($fh);
205          }          }
206    

Legend:
Removed from v.73  
changed lines
  Added in v.108

  ViewVC Help
Powered by ViewVC 1.1.26