/[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 39 by dpavlin, Thu Jun 14 11:56:26 2007 UTC revision 81 by dpavlin, Tue Jul 22 01:16:52 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 74  sub unit { Line 75  sub unit {
75          my @units = qw/b k M G/;          my @units = qw/b k M G/;
76          my $o = 0;          my $o = 0;
77    
78          while ( ( $v / 1024 ) >= 1 ) {          while ( ( $v / 10000 ) >= 1 ) {
79                  $o++;                  $o++;
80                  $v /= 1024;                  $v /= 1024;
81          }          }
# 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  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 ) {
104    
105                  my $state = proc2hash( "$proc_acpi_battery/state" );                          my $state = proc2hash( "$proc_acpi_battery/state" );
106    
107                  if ( $state->{'present rate'} != 0 ) {                          if ( $state->{'present rate'} =~ m/^\d+$/ && $state->{'present rate'} != 0 ) {
108                          my $info = proc2hash( "$proc_acpi_battery/info" );                                  my $info = proc2hash( "$proc_acpi_battery/info" );
109    
110                          my $pcnt = $state->{'remaining capacity'} / $info->{'design capacity'};                                  my $pcnt = $state->{'remaining capacity'} / $info->{'design capacity'};
111    
112                          my $time = $state->{'remaining capacity'} / ( $state->{'present rate'} );                                  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' );                                  $time = ( $info->{'design capacity'} - $state->{'remaining capacity'} ) / $state->{'present rate'} if ( $state->{'charging state'} eq 'charging' );
114    
115                          warn "time = $time\n" if ($debug);                                  warn "time = $time\n" if ($debug);
116    
117                          my $hh = int( $time );                                  my $hh = int( $time );
118                          my $mm = int( ( $time - $hh ) * 60 );                                  my $mm = int( ( $time - $hh ) * 60 );
119                          my $ss = ( $time * 3600 ) % 60;                                  my $ss = ( $time * 3600 ) % 60;
120    
121                          $bat = sprintf("%s %2d%% %02d:%02d:%02d %3.1fW!| ",                                  $bat = sprintf("%s %2d%% %02d:%02d:%02d %3.1fW!| ",
122                                  substr($state->{'charging state'},0,1),                                          substr($state->{'charging state'},0,1),
123                                  $pcnt * 100, $hh, $mm, $ss,                                          $pcnt * 100, $hh, $mm, $ss,
124                                  $state->{'present rate'} / 1000                                          $state->{'present rate'} / 1000
125                          );                                  );
   
                         } else {  
                                 $bat = '';  
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 177  while ( 1 ) { Line 182  while ( 1 ) {
182          my $d_write = ( $d_w - $ld_w ) / $dt;          my $d_write = ( $d_w - $ld_w ) / $dt;
183          ( $ld_r, $ld_w ) = ( $d_r, $d_w );          ( $ld_r, $ld_w ) = ( $d_r, $d_w );
184    
185          printf("%s | %s |%5s D %-5s|%5s > %-5s| %s%s\n",          my $out = sprintf("%s | %s |%5s D %-5s|%5s > %-5s| %s%s\n",
186                  $s,                  $s,
187                  $load,                  $load,
188                  unit( $d_read ), unit( $d_write ),                  unit( $d_read ), unit( $d_write ),
# Line 185  while ( 1 ) { Line 190  while ( 1 ) {
190                  $bat, $temp,                  $bat, $temp,
191          );          );
192    
193            print $out;
194            if ( $awesome ) {
195                    open(my $fh, '|-', 'awesome-client') || die "can't pipe to awesome-client: $!";
196                    print $fh "0 widget_tell mystatusbar dwm-status text $out\n";
197                    close($fh);
198            }
199    
200          sleep $dt;          sleep $dt;
201  }  }
202    

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

  ViewVC Help
Powered by ViewVC 1.1.26