Battery Script

The other thing to try is putting a marker in your titlebar to separate the status info from the actual title. Choose somethign that’s unlikely to appear in a title normally. Let’s say " ~##~ "

That way you don’t need to use the env variable; you can use sed instead, the same way as when you set it. That way if you get more than one lot of status information, the greedy pattern matching used by sed will clear the lot in one go. The problem may still happen, but you can at least clear it by de- and re-focussing the window.

This would make a good perl module. I might take a crack at that sometime.

If i ask really nice could you tell me what sed command i would use. I absoultly HATE sed. It took me for ever just to figure out how to to get the WM_NAME string.

Thanks
VoiDeR

I was thinking of:

sed 's/.* ~##~ //'

That should work, so long as tilde and hash don’t have any special meaning in sed regular expressions. I don’t think they do

Here, a present for you :slight_smile:

Stick it in your module path, chmod +x it, and start it like any other module. It’ll pick up the focus events and set your windows, and it stores the previous window title internally.

It keeps track of battery status and of email, checking every five seconds. This means that if you whisk your focus over 10 windows in a second, you don’t waste CPU time calculating battery and email status 10 times over.

Ideally this wants a few config options. You should be able to specify a format, and maybe the values to format it with. And as Thomas pointed out, it should catch property change events as well, just in case the title changes.

But this should do for most purposes.

[edit] typos

All i can say is WOW and YOU ARE THE MAN. It works almost flawlessly. I had to comment out the sub for the battery because my laptop uses apm. Which out puts like this

0.5 1.1 0x00 0x01 0x00 0x01 100% -1 min

Or from /proc/pmu/battery_0

flags      : 00000011
charge     : 3344
max_charge : 3344
current    : 0
voltage    : 12318
time rem.  : 0

Also theres a funny square at the end of the title

I looked through the code but can’t figure out where its coming from. Other than that this is awsome. When i combine it with your bigpager and add the extra buttons to the title bar ill have a completely emptly but fully functinal desktop.

Thanks VoiDeR

Thank you :smiley: I had the idea and… well, I’d like to get a few of these written in the hope of encouraging some of the others on this list to join in. Modules are a lot easier to write than people think, and they are so very useful.

Anyway, the funny square is, I think, the a newline I stuck on the end of the formatted title string. Force of habit, that; didn’t show up against my decor.

For the battery level, the easiest way is probably just to call your shell script. Perl processes backquoutes in the same way as bash does. So this should work:

$battery_level = '/home/voider/.fvwm/scripts/battery`;[/code]

Of course, your script is fairly close to perl anyway. I've not tested this, (no apm for a start) but it should be about right.

[code]#! /usr/bin/perl -w
use strict;

sub foo
{
        my ($cur, $max) = (0,0);
        my $file = "/proc/pmu/battery_0";
#
#       open the file
#
        open IN, "$file" or die "can't open $file: $!";
#
#       loop through the lines
#
        while(<IN>) {
                /^charge.*:(.*)/ and do {
                        $cur = $1;      # $1 == pattern match in brackets
                        next;           # skip rest of loop
                };
                /^max_charge.*:(.*)/ and do {
                        $max = $1;      # and again...
                        next;
                };
        }
#        
#       close the file
#
        close IN;
#        
#       calc percentage and return it, stringified
#
        my $pc = $curr * 100 / $max;
        return "$pc";
}

I also hope to have a thumbnailing module working in much the same way finished in the next few days

Well it works perfectly now. I add your second script to the module and fixed the 2 errors to complained about and after some diging i found the thing that was adding the square. I think im going to learn perl. Ive been looking at alot of other langs. but perl looks to be layed out better and seems to read more logicly. Im looking forward to your thumbnail module. The current way of doing it really slows my computer down.

Thanks
VoiDeR