/[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 40 by dpavlin, Fri Jun 15 20:34:04 2007 UTC revision 80 by dpavlin, Tue Jul 22 01:15:19 2008 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;
20    
21  $|=1;  $|=1;
22    
# Line 56  find_proc_acpi('thermal_zone', sub { Line 57  find_proc_acpi('thermal_zone', sub {
57    
58  find_proc_acpi('battery', sub {  find_proc_acpi('battery', sub {
59          my $bat = shift;          my $bat = shift;
60          return unless $bat =~ /BAT/;          return unless $bat =~ /\w+/;
61    
62          warn "# testing battery $bat\n" if ( $debug );          warn "# testing battery $bat\n" if ( $debug );
63    
# Line 90  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    sub read_file {
100            my $path = shift;
101            open(my $fh, '<', $path) || die "can't open $path: $!";
102            my $c = <$fh>;
103            chomp($c);
104            close($fh);
105            return $c;
106    }
107    
108  while ( 1 ) {  while ( 1 ) {
109          my $s = strftime("%Y-%m-%d %H:%M:%S", localtime());          my $s = strftime("%Y-%m-%d %H:%M:%S", localtime());
110    
111          if ( $i % $acpi_every == 0 && $proc_acpi_battery ) {          if ( $i % $acpi_every == 0 ) {
112                    if ( $proc_acpi_battery ) {
                 my $state = proc2hash( "$proc_acpi_battery/state" );  
113    
114                  if ( $state->{'present rate'} != 0 ) {                          my $state = proc2hash( "$proc_acpi_battery/state" );
                         my $info = proc2hash( "$proc_acpi_battery/info" );  
115    
116                          my $pcnt = $state->{'remaining capacity'} / $info->{'design capacity'};                          if ( $state->{'present rate'} =~ m/^\d+$/ && $state->{'present rate'} != 0 ) {
117                                    my $info = proc2hash( "$proc_acpi_battery/info" );
118    
119                          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' );  
120    
121                          warn "time = $time\n" if ($debug);                                  my $time = $state->{'remaining capacity'} / ( $state->{'present rate'} );
122                                    $time = ( $info->{'design capacity'} - $state->{'remaining capacity'} ) / $state->{'present rate'} if ( $state->{'charging state'} eq 'charging' );
123    
124                          my $hh = int( $time );                                  warn "time = $time\n" if ($debug);
                         my $mm = int( ( $time - $hh ) * 60 );  
                         my $ss = ( $time * 3600 ) % 60;  
125    
126                          $bat = sprintf("%s %2d%% %02d:%02d:%02d %3.1fW!| ",                                  my $hh = int( $time );
127                                  substr($state->{'charging state'},0,1),                                  my $mm = int( ( $time - $hh ) * 60 );
128                                  $pcnt * 100, $hh, $mm, $ss,                                  my $ss = ( $time * 3600 ) % 60;
                                 $state->{'present rate'} / 1000  
                         );  
129    
130                          } else {                                  $bat = sprintf("%s %2d%% %02d:%02d:%02d %3.1fW!| ",
131                                  $bat = '';                                          substr($state->{'charging state'},0,1),
132                                            $pcnt * 100, $hh, $mm, $ss,
133                                            $state->{'present rate'} / 1000
134                                    );
135                          }                          }
136                    } elsif ( -e $sys_fs ) {
137                            my $full = read_file( "$sys_fs/charge_full" );
138                            my $now = read_file( "$sys_fs/charge_now" );
139                            $bat = sprintf("%2d%% | ", $now * 100 / $full );
140                    }
141          } else {          } else {
142                  $bat =~ s/!(\|\s)$/ $1/;                  $bat =~ s/!(\|\s)$/ $1/;
143          }          }
# Line 177  while ( 1 ) { Line 191  while ( 1 ) {
191          my $d_write = ( $d_w - $ld_w ) / $dt;          my $d_write = ( $d_w - $ld_w ) / $dt;
192          ( $ld_r, $ld_w ) = ( $d_r, $d_w );          ( $ld_r, $ld_w ) = ( $d_r, $d_w );
193    
194          printf("%s | %s |%5s D %-5s|%5s > %-5s| %s%s\n",          my $out = sprintf("%s | %s |%5s D %-5s|%5s > %-5s| %s%s\n",
195                  $s,                  $s,
196                  $load,                  $load,
197                  unit( $d_read ), unit( $d_write ),                  unit( $d_read ), unit( $d_write ),
# Line 185  while ( 1 ) { Line 199  while ( 1 ) {
199                  $bat, $temp,                  $bat, $temp,
200          );          );
201    
202            print $out;
203            if ( $awesome ) {
204                    open(my $fh, '|-', 'awesome-client') || die "can't pipe to awesome-client: $!";
205                    print $fh "0 widget_tell mystatusbar dwm-status text $out\n";
206                    close($fh);
207            }
208    
209          sleep $dt;          sleep $dt;
210  }  }
211    

Legend:
Removed from v.40  
changed lines
  Added in v.80

  ViewVC Help
Powered by ViewVC 1.1.26