/[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 59 by dpavlin, Fri Jan 18 19:10:10 2008 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 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 187  while ( 1 ) { Line 200  while ( 1 ) {
200          );          );
201    
202          print $out;          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  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26