class qdii::xorg {
  if ($qdii::is_desktop) {
      if ($qdii::at_work) {
          $pkg_name = 'xorg'
      }
      else {
          $pkg_name = 'xorg-server'
      }
      File {
        ensure => file,
        owner  => 'qdii',
        mode   => '0600',
      }
      package { 'xorg-server':
        ensure => 'latest',
        name   => $pkg_name,
      }
      file { 'xinitrc':
        path   => "$qdii::homedir/.xinitrc",
        source => 'puppet:///modules/qdii/dotfiles/xinitrc',
      }
      file { 'Xdefaults':
        path   => "$qdii::homedir/.Xdefaults",
        source => 'puppet:///modules/qdii/dotfiles/Xresources',
      }
      file { 'Xresources':
        path   => "$qdii::homedir/.Xresources",
        source => 'puppet:///modules/qdii/dotfiles/Xresources',
      }
      file { 'Xresources.dark':
        path   => "$qdii::homedir/.Xresources.dark",
        source => 'puppet:///modules/qdii/dotfiles/Xresources.dark',
      }
      file { 'xprofile':
        path   => "$qdii::homedir/.xprofile",
        source => 'puppet:///modules/qdii/dotfiles/xprofile',
      }
      file { 'xorg-conf-dir':
        path   => '/etc/X11/xorg.conf.d',
        ensure => directory,
        owner  => 'root',
      }
      file { 'xorg-evdev':
        path    => '/etc/X11/xorg.conf.d/10-evdev.conf',
        source  => 'puppet:///modules/qdii/dotfiles/10-evdev.conf',
        owner   => 'root',
        mode    => '0644',
        require => File['xorg-conf-dir'],
      }
      file { 'xorg-synaptics':
        path    => '/etc/X11/xorg.conf.d/70-synaptics.conf',
        source  => 'puppet:///modules/qdii/dotfiles/70-synaptics.conf',
        owner   => 'root',
        mode    => '0644',
        require => File['xorg-conf-dir'],
      }
      file { 'dpms_toggle':
        path   => '/usr/local/bin/dpms_toggle',
        source => 'puppet:///modules/qdii/misc/dpms_toggle',
        owner  => 'root',
        mode   => '0755',
      }
      exec { 'update-dirs-dsk':
        command => "/usr/bin/xdg-user-dirs-update --set DESKTOP /root/dsk",
      }
      exec { 'update-dirs-dl':
        command => "/usr/bin/xdg-user-dirs-update --set DOWNLOAD /root/dl",
      }
      exec { 'update-dirs-tmpl':
        command => "/usr/bin/xdg-user-dirs-update --set TEMPLATES /root/tmpl",
      }
      exec { 'update-dirs-pub':
        command => "/usr/bin/xdg-user-dirs-update --set PUBLICSHARE /root/pub",
      }
      exec { 'update-dirs-doc':
        command => "/usr/bin/xdg-user-dirs-update --set DOCUMENTS /root/doc",
      }
      exec { 'update-dirs-music':
        command => "/usr/bin/xdg-user-dirs-update --set MUSIC /root/snd",
      }
      exec { 'update-dirs-pictures':
        command => "/usr/bin/xdg-user-dirs-update --set PICTURES /root/pic",
      }
      exec { 'update-dirs-videos':
        command => "/usr/bin/xdg-user-dirs-update --set VIDEOS /root/vid",
      }
      exec { 'update-dirs-qdii-dsk':
        command => "/usr/bin/xdg-user-dirs-update --set DESKTOP ${qdii::homedir}/dsk",
        user    => 'qdii',
      }
      exec { 'update-dirs-qdii-dl':
        command => "/usr/bin/xdg-user-dirs-update --set DOWNLOAD ${qdii::homedir}/dl",
        user    => 'qdii',
      }
      exec { 'update-dirs-qdii-tmpl':
        command => "/usr/bin/xdg-user-dirs-update --set TEMPLATES ${qdii::homedir}/tmpl",
        user    => 'qdii',
      }
      exec { 'update-dirs-qdii-pub':
        command => "/usr/bin/xdg-user-dirs-update --set PUBLICSHARE ${qdii::homedir}/pub",
        user    => 'qdii',
      }
      exec { 'update-dirs-qdii-doc':
        command => "/usr/bin/xdg-user-dirs-update --set DOCUMENTS ${qdii::homedir}/doc",
        user    => 'qdii',
      }
      exec { 'update-dirs-qdii-music':
        command => "/usr/bin/xdg-user-dirs-update --set MUSIC ${qdii::homedir}/snd",
        user    => 'qdii',
      }
      exec { 'update-dirs-qdii-pictures':
        command => "/usr/bin/xdg-user-dirs-update --set PICTURES ${qdii::homedir}/pic",
        user    => 'qdii',
      }
      exec { 'update-dirs-qdii-videos':
        command => "/usr/bin/xdg-user-dirs-update --set VIDEOS ${qdii::homedir}/vid",
        user    => 'qdii',
      }
      exec { 'autoenable-bluetooth':
        command => "/usr/bin/sed -i 's/^#AutoEnable.*/AutoEnable=true/' /etc/bluetooth/main.conf"
      }

      # Sway greeter
      file { 'greetd-config-directory':
        ensure => 'directory',
        path   => '/etc/greetd',
        owner  => 'root',
        mode   => '0755',
      }
      file { 'greetd-sway-config':
        ensure => 'file',
        path   => '/etc/greetd/sway-config',
        source => 'puppet:///modules/qdii/misc/sway-config',
        owner  => 'root',
        mode   => '0644',
        require => File['greetd-config-directory'],
      }
      file { 'greetd-sway-config2':
        ensure  => 'file',
        path    => '/etc/greetd/config.toml',
        source  => 'puppet:///modules/qdii/misc/config.toml',
        owner   => 'root',
        mode    => '0644',
        require => File['greetd-config-directory'],
      }

      # Qt
      file { 'qt5ct-config-directory':
        ensure => 'directory',
        path   => "${qdii::homedir}/.config/qt5ct",
      }
      -> file { 'qt5ct-config-colors-directory':
        ensure => 'directory',
        path   => "${qdii::homedir}/.config/qt5ct/colors",
      }
      -> file { 'qt5ct-solarized-dark':
        ensure => 'file',
        path   => "${qdii::homedir}/.config/qt5ct/colors/solarized-dark.conf",
        source  => 'puppet:///modules/qdii/misc/solarized-dark.conf',
      }
      package { 'qt5ct':
        ensure => 'latest',
        name   => 'qt5ct',
      }
      file { 'qt5ct-config':
        ensure  => 'file',
        path    => "${qdii::homedir}/.config/qt5ct/qt5ct.conf",
        source  => 'puppet:///modules/qdii/misc/qt5ct.conf',
        require => File['qt5ct-config-directory']
      }

      # GTK
      file { 'gtk3-config-directory':
        ensure => 'directory',
        path   => "${qdii::homedir}/.config/gtk-3.0",
      }
      -> file { 'gtk3-bookmarks':
        ensure  => 'file',
        path    => "${qdii::homedir}/.config/gtk-3.0/bookmarks",
        source  => 'puppet:///modules/qdii/misc/bookmarks',
        owner   => 'qdii',
        mode    => '0644',
      }
      file {'gtk3-themes':
        ensure => 'directory',
        path   => "${qdii::homedir}/.themes",
      }
      file {'gtk3-icons':
        ensure => 'directory',
        path   => "${qdii::homedir}/.icons",
      }
      archive { '/tmp/arc-dark-archive.zip':
        source       => 'puppet:///modules/qdii/misc/Arc-Dark-Solarized_1.4.zip',
        extract      => true,
        extract_path => "${qdii::homedir}/.themes",
        creates      => "${qdii::homedir}/.themes/Arc-Dark-Solarized-GTK",
        cleanup      => true,
        require      => File['gtk3-themes'],
      }
      archive { '/tmp/solarized-blue-archive.zip':
        source       => 'puppet:///modules/qdii/misc/Solarized-Dark-Blue-3.36_2.0.4.zip',
        extract      => true,
        extract_path => "${qdii::homedir}/.themes",
        creates      => "${qdii::homedir}/.themes/Solarized-Dark-Blue-3.36",
        cleanup      => true,
        require      => File['gtk3-themes'],
      }
      archive { '/tmp/solarized-blue-iconpack-archive.zip':
        source       => 'puppet:///modules/qdii/misc/Solarized-Dark-Blue-Numix.zip',
        extract      => true,
        extract_path => "${qdii::homedir}/.icons",
        creates      => "${qdii::homedir}/.icons/Solarized-Dark-Blue-Numix",
        cleanup      => true,
        require      => File['gtk3-icons'],
      }
      archive { '/tmp/solarized-deluxe-iconpack-archive.zip':
        source       => 'puppet:///modules/qdii/misc/Solarized-Deluxe-Iconpack_1.8.zip',
        extract      => true,
        extract_path => "${qdii::homedir}/.icons",
        creates      => "${qdii::homedir}/.icons/Solarized-Deluxe-Iconpack",
        cleanup      => true,
        require      => File['gtk3-icons'],
      }
      archive { '/tmp/solarized-colors-cursors-archive.zip':
        source       => 'puppet:///modules/qdii/misc/Solarized-Colors-Cursors_1.8.zip',
        extract      => true,
        extract_path => "${qdii::homedir}/.icons",
        creates      => "${qdii::homedir}/.icons/Solarized-Colors-Cursors",
        cleanup      => true,
        require      => File['gtk3-icons'],
      }
  }
}
