class qdii::i3 {
  if $qdii::is_desktop {
    package { [
      'brightnessctl',
      'dunst',
      'feh',
      'gammastep',
      'grim',
      'keepassxc',
      'pavucontrol',
      'powertop',
      'rofi',
      'slurp',
      'sway', 'swaylock', 'swayidle',
      'waybar',
      'wl-clipboard',
      'wofi',     # Rofi for wayland
      'wtype',     # Needed by rofimoji
    ]: ensure =>  latest,
    }

    file { 'i3-config-directory':
      ensure => 'directory',
      owner => 'qdii',
      mode => '0600',
      path => "$qdii::homedir/.i3",
    }
    file { 'i3-new-config-directory':
      ensure => 'directory',
      owner => 'qdii',
      mode => '0600',
      path => "$qdii::homedir/.config/i3",
    }
    file { 'sway-config-directory':
      ensure => 'directory',
      owner => 'qdii',
      mode => '0600',
      path => "$qdii::homedir/.config/sway",
    }
    if $qdii::at_work {
      $i3suffix = '.work'
    } else {
      $i3suffix = '.perso'
    }
    file { 'i3-new-config':
      path    => "$qdii::homedir/.config/i3/config",
      source  => "puppet:///modules/qdii/dotfiles/i3config${i3suffix}",
      owner   => 'qdii',
      mode    => '0600',
      require =>  File['i3-new-config-directory'],
    }
    file { 'i3config':
      ensure  => file,
      path    => "$qdii::homedir/.i3/config",
      source  => "puppet:///modules/qdii/dotfiles/i3config${i3suffix}",
      owner   => 'qdii',
      mode    => '0600',
      require =>  File['i3-config-directory'],
    }
    file { 'i3get':
      ensure => file,
      path => '/usr/local/bin/i3get',
      source => 'puppet:///modules/qdii/misc/i3get',
      owner => 'qdii',
      mode => '0777',
    }
    file { 'anypaste':
      ensure => file,
      path => '/usr/local/bin/anypaste',
      source => 'puppet:///modules/qdii/misc/anypaste',
      owner => 'qdii',
      mode => '0777',
    }
    file { 'i3cast':
      ensure  => file,
      path    => '/usr/local/bin/i3cast',
      source  => 'puppet:///modules/qdii/misc/i3cast',
      owner   => 'qdii',
      mode    => '0777',
      require => File['anypaste'],
    }
    file { 'i3run':
      ensure => file,
      path => '/usr/local/bin/i3run',
      source => 'puppet:///modules/qdii/misc/i3run',
      owner => 'qdii',
      mode => '0777',
    }
    file { 'swayprop':
      ensure => file,
      path => '/usr/local/bin/swayprop',
      source => 'puppet:///modules/qdii/misc/swayprop',
      owner => 'qdii',
      mode => '0777',
    }
    file { 'swayconfig':
      ensure  => file,
      path    => "$qdii::homedir/.config/sway/config",
      source  => "puppet:///modules/qdii/dotfiles/swayconfig",
      owner   => 'qdii',
      mode    => '0600',
      require =>  File['sway-config-directory'],
    }
    file { 'waybar-config-directory':
      ensure => 'directory',
      owner  => 'qdii',
      mode   => '0600',
      path   => "$qdii::homedir/.config/waybar",
    }
    file { 'waybarconfig':
      ensure  => file,
      path    => "$qdii::homedir/.config/waybar/config",
      source  => "puppet:///modules/qdii/dotfiles/waybarconfig",
      owner   => 'qdii',
      mode    => '0600',
      require =>  File['waybar-config-directory'],
    }
    file { 'waybarstyle':
      ensure  => file,
      path    => "$qdii::homedir/.config/waybar/style.css",
      source  => "puppet:///modules/qdii/dotfiles/waybarstyle",
      owner   => 'qdii',
      mode    => '0600',
      require =>  File['waybar-config-directory'],
    }
    file { 'wofi-config-directory':
      ensure => 'directory',
      owner  => 'qdii',
      mode   => '0600',
      path   => "$qdii::homedir/.config/wofi",
    }
    file { 'wofi_theme':
      ensure => file,
      path    => "$qdii::homedir/.config/wofi/style.css",
      source  => "puppet:///modules/qdii/dotfiles/wofi_style.css",
      owner   => 'qdii',
      mode    => '0600',
      require =>  File['wofi-config-directory'],
    }
    file { 'take_screenshot':
      ensure => file,
      path   => '/usr/local/bin/take_screenshot',
      source => 'puppet:///modules/qdii/misc/take_screenshot',
      owner  => 'qdii',
      mode   => '0777',
    }
    file { 'imgur.sh':
      ensure => file,
      path   => '/usr/local/bin/imgur.sh',
      source => 'puppet:///modules/qdii/misc/imgur.sh',
      owner  => 'qdii',
      mode   => '0777',
    }
    file { 'take_video':
      ensure => file,
      path   => '/usr/local/bin/take_video',
      source => 'puppet:///modules/qdii/misc/take_video',
      owner  => 'qdii',
      mode   => '0777',
    }
    file { "gammastep_config_dir":
      path    => "$qdii::homedir/.config/gammastep",
      ensure  => directory,
      require => File['qdii_config_dir'],
    }
    file { "gammastep_config":
      path    => "$qdii::homedir/.config/gammastep/config.ini",
      source  => 'puppet:///modules/qdii/dotfiles/gammastep_config',
      ensure  => present,
      require => File['gammastep_config_dir'],
    }
    file { "urxvt_config_dir":
      path    => "$qdii::homedir/.urxvt",
      ensure  => directory,
    }
    -> file { "urxvt_ext_config_dir":
      path    => "$qdii::homedir/.urxvt/ext",
      ensure  => directory,
    }
    -> file { "urxvt_resize_font":
      source => 'puppet:///modules/qdii/misc/resize-font',
      path    => "$qdii::homedir/.urxvt/ext/resize-font",
      ensure  => file,
    }
    file { "/usr/local/bin/sw":
      source => 'puppet:///modules/qdii/misc/sw',
      path   => '/usr/local/bin/sw',
      mode   => '0777',
    }
    file { "default-pulseaudio-config-dir":
      ensure  => "directory",
      owner   => "qdii",
      path    => "$qdii::homedir/.config/pulse",
      require => File['qdii_config_dir'],
    }
    -> file { "default-pulseaudio":
      source => 'puppet:///modules/qdii/dotfiles/default.pa',
      owner  => "qdii",
      path   => "$qdii::homedir/.config/pulse/default.pa",
    }
    file { "wlr_drm_devices":
      ensure  => "file",
      path    => "$qdii::homedir/.config/environment.d/11-qdii-gpus.conf",
      source  => "puppet:///modules/qdii/misc/wlr_drm_devices.$::hostname",
      owner   => "qdii",
      require => File['environment-directory'],
    }
    file { "sway-launcher-desktop":
      ensure => "file",
      path   => "/usr/local/bin/sway-launcher-desktop",
      source => "puppet:///modules/qdii/misc/sway-launcher-desktop",
      owner  => "qdii",
      mode   => "0777",
    }

    case $facts['os']['name'] {
      /^(Debian|Ubuntu)$/: {
        file { 'swappy':
          ensure => file,
          path => '/usr/local/bin/swappy',
          source => 'puppet:///modules/qdii/misc/swappy',
          owner => 'qdii',
          mode => '0777',
        }
        package { [
          'qtwayland5',
          'rxvt-unicode',
          'wireshark',
        ]: ensure => installed }
      }
      'ArchLinux': {
        package { [
          'otf-font-awesome',  # Needed for swappy
          'powerline-fonts',
          'playerctl',
          'python-pygments',
          'rofimoji',
          'rxvt-unicode-terminfo',
          'swappy',
          'the_silver_searcher',
          'wf-recorder',
          'wireshark-cli',
          'wireshark-qt',
        ]: ensure => latest }
      }
    }
  }
}
