#
# This file is a part of the NsCDE - Not so Common Desktop Environment
# Author: Hegel3DReloaded
# Licence: GPLv3
#

UseGettext {$NSCDE_ROOT/share/locale;NsCDE-KeyboardMgr}
WindowLocaleTitle {Style Manager - Keyboard}
WindowSize 460 350
Colorset 22

Init
Begin
   Set $genfile= (GetOutput {sh -c "echo $FVWM_USERDIR/Xset.conf"} -1 1)
   Set $FILE = $genfile

   ChangeValue 9 (GetOutput  {xset -q | egrep 'auto repeat:' } 0 7)
   If (GetOutput  {xset -q | egrep 'auto repeat:' } 0 3)==on Then
   Begin
      ChangeValue 3 1
   End
   ChangeValue 5 (GetOutput  {xset -q | egrep 'auto repeat delay:' } 0 4)
   ChangeValue 7 (GetOutput  {xset -q | egrep 'auto repeat delay:' } 0 7)

   Set $DefFont = (GetOutput {$NSCDE_TOOLSDIR/getfont -v -t normal -s medium -Z 11.5} 1 -1)
   ChangeFont 2 $DefFont
   ChangeFont 3 $DefFont
   ChangeFont 4 $DefFont
   ChangeFont 6 $DefFont
   ChangeFont 8 $DefFont
   ChangeFont 14 $DefFont

   Set $BtnFont = (GetOutput {$NSCDE_TOOLSDIR/getfont -v -t normal -s medium -Z 16} 1 -1)
   ChangeFont 11 $BtnFont
   ChangeFont 12 $BtnFont
   ChangeFont 13 $BtnFont
   ChangeFont 14 $BtnFont

   Set $HScrollBarFont = (GetOutput {$NSCDE_TOOLSDIR/getfont -v -t normal -s small -Z 11.5} 1 -1)
   ChangeFont 5 $HScrollBarFont
   ChangeFont 7 $HScrollBarFont
   ChangeFont 9 $HScrollBarFont

   # Key bindings
   Key Escape A 14 1 {KeyClose}
   Key Return M 11 1 {KeyApply}
   Key Return C 12 1 {KeySave}
   Key Q C 14 1 {KeyClose}
   Key F1 A 13 1 {KeyHelp}
   Key Help A 13 1 {KeyHelp}

   # Locale stuff: Hack to keep leading or ending space(s)
   # which will be trimmed by LocaleTitle Widget directive.
   ChangeLocaleTitle 3 (GetTitle 3)
End

Widget 1
Property
   Position 10 4
   Flags NoReliefString NoFocus
   Type ItemDraw
   Title {}
   Icon NsCDE/DtKeybd.l.pm
   Main
      Case message of
      SingleClic :
      Begin
      End
End

Widget 2
Property
   Size 100 0
   Position 352 8
   Flags NoReliefString
   Type PushButton
   LocaleTitle {Default}
   Font "xft:::pixelsize=15"
   Main
      Case message of
      SingleClic :
      Begin
         Do {Exec xset r on r rate 512 16 c 50}
         ChangeValue 3 1
         ChangeValue 5 512
         ChangeValue 7 16
         ChangeValue 9 50
         ShowWidget 4
         ShowWidget 5
         ShowWidget 6
         ShowWidget 7
         WarpPointer 12
      End
End

Widget 3
   Property
   Position 10 68
   Flags NoReliefString
   Type CheckBox
   Title { Auto Repeat                                }
   Font "xft:::pixelsize=14"
   Main
      Case message of
      SingleClic :
      Begin
         If (GetValue 3) == 0 Then
         Begin
            HideWidget 4
            HideWidget 5
            HideWidget 6
            HideWidget 7
         End
         Else
         Begin
            ShowWidget 4
            ShowWidget 5
            ShowWidget 6
            ShowWidget 7
         End
      End
End

Widget 4
   Property
   Position 8 120
   Size 106 0
   Flags NoReliefString NoFocus Right
   Type ItemDraw
   LocaleTitle {Start Delay}
   Font "xft:::pixelsize=15"
   Main
      Case message of
      SingleClic :
      Begin
      End
End

Widget 5
   Property
   Size 328 1
   Position 120 100
   Flags NoReliefString
   Type HScrollBar
   Font "xft:::pixelsize=14"
   MinValue 0
   MaxValue 10000
   Main
      Case message of
      SingleClic :
      Begin
      End
End

Widget 6
   Property
   Position 8 180
   Size 106 0
   Flags NoReliefString NoFocus Right
   Type ItemDraw
   LocaleTitle {Repeat Delay}
   Font "xft:::pixelsize=15"
   Main
      Case message of
      SingleClic :
      Begin
      End
End

Widget 7
   Property
   Size 328 1
   Position 120 160
   Flags NoReliefString
   Type HScrollBar
   Font "xft:::pixelsize=14"
   MinValue 0
   MaxValue 255
   Value 0
   Main
      Case message of
      SingleClic :
      Begin
      End
End

Widget 8
   Property
   Position 8 242
   Size 106 0
   Flags NoReliefString NoFocus Right
   Type ItemDraw
   LocaleTitle {Click Volume}
   Font "xft:::pixelsize=15"
   Main
      Case message of
      SingleClic :
      Begin
      End
End

Widget 9
   Property
   Size 328 1
   Position 120 224
   Flags NoReliefString
   Type HScrollBar
   Font "xft:::pixelsize=14"
   MinValue 0
   MaxValue 100
   Value 0
   Main
      Case message of
      SingleClic :
      Begin
      End
End

Widget 10
   Property
   Size 452 0
   Position 2 296
   Type Rectangle
   Main
      Case message of
      SingleClic :
      Begin
      End
End

Widget 11
   Property
   Size 100 0
   Position 10 310
   Flags NoReliefString
   Type PushButton
   LocaleTitle {Apply}
   Font "xft:::pixelsize=15"
   Main
      Case message of
      SingleClic :
      Begin
         SendSignal 11 1
      End
      1 :
      Begin
         Do {Exec xset c } (GetValue 9)
         If (GetValue 3) == 1 Then
            Do {Exec xset r on r rate } (GetValue 5) { } (GetValue 7)
         Else
            Do {Exec xset r off}
      End
End

Widget 12
   Property
   Size 100 0
   Position 123 310
   Flags NoReliefString
   Type PushButton
   LocaleTitle {Save}
   Font "xft:::pixelsize=15"
   Main
      Case message of
      SingleClic :
      Begin
         SendSignal 12 1
      End
      1 :
      Begin
         # Workaround for FvwmScript WriteToFile which truncates existing file if it
         # doesn't find script's signature in it.
         Set $CheckEntryCmd = {egrep -q '^#KeyboardMgr,[1-9]*' "} $FILE {"; echo $?}
         Set $CheckEntry = (GetOutput $CheckEntryCmd 1 -1)

         If $CheckEntry <> 0 Then
         Begin
            Set $PrepareFileCmd = {(echo '#KeyboardMgr,00000'; echo '#end') >> "} $FILE {"}
            Set $PrepareFile = (GetOutput $PrepareFileCmd 1 -1)
         End

         Do {Exec xset c } (GetValue 9)
         If (GetValue 3) == 1 Then
         Begin
            Do {Exec xset r on r rate }  (GetValue 5) { } (GetValue 7)
            WriteToFile $FILE {xset r on r rate }  (GetValue 5) { } (GetValue 7) { c } (GetValue 9)
         End
         Else
         Begin
            Do {Exec xset r off}
            WriteToFile $FILE {xset r off c } (GetValue 9)
         End
         Do {Exec chmod +x } $FILE
         Quit
     End
End

Widget 13
   Property
   Size 100 0
   Position 235 310
   Flags NoReliefString
   Type PushButton
   LocaleTitle {Help}
   Font "xft:::pixelsize=15"
   Main
      Case message of
      SingleClic :
      Begin
         SendSignal 13 1
      End
      1 :
      Begin
         Do {f_DisplayURL "$[gt.Keyboard Style Manager]" html/NsCDE-KeyboardMgr.html}
      End
End

Widget 14
   Property
   Size 100 0
   Position 348 310
   Flags NoReliefString
   Type PushButton
   LocaleTitle {Dismiss}
   Font "xft:::pixelsize=15"
   Main
      Case message of
      SingleClic :
      Begin
         SendSignal 14 1
      End
      1 :
      Begin
         Quit
      End
End

