Battery Script

Ive wrote a script to display my current battery status. heres what i have so far.

bash script to get the info

cur=`grep '^charge' /proc/pmu/battery_0|sed -e 's/.*://'`
max=`grep '^max_charge' /proc/pmu/battery_0|sed -e 's/.*://'`

echo "($cur*100)/$max"|bc

Heres the FvwmScript part

WindowTitle {FvwmApplet-Battery}
WindowSize  32 32		# Taille
Font		"xft:Comic Sans MS:style=Bold:size=10"

  Set $MainColorset=(GetScriptArgument 1)
  If $MainColorset <> {} Then
   ChangeColorset 0 $MainColorset
   ChangeColorset 0 $MainColorset
  Set $tmp = (GetOutput {exec /home/voider/.fvwm/scripts/battery} 1 -1)
  ChangeTitle 1 $tmp

  If (RemainderOfDiv (GetTime) 30)==0 Then
    Set $tmp = (GetOutput {exec /home/voider/.fvwm/scripts/battery} 1 -1)
    ChangeTitle  1 $tmp

Widget 1
 Position 0 0
 Size 32 32
 Type ItemDraw
 Flags NoReliefString
 Title {}
 Case message of
  SingleClic :

I swallowed it in in my panel and it works great but i cant get it be transparent and i can figure out how get get the % sign after it. Heres a picture of what it looks like.

Any help would be greatly accepted

well you should be able to write

ChangeTitle  1 $tmp{%}

Or if FvwmScript eats percents for some reason, you can use the shell printf command:

printf '%02d%%' "($cur*100)/$max"|bc 

Which has the advantage of zero-padding your percentage so you get “05%” rather than “5%”

Are you passing a transparent colorset to the script? The script needs to be transparent (I think) and the panel RootTransparent

Totally Awsome. Any suggetions on how to read new/read email from and mbox format. Ive seen a few scripts floating around but i cant get anyof them to work with fvwm.


What do you want to do?

There are a bunch of perl modules on CPAN to read mbox format stuff. Or you can extract a lot of information just using tools like grep and awk

I would like to get it to output new/total. Whats CPAN if i might ask? Is there any way to display information in the title bar of a window. I have a g3 ibook that will only do 1024x768 and im trying to get as much screen realestate as possible. I would like to totally get away from anytype of button bars or anything that i have to minize a window to see.


It’s the Comprehensive Perl Archive Network. Chock full of perl modules to do just about anything.

For a quick count of new/total mesages, you can do something like

perl -e ' my ($from, $status) = (0,0); open IN, qq(/var/mail/$ENV{ USER }) or die qq(open mailbox failed $!); while(<IN>) { /^From / and $from++; /^Status: / and $status++; } close IN; my $total = $from; my $new = $total = $status; print "$new/$total\n"; '
This works on the basis that new messages don’t yet have a Status: field, but that all messages have a From field

Try this:

Exec xprop -id $[] -set WM_NAME "foo"

Cool. Look forward to seeing that one :slight_smile:

Did you see the FvwmMonitor module IO posted? That’s designed with the idea of reducing all your launchers and monitors to a single icon button. It’s also got the original version of that perl script in the sample config :wink: The same config sets up a POP3 mailbox monitor, a battery level display (which ios where we came in) and an xterm/console launcher - all from one button, all user defined from your config file. I like to make good use of my screen estate too…

Theres alot of neat stuff on the CPAN site. Ill be book marking that.

Exec xprop -id $[] -set WM_NAME "foo" 

Im not at my laptop now so i cant try this but im guessing this renames the window. What i was wondering if it was possible to have something like this

Where my battery and new mail is displayed in the title bar. The only problem would be inorder for it to refresh id have to open another window. I already have plans to use the extra 7 title buttons for things like change the volume and opening Terms and things like that. Id like to incorperate asmuch in to the title bar as possible. That way any buttonbar that i would need could be very small.

I actually did look breifly at the FvwmMonitor but haveing no programming knowledge (havent decieded whether to learn python or perl) it kinda confused me.

So using pixmap buttons is out as well, huh? You don’t leave a guy much to work with :slight_smile:

How about multipixmap decors? You could use the LeftEnd and RightEnd pixmaps to display graphics indiciating the state of email & battery charge. You could use UpdateDecor to display state changes.

The trouble would be finding a way to convert text into graphics. I don’t know of an easy way to do that. Of course, if you can live without the digits, you can use different coloured envelopes (eg: grey=no mail, green = old mail, red = new mail) and a collection of battery gague images to display the info graphically.

There’s also the possibility of using different decors on different windows to give you more buttons and icons to play with.

Thanks. I guess I need a few more examples if it’s ever going to catch on.

You can use shell commands and scripts rather than perl to drive it, but I guess that doesn’t come across. Oh well, it’s all feedback :slight_smile:

I actually like the idea of using pixmap for the battery and mail. Especially the battery, i could have it in intervals of 10%s. That way the decor wouldnt have to be updated so often.
If you could point me in the right direction on what i need to do that would be great. Ill start working on some pixmaps for mail and battery.


can do :slight_smile:

After playing around with using pixmaps i came to the conclusion that its just to much of a pain. With a thin title bar the pixmaps where so small that you couldnt really tell what level it was at. After rereading this post i decided to play around with the xprop command. When i did

xprop -id “window id #” -set WM_NAME /home/voider/bin/battery_stat

It set the title to 100%. Which was awsome and exactly what i wanted. Only downside is how do i execute this command for every window that opens and also it would be a real pain to have all my windows titled 100%. What i was thinking was writing a script that would

  1. set the title to battery status
  2. reset the title back to original
  3. set the title to email status
  4. reset the title back to original
  5. repeat if possible

I could probably do this in bash but i can’t figure out how to have to script get the window id and the name of any new opened windows. The other option i was think which would be easier would be to have it just set for term windows. Since i always have altlest 1 Eterm open. Im still on sure how to get the id of every new term window that opens.


i have an alternative idea to solve your problem:
what about a FvwmScript Widget, or some FvwmButtons on top of your screen, which changes, lets say every 10 seconds. You’re loop just needs to adopt the new title, when focus changes. Additionally you’re windows remain title less. One could also do some window cycle buttons … and close button for the currently focsued window.

just some thoughts … :slight_smile:
If you like, however i could provide some code for the window cycle and title name for the buttons

Yes please do post. Im up for any and all idea’s. Im really new to Fvwm so im not sure what all it can do. I take any and all code i can get :smiley:


Use conditional commands to get the window id. either Current WindowId <func> or

All (Focussed) WindowId <func> will call func in the context of the current (or focussed) window. Inside func, the variable $[] will contain the window id you need.

This would let you just set the current window. You could store the old window title in a environment variable and use it to restore the name by catching lose focus events with FvwmEvent.

Alternatively, catch gain and lost focus events to format the focussed window title bar thus:

window_title_string : mail new/total : battery 99%

then you don’t lose the title info and it’s easier to reset.

To update the header, use the Schedule command

Heller, I’m interested in your scrolling buttons solution as well. I’ve been playing with that idea myself.

window_title_string : mail new/total : battery 99%

Is beautiful. Where can i fint in the man pages how to do this. Im guessing that Current WindowId gets the WindowId of what ever window opens. Like if i have a function FvwmEterm that opens an Eterm. If i use Current WindowId FvwmEterm it would give me the WindowId of that newly spawned Eterm. Or am i way off base here.


A little. Mind you, so was I… :slight_smile:

Fvwm commands don’t return things like window ids. On the other hand, you can get the window id of the window context from the environment variable $[]. The trouble is that opening a window is not enough to change the context.

The way to get around this is with conditional commands. The conditional commands let you search for a window by a number of criteria and execute the commands that follow them in the context of the windows they found. So

Current Echo $[]
should print the id of the currently focussed window. WindowId lets you set the context the window specified by id if id is known. ThisWindow (which is what I was thinking of when I wrote WindowId earlier) forces the windowid context. It shouldn’t be necessary in most cases, but in practice I often need to add it. You can get the details by searching for CONDITIONAL COMMANDS in the manual.

The other useful resource here is the FvwmEvent module. You can set this to execute fvwm commands when certain things happen. there’s a new window event which you can catch perform operations on that window, and you can also catch gain and lose focus events. Cofigure the PassId option and the window id gets added as a parameter your event actions

*FvwmEvent: Cmd *FvwmEvent: PassId *FvwmEvent: focus_change FuncToggleTitleStatus
Will call FuncToggleTitleStatus with the window id in $0. Then you can use something like:

[code]AddToFunc FuncToggleTitleStatus

  • I WindowId (Focused) Exec xprop -id $0 … # add status info to title
  • I TestRc (!Match) Exec xprop -id $0 … # remove status info from title
    to change your title bars

Man FvwmEvent for more info on that module.

And just to add to that: I’ve posted an updated version of FvwmMonitor and a quick HOWTO describing its use. No perl required! :smiley:


hi, here is the code i talked about, can’t remember if the close button reaaly works … just try it

[code]*FvwmDock: (2x1, Id next_window, Icon icons/prev.png, ActionOnPress, Action(Mouse 1) Prev (AcceptsFocus) Focus)
*FvwmDock: (2x1, Id close_window, Icon icons/close.png, ActionOnPress, Action(Mouse 1) Pick Close )
*FvwmDock: (54x1, Id titel, Title $[])
*FvwmDock: (2x1, Id prev_window, Icon icons/next.png, ActionOnPress, Action(Mouse 1) Next (AcceptsFocus) Focus)
*FvwmDock: (2x1, Icon icons/eject.png, ActionOnPress, Action(Mouse 1) Window-List $left $top)

#*FvwmEvent: focus_change “SendToModule FvwmDock ChangeButton titel Title $$[]”
*FvwmEvent: focus_change “SendToModule FvwmDock ChangeButton close_window Action(Mouse 1) Next ($$[]) close)”
*FvwmEvent: focus_change “SendToModule FvwmDock ChangeButton titel Title $$[]”[/code]

Ok i have everything working except i have a few bugs that i need help with. Heres what i have so far.

*FvwmEvent: Cmd
*FvwmEvent: PassId
*FvwmEvent: focus_change AddStatus
*FvwmEvent: leave_window RemoveStatus 

AddToFunc AddStatus
+ I PipeRead "echo SetEnv fvwm_wname `xprop -id $[] | grep 'WM_NAME(STRING)' | sed -e 's/.*= //'`"
+ I PipeRead "echo SetEnv fvwm_battery `/home/voider/.fvwm/scripts/battery`"
+ I PipeRead "echo SetEnv fvwm_mail `/home/voider/.fvwm/scripts/mailcheck`"
+ I ThisWindow (Focused) Exec xprop -id $[] -set WM_NAME "$[fvwm_wname]   $[fvwm_battery]   $[fvwm_mail]"

AddToFunc RemoveStatus
+ I Exec xprop -id $[] -set WM_NAME "$[fvwm_wname]"

Problem 1 is i cant get the window name to update when i change focus and then change back. For instance i open an eterm and the title is
voider@ibook:~ 95% 0/5
I cd to /usr/src then i change the focus to mozilla and then back to the eterm. Instead of showing voider@ibook: /usr/src 95% 0/5 it show voider@ibook:~ blah blah blah.

Problem 2 i can’t really explain what happens so i took a screenshot.
This is the way the bar usaually looks.

And sometime if i change focus so fast i get this.

For some reason the battery status and the mailcheck get save as the original window name then when focus get set back an additional battery and mail status get tacked on the end. Man i hope this all makes sense.

Just wanted to let you know Nick Fortune I checked out your FvwmMonitor again. Aswome! If i ever get gentoo installed on my desktop again ill be using that little dodad.


I’d also look at using the ‘property_change’ event as well – especially as you’re (re)setting the title each time.

In both cases, what’s likely is that you have a race condition, and events are happening to quickly to be processed. Whether you like it or not, to your FvwmEvent configuration, try adding:

*FvwmEvent:  Delay 1

– Thomas Adam