#
# LiNiO <linio@wonder.pl> - 2005.01.15
# 2005.08.12 - je¶li warto¶æ siê nie zmieni³a, nie wy¶wietla jej ponownie - usuniêcie efektu "migotania"

WindowTitle {FvwmScript-AcpiBatt}
WindowSize 48 24
Font "xft:Tahoma:pixelsize=12:Bold"
Colorset 1

Init
Begin
  Set $last = (GetOutput {cat /proc/acpi/battery/BAT?/info} 3 4)
  Set $remaining = (GetOutput {cat /proc/acpi/battery/BAT?/state} 5 3)
  Set $acstate = (GetOutput {cat /proc/acpi/ac_adapter/AC*/state} 1 2)
  Set $batt = (Mult 100 $remaining)
  Set $batt = (Div $batt $last)
  Set $batt = $batt %
  Set $batt_prev = -1

  If $acstate==off-line Then
    Set $batt = * $batt 
  ChangeTitle 1 $batt
End

PeriodicTasks
Begin 
 If (RemainderOfDiv (GetTime) 30)==0 Then
 Begin
   If $batt==$batt_prev Then
   Begin
     # do nothing
   End
   Else
   Begin

    Set $last = (GetOutput {cat /proc/acpi/battery/BAT?/info} 3 4)
    Set $remaining = (GetOutput {cat /proc/acpi/battery/BAT?/state} 5 3)
    Set $batt = (Mult 100 $remaining)
    Set $batt = (Div $batt $last)
    Set $batt_prev = $batt
    Set $acstate = (GetOutput {cat /proc/acpi/ac_adapter/AC*/state} 1 2)

    If $batt>99 Then
      ChangeColorset 1 1
    Else
      Begin
      If $batt>74 Then
        ChangeForeColor 1 {#FFFF00}
      Else
        Begin
        If $batt>49 Then
          ChangeForeColor 1 {#FFBB00}
        Else
          Begin
          If $batt>24 Then
            ChangeForeColor 1 {#FF8800}
          Else
  	  Begin
            If $batt>12 Then
              ChangeForeColor 1 {#FF4400}
            Else
              ChangeForeColor 1 {#FF0000}
            End
          End
        End
      End
    
      Set $batt = $batt %

      If $acstate==off-line Then
        Set $batt = * $batt 

      ChangeTitle 1 $batt
    End

  End
End

Widget 1
Property
Position 0 -2
Size 48 24
Type ItemDraw
Flags NoReliefString
Title {}
Colorset 1
Main
Case message of
 SingleClic :
 Begin
 End
End

