/[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 57 by dpavlin, Thu Jan 10 20:11:42 2008 UTC revision 80 by dpavlin, Tue Jul 22 01:15:19 2008 UTC
# Line 8  use strict; Line 8  use strict;
8  use POSIX qw/strftime/;  use POSIX qw/strftime/;
9  use File::Slurp;  use File::Slurp;
10  use Time::HiRes;  use Time::HiRes;
11  eval "use Data::Dump qw/dump/;";  use Data::Dump qw/dump/;
12    
13  my $dt = 3;  my $dt = 3;
14  my $acpi_every = 10;  my $acpi_every = 10;
# 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 = 0;  
20    
21  $|=1;  $|=1;
22    
# Line 92  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  if ( $awesome ) {  sub read_file {
100          undef $awesome;          my $path = shift;
101          open( $awesome, '|-', 'awesome-client' ) || die "can't open awesome-client: $!";          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 192  while ( 1 ) { Line 199  while ( 1 ) {
199                  $bat, $temp,                  $bat, $temp,
200          );          );
201    
202            print $out;
203          if ( $awesome ) {          if ( $awesome ) {
204                  print $awesome "0 statusbar_set_text $out";                  open(my $fh, '|-', 'awesome-client') || die "can't pipe to awesome-client: $!";
205          } else {                  print $fh "0 widget_tell mystatusbar dwm-status text $out\n";
206                  print $out;                  close($fh);
207          }          }
208    
209          sleep $dt;          sleep $dt;

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

  ViewVC Help
Powered by ViewVC 1.1.26