WindowTitle {Screen Setup}
WindowSize 695 400		# Taille
#ForeColor	{black}
#BackColor	{grey85}
#ShadowColor	{grey55}
#HilightColor	{grey100}
#Font		-adobe-helvetica-bold-r-*-*-12-*

Init
 Begin
  WarpPointer 1

  Set $FILE=(GetScriptArgument 1)
  If $FILE=={} Then
   Set $FILE={.xinitrc-fvwm}
  Set $CAT={cat ~/} $FILE

  #Screen Saver
  Set $pos=0
  Set $finish=1
  While $finish=={1} Do
  Begin
    Set $pos=(Add $pos 1)
    Set $tmp=(GetOutput {xset -q} $pos 1)
    If $tmp=={Screen} Then
      Set $finish=0
    If $pos=={50} Then
      Set $finish=0
  End
  If $pos=={50} Then
  Begin
   Do {Echo ScreenSetup: uncompatible xset}
   #Quit
  End
  Set $pos=(Add $pos 1)
  If (GetOutput  {xset -q} $pos 3) == {yes} Then
   ChangeValue 10 1
  Else
   ChangeValue 11 1
  Set $pos=(Add $pos 1)
  ChangeTitle 14 (GetOutput {xset -q} $pos 2)
  ChangeTitle 15 (GetOutput {xset -q} $pos 4)

  # Dpms
  Set $pos=0
  Set $finish=1
  While $finish=={1} Do
  Begin
    Set $pos=(Add $pos 1)
    Set $tmp=(GetOutput {xset -q} $pos 1)
    If $tmp=={Font} Then
      Set $finish=0
    If $pos=={30} Then
      Set $finish=0
  End
  If $pos=={50} Then
  Begin
   Do {Echo ScreenSetup: uncompatible xset}
   Quit
  End
  Set $pos=(Add $pos 4)
  ChangeTitle 63 (GetOutput {xset -q} $pos 2)
  ChangeTitle 65 (GetOutput {xset -q} $pos 4)
  ChangeTitle 67 (GetOutput {xset -q} $pos 6)
  Set $pos=(Add $pos 1)
  If (GetOutput  {xset -q} $pos 3) == {Enabled} Then
   ChangeValue 60 1
  Else
   ChangeValue 61 1

  # Background
  Set $pos=0
  Set $finish=1
  While $finish=={1} Do
  Begin
    Set $pos=(Add $pos 1)
    Set $tmp=(GetOutput $CAT $pos 1)
    If $tmp=={#ScreenMark} Then
      Set $finish=0
    If $pos=={50} Then
      Set $finish=0
  End
  ChangeValue 4 0
  ChangeValue 5 0
  ChangeValue 50 1
  Set $BColor={#0EC4B8}
  ChangeTitle 7 {/usr/include/X11/pixmaps/fvwm2.xpm}
  ChangeIcon 8 /usr/include/X11/pixmaps/fvwm2.xpm
  Set $pos=(Add $pos 1)
  Set $test=(GetOutput  $CAT $pos 1)
  If $test=={xpmroot} Then
  Begin
   ChangeTitle 7 (GetOutput  $CAT $pos 2)
   ChangeIcon 8 (GetTitle 7)
   ChangeValue 50 0
   ChangeValue 5 1
  End
  If $test=={xsetroot} Then
  Begin
   Set $BColor=(StrCopy (GetOutput  $CAT $pos 3) 2 8)
   ChangeValue 4 1
   ChangeValue 50 0
   ChangeTitle 24 $BColor
   ChangeBackColor 6 $BColor
   ChangeValue 20 (HexToNum (StrCopy $BColor 2 3))
   ChangeValue 21 (HexToNum (StrCopy $BColor 4 5))
   ChangeValue 22 (HexToNum (StrCopy $BColor 6 7))
  End
  # xscreensaver
  Set $pos=(Add $pos 3)
  Set $xsstest=(GetOutput $CAT $pos 1)
  If $xsstest=={xscreensaver} Then
   ChangeValue 72 1
End

PeriodicTasks
 Begin
  Set $MSG=(ReceivFromScript $BROWSER)
  If $MSG <> {No message} Then
  Begin
   ChangeTitle 7 $MSG
   ChangeIcon 8 $MSG
  End
 End

#-----------------------------------------------------------------------------
# Ok, apply and cancel buttons

Widget 1
Property
 Size 70 30
 Position 180 355
 Type PushButton
 Flags NoReliefString
 Title {Apply}
Main
 Case message of
  SingleClic :
  Begin
   # Background
   If (GetValue 5) == 1 Then
    Do {Exec xpmroot } (GetTitle 7)
   If (GetValue 4) == 1 Then
    Do {Exec xsetroot -solid "} $BColor {"}
   # screen-saver
   Do {Exec xset s } (GetTitle 14) { } (GetTitle 15)
   If (GetValue 10)==1 Then
    Do {Exec xset s blank}
   Else
    Do {Exec xset s noblank}
   # dpms
   If (GetValue 60)==1 Then
    Do {Exec xset dpms } (GetTitle 63) { } (GetTitle 65) { } (GetTitle 67)
   Else
    Do {Exec xset -dpms}
   # xscreensaver
   If (GetValue 72) == 1 Then
   Begin
    Do {Exec xscreensaver-command -exit}
    Do {Exec xscreensaver -no-splash&}
   End
   Else
    Do {Exec exec xscreensaver-command -exit}
  End
End

Widget 2
Property
 Size 70 30
 Position 315 355
 Type PushButton
 Flags NoReliefString
 Title {OK}
Main
 Case message of
  SingleClic :
  Begin
   WriteToFile $FILE {#ScreenMark}

   # Background
   If (GetValue 5)==1 Then
   Begin
    Do {Exec xpmroot } (GetTitle 7)
    WriteToFile $FILE {xpmroot } (GetTitle 7)
   End
   If (GetValue 4)==1 Then
   Begin
    Do {Exec xsetroot -solid "} $BColor {"}
    WriteToFile $FILE {xsetroot -solid "} $BColor {"}
   End
   If (GetValue 50)==1 Then
     WriteToFile $FILE {#xsetroot -solid "} $BColor {"}

   # saver
   If (GetValue 10)==1 Then
    Set $tmp2 = { s blank}
   Else
    Set $tmp2 = { s noblank}
   Do {Exec xset s } (GetTitle 14) { } (GetTitle 15) $tmp2
   WriteToFile $FILE {xset s } (GetTitle 14) { } (GetTitle 15) $tmp2

   # dpms
   If (GetValue 60)==1 Then
   Begin
    Do {Exec xset dpms } (GetTitle 63) { } (GetTitle 65) { } (GetTitle 67)
    WriteToFile $FILE {xset dpms } (GetTitle 63) { } (GetTitle 65) { } (GetTitle 67)
   End
   Else
   Begin
    Do {Exec xset -dpms}
    WriteToFile $FILE {xset -dpms}
   End

   # xscreensaver
   If (GetValue 72) == 1 Then
   Begin
    Do {Exec xscreensaver-command -exit}
    Do {Exec xscreensaver -no-splash&}
    WriteToFile $FILE {xscreensaver -no-splash&}
   End
   Else
   Begin
    Do {Exec exec xscreensaver-command -exit}
    WriteToFile $FILE {#xscreensaver}
   End
   
   Do {Exec chmod +x } $FILE
   Quit
  End
End

Widget 3
Property
 Size 70 30
 Position 450 355
 Type PushButton
 Flags NoReliefString
 Title {Cancel}
Main
 Case message of
  SingleClic :
  Begin
   Quit
  End
End

#----------------------------------------------------------------------------
# Left rectangle

Widget 16
Property
 Size 410 330
 Position 10 13
 Type Rectangle
Main
 Case message of
  SingleClic :
  Begin
  End
End

Widget 18
Property
 Position 15 10
 Type ItemDraw
 Flags NoReliefString NoFocus	
 Title {Background}
Main
 Case message of
  SingleClic :
  Begin
  End
End

#---------- Uniform color

Widget 4
Property
 Position 30 30
 Type RadioButton
 Flags NoReliefString
 Title {Uniform color:}
Main
 Case message of
  SingleClic :
  Begin
   ChangeValue 4 1
   ChangeValue 5 0 
   ChangeValue 50 0
  End
End

Widget 6
Property
 Size 50 50
 Position 60 80
 Flags NoFocus
 Type ItemDraw
 BackColor {#0EC4B8}
Main
 Case message of
  SingleClic :
  Begin
  End
End

Widget 23
Property
 Size 60 60
 Position 55 75
 Type Rectangle
Main
 Case message of
  SingleClic :
  Begin
  End
End

Widget 24
Property
 Size 50 50
 Position 58 140
 Type ItemDraw
 Flags NoReliefString NoFocus
 Title {#0EC4B8}
Main
 Case message of
  SingleClic :
  Begin
  End
End

Widget 20
Property
 Size 250 20
 Position 155 20
 Type HScrollBar
 Flags NoReliefString
 Value 14
 MinValue 0
 MaxValue 255
Main
 Case message of
  SingleClic :
  Begin
   Set $BColor = {#} (NumToHex (GetValue 20) 2) (NumToHex (GetValue 21) 2) (NumToHex (GetValue 22) 2)
   ChangeTitle 24 $BColor
   ChangeBackColor 6 $BColor
  End
End

Widget 21
Property
 Size 250 20
 Position 155 75
 Type HScrollBar
 Flags NoReliefString
 Value 196
 MinValue 0
 MaxValue 255
Main
 Case message of
  SingleClic :
  Begin
   Set $BColor = {#} (NumToHex (GetValue 20) 2) (NumToHex (GetValue 21) 2) (NumToHex (GetValue 22) 2)
   ChangeTitle 24 $BColor
   ChangeBackColor 6 $BColor
  End
End

Widget 22
Property
 Size 250 20
 Position 155 130
 Type HScrollBar
 Flags NoReliefString
 Value 184
 MinValue 0
 MaxValue 255
Main
 Case message of
  SingleClic :
  Begin
   Set $BColor = {#} (NumToHex (GetValue 20) 2) (NumToHex (GetValue 21) 2) (NumToHex (GetValue 22) 2)
   ChangeTitle 24 $BColor
   ChangeBackColor 6 $BColor
  End
End

#--------- Pixmaps

Widget 5
Property
 Position 30 220
 Type RadioButton
 Flags NoReliefString
 Title {Pixmap:}
Main
 Case message of
  SingleClic :
  Begin
   ChangeValue 4 0
   ChangeValue 5 1
   ChangeValue 50 0
  End
End

Widget 7
Property
 Size 280 30
 Position 30 280
 Type TextField
 Flags NoReliefString
 Title {/usr/X11/include/X11/pixmaps/fvwm2.xpm}
Main
 Case message of
  SingleClic :
  Begin
   ChangeIcon 8 (GetTitle 7) 
  End
End

Widget 25
Property
 Position 327 279
 Type PushButton
 Flags NoReliefString
 Title {Browser...}
Main
 Case message of
  SingleClic :
  Begin
   Set $ARG={FvwmScript-FileBrowser } (GetTitle 7) { Hello word}
   Set $BROWSER=(LaunchScript $ARG )
  End
End

Widget 8
Property
 Size 175 75
 Position 120 195
 Flags NoReliefString NoFocus
 Type ItemDraw
 Icon /usr/X11/include/X11/pixmaps/fvwm2.xpm
Main
 Case message of
  SingleClic :
  Begin
  End
End

Widget 9
Property
 Size 179 79
 Position 118 193
 Type Rectangle
Main
 Case message of
  SingleClic :
  Begin
  End
End

#--------- Disabled

Widget 50
Property
 Position 30 320
 Type RadioButton
 Flags NoReliefString
 Title {Disable xinit background}
Main
 Case message of
  SingleClic :
  Begin
   ChangeValue 4 0
   ChangeValue 5 0
   ChangeValue 50 1
  End
End

#----------------------------------------------------------------------------
# Right up rectangle


Widget 17
Property
 Size 260 105
 Position 425 13
 Type Rectangle
Main
 Case message of
  SingleClic :
  Begin
  End
End

Widget 19
Property
 Position 430 10
 Type ItemDraw
 Flags NoReliefString NoFocus
 Title {Screen-saver}
Main
 Case message of
  SingleClic :
  Begin
  End
End


Widget 10
Property
 Position 440 40
 Type RadioButton
 Flags NoReliefString
 Title {Blank}
Main
 Case message of
  SingleClic :
  Begin
   ChangeValue 11 0
  End
End

Widget 12
Property
 Position 505 40
 Type ItemDraw
 Flags NoReliefString NoFocus
 Title {Timeout(s):}
Main
 Case message of
  SingleClic :
  Begin
  End
End

Widget 14
Property
 Size 80 79
 Position 590 37
 Flags NoReliefString
 Type TextField
Main
 Case message of
  SingleClic :
  Begin
  End
End

Widget 11
Property
 Position 440 85
 Type RadioButton
 Flags NoReliefString
 Title {Pattern}
Main
 Case message of
  SingleClic :
  Begin
   ChangeValue 10 0
  End
End


Widget 13
Property
 Position 525 85
 Type ItemDraw
 Flags NoReliefString NoFocus
 Title {Cycle(s):}
Main
 Case message of
  SingleClic :
  Begin
   ChangeValue 10 0
  End
End

Widget 15
Property
 Size 80 79
 Position 590 82
 Flags NoReliefString
 Type TextField
Main
 Case message of
  SingleClic :
  Begin
   ChangeValue 10 0
  End
End


#----------------------------------------------------------------------------
# Right middle rectangle


Widget 57
Property
 Size 260 135
 Position 425 128
 Type Rectangle
Main
 Case message of
  SingleClic :
  Begin
  End
End

Widget 59
Property
 Position 430 120
 Type ItemDraw
 Flags NoReliefString NoFocus
 Title {DPMS}
Main
 Case message of
  SingleClic :
  Begin
  End
End


Widget 60
Property
 Position 440 150
 Type RadioButton
 Flags NoReliefString
 Title {Enable}
Main
 Case message of
  SingleClic :
  Begin
   ChangeValue 61 0
  End
End


Widget 61
Property
 Position 580 150
 Type RadioButton
 Flags NoReliefString
 Title {Disable}
Main
 Case message of
  SingleClic :
  Begin
   ChangeValue 60 0
  End
End

Widget 62
Property
 Position 440 180
 Type ItemDraw
 Flags NoReliefString NoFocus
 Title {Standby(s):}
Main
 Case message of
  SingleClic :
  Begin
  End
End

Widget 63
Property
 Size 60 20
 Position 530 177
 Type TextField
 Flags NoReliefString
 Title{1000}
Main
 Case message of
  SingleClic :
  Begin
  End
End

Widget 64
Property
 Position 440 205
 Type ItemDraw
 Flags NoReliefString NoFocus
 Title {Suspend(s):}
Main
 Case message of
  SingleClic :
  Begin
  End
End

Widget 65
Property
 Size 60 20
 Position 530 202
 Type TextField
 Flags NoReliefString
 Title{1000}
Main
 Case message of
  SingleClic :
  Begin
  End
End

Widget 66
Property
 Position 440 230
 Type ItemDraw
 Flags NoReliefString NoFocus
 Title {Off(s):}
Main
 Case message of
  SingleClic :
  Begin
  End
End

Widget 67
Property
 Size 60 20
 Position 530 227
 Type TextField
 Flags NoReliefString
 Title{1000}
Main
 Case message of
  SingleClic :
  Begin
  End
End

#----------------------------------------------------------------------------
# Right down rectangle


Widget 70
Property
 Size 260 65
 Position 425 278
 Type Rectangle
Main
 Case message of
  SingleClic :
  Begin
  End
End

Widget 71
Property
 Position 430 270
 Type ItemDraw
 Flags NoReliefString NoFocus
 Title {xscreensaver}
Main
 Case message of
  SingleClic :
  Begin
  End
End


Widget 72
Property
 Position 440 298
 Type CheckBox
 Flags NoReliefString
 Title {Enable}
Main
 Case message of
  SingleClic :
  Begin
   If (GetValue 72) == 1 Then
   Begin
    Set $SSTIMOUT= (GetTitle 14)
    Set $SSCYCLE= (GetTitle 15)
    ChangeTitle 14 {0}
    ChangeTitle 15 {0}
   End
   Else
   Begin
    ChangeTitle 14 $SSTIMOUT
    ChangeTitle 15 $SSCYCLE
   End 
  End
End


Widget 73
Property
 Position 550 295
 Type PushButton
 Flags NoReliefString
 Title {Config and Demo}
Main
 Case message of
  SingleClic :
  Begin
   Do {Exec xscreensaver-command -prefs&}
  End
End


















