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

UseGettext {$NSCDE_ROOT/share/locale;NsCDE-ColorMgr}
WindowLocaleTitle {Style Manager - Color}
WindowSize 448 464
Colorset 22

Init
Begin
   # CurrDesk - for Backdrop syncronization during preview
   Set $CurrDesk = (Add (GetScriptArgument 1) 1)
   If $CurrDesk == {} Then
   Begin
      Set $CurrDesk = 1
   End

   Set $StaticConfCheck = (GetOutput {test -f "$FVWM_USERDIR/Colorset.fvwmconf" && echo 1} 1 1)
   If $StaticConfCheck == 1 Then
   Begin
      Do {f_Notifier "Color Style Manager" "Dismiss" "NsCDE/Error.xpm" }
         {"$[gt.Static file Colorset.fvwmconf exists and is read }
         {instead of regular Colorset.fvwmgen which is produced by the }
         {Color Style Manager. In order to use Color Style Manager, static }
         {file Colorset.fvwmconf must be removed from directory] $[FVWM_USERDIR]"}
      Quit
   End

   # Defined as NSCDE_PALETTE_NCOLORS in Colorset.fvwmconf/fvwmgen
   Set $Ncolors = (GetScriptArgument 2)
   If $Ncolors == {} Then
   Begin
      Do {f_Notifier "Color Style Manager" "Dismiss" "NsCDE/Error.xpm" "Default number of colors is not defined. Setting default number of colors to 8."}
      Set $Ncolors = 8
   End

   If $Ncolors == 4 Then
   Begin
      HideWidget 11
      HideWidget 13
      HideWidget 15
      HideWidget 17
      ChangeSize 10 64 72
      ChangeSize 12 64 72
      ChangeSize 14 64 72
      ChangeSize 16 64 72
      ChangeIcon 9 NsCDE/Bframe4.xpm
      ChangeSize 9 72 80
   End
   If $Ncolors == 8 Then
   Begin
      ShowWidget 11
      ShowWidget 13
      ShowWidget 15
      ShowWidget 17
      ChangeSize 10 64 32
      ChangeSize 11 64 32
      ChangeSize 12 64 32
      ChangeSize 13 64 32
      ChangeSize 14 64 32
      ChangeSize 15 64 32
      ChangeSize 16 64 32
      ChangeSize 17 64 32
      ChangeIcon 9 NsCDE/Bframe8.xpm
      ChangeSize 9 72 40
   End

   # Default Front Panel Variant
   Do {SendToModule ColorMgr SendString 20 2 $[infostore.fp_8color_variant]}

   # Default Front Panel Variant
   Set $WsmRoutineCalled = 0
   Do {SendToModule ColorMgr SendString 20 3 $[infostore.wsmcolored]}

   Set $Palettes = (GetOutput {$NSCDE_TOOLSDIR/colormgr -p} 1 -1)
   ChangeTitle 3 $Palettes

   # For Keybindings not to go beyond min and max
   Set $ListTotal = (GetOutput {$NSCDE_TOOLSDIR/colormgr -p | tr '|' '\n' | wc -l} 1 1)

   Set $PreviewContaminated = 0
   Set $SelectedColorset = 0

   Set $Current = (GetOutput {echo $NSCDE_PALETTE} 1 -1)
   Set $CurrentPaletteValueCmd = {$NSCDE_TOOLSDIR/colormgr -N "} $Current {.dp"}
   Set $CurrentPaletteValue = (GetOutput $CurrentPaletteValueCmd 1 -1)
   If $CurrentPaletteValue <> {} Then
   Begin
      ChangeValue 3 $CurrentPaletteValue
      SendSignal 3 1
   End

   Set $CustomExistedBefore = (GetOutput {ls "$FVWM_USERDIR/palettes/Custom.dp" > /dev/null 2>&1; echo $?} 1 1)

   # Keybindings
   Key Q C 33 1 {KeyClose}
   Key Return C 32 1 {KeyOk}
   Key P A 4 1 {KeyPreview}
   Key M A 19 4 {KeyModColor}
   Key C A 20 4 {KeyNumColors}
   Key I A 21 1 {KeyIntegOpts}
   Key Down A 3 2 {KeyDown}
   Key Up A 3 2 {KeyUp}
   Key F1 A 34 1 {KeyHelp}
   Key Help A 34 1 {KeyHelp}

   # Set different font for some elements
   Set $DefaultFont = (GetOutput {$NSCDE_TOOLSDIR/getfont -v -t normal -s medium -Z 12} 1 -1)
   ChangeFont 1 $DefaultFont
   ChangeFont 7 $DefaultFont
   ChangeFont 19 $DefaultFont
   ChangeFont 20 $DefaultFont
   ChangeFont 21 $DefaultFont

   Set $BtnFont = (GetOutput {$NSCDE_TOOLSDIR/getfont -v -t normal -s medium -Z 16} 1 -1)
   ChangeFont 32 $BtnFont
   ChangeFont 33 $BtnFont
   ChangeFont 34 $BtnFont
   ChangeFont 4 $BtnFont
   ChangeFont 5 $BtnFont
   ChangeFont 6 $BtnFont

   Set $ListFont = (GetOutput {$NSCDE_TOOLSDIR/getfont -v -t normal -s medium -Z 14} 1 -1)
   ChangeFont 3 $ListFont

   Set $SmallFont = (GetOutput {$NSCDE_TOOLSDIR/getfont -v -t normal -s small -Z 11} 1 -1)
   Set $ExtraSmallFont = (GetOutput {$NSCDE_TOOLSDIR/getfont -v -t normal -s small -Z 10.25} 1 -1)

   # Provide defaults for integration options.
   # 1. Backdrops
   # 2. X Resources
   # 3. GTK2
   # 4. GTK3
   # 5. Qt4
   # 6. Qt5 via GTK2 plugin
   # 7. Qt5 via Kvantum NsCDE plugin 
   # 8. Qt6 via Kvantum NsCDE plugin
   # 9. Reserved for GTK4
   # 10. Local $FVWM_USERDIR/libexec/colormgr.local

   # Saved Integration String
   # WARNING: order of options to -K of confget is important!
   Set $IntegrationStringCmd = {$NSCDE_TOOLSDIR/confget -c $FVWM_USERDIR/StyleMgr.ini -s ColorMgr -d "" -D 2 -K }
       {integrate_backdrops,integrate_xresources,integrate_gtk2,integrate_gtk3,integrate_qt4,integrate_qt5g,}
       {integrate_qt5k,integrate_qt6,integrate_gtk4,integrate_local}
   Set $IntegrationString = (GetOutput $IntegrationStringCmd 1 1)

   Set $SetBackdrops = (StrCopy $IntegrationString 1 1)
   Set $InitialSetBackdrops = $SetBackdrops
   If $SetBackdrops <> 0 Then
   Begin
      If $SetBackdrops <> 1 Then
      Begin
         Set $SetBackdrops = 1
      End
   End

   Set $SetXresources = (StrCopy $IntegrationString 2 2)
   Set $InitialSetXresources = $SetXresources
   If $SetXresources <> 0 Then
   Begin
      If $SetXresources <> 1 Then
      Begin
         Set $SetXresources = 1
      End
   End

   Set $SetGtk2 = (StrCopy $IntegrationString 3 3)
   Set $InitialSetGtk2 = $SetGtk2
   If $SetGtk2 <> 0 Then
   Begin
      If $SetGtk2 <> 1 Then
      Begin
         Set $SetGtk2 = 1
      End
   End

   Set $SetGtk3 = (StrCopy $IntegrationString 4 4)
   Set $InitialSetGtk3 = $SetGtk3
   If $SetGtk3 <> 0 Then
   Begin
      If $SetGtk3 <> 1 Then
      Begin
         Set $SetGtk3 = 1
      End
   End

   Set $SetQt4 = (StrCopy $IntegrationString 5 5)
   Set $InitialSetQt4 = $SetQt4
   If $SetQt4 <> 0 Then
   Begin
      If $SetQt4 <> 1 Then
      Begin
         Set $SetQt4 = 1
      End
   End

   Set $SetQt5Gtk = (StrCopy $IntegrationString 6 6)
   Set $InitialSetQt5Gtk = $SetQt5Gtk
   If $SetQt5Gtk <> 0 Then
   Begin
      If $SetQt5Gtk <> 1 Then
      Begin
         Set $SetQt5Gtk = 0
      End
   End

   Set $SetQt5Kv = (StrCopy $IntegrationString 7 7)
   Set $InitialSetQt5Kv = $SetQt5Kv
   If $SetQt5Kv <> 0 Then
   Begin
      If $SetQt5Kv <> 1 Then
      Begin
         Set $SetQt5Kv = 1
      End
   End

   Set $SetQt6Kv = (StrCopy $IntegrationString 8 8)
   Set $InitialSetQt6Kv = $SetQt6Kv
   If $SetQt6Kv <> 0 Then
   Begin
      If $SetQt6Kv <> 1 Then
      Begin
         Set $SetQt6Kv = 1
      End
   End

   Set $SetGtk4 = (StrCopy $IntegrationString 9 9)
   Set $InitialSetGtk4 = $SetGtk4
   If $SetGtk4 <> 0 Then
   Begin
      If $SetGtk4 <> 1 Then
      Begin
         Set $SetGtk4 = 0
      End
   End

   Set $SetColormgrLocal = (StrCopy $IntegrationString 10 10)
   Set $InitialSetColormgrLocal = $SetColormgrLocal
   If $SetColormgrLocal <> 0 Then
   Begin
      If $SetColormgrLocal <> 1 Then
      Begin
         Set $SetColormgrLocal = 1
      End
   End

   # Get ride of possible "2" initial value, otherwise we can get checked checkbox in ColorIntegrationDialog
   Set $IntegrationString = $SetBackdrops $SetXresources $SetGtk2 $SetGtk3 $SetQt4 $SetQt5Gtk $SetQt5Kv $SetQt6Kv $SetGtk4 $SetColormgrLocal

   Set $GtkStr = {00}
   Set $Gtk2Str = 0
   Set $Gtk3Str = 0

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

   # Get FVWM3 DesktopConfiguratio mode
   # Default is global and fvwm2
   Set $Fvwm3DesktopNonGlobalMode = 0
   Do {SendToModule ColorMgr SendString 4 2 $[FVWM_IS_FVWM3]_$[monitor.count]_$[infostore.desktopconfiguration]}

   # Inform Color Style Manager if we are using xsettingsd to restart it.
   Do {SendToModule ColorMgr SendString 4 3 $[infostore.nscde_use_xsettingsd]}
End

PeriodicTasks
Begin
   Set $MSG = (ReceivFromScript $BROWSER)
   If $MSG <> {No message} Then
   Begin
     Do {SendToModule ColorMgr SendString 5 1 } $MSG
   End

   If $CurrentModifiedPalette == {Custom} Then
   Begin
      Set $INPUTMSG = (ReceivFromScript $INPUTFORM)
      If $INPUTMSG <> {No message} Then
      Begin
        If $INPUTMSG <> {Cancel} Then
        Begin
           Do {Schedule 250 SendToModule ColorMgr SendString 19 3 } $INPUTMSG
        End
        Else
        Begin
           # On Palette change, clear color modifications of the past palette
           Set $CurrentModifiedPalette = {}
           If $CustomExistedBefore <> 0 Then
           Begin
              Do {Exec exec rm -f "$FVWM_USERDIR/palettes/Custom.dp"}
           End
           ChangeValue 3 $PreModPaletteValue
           SendSignal 3 1
        End
      End
   End
End

QuitFunc
Begin
   # Remove notice if it still exists.
   Do {SendToModule WaitNotice SendString 3 1 Quit}

   # TransientDialog like windows cleanup
   Do {KillModule FvwmScript NColorsDialog}
   Do {KillModule FvwmScript ModifyColor}
   Do {KillModule FvwmScript ColorIntegrationDialog}
   Do {KillModule FvwmScript FilePicker}
   Do {KillModule FvwmScript ActionForm}
   Do {KillModule FvwmScript InputForm}

   # Cleanup on exit
   Do {Exec exec rm -f '} $FullColor {' "$FVWM_USERDIR/tmp/Colorset-Preview.conf" }
      {$FVWM_USERDIR/tmp/*-Preview $FVWM_USERDIR/tmp/backer-*.pm $FVWM_USERDIR/tmp/backer-*.png }
      {"$FVWM_USERDIR/tmp/__colors.tmp"}
End

Widget 1
   Property
   Size 4 0
   Position 16 8
   Type ItemDraw
   Flags NoReliefString Left NoFocus
   Title { Palettes }
   Font "xft:::pixelsize=15"
   Main
      Case message of
      SingleClic :
      Begin
      End
End

Widget 2
   Property
   Size 432 186
   Position 8 18
   Type Rectangle
End

Widget 3
   Property
   Size 248 164
   Position 20 30
   Type List
   Flags NoReliefString
   Title {}
   Colorset 20
   Main
      Case message of
      SingleClic :
      Begin
         SendSignal 3 1
      End
      1 :
      Begin
         Set $PalNumToNameCmd =  {$NSCDE_TOOLSDIR/colormgr -n } (GetValue 3)
         Set $PalNumToName = { } (GetOutput $PalNumToNameCmd 1 -1)

         # Calculate chars in the current palette name
         # All this for decor purpose
         Set $StrLen = 1
         Set $iter = 0
         While $iter <> 1 Do
         Begin
            Set $NameStr = (StrCopy $PalNumToName $StrLen $StrLen)
            If $NameStr <> {} Then
            Begin
               Set $iter = 0
               Set $StrLen = (Add $StrLen 1)
            End
            Else
            Begin
               Set $iter = 1
               Set $StrLen = (Mult (Add $StrLen -1) 8)
            End
         End

         # Set palette name and size at the upper left corner of rectangle
         Set $StrSpace = (Add $StrLen 14)
         ChangeSize 7 $StrSpace 22
         ChangeTitle 7 $PalNumToName

         # Figure out Palette Path
         Set $PalettePathCmd = {$NSCDE_TOOLSDIR/colormgr -e -g } $PalNumToName
         Set $PalettePath = (GetOutput $PalettePathCmd 1 -1)

         # Colorsets 61 - 68 are for Color Style Manager preview only
         Do {PipeRead "$[NSCDE_TOOLSDIR]/palette_colorgen -n } $Ncolors { -p } $PalettePath { -C}

         ChangeColorset 10 61
         ChangeColorset 11 65
         ChangeColorset 12 62
         ChangeColorset 13 66
         ChangeColorset 14 63
         ChangeColorset 15 67
         ChangeColorset 16 64
         ChangeColorset 17 68

         Set $FullColorCmd = {$NSCDE_TOOLSDIR/colormgr -c } $Ncolors { -f } $PalettePath
         Set $FullColor = (GetOutput $FullColorCmd 1 -1)
         ChangeIcon 18 $FullColor

      End
      2 :
      Begin
         If (LastString) == {KeyDown} Then
         Begin
            Set $NextListItem = (Add (GetValue 3) 1)
            If (GetValue 3) < $ListTotal Then
            Begin
               ChangeValue 3 $NextListItem
            End
            Else
            Begin
               ChangeValue 3 1
            End
         End

         If (LastString) == {KeyUp} Then
         Begin
            Set $NextListItem = (Add (GetValue 3) -1)
            If (GetValue 3) > 1 Then
            Begin
               ChangeValue 3 $NextListItem
            End
            Else
            Begin
               ChangeValue 3 $ListTotal
            End
         End

         SendSignal 3 1
      End
End

Widget 4
   Property
   Size 120 22
   Position 296 44
   Type PushButton
   Flags NoReliefString
   Title { Preview | Preview | Revert }
   Font "xft:::pixelsize=15"
   Main
      Case message of
      SingleClic :
      Begin
         SendSignal 4 1
      End
      1 :
      Begin
         Set $PreviewContaminated = 1
         SendSignal 4 4
         If $PerformBackdropSync <> {} Then
         Begin
            If $Fvwm3DesktopNonGlobalMode == 0 Then
            Begin
               Do {Exec exec fvwm-root -r } $PerformBackdropSync
            End
            Else
            Begin
               Do {Exec exec /usr/bin/ksh -c 'convert }
               {\( $[FVWM_USERDIR]/backer/bgcache/$[infostore.monitordata]/$[infostore.monitorbackdata].png \) }
               {\( -size $[monitor.$[monitor.current].width]x$[monitor.$[monitor.current].height] tile:} $PerformBackdropSync
               { -geometry +$[monitor.$[monitor.current].x]+$[monitor.$[monitor.current].y] -compose over \) -composite "}
               $PerformBackdropSync {.png" && fvwm-root -r "} $PerformBackdropSync {.png"'}
            End
         End
         Do {Read } $PerformPaletteChange
         Do {Schedule 120 Refresh}

         If (GetValue 4) == 2 Then
         Begin
            Set $RestoreXresources = (GetOutput {xrdb -remove; xrdb -cpp /usr/bin/cpp < $FVWM_USERDIR/Xdefaults} 1 -1)
            Do {f_ReadCfg Backdrops}
            Do {f_ReadCfg Colorset}

            If $Fvwm3DesktopNonGlobalMode == 1 Then
            Begin
               Do {f_SetupMonitorData}
               Do {Schedule 120 f_SetFvwm3NonGlobalBackground}
            End

            Set $PreviewContaminated = 0
         End
      End
      2 :
      Begin
         Set $IsFvwm3 = (StrCopy (LastString) 1 1)
         Set $Monitors = (StrCopy (LastString) 3 3)
         Set $DesktopModel = (StrCopy (LastString) 5 35)

         If (Add $IsFvwm3 $Monitors) >= 3 Then
         Begin
            If $DesktopModel == {per-monitor} Then
            Begin
               Set $Fvwm3DesktopNonGlobalMode = 1
            End
            If $DesktopModel == {shared} Then
            Begin
               Set $Fvwm3DesktopNonGlobalMode = 1
            End
         End
      End
      3 :
      Begin
         Set $CheckUseXsettingsd = (LastString)
      End
      4 :
      Begin
         Set $PerformPaletteChangeCmd = {$NSCDE_TOOLSDIR/colormgr -t } $FpVariantArg { } $WsmVariantArg { -e -c } $Ncolors { -g } $PalNumToName { -F}
         Set $PerformPaletteChange = (GetOutput $PerformPaletteChangeCmd 2 -1)
         Set $PerformProgBitsChangeCmd = {$NSCDE_TOOLSDIR/colormgr -t } $FpVariantArg { -e -c } $Ncolors { -g } $PalNumToName { -P}
         Set $PerformProgBitsChange = (GetOutput $PerformProgBitsChangeCmd 1 -1)

         If $SetXresources == 1 Then 
         Begin 
            Set $PerformXresourceChangeCmd = {$NSCDE_TOOLSDIR/colormgr -t -e -c } $Ncolors { -g } $PalNumToName { -X}
            Set $PerformXresourceChange = (GetOutput $PerformXresourceChangeCmd 2 -1)
         End

         If $SetBackdrops == 1 Then
         Begin
            Set $PerformBackdropSyncCmd = {$NSCDE_TOOLSDIR/colormgr -t -e -c } $Ncolors { -g } $PalNumToName { -b}
            # 1st and 2nd lines are pallete path/name and backdrop template, the rest is sorted in desk num order from 3-10 (8)
            Set $bpospreview = (Add $CurrDesk 2)
            Set $PerformBackdropSync = (GetOutput $PerformBackdropSyncCmd $bpospreview -1)
         End
      End
End

Widget 5
   Property
   Size 120 22
   Position 296 100
   Type PushButton
   Flags NoReliefString
   LocaleTitle { Add ... }
   Font "xft:::pixelsize=15"
   Main
      Case message of
      SingleClic :
      Begin
         Set $ARG={FilePicker }
         Set $BROWSER=(LaunchScript $ARG )
      End
      1 :
      Begin
         Set $CheckPaletteFileCmd = {$NSCDE_TOOLSDIR/colormgr -C } (LastString)
         Set $CheckPaletteFile = (GetOutput $CheckPaletteFileCmd 1 -1)
         If $CheckPaletteFile == 8 Then
         Begin
            Do {Exec exec cp "} (LastString) {" $FVWM_USERDIR/palettes/}
            Set $Palettes = (GetOutput {$NSCDE_TOOLSDIR/colormgr -p} 1 -1)
            ChangeTitle 3 $Palettes
         End
         Else
         Begin
            Do {f_Notifier "Color Style Manager" "Dismiss" "NsCDE/Error.xpm" "$[gt.Selected file] \\\"} (LastString) {\\\" $[gt.is not a valid CDE/NsCDE Palette file.]"}
         End
      End
End

Widget 6
   Property
   Size 120 22
   Position 296 154
   Type PushButton
   Flags NoReliefString
   LocaleTitle { Delete ... }
   Font "xft:::pixelsize=15"
   Main
      Case message of
      SingleClic :
      Begin
         Set $DelPalNumToNameCmd =  {$NSCDE_TOOLSDIR/colormgr -n } (GetValue 3)
         Set $DelPalNumToName = (GetOutput $DelPalNumToNameCmd 1 -1)
         Set $CheckDelPathCmd = {$NSCDE_TOOLSDIR/colormgr -e -g } $DelPalNumToName
         Set $CheckDelPath = (GetOutput $CheckDelPathCmd 1 -1)
         Do {f_RunQuickScriptDialog ActionForm "$[gt.Delete Palette] } $DelPalNumToName {" "$[gt.Yes]" "$[gt.No]" "$[gt.Delete Palette]" "SendToModule ColorMgr SendString 6 1 confirmed"}
      End
      1 :
      Begin
         If (LastString) == {confirmed} Then
         Begin
            Set $RmPaletteCmd = {rm -f } $CheckDelPath { 2>&1}
            Set $RmPalette = (GetOutput $RmPaletteCmd 1 -1)
            If $RmPalette <> {} Then
            Begin
               Do {f_Notifier "Color Style Manager" "Dismiss" "NsCDE/Error.xpm" "} $RmPalette {"}
            End
            Else
            Begin
               Set $Palettes = (GetOutput {$NSCDE_TOOLSDIR/colormgr -p} 1 -1)
               ChangeTitle 3 $Palettes
            End
         End
      End
End

Widget 7
   Property
   Size 10 0
   Position 16 205
   Type ItemDraw
   Flags NoReliefString Left NoFocus
   Title {Palette Name}
   Font "xft:::pixelsize=15"
   Main
      Case message of
      SingleClic :
      Begin
      End
End

Widget 8
   Property
   Size 432 100
   Position 8 216
   Type Rectangle
End

Widget 9
   Property
   Size 72 40
   Position 18 226
   Type ItemDraw
   Flags NoReliefString Hidden
   Title {}
   Icon NsCDE/Bframe8.xpm
   Main
      Case message of
      SingleClic :
      Begin
      End
End

Widget 10
   Property
   Size 64 32
   Position 22 230
   Type PushButton
   Title {}
   Flags NoReliefString
   BackColor {#ffffffffffff}
   Main
      Case message of
      SingleClic :
      Begin
         If (GetTitle 10) == {} Then
         Begin
            ChangeTitle 10 {Abc}
            ChangeTitle 11 {}
            ChangeTitle 12 {}
            ChangeTitle 13 {}
            ChangeTitle 14 {}
            ChangeTitle 15 {}
            ChangeTitle 16 {}
            ChangeTitle 17 {}
            ShowWidget 9
            ChangePosition 9 18 226
            Set $SelectedColorset = 61
            Set $WidgetOfColorset = 10
         End
         Else
         Begin
            ChangeTitle 10 {}
            HideWidget 9
            Set $SelectedColorset = 0
            Set $WidgetOfColorset = 0
         End
      End
End

Widget 11
   Property
   Size 64 32
   Position 22 274
   Type PushButton
   Title {}
   Flags NoReliefString
   BackColor {#ffffffffffff}
   Main
      Case message of
      SingleClic :
      Begin
         If (GetTitle 11) == {} Then
         Begin
            ChangeTitle 10 {}
            ChangeTitle 11 {Abc}
            ChangeTitle 12 {}
            ChangeTitle 13 {}
            ChangeTitle 14 {}
            ChangeTitle 15 {}
            ChangeTitle 16 {}
            ChangeTitle 17 {}
            ShowWidget 9
            ChangePosition 9 18 270
            Set $SelectedColorset = 65
            Set $WidgetOfColorset = 11
         End
         Else
         Begin
            ChangeTitle 11 {}
            HideWidget 9
            Set $SelectedColorset = 0
            Set $WidgetOfColorset = 0
         End
      End
End

Widget 12
   Property
   Size 64 32
   Position 100 230
   Type PushButton
   Title {}
   Flags NoReliefString
   BackColor {#ffffffffffff}
   Main
      Case message of
      SingleClic :
      Begin
         If (GetTitle 12) == {} Then
         Begin
            ChangeTitle 10 {}
            ChangeTitle 11 {}
            ChangeTitle 12 {Abc}
            ChangeTitle 13 {}
            ChangeTitle 14 {}
            ChangeTitle 15 {}
            ChangeTitle 16 {}
            ChangeTitle 17 {}
            ShowWidget 9
            ChangePosition 9 96 226
            Set $SelectedColorset = 62
            Set $WidgetOfColorset = 12
         End
         Else
         Begin
            ChangeTitle 12 {}
            HideWidget 9
            Set $SelectedColorset = 0
            Set $WidgetOfColorset = 0
         End
      End
End

Widget 13
   Property
   Size 64 32
   Position 100 274
   Type PushButton
   Title {}
   Flags NoReliefString
   BackColor {#ffffffffffff}
   Main
      Case message of
      SingleClic :
      Begin
         If (GetTitle 13) == {} Then
         Begin
            ChangeTitle 10 {}
            ChangeTitle 11 {}
            ChangeTitle 12 {}
            ChangeTitle 13 {Abc}
            ChangeTitle 14 {}
            ChangeTitle 15 {}
            ChangeTitle 16 {}
            ChangeTitle 17 {}
            ShowWidget 9
            ChangePosition 9 96 270
            Set $SelectedColorset = 66
            Set $WidgetOfColorset = 13
         End
         Else
         Begin
            ChangeTitle 13 {}
            HideWidget 9
            Set $SelectedColorset = 0
            Set $WidgetOfColorset = 0
         End
      End
End

Widget 14
   Property
   Size 64 32
   Position 178 230
   Type PushButton
   Title {}
   Flags NoReliefString
   BackColor {#ffffffffffff}
   Main
      Case message of
      SingleClic :
      Begin
         If (GetTitle 14) == {} Then
         Begin
            ChangeTitle 10 {}
            ChangeTitle 11 {}
            ChangeTitle 12 {}
            ChangeTitle 13 {}
            ChangeTitle 14 {Abc}
            ChangeTitle 15 {}
            ChangeTitle 16 {}
            ChangeTitle 17 {}
            ShowWidget 9
            ChangePosition 9 174 226
            Set $SelectedColorset = 63
            Set $WidgetOfColorset = 14
         End
         Else
         Begin
            ChangeTitle 14 {}
            HideWidget 9
            Set $SelectedColorset = 0
            Set $WidgetOfColorset = 0
         End
      End
End

Widget 15
   Property
   Size 64 32
   Position 178 274
   Type PushButton
   Title {}
   Flags NoReliefString
   BackColor {#ffffffffffff}
   Main
      Case message of
      SingleClic :
      Begin
         If (GetTitle 15) == {} Then
         Begin
            ChangeTitle 10 {}
            ChangeTitle 11 {}
            ChangeTitle 12 {}
            ChangeTitle 13 {}
            ChangeTitle 14 {}
            ChangeTitle 15 {Abc}
            ChangeTitle 16 {}
            ChangeTitle 17 {}
            ShowWidget 9
            ChangePosition 9 174 270
            Set $SelectedColorset = 67
            Set $WidgetOfColorset = 15
         End
         Else
         Begin
            ChangeTitle 15 {}
            HideWidget 9
            Set $SelectedColorset = 0
            Set $WidgetOfColorset = 0
         End
      End
End

Widget 16
   Property
   Size 64 32
   Position 256 230
   Type PushButton
   Title {}
   Flags NoReliefString
   BackColor {#ffffffffffff}
   Main
      Case message of
      SingleClic :
      Begin
         If (GetTitle 16) == {} Then
         Begin
            ChangeTitle 10 {}
            ChangeTitle 11 {}
            ChangeTitle 12 {}
            ChangeTitle 13 {}
            ChangeTitle 14 {}
            ChangeTitle 15 {}
            ChangeTitle 16 {Abc}
            ChangeTitle 17 {}
            ShowWidget 9
            ChangePosition 9 252 226
            Set $SelectedColorset = 64
            Set $WidgetOfColorset = 16
         End
         Else
         Begin
            ChangeTitle 16 {}
            HideWidget 9
            Set $SelectedColorset = 0
            Set $WidgetOfColorset = 0
         End
      End
End

Widget 17
   Property
   Size 64 32
   Position 256 274
   Type PushButton
   Title {}
   Flags NoReliefString
   BackColor {#ffffffffffff}
   Main
      Case message of
      SingleClic :
      Begin
         If (GetTitle 17) == {} Then
         Begin
            ChangeTitle 10 {}
            ChangeTitle 11 {}
            ChangeTitle 12 {}
            ChangeTitle 13 {}
            ChangeTitle 14 {}
            ChangeTitle 15 {}
            ChangeTitle 16 {}
            ChangeTitle 17 {Abc}
            ShowWidget 9
            ChangePosition 9 252 270
            Set $SelectedColorset = 68
            Set $WidgetOfColorset = 17
         End
         Else
         Begin
            ChangeTitle 17 {}
            HideWidget 9
            Set $SelectedColorset = 0
            Set $WidgetOfColorset = 0
         End
      End
End

Widget 18
   Property
   Size 84 32
   Position 339 274
   Type ItemDraw
   Flags NoReliefString NoFocus
   Title {}
   Icon NsCDE/None.xpm
   Colorset 50
   Main
      Case message of
      SingleClic :
      Begin
      End
End

Widget 19
   Property
   Size 88 32
   Position 338 230
   Type PushButton
   Flags NoReliefString
   LocaleTitle {Modify}
   Font "xft:::pixelsize=15"
   Main
      Case message of
      SingleClic :
      Begin
         SendSignal 19 4
      End
      # Called from ModifyColor Module to change color
      1 :
      Begin
         # Cleanup is done in QuitFunc, but do it here anyway, not to append into existing tmp file
         Set $Cleanup = (GetOutput {rm -f "$FVWM_USERDIR/tmp/__colors.tmp" 2>&1} 1 -1)
         If $Cleanup <> {} Then
         Begin
            Do {f_Notifier "Color Style Manager" "Dismiss" "NsCDE/Error.xpm" "$[gt.Error removing] \\\"$FVWM_USERDIR/tmp/__colors.tmp\\\": } $Cleanup {"}
         End

         # Save old value of the list in case of cancel from input form
         Set $PreModPaletteValue = (GetValue 3)
         Set $CustomExistedBefore = (GetOutput {ls "$FVWM_USERDIR/palettes/Custom.dp" > /dev/null 2>&1; echo $?} 1 1)

         # Compose new palette and call it Custom.dp.
         # Useless echo of widget numbers after appending into __colors.tmp is here
         # to workaround FvwmScript For implementation which somehow truncates same
         # Rpart Gpart and Bpart values if they follow one after another - $w will
         # give difference (numbers 10 - 17). Stupid bug ...
         Set $w = 9
         While $w < 17 Do
         Begin
            Set $w = (Add $w 1)
            Set $CS = (GetBack $w)
            Set $Rpart = (StrCopy $CS 1 2) (StrCopy $CS 1 2)
            Set $Gpart = (StrCopy $CS 3 4) (StrCopy $CS 3 4)
            Set $Bpart = (StrCopy $CS 5 6) (StrCopy $CS 5 6)
            Set $FillPaletteCmd = {echo '#} $Rpart $Gpart $Bpart {' >> "$FVWM_USERDIR/tmp/__colors.tmp"; echo "} $w {" > /dev/null}
            Set $FillPalette = (GetOutput $FillPaletteCmd 1 -1)
         End
         Set $RightReorderCmd = {(sed -n '1p;3p;5p;7p' "$FVWM_USERDIR/tmp/__colors.tmp" ; sed -n '2p;4p;6p;8p' "$FVWM_USERDIR/tmp/__colors.tmp") > "$FVWM_USERDIR/palettes/Custom.dp"}
         Set $RightReorder = (GetOutput $RightReorderCmd 1 -1)

         # Refresh palettes list, select Custom.dp
         Set $Palettes = (GetOutput {$NSCDE_TOOLSDIR/colormgr -p} 1 -1)
         ChangeTitle 3 $Palettes
         Set $CurrentModifiedPalette = (GetOutput {$NSCDE_TOOLSDIR/colormgr -N "Custom.dp"} 1 1)
         ChangeValue 3 $CurrentModifiedPalette
         SendSignal 3 1
         Set $CurrentModifiedPalette = {Custom}
      End
      2 :
      Begin
         # Rename Custom Palette?
         If $CurrentModifiedPalette == {Custom} Then
         Begin
            Set $INPUTMSG = {InputForm "$[gt.New Palette Name?]" "Custom"}
            Set $INPUTFORM = (LaunchScript $INPUTMSG)
         End
      End
      3 :
      Begin
         If $INPUTMSG <> {Custom} Then
         Begin
            # Basic input sanity check
            Set $INPUTMSGCmd = {echo '} $INPUTMSG {' | $NSCDE_TOOLSDIR/ised -c 's/>\|<\|\/\|;\|:\|\[\|\]\|\\\|\$\|#\|%\|\&\|"\|\!\|\^\|\*\|(\|)\||\|?\| //g' -o -f -}
            Set $INPUTMSG = (GetOutput $INPUTMSGCmd 1 1)
            If $INPUTMSG == {} Then
            Begin
               Set $INPUTMSG = {Custom}
            End

            # Rename from Custom only if new value is not already Custom
            If $INPUTMSG <> {Custom} Then
            Begin
               Set $RenamePaletteCmd = {mv -f "$FVWM_USERDIR/palettes/Custom.dp" "$FVWM_USERDIR/palettes/} $INPUTMSG {.dp" 2>&1}
               Set $RenamePalette = (GetOutput $RenamePaletteCmd 1 -1)
               If $RenamePalette <> {} Then
               Begin
                  Do {f_Notifier "Color Style Manager" "Dismiss" "NsCDE/Error.xpm" }
                     {"$[gt.Error renaming] \\\"$FVWM_USERDIR/palettes/Custom.dp\\\" }
                     {$[gt.into] \\\"$FVWM_USERDIR/palettes/} $INPUTMSG {.dp\\\": } $RenamePalette {"}
               End
            End
         End

         # Refresh palettes list, select new name
         Set $Palettes = (GetOutput {$NSCDE_TOOLSDIR/colormgr -p} 1 -1)
         ChangeTitle 3 $Palettes
         Set $CurrentModifiedPaletteCmd = {$NSCDE_TOOLSDIR/colormgr -N "} $INPUTMSG {.dp"}
         Set $CurrentModifiedPalette = (GetOutput $CurrentModifiedPaletteCmd 1 1)
         ChangeValue 3 $CurrentModifiedPalette
         SendSignal 3 1

         # Normally performed by Ok action, but here is exception. If this is modified new palette.
         SendSignal 32 1
      End
      4 :
      Begin
         If $SelectedColorset <> 0 Then
         Begin
            Do {f_ToggleFvwmModule FvwmScript ModifyColor } $SelectedColorset { } (GetBack $WidgetOfColorset)
         End
         Else
         Begin
            Do {f_Notifier "Color Style Manager" "Dismiss" "NsCDE/Info.xpm" "Select one of the base colors of the current palette which you want to modify."}
         End
      End
End

Widget 20
   Property
   Size 422 20
   Position 12 328
   Type PushButton
   Flags NoReliefString
   LocaleTitle {Number Of Colors ...}
   Font "xft:::pixelsize=15"
   Main
      Case message of
      SingleClic :
      Begin
         Do {f_ToggleFvwmModule FvwmScript NColorsDialog } $Ncolors { } (StrCopy $FpVariantArg 2 2) { } (StrCopy $WsmVariantArg 2 2)
      End
      1 :
      Begin
         Set $Ncolors = (LastString)
         If $Ncolors == 4 Then
         Begin
            HideWidget 11
            HideWidget 13
            HideWidget 15
            HideWidget 17
            ChangeSize 10 64 72
            ChangeSize 12 64 72
            ChangeSize 14 64 72
            ChangeSize 16 64 72
            ChangeIcon 9 NsCDE/Bframe4.xpm
            ChangeSize 9 72 80
         End
         If $Ncolors == 8 Then
         Begin
            # Refresh last 4 colors if we change from 4 to 8 colors
            SendSignal 3 1

            ShowWidget 11
            ShowWidget 13
            ShowWidget 15
            ShowWidget 17
            ChangeSize 10 64 32
            ChangeSize 12 64 32
            ChangeSize 14 64 32
            ChangeSize 16 64 32
            ChangeIcon 9 NsCDE/Bframe8.xpm
            ChangeSize 9 72 40
         End
      End
      2 :
      Begin
         If (LastString) == {8} Then
         Begin
            Set $FpVariantArg = {-8}
         End
         Else
         Begin
            Set $FpVariantArg = {-5}
         End
      End
      3 :
      Begin
         If (LastString) == {1} Then
         Begin
            If $WsmRoutineCalled <> 1 Then
            Begin
               Set $WsmRoutineCalled = 1
               Set $WsmVariantArgInitial = {-w}
            End
            Set $WsmVariantArg = {-w}
         End
         Else
         Begin
            If $WsmRoutineCalled <> 1 Then
            Begin
               Set $WsmRoutineCalled = 1
               Set $WsmVariantArgInitial = {}
            End
            Set $WsmVariantArg = {}
         End
      End
      4 :
      Begin
         Do {f_ToggleFvwmModule FvwmScript NColorsDialog } $Ncolors { } (StrCopy $FpVariantArg 2 2) { } (StrCopy $WsmVariantArg 2 2)
      End
End

Widget 21
   Property
   Size 422 20
   Position 12 370
   Type PushButton
   Flags NoReliefString
   Title { Color Style Integration Options ... }
   Font "xft:::pixelsize=15"
   Main
      Case message of
      SingleClic :
      Begin
         SendSignal 21 1
      End
      # Spawn integrations dialog
      1 :
      Begin
         Do {f_ToggleFvwmModule FvwmScript ColorIntegrationDialog } $IntegrationString
      End
      # Build a string of integrations - received with SendToModule
      # from ColorIntegrationDialog. Provide defaults if value is
      # not 0 or 1.
      2 :
      Begin
         Set $IntegrationString = (LastString)

         Set $SetBackdrops = (StrCopy $IntegrationString 1 1)
         If $SetBackdrops <> {1} Then
         Begin
            If $SetBackdrops <> {0} Then
            Begin
               Set $SetBackdrops = 1
            End
         End

         Set $SetXresources = (StrCopy $IntegrationString 2 2)
         If $SetXresources <> {1} Then
         Begin
            If $SetXresources <> {0} Then
            Begin
               Set $SetXresources = 1
            End
         End

         Set $SetGtk2 = (StrCopy $IntegrationString 3 3)
         If $SetGtk2 <> {1} Then
         Begin
            If $SetGtk2 <> {0} Then
            Begin
               Set $SetGtk2 = 1
            End
         End

         Set $SetGtk3 = (StrCopy $IntegrationString 4 4)
         If $SetGtk3 <> {1} Then
         Begin
            If $SetGtk3 <> {0} Then
            Begin
               Set $SetGtk3 = 1
            End
         End

         Set $SetQt4 = (StrCopy $IntegrationString 5 5)
         If $SetQt4 <> {1} Then
         Begin
            If $SetQt4 <> {0} Then
            Begin
               Set $SetQt4 = 1
            End
         End

         Set $SetQt5Gtk = (StrCopy $IntegrationString 6 6)
         If $SetQt5Gtk <> {1} Then
         Begin
            If $SetQt5Gtk <> {0} Then
            Begin
               Set $SetQt5Gtk = 0
            End
         End

         Set $SetQt5Kv = (StrCopy $IntegrationString 7 7)
         If $SetQt5Kv <> {1} Then
         Begin
            If $SetQt5Kv <> {0} Then
            Begin
               Set $SetQt5Kv = 1
            End
         End

         Set $SetQt6Kv = (StrCopy $IntegrationString 8 8)
         If $SetQt6Kv <> {1} Then
         Begin
            If $SetQt6Kv <> {0} Then
            Begin
               Set $SetQt6Kv = 1
            End
         End

         Set $SetGtk4 = (StrCopy $IntegrationString 9 9)
         If $SetGtk4 <> {1} Then
         Begin
            If $SetGtk4 <> {0} Then
            Begin
               Set $SetGtk4 = 0
            End
         End

         Set $SetColormgrLocal = (StrCopy $IntegrationString 10 10)
         If $SetColormgrLocal <> {1} Then
         Begin
            If $SetColormgrLocal <> {0} Then
            Begin
               Set $SetColormgrLocal = 1
            End
         End
      End
End

Widget 22
   Property
   Size 442 1
   Position 3 412
   Type Rectangle
End

Widget 32
   Property
   Size 120 26
   Position 16 424
   Type PushButton
   Flags NoReliefString
   LocaleTitle {OK}
   Font "xft:::pixelsize=15"
   Main
      Case message of
      SingleClic :
      Begin
         # Modified Palette handling
         If $CurrentModifiedPalette == {Custom} Then
         Begin
            SendSignal 19 2
         End
         Else
         Begin
            SendSignal 32 1
         End
      End
      # Main Wrapper
      1 :
      Begin
         Do {Module FvwmScript WaitNotice "$[gt.Working ...]" "$[gt.Please wait for changes to be applied]" "$[gt.and new color theme loaded.]" 8000}

         # Build palette and program bits
         Set $PerformPaletteChangeCmd = {$NSCDE_TOOLSDIR/colormgr } $FpVariantArg { } $WsmVariantArg { -e -c } $Ncolors { -g } $PalNumToName { -F}
         Set $PerformPaletteChange = (GetOutput $PerformPaletteChangeCmd 2 -1)
         Set $PerformProgBitsChangeCmd = {$NSCDE_TOOLSDIR/colormgr } $FpVariantArg { -e -c } $Ncolors { -g } $PalNumToName { -P}
         Set $PerformProgBitsChange = (GetOutput $PerformProgBitsChangeCmd 1 -1)

         If $SetXresources == 1 Then
         Begin
            Set $PerformXresourceChangeCmd = {$NSCDE_TOOLSDIR/colormgr -e -c } $Ncolors { -g } $PalNumToName { -X}
            Set $PerformXresourceChange = (GetOutput $PerformXresourceChangeCmd 2 -1)
         End

         If $SetBackdrops == 1 Then
         Begin
            Set $PerformBackdropSyncCmd = {$NSCDE_TOOLSDIR/colormgr -e -c } $Ncolors { -g } $PalNumToName { -b}
            # 1st and 2nd lines are pallete path/name and backdrop template, the rest is sorted in desk num order from 3-10 (8)
            Set $bpospreview = (Add $CurrDesk 2)
            Set $PerformBackdropSync = (GetOutput $PerformBackdropSyncCmd $bpospreview -1)
         End

         # System widget and program integrations block.

         # GTK block
         If $SetGtk2 == 1 Then
         Begin
            Set $Gtk2Str = 1
         End

         If $SetGtk3 == 1 Then
         Begin
            Set $Gtk3Str = 1
         End

         Set $GtkStr = $Gtk2Str $Gtk3Str

         If $GtkStr <> {00} Then
         Begin
            Set $Foreground4Cmd = {$NSCDE_TOOLSDIR/palette_colorgen -n } $Ncolors { -p } $PalettePath { -l | egrep '^fg_color_4'}
            Set $Foreground4 = (GetOutput $Foreground4Cmd 1 2)
         End

         If $GtkStr == {11} Then
         Begin
            Set $PerformGtkCmd = {$NSCDE_TOOLSDIR/themegen } $PalettePath { } $Ncolors { gtk2 gtk3}
            Set $PerformGtk = (GetOutput $PerformGtkCmd 1 -1)

            If $Foreground4 == {#ffffffffffff} Then
            Begin
               Set $DoDark1 = (GetOutput {$NSCDE_TOOLSDIR/confset -t properties -c "$HOME/.gtkrc-2.0" -k gtk-application-prefer-dark-theme -v '1'} 1 -1)
               Set $DoDark2 = (GetOutput {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/gtk-3.0/settings.ini" -s Settings -k gtk-application-prefer-dark-theme -v 1} 1 -1)
            End
            If $Foreground4 == {#000000000000} Then
            Begin
               Set $DoDark1 = (GetOutput {$NSCDE_TOOLSDIR/confset -t properties -c "$HOME/.gtkrc-2.0" -k gtk-application-prefer-dark-theme -r} 1 -1)
               Set $DoDark2 = (GetOutput {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/gtk-3.0/settings.ini" -s Settings -k gtk-application-prefer-dark-theme -r} 1 -1)
            End

            Set $CheckGtkrc2_a = (GetOutput {egrep -q "gtk-theme-name.*NsCDE" "$HOME/.gtkrc-2.0" 2>/dev/null ; echo $?} 1 -1)
            If $CheckGtkrc2_a <> 0 Then
            Begin
               Set $DoGtkrc2_a = (GetOutput {$NSCDE_TOOLSDIR/confset -t properties -c "$HOME/.gtkrc-2.0" -k gtk-theme-name -v ' "NsCDE"'} 1 -1)
            End

            Set $CheckGtkrc2_b = (GetOutput {egrep -q "gtk-icon-theme-name.*NsCDE" "$HOME/.gtkrc-2.0" 2>/dev/null ; echo $?} 1 -1)
            If $CheckGtkrc2_b <> 0 Then
            Begin
               Set $DoGtkrc2_b = (GetOutput {$NSCDE_TOOLSDIR/confset -t properties -c "$HOME/.gtkrc-2.0" -k gtk-icon-theme-name -v ' "NsCDE"'} 1 -1)
            End

            Set $CheckGtk3Exist = (GetOutput {ls -1d "$HOME/.config/gtk-3.0" > /dev/null 2>&1; echo $?} 1 -1)
            If $CheckGtk3Exist <> 0 Then
            Begin
               Set $MkGtk3 = (GetOutput {mkdir -p "$HOME/.config/gtk-3.0"} 1 -1)
            End

            Set $CheckGtkrc3a = (GetOutput {egrep -q "gtk-theme-name.*NsCDE" "$HOME/.config/gtk-3.0/settings.ini" 2>/dev/null ; echo $?} 1 -1)
            If $CheckGtkrc3a <> 0 Then
            Begin
               Set $DoGtkrc3a = (GetOutput {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/gtk-3.0/settings.ini" -s Settings -k gtk-theme-name -v NsCDE} 1 -1)
            End
            Set $CheckGtkrc3b = (GetOutput {egrep -q "gtk-icon-theme-name.*NsCDE" "$HOME/.config/gtk-3.0/settings.ini" 2>/dev/null ; echo $?} 1 -1)
            If $CheckGtkrc3b <> 0 Then
            Begin
               Set $DoGtkrc3b = (GetOutput {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/gtk-3.0/settings.ini" -s Settings -k gtk-icon-theme-name -v NsCDE} 1 -1)
            End

            # Handle stupid light/dark/default override of the theme
            Set $CheckGsettings = (GetOutput {/usr/bin/ksh -c "whence -q gsettings; echo $?"} 1 -1)
            If $CheckGsettings == 0 Then
            Begin
               Set $CheckGsettingsColorScheme = (GetOutput {gsettings get org.gnome.desktop.interface color-scheme 2>/dev/null} 1 -1)
               If $CheckGsettingsColorScheme <> {} Then
               Begin
                  If $CheckGsettingsColorScheme <> {'default'} Then
                  Begin
                     Set $GsettingsColorScheme = (GetOutput {gsettings set org.gnome.desktop.interface color-scheme default} 1 -1)
                  End
               End
            End
         End

         If $GtkStr == {10} Then
         Begin
            Set $PerformGtkCmd = {$NSCDE_TOOLSDIR/themegen } $PalettePath { } $Ncolors { gtk2 False}
            Set $PerformGtk = (GetOutput $PerformGtkCmd 1 -1)

            Set $DeintegrateGtk3Check_a = (GetOutput {$NSCDE_TOOLSDIR/confget -c "$HOME/.config/gtk-3.0/settings.ini" -s Settings -k gtk-theme-name} 1 1)
            If $DeintegrateGtk3Check_a == {NsCDE} Then
            Begin
               Set $DeintegrateGtk3_a = (GetOutput {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/gtk-3.0/settings.ini" -s Settings -k gtk-theme-name -r} 1 1)
            End
            Set $DeintegrateGtk3Check_b = (GetOutput {$NSCDE_TOOLSDIR/confget -c "$HOME/.config/gtk-3.0/settings.ini" -s Settings -k gtk-icon-theme-name} 1 1)
            If $DeintegrateGtk3Check_b == {NsCDE} Then
            Begin
               Set $DeintegrateGtk3_b = (GetOutput {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/gtk-3.0/settings.ini" -s Settings -k gtk-icon-theme-name -r} 1 1)
            End
            Set $DeintegrateGtk3_c = (GetOutput {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/gtk-3.0/settings.ini" -s Settings -k gtk-application-prefer-dark-theme -r} 1 1)

            If $Foreground4 == {#ffffffffffff} Then
            Begin
               Set $DoDark1 = (GetOutput {$NSCDE_TOOLSDIR/confset -t properties -c "$HOME/.gtkrc-2.0" -k gtk-application-prefer-dark-theme -v '1'} 1 -1)
            End
            If $Foreground4 == {#000000000000} Then
            Begin
               Set $DoDark1 = (GetOutput {$NSCDE_TOOLSDIR/confset -t properties -c "$HOME/.gtkrc-2.0" -k gtk-application-prefer-dark-theme -r} 1 -1)
            End

            Set $CheckGtkrc2_a = (GetOutput {egrep -q "gtk-theme-name.*NsCDE" "$HOME/.gtkrc-2.0" 2>/dev/null ; echo $?} 1 -1)
            If $CheckGtkrc2_a <> 0 Then
            Begin
               Set $DoGtkrc2_a = (GetOutput {$NSCDE_TOOLSDIR/confset -t properties -c "$HOME/.gtkrc-2.0" -k gtk-theme-name -v ' "NsCDE"'} 1 -1)
            End
            Set $CheckGtkrc2_b = (GetOutput {egrep -q "gtk-icon-theme-name.*NsCDE" "$HOME/.gtkrc-2.0" 2>/dev/null ; echo $?} 1 -1)
            If $CheckGtkrc2_b <> 0 Then
            Begin
               Set $DoGtkrc2_b = (GetOutput {$NSCDE_TOOLSDIR/confset -t properties -c "$HOME/.gtkrc-2.0" -k gtk-icon-theme-name -v ' "NsCDE"'} 1 -1)
            End
         End

         If $GtkStr == {01} Then
         Begin
            Set $PerformGtkCmd = {$NSCDE_TOOLSDIR/themegen } $PalettePath { } $Ncolors { False gtk3}
            Set $PerformGtk = (GetOutput $PerformGtkCmd 1 -1)

            Set $DeintegrateGtk2a =
             (GetOutput {$NSCDE_TOOLSDIR/ised -f "$HOME/.gtkrc-2.0" -c '/^\([[:space:]]\+\)\?gtk-theme-name\([[:space:]]\+\)\?=\([[:space:]]\+\)\?"NsCDE".*/d' 2>/dev/null} 1 -1)
            Set $DeintegrateGtk2b =
             (GetOutput {$NSCDE_TOOLSDIR/ised -f "$HOME/.gtkrc-2.0" -c '/^\([[:space:]]\+\)\?gtk-icon-theme-name\([[:space:]]\+\)\?=\([[:space:]]\+\)\?"NsCDE".*/d' 2>/dev/null} 1 -1)
            Set $DeintegrateGtk2c =
             (GetOutput {$NSCDE_TOOLSDIR/confset -t properties -c "$HOME/.gtkrc-2.0" -k gtk-application-prefer-dark-theme -r} 1 -1)

            If $Foreground4 == {#ffffffffffff} Then
            Begin
               Set $DoDark2 = (GetOutput {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/gtk-3.0/settings.ini" -s Settings -k gtk-application-prefer-dark-theme -v 1} 1 -1)
            End
            If $Foreground4 == {#000000000000} Then
            Begin
               Set $DoDark2 = (GetOutput {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/gtk-3.0/settings.ini" -s Settings -k gtk-application-prefer-dark-theme -r} 1 -1)
            End

            Set $CheckGtk3Exist = (GetOutput {ls -1d "$HOME/.config/gtk-3.0" > /dev/null 2>&1; echo $?} 1 -1)
            If $CheckGtk3Exist <> 0 Then
            Begin
               Set $MkGtk3 = (GetOutput {mkdir -p "$HOME/.config/gtk-3.0"} 1 -1)
            End

            Set $CheckGtkrc3a = (GetOutput {egrep -q "gtk-theme-name.*NsCDE" "$HOME/.config/gtk-3.0/settings.ini" 2>/dev/null ; echo $?} 1 -1)
            If $CheckGtkrc3a <> 0 Then
            Begin
               Set $DoGtkrc3a = (GetOutput {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/gtk-3.0/settings.ini" -s Settings -k gtk-theme-name -v NsCDE} 1 -1)
            End
            Set $CheckGtkrc3b = (GetOutput {egrep -q "gtk-icon-theme-name.*NsCDE" "$HOME/.config/gtk-3.0/settings.ini" 2>/dev/null ; echo $?} 1 -1)
            If $CheckGtkrc3b <> 0 Then
            Begin
               Set $DoGtkrc3b = (GetOutput {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/gtk-3.0/settings.ini" -s Settings -k gtk-icon-theme-name -v NsCDE} 1 -1)
            End

            # Handle stupid light/dark/default override of the theme
            Set $CheckGsettings = (GetOutput {/usr/bin/ksh -c "whence -q gsettings; echo $?"} 1 -1)
            If $CheckGsettings == 0 Then
            Begin
               Set $CheckGsettingsColorScheme = (GetOutput {gsettings get org.gnome.desktop.interface color-scheme 2>/dev/null} 1 -1)
               If $CheckGsettingsColorScheme <> {} Then
               Begin
                  If $CheckGsettingsColorScheme <> {'default'} Then
                  Begin
                     Set $GsettingsColorScheme = (GetOutput {gsettings set org.gnome.desktop.interface color-scheme default} 1 -1)
                  End
               End
            End
         End

         If $GtkStr == {00} Then
         Begin
            Set $DeintegrateGtk2a =
             (GetOutput {$NSCDE_TOOLSDIR/ised -f "$HOME/.gtkrc-2.0" -c '/^\([[:space:]]\+\)\?gtk-theme-name\([[:space:]]\+\)\?=\([[:space:]]\+\)\?"NsCDE".*/d' 2>/dev/null} 1 -1)
            Set $DeintegrateGtk2b =
             (GetOutput {$NSCDE_TOOLSDIR/ised -f "$HOME/.gtkrc-2.0" -c '/^\([[:space:]]\+\)\?gtk-icon-theme-name\([[:space:]]\+\)\?=\([[:space:]]\+\)\?"NsCDE".*/d' 2>/dev/null} 1 -1)
            Set $DeintegrateGtk2c =
             (GetOutput {$NSCDE_TOOLSDIR/confset -t properties -c "$HOME/.gtkrc-2.0" -k gtk-application-prefer-dark-theme -r} 1 -1)

            Set $DeintegrateGtk3Check_a = (GetOutput {$NSCDE_TOOLSDIR/confget -c "$HOME/.config/gtk-3.0/settings.ini" -s Settings -k gtk-theme-name} 1 1)
            If $DeintegrateGtk3Check_a == {NsCDE} Then
            Begin
               Set $DeintegrateGtk3_a = (GetOutput {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/gtk-3.0/settings.ini" -s Settings -k gtk-theme-name -r} 1 1)
            End
            Set $DeintegrateGtk3Check_b = (GetOutput {$NSCDE_TOOLSDIR/confget -c "$HOME/.config/gtk-3.0/settings.ini" -s Settings -k gtk-icon-theme-name} 1 1)
            If $DeintegrateGtk3Check_b == {NsCDE} Then
            Begin
               Set $DeintegrateGtk3_b = (GetOutput {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/gtk-3.0/settings.ini" -s Settings -k gtk-icon-theme-name -r} 1 1)
            End
            Set $DeintegrateGtk3_c = (GetOutput {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/gtk-3.0/settings.ini" -s Settings -k gtk-application-prefer-dark-theme -r} 1 1)

            Set $PerformGtk2Cmd = {$NSCDE_TOOLSDIR/themegen } $PalettePath { } $Ncolors { False False}
            Set $PerformGtk2 = (GetOutput $PerformGtk2Cmd 1 -1)
         End

         # Qt4
         If $SetQt4 == 1 Then
         Begin
            Set $CheckDotConfigExist = (GetOutput {ls -1d "$HOME/.config" > /dev/null 2>&1; echo $?} 1 -1)
            If $CheckDotConfigExist <> 0 Then
            Begin
               Set $MkDotConf = (GetOutput {mkdir -p "$HOME/.config"} 1 -1)
            End
            Set $DoTroll = (GetOutput {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/Trolltech.conf" -s Qt -k style -v 'GTK+'} 1 -1)
         End

         # Qt5 with GTK2 engine
         If $SetQt5Gtk == 1 Then
         Begin
            Set $CheckDotConfigExist = (GetOutput {ls -1d "$HOME/.config/qt5ct" > /dev/null 2>&1; echo $?} 1 -1)
            If $CheckDotConfigExist <> 0 Then
            Begin
               Set $MkDotConf = (GetOutput {mkdir -p "$HOME/.config/qt5ct"} 1 -1)
            End
            Set $DoQt5Ct1 = (GetOutput {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/qt5ct/qt5ct.conf" -s Appearance -k style -v gtk2} 1 -1)
            Set $DoQt5Ct2 = (GetOutput {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/qt5ct/qt5ct.conf" -s Appearance -k standard_dialogs -v gtk2} 1 -1)
            Set $DoQt5Ct3 = (GetOutput {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/qt5ct/qt5ct.conf" -s Appearance -k icon_theme -v NsCDE} 1 -1)
            Set $DoQt5Ct4 = (GetOutput {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/qt5ct/qt5ct.conf" -s Interface -k menus_have_icons -v false} 1 -1)

            Set $Qt5CtColorsApplyCmd = {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/qt5ct/qt5ct.conf" -s Appearance -k custom_palette -v false}
            Set $Qt5CtColorsApply = (GetOutput $Qt5CtColorsApplyCmd 1 -1)

            Set $Qt5CtQssRemoveCmd = {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/qt5ct/qt5ct.conf" -s Interface -k stylesheets -v '@Invalid()'}
            Set $Qt5CtQssRemove = (GetOutput $Qt5CtQssRemoveCmd 1 -1)
         End

         # Qt5 with Kvantum engine
         If $SetQt5Kv == 1 Then
         Begin
            Set $CheckDotConfigExist = (GetOutput {ls -1d "$HOME/.config/qt5ct" > /dev/null 2>&1; echo $?} 1 -1)
            If $CheckDotConfigExist <> 0 Then
            Begin
               Set $MkDotConf = (GetOutput {mkdir -p "$HOME/.config/qt5ct"} 1 -1)
            End
            Set $CheckKvantumConfigDirExist = (GetOutput {ls -1d "$HOME/.config/Kvantum/NsCDE" > /dev/null 2>&1; echo $?} 1 -1)
            If $CheckKvantumConfigDirExist <> 0 Then
            Begin
               Set $MkKvantumDirConf = (GetOutput {mkdir -p "$HOME/.config/Kvantum/NsCDE"} 1 -1)
            End

            Set $GeneralKvantumConfig = (GetOutput {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/Kvantum/kvantum.kvconfig" -s General -k theme -v NsCDE} 1 -1)

            Set $NsCDEKvConfigCmd = {$NSCDE_TOOLSDIR/palette_colorgen -n } $Ncolors { -p } $PalettePath { -i "$NSCDE_DATADIR/integration/qt_kvantum/NsCDE_kvconfig.tmpl"}
                                 { -s -c > "$HOME/.config/Kvantum/NsCDE/NsCDE.kvconfig"}
            Set $NsCDEKvConfig = (GetOutput $NsCDEKvConfigCmd 1 -1)

            Set $NsCDEKvSvgCmd = {$NSCDE_TOOLSDIR/palette_colorgen -n } $Ncolors { -p } $PalettePath { -i "$NSCDE_DATADIR/integration/qt_kvantum/NsCDE_svg.tmpl"}
                                 { -s -c > "$HOME/.config/Kvantum/NsCDE/NsCDE.svg"}
            Set $NsCDEKvSvg = (GetOutput $NsCDEKvSvgCmd 1 -1)

            Set $DoQt5Ct1 = (GetOutput {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/qt5ct/qt5ct.conf" -s Appearance -k style -v kvantum} 1 -1)
            Set $DoQt5Ct2 = (GetOutput {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/qt5ct/qt5ct.conf" -s Appearance -k standard_dialogs -v gtk2} 1 -1)
            Set $DoQt5Ct3 = (GetOutput {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/qt5ct/qt5ct.conf" -s Appearance -k icon_theme -v NsCDE} 1 -1)
            Set $DoQt5Ct4 = (GetOutput {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/qt5ct/qt5ct.conf" -s Interface -k menus_have_icons -v false} 1 -1)

            Set $CheckQt5CtColorsDirExist = (GetOutput {ls -1d "$HOME/.config/qt5ct/colors" > /dev/null 2>&1; echo $?} 1 -1)
            If $CheckQt5CtColorsDirExist <> 0 Then
            Begin
               Set $MkQt5ColorsDir = (GetOutput {mkdir -p "$HOME/.config/qt5ct/colors"} 1 -1)
            End

            Set $Qt5ColorsConfCmd = {$NSCDE_TOOLSDIR/palette_colorgen -n } $Ncolors { -p } $PalettePath { -i "$NSCDE_DATADIR/integration/qt_kvantum/NsCDE_conf.tmpl"}
                                 { -s -c > "$HOME/.config/qt5ct/colors/NsCDE-Kvantum.conf"}
            Set $Qt5ColorsConf = (GetOutput $Qt5ColorsConfCmd 1 -1)

            Set $Qt5CtColorsConfCmd = {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/qt5ct/qt5ct.conf" -s Appearance -k color_scheme_path -v "$HOME/.config/qt5ct/colors/NsCDE-Kvantum.conf"}
            Set $Qt5CtColorsConf = (GetOutput $Qt5CtColorsConfCmd 1 -1)

            Set $Qt5CtColorsApplyCmd = {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/qt5ct/qt5ct.conf" -s Appearance -k custom_palette -v true}
            Set $Qt5CtColorsApply = (GetOutput $Qt5CtColorsApplyCmd 1 -1)

            Set $CheckQt5CtQssDirExist = (GetOutput {ls -1d "$HOME/.config/qt5ct/qss" > /dev/null 2>&1; echo $?} 1 -1)
            If $CheckQt5CtQssDirExist <> 0 Then
            Begin
               Set $MkQt5QssDir = (GetOutput {mkdir -p "$HOME/.config/qt5ct/qss"} 1 -1)
            End

            Set $QssConfCmd = {$NSCDE_TOOLSDIR/palette_colorgen -n } $Ncolors { -p } $PalettePath { -i "$NSCDE_DATADIR/integration/qt_kvantum/NsCDE-Kvantum_qss.tmpl"}
                                 { -s -c > "$HOME/.config/qt5ct/qss/NsCDE-Kvantum.qss"}
            Set $QssConf = (GetOutput $QssConfCmd 1 -1)

            Set $QssQt5CtConfCmd = {$NSCDE_TOOLSDIR/confget -c "$HOME/.config/qt5ct/qt5ct.conf" -s Interface -k stylesheets 2>/dev/null; echo $?}
            Set $QssQt5CtConfOutput = (GetOutput $QssQt5CtConfCmd 1 -1)
            Set $QssQt5CtConfStatus = (GetOutput $QssQt5CtConfCmd 2 1)

            Set $QssQt5CtConfCheck1Cmd = {echo '} $QssQt5CtConfOutput {' | egrep -q '\/qss\/NsCDE-Kvantum\.qss'; echo $?}
            Set $QssQt5CtConfCheck2Cmd = {echo '} $QssQt5CtConfOutput {' | egrep -q '@Invalid\(\)'; echo $?}
            Set $QssQt5CtConfCheck1 = (GetOutput $QssQt5CtConfCheck1Cmd 1 1)
            Set $QssQt5CtConfCheck2 = (GetOutput $QssQt5CtConfCheck2Cmd 1 1)

            If $QssQt5CtConfCheck1 <> 0 Then
            Begin
               If $QssQt5CtConfCheck2 == 0 Then
               Begin
                  Set $WriteQssCmd = {$NSCDE_TOOLSDIR/confset -c "$HOME/.config/qt5ct/qt5ct.conf" -s Interface -k stylesheets -v "$HOME/.config/qt5ct/qss/NsCDE-Kvantum.qss"}
                  Set $WriteQss = (GetOutput $WriteQssCmd 1 -1)
               End
               Else
               Begin
                  If $QssQt5CtConfStatus == 3 Then
                  Begin
                     Set $WriteQssCmd = {$NSCDE_TOOLSDIR/confset -c "$HOME/.config/qt5ct/qt5ct.conf" -s Interface -k stylesheets -v "$HOME/.config/qt5ct/qss/NsCDE-Kvantum.qss"}
                     Set $WriteQss = (GetOutput $WriteQssCmd 1 -1)
                  End
                  Else
                  Begin
                     If $QssQt5CtConfOutput <> {} Then
                     Begin
                        Set $WriteQssCmd = {$NSCDE_TOOLSDIR/confset -c "$HOME/.config/qt5ct/qt5ct.conf" -s Interface -k stylesheets -v "} $QssQt5CtConfOutput {,$HOME/.config/qt5ct/qss/NsCDE-Kvantum.qss"}
                     End
                     Else
                     Begin
                        Set $WriteQssCmd = {$NSCDE_TOOLSDIR/confset -c "$HOME/.config/qt5ct/qt5ct.conf" -s Interface -k stylesheets -v "$HOME/.config/qt5ct/qss/NsCDE-Kvantum.qss"}
                     End
                     Set $WriteQss = (GetOutput $WriteQssCmd 1 -1)
                  End
               End
            End
         End

         # Qt6 with Kvantum engine
         If $SetQt6Kv == 1 Then
         Begin
            Set $CheckDotConfigExist = (GetOutput {ls -1d "$HOME/.config/qt6ct" > /dev/null 2>&1; echo $?} 1 -1)
            If $CheckDotConfigExist <> 0 Then
            Begin
               Set $MkDotConf = (GetOutput {mkdir -p "$HOME/.config/qt6ct"} 1 -1)
            End
            Set $CheckKvantumConfigDirExist = (GetOutput {ls -1d "$HOME/.config/Kvantum/NsCDE" > /dev/null 2>&1; echo $?} 1 -1)
            If $CheckKvantumConfigDirExist <> 0 Then
            Begin
               Set $MkKvantumDirConf = (GetOutput {mkdir -p "$HOME/.config/Kvantum/NsCDE"} 1 -1)
            End

            Set $GeneralKvantumConfig = (GetOutput {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/Kvantum/kvantum.kvconfig" -s General -k theme -v NsCDE} 1 -1)

            Set $NsCDEKvConfigCmd = {$NSCDE_TOOLSDIR/palette_colorgen -n } $Ncolors { -p } $PalettePath { -i "$NSCDE_DATADIR/integration/qt_kvantum/NsCDE_kvconfig.tmpl"}
                                 { -s -c > "$HOME/.config/Kvantum/NsCDE/NsCDE.kvconfig"}
            Set $NsCDEKvConfig = (GetOutput $NsCDEKvConfigCmd 1 -1)

            Set $NsCDEKvSvgCmd = {$NSCDE_TOOLSDIR/palette_colorgen -n } $Ncolors { -p } $PalettePath { -i "$NSCDE_DATADIR/integration/qt_kvantum/NsCDE_svg.tmpl"}
                                 { -s -c > "$HOME/.config/Kvantum/NsCDE/NsCDE.svg"}
            Set $NsCDEKvSvg = (GetOutput $NsCDEKvSvgCmd 1 -1)

            Set $DoQt6Ct1 = (GetOutput {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/qt6ct/qt6ct.conf" -s Appearance -k style -v kvantum} 1 -1)
            Set $DoQt6Ct2 = (GetOutput {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/qt6ct/qt6ct.conf" -s Appearance -k standard_dialogs -v gtk3} 1 -1)
            Set $DoQt6Ct3 = (GetOutput {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/qt6ct/qt6ct.conf" -s Appearance -k icon_theme -v NsCDE} 1 -1)
            Set $DoQt6Ct4 = (GetOutput {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/qt6ct/qt6ct.conf" -s Interface -k menus_have_icons -v false} 1 -1)

            Set $CheckQt6CtColorsDirExist = (GetOutput {ls -1d "$HOME/.config/qt6ct/colors" > /dev/null 2>&1; echo $?} 1 -1)
            If $CheckQt6CtColorsDirExist <> 0 Then
            Begin
               Set $MkQt6ColorsDir = (GetOutput {mkdir -p "$HOME/.config/qt6ct/colors"} 1 -1)
            End

            Set $Qt6ColorsConfCmd = {$NSCDE_TOOLSDIR/palette_colorgen -n } $Ncolors { -p } $PalettePath { -i "$NSCDE_DATADIR/integration/qt_kvantum/NsCDE_conf.tmpl"}
                                 { -s -c > "$HOME/.config/qt6ct/colors/NsCDE-Kvantum.conf"}
            Set $Qt6ColorsConf = (GetOutput $Qt6ColorsConfCmd 1 -1)

            Set $Qt6CtColorsConfCmd = {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/qt6ct/qt6ct.conf" -s Appearance -k color_scheme_path -v "$HOME/.config/qt6ct/colors/NsCDE-Kvantum.conf"}
            Set $Qt6CtColorsConf = (GetOutput $Qt6CtColorsConfCmd 1 -1)

            Set $Qt6CtColorsApplyCmd = {$NSCDE_TOOLSDIR/confset -t ini -c "$HOME/.config/qt6ct/qt6ct.conf" -s Appearance -k custom_palette -v true}
            Set $Qt6CtColorsApply = (GetOutput $Qt6CtColorsApplyCmd 1 -1)

            Set $CheckQt6CtQssDirExist = (GetOutput {ls -1d "$HOME/.config/qt6ct/qss" > /dev/null 2>&1; echo $?} 1 -1)
            If $CheckQt6CtQssDirExist <> 0 Then
            Begin
               Set $MkQt6QssDir = (GetOutput {mkdir -p "$HOME/.config/qt6ct/qss"} 1 -1)
            End

            Set $QssConfCmd = {$NSCDE_TOOLSDIR/palette_colorgen -n } $Ncolors { -p } $PalettePath { -i "$NSCDE_DATADIR/integration/qt_kvantum/NsCDE-Kvantum_qss.tmpl"}
                                 { -s -c > "$HOME/.config/qt6ct/qss/NsCDE-Kvantum.qss"}
            Set $QssConf = (GetOutput $QssConfCmd 1 -1)

            Set $QssQt6CtConfCmd = {$NSCDE_TOOLSDIR/confget -c "$HOME/.config/qt5ct/qt6ct.conf" -s Interface -k stylesheets 2>/dev/null; echo $?}
            Set $QssQt6CtConfOutput = (GetOutput $QssQt6CtConfCmd 1 -1)
            Set $QssQt6CtConfStatus = (GetOutput $QssQt6CtConfCmd 2 1)

            Set $QssQt6CtConfCheck1Cmd = {echo '} $QssQt6CtConfOutput {' | egrep -q '\/qss\/NsCDE-Kvantum\.qss'; echo $?}
            Set $QssQt6CtConfCheck2Cmd = {echo '} $QssQt6CtConfOutput {' | egrep -q '@Invalid\(\)'; echo $?}
            Set $QssQt6CtConfCheck1 = (GetOutput $QssQt6CtConfCheck1Cmd 1 1)
            Set $QssQt6CtConfCheck2 = (GetOutput $QssQt6CtConfCheck2Cmd 1 1)

            If $QssQt6CtConfCheck1 <> 0 Then
            Begin
               If $QssQt6CtConfCheck2 == 0 Then
               Begin
                  Set $WriteQssCmd = {$NSCDE_TOOLSDIR/confset -c "$HOME/.config/qt6ct/qt6ct.conf" -s Interface -k stylesheets -v "$HOME/.config/qt6ct/qss/NsCDE-Kvantum.qss"}
                  Set $WriteQss = (GetOutput $WriteQssCmd 1 -1)
               End
               Else
               Begin
                  If $QssQt6CtConfStatus == 3 Then
                  Begin
                     Set $WriteQssCmd = {$NSCDE_TOOLSDIR/confset -c "$HOME/.config/qt6ct/qt6ct.conf" -s Interface -k stylesheets -v "$HOME/.config/qt6ct/qss/NsCDE-Kvantum.qss"}
                     Set $WriteQss = (GetOutput $WriteQssCmd 1 -1)
                  End
                  Else
                  Begin
                     If $QssQt6CtConfOutput <> {} Then
                     Begin
                        Set $WriteQssCmd = {$NSCDE_TOOLSDIR/confset -c "$HOME/.config/qt6ct/qt6ct.conf" -s Interface -k stylesheets -v "} $QssQt6CtConfOutput {,$HOME/.config/qt6ct/qss/NsCDE-Kvantum.qss"}
                     End
                     Else
                     Begin
                        Set $WriteQssCmd = {$NSCDE_TOOLSDIR/confset -c "$HOME/.config/qt6ct/qt6ct.conf" -s Interface -k stylesheets -v "$HOME/.config/qt6ct/qss/NsCDE-Kvantum.qss"}
                     End
                     Set $WriteQss = (GetOutput $WriteQssCmd 1 -1)
                  End
               End
            End
         End

         # Our $[FVWM_USERDIR]/libexec/colormgr.local
         If $SetColormgrLocal == 1 Then
         Begin
            Set $CheckUserCustomScriptExist = (GetOutput {ls -1 "$FVWM_USERDIR/libexec/colormgr.local" > /dev/null 2>&1; echo $?} 1 -1)
            If $CheckUserCustomScriptExist == 0 Then
            Begin
               Set $RunUserScriptCmd = {$FVWM_USERDIR/libexec/colormgr.local } $PalettePath { } $Ncolors
               Set $RunUserScript = (GetOutput $RunUserScriptCmd 1 -1)
            End
            Do {Test (EnvMatch infostore.nscde_use_rofi 1, F $[FVWM_USERDIR]/NsCDE.rasi) Exec exec rm -f $[FVWM_USERDIR]/NsCDE.rasi}
         End

         # See if there is a need to change integrate_* values in StyleMgr.ini and do it if it is.
         If $SetBackdrops <> $InitialSetBackdrops Then
         Begin
            Set $WriteBackdropsCmd = {$NSCDE_TOOLSDIR/confset -t ini -c $FVWM_USERDIR/StyleMgr.ini -s ColorMgr -k integrate_backdrops -v } $SetBackdrops
            Set $WriteBackdrops = (GetOutput $WriteBackdropsCmd 1 -1)
         End

         If $SetXresources <> $InitialSetXresources Then
         Begin
            Set $WriteXresourcesCmd = {$NSCDE_TOOLSDIR/confset -t ini -c $FVWM_USERDIR/StyleMgr.ini -s ColorMgr -k integrate_xresources -v } $SetXresources
            Set $WriteXresources = (GetOutput $WriteXresourcesCmd 1 -1)
         End

         If $SetGtk2 <> $InitialSetGtk2 Then
         Begin
            Set $WriteGtk2Cmd = {$NSCDE_TOOLSDIR/confset -t ini -c $FVWM_USERDIR/StyleMgr.ini -s ColorMgr -k integrate_gtk2 -v } $SetGtk2
            Set $WriteGtk2 = (GetOutput $WriteGtk2Cmd 1 -1)
         End

         If $SetGtk3 <> $InitialSetGtk3 Then
         Begin
            Set $WriteGtk3Cmd = {$NSCDE_TOOLSDIR/confset -t ini -c $FVWM_USERDIR/StyleMgr.ini -s ColorMgr -k integrate_gtk3 -v } $SetGtk3
            Set $WriteGtk3 = (GetOutput $WriteGtk3Cmd 1 -1)
         End

         If $SetQt4 <> $InitialSetQt4 Then
         Begin
            Set $WriteQt4Cmd = {$NSCDE_TOOLSDIR/confset -t ini -c $FVWM_USERDIR/StyleMgr.ini -s ColorMgr -k integrate_qt4 -v } $SetQt4
            Set $WriteQt4 = (GetOutput $WriteQt4Cmd 1 -1)
         End

         If $SetQt5Gtk <> $InitialSetQt5Gtk Then
         Begin
            Set $WriteQt5GtkCmd = {$NSCDE_TOOLSDIR/confset -t ini -c $FVWM_USERDIR/StyleMgr.ini -s ColorMgr -k integrate_qt5g -v } $SetQt5Gtk
            Set $WriteQt5Gtk = (GetOutput $WriteQt5GtkCmd 1 -1)
         End

         If $SetQt5Kv <> $InitialSetQt5Kv Then
         Begin
            Set $WriteQt5KvCmd = {$NSCDE_TOOLSDIR/confset -t ini -c $FVWM_USERDIR/StyleMgr.ini -s ColorMgr -k integrate_qt5k -v } $SetQt5Kv
            Set $WriteQt5Kv = (GetOutput $WriteQt5KvCmd 1 -1)
         End

         If $SetQt6Kv <> $InitialSetQt6Kv Then
         Begin
            Set $WriteQt6KvCmd = {$NSCDE_TOOLSDIR/confset -t ini -c $FVWM_USERDIR/StyleMgr.ini -s ColorMgr -k integrate_qt6 -v } $SetQt6Kv
            Set $WriteQt6Kv = (GetOutput $WriteQt6KvCmd 1 -1)
         End

         If $SetColormgrLocal <> $InitialSetColormgrLocal Then
         Begin
            Set $WriteColormgrLocalCmd = {$NSCDE_TOOLSDIR/confset -t ini -c $FVWM_USERDIR/StyleMgr.ini -s ColorMgr -k integrate_local -v } $SetColormgrLocal
            Set $WriteColormgrLocal = (GetOutput $WriteColormgrLocalCmd 1 -1)
         End

         # Signal to 4 : to reload everything.
         SendSignal 32 4
      End
      4 :
      Begin
         # Reload things with new configuration

         # Reread new colorset
         Do {f_ReadCfg Colorset}

         # Handle Front Panel artefacts
         Do {Schedule 600 SendToModule FrontPanel ChangeButton FpLock Icon "NsCDE/FpLock.xpm" PressIcon "NsCDE/FpLockP.xpm"}
         If $WsmVariantArgInitial <> $WsmVariantArg Then
         Begin
            If $WsmVariantArg == {-w} Then
            Begin
               Do {InfoStoreAdd wsmcolored 1}
               Do {Schedule 650 SendToModule FrontPanel ChangeButton FpWSM Colorset 22}
               Do {Schedule 700 SendToModule $[infostore.WSM] SendString 30 1 wsmcolored}
            End
            Else
            Begin
               Do {InfoStoreAdd wsmcolored 0}
               Do {Schedule 650 SendToModule FrontPanel ChangeButton FpWSM Colorset 23}
               Do {Schedule 700 SendToModule $[infostore.WSM] SendString 30 1 wsmclassic}
            End
         End

         # Handle Front Panel small artefacts
         Do {SendToModule FrontPanel ChangeButton PanelMenu Icon "NsCDE/FpMenu.xpm"}
         Do {SendToModule FrontPanel ChangeButton PanelHandleLeft Icon "NsCDE/FpHandle.xpm"}
         Do {SendToModule FrontPanel ChangeButton PanelIconify Icon "NsCDE/FpIconify.xpm"}
         Do {SendToModule FrontPanel ChangeButton PanelHandleRight Icon "NsCDE/FpHandle.xpm"}

         # Handle fvwm2 Front Panel small artefacts
         If $IsFvwm3 <> 1 Then
         Begin
            Set $fpid = 0
            While $fpid < 20 Do
            Begin
               Set $fpid = (Add $fpid 1)
               Do {Test (EnvMatch infostore.NsCDE-Subpanel} $fpid
                  {-enabled 1) SendToModule FrontPanel ChangeButton NsCDE-Subpanel} $fpid
                  { Icon $[infostore.FP.LnchIcon]}
               Do {Test (EnvMatch infostore.NsCDE-Subpanel} $fpid
                  {-enabled 1) SendToModule FrontPanel ChangeButton NsCDE-Subpanel} $fpid
                  { PressIcon $[infostore.FP.LnchPressIcon]}
            End
         End

         # Handle Front Panel Subpanels "Install Icon"
         Set $subfpid = 0
         While $subfpid < 20 Do
         Begin
            Set $subfpid = (Add $subfpid 1)
            Do {Test (EnvMatch infostore.NsCDE-Subpanel} $subfpid {-Enabled 1)}
               { SendToModule NsCDE-Subpanel} $subfpid { ChangeButton inst_ico_s} $subfpid
               { Icon NsCDE/FpInstIcon.xpm}
         End

         # Reread backdrops
         If $SetBackdrops == 1 Then
         Begin
            Do {f_ReadCfg Backdrops}

            If $Fvwm3DesktopNonGlobalMode == 1 Then
            Begin
               Do {f_CleanupBackgroundCache}
               Do {f_SetupMonitorData}
               Do {Schedule 120 f_SetFvwm3NonGlobalBackground}
            End
         End

         # Reload Xresources
         If $SetXresources == 1 Then
         Begin
            # Reload X resources
            Set $ReloadXresources = (GetOutput {xrdb -remove; xrdb -cpp /usr/bin/cpp < $FVWM_USERDIR/Xdefaults} 1 -1)
         End

         # Stalonetray, Dunst, Xscreensaver
         Do {Test (EnvMatch infostore.nscde_use_stalonetray 1) f_Stalonetray restart}
         Do {Test (EnvMatch infostore.nscde_use_dunst 1) f_Dunst restart}
         Do {Test (EnvMatch infostore.nscde_use_xscreensaver 1) f_Xscreensaver -restart}

         # Reload Xsettingsd if it is used
         If $CheckUseXsettingsd == 1 Then
         Begin
            Do {f_Xsettingsd stop}
            Set $CheckXstSetup = (GetOutput {egrep -q '^Net\/ThemeName[[:space:]]+"NsCDE"' $FVWM_USERDIR/Xsettingsd.conf; echo $?} 1 1)
            If $CheckXstSetup <> 0 Then
            Begin
               Set $SetXstEntry = (GetOutput {$NSCDE_TOOLSDIR/ised -c 's/\(^Net\/ThemeName[[:space:]]\+\).*/\1"NsCDE"/g' -f $FVWM_USERDIR/Xsettingsd.conf} 1 -1)
	       End
            Do {Schedule 1250 f_Xsettingsd start}
         End

         # Final touch
         Do {Test (x xrefresh) Schedule 2000 Exec exec xrefresh}

         # Quit, no restart.
         Quit
      End
End

Widget 33
   Property
   Size 120 26
   Position 166 424
   Type PushButton
   Flags NoReliefString
   LocaleTitle {Close}
   Font "xft:::pixelsize=15"
   Main
      Case message of
      SingleClic :
      Begin
         SendSignal 33 1
      End
      1 :
      Begin
         # Misc cleanups
         If $CustomExistedBefore <> 0 Then
         Begin
            Do {Exec exec rm -f "$FVWM_USERDIR/palettes/Custom.dp"}
         End

         # Read back old theme if preview was used during the work with ColorMgr
         If $PreviewContaminated == 1 Then
         Begin
            Set $RestoreXresources = (GetOutput {xrdb -remove; xrdb -cpp /usr/bin/cpp < $FVWM_USERDIR/Xdefaults} 1 -1)

            Do {f_ReadCfg Backdrops}
            Do {f_ReadCfg Colorset}
            Do {Schedule 340 Refresh}

            If $Fvwm3DesktopNonGlobalMode == 1 Then
            Begin
               Do {f_SetupMonitorData}
               Do {Schedule 120 f_SetFvwm3NonGlobalBackground}
            End
         End

         # Get out finally
         Quit
      End
End

Widget 34
   Property
   Size 120 26
   Position 314 424
   Type PushButton
   Flags NoReliefString
   LocaleTitle {Help}
   Font "xft:::pixelsize=15"
   Main
      Case message of
      SingleClic :
      Begin
         SendSignal 34 1
      End
      1 :
      Begin
         Do {f_DisplayURL "$[gt.Color Style Manager]" html/NsCDE-ColorMgr.html}
      End
End

