#
#  Sway configuration
#
#  flake.nix
#   ├─ ./hosts
#   │   └─ ./laptop
#   │       └─ default.nix
#   └─ ./modules
#       └─ ./desktop
#           └─ ./hyprland
#               └─ hyprland.nix *
#

{ config, lib, user, pkgs, desktop, ... }:

{
  imports = [ ../waybar.nix ];

  environment = {
    loginShellInit = ''
      if [ -z $DISPLAY ] &&  [ $UID != 0 ] && [ "$(tty)" = "/dev/tty1" ]; then
        exec sway
      fi
    '';                                   # Will automatically open sway when logged into tty1
    systemPackages = with pkgs; [
      xdg-desktop-portal-wlr
      sway
      swaylock
      swayidle
      slurp
      grim
      bemenu
      lxqt.lxqt-openssh-askpass
      rocmPackages.clr.icd
      rocmPackages.clr
      clinfo
      waybar
      rot8
      glib
    ];
  };

  programs = {
    sway.enable = true;
    sway.extraSessionCommands =  ''
      export MOZ_ENABLE_WAYLAND="1";
      export MOZ_WEBRENDER="1";
      export MOZ_USE_XINPUT2="2";
      export MOZ_DBUS_REMOTE="1";
      export WLR_RENDERER="vulkan";
      export LIBVA_DRIVER_NAME="iHD";
      export VDPAU_DRIVER="iHD";
      export XDG_SESSION_TYPE="wayland";
      #export XDG_CURRENT_DESKTOP="Unity";
      #export QT_QPA_PLATFORMTHEME="wayland-egl";
      export GST_VAAPI_ALL_DRIVERS="1";
      export GTK_THEME="Arc";
      export _JAVA_AWT_WM_NONREPARENTING="1";
      #export LIBCL_ALWAYS_SOFTWARE="1";       # For applications in VM like alacritty to work
      #export WLR_NO_HARDWARE_CURSORS="1";     # For cursor in VM
    '';
    ssh.enableAskPassword = true;
    ssh.askPassword = "${pkgs.lxqt.lxqt-openssh-askpass}/bin/lxqt-openssh-askpass";
  };

  security.pam.services.swaylock = {};

  xdg.portal = {                                  # Required for flatpak with windowmanagers
    enable = true;
    wlr.enable = true;
    extraPortals = [ pkgs.xdg-desktop-portal-gtk ];
  };
}