{
  inputs,
  pkgs,
  ...
}: let
  global = import ../global-var.nix;
in {
  programs.hyprland = {
    enable = true;
    package = inputs.hyprland.packages.${pkgs.system}.hyprland;
  };

  home-manager.users.${global.username} = {pkgs, ...}: {
    home.file.".icons/default".source = "${pkgs.catppuccin-cursors.mochaDark}/share/icons/catppuccin-mocha-dark-cursors";

    services.hypridle = {
      enable = true;
      settings = {
        general = {
          after_sleep_cmd = "hyprctl dispatch dpms on";
          ignore_dbus_inhibit = false;
          lock_cmd = "hyprlock";
        };

        listener = [
          {
            timeout = 450;
            on-timeout = "brightness-ctrl set 20";
            on-resume = "brightness-ctrl set 100";
          }
          {
            timeout = 500;
            on-timeout = "hyprlock";
          }
        ];
      };
    };

    programs.hyprlock = {
      enable = true;
      settings = {
        general = {
          ignore_empty_input = true;
        };

        background = [
          {
            path = "screenshot";
            blur_passes = 3;
            blur_size = 8;
          }
        ];

        label = [
          {
            text = "Welcome back, $USER";
            monitor = "";
            font_size = 30;
            size = "200, 50";
            position = "0, 70";
            halign = "center";
            valign = "center";
          }
          {
            text = "$TIME";
            monitor = "";
            font_size = 48;
            size = "200, 50";
            position = "0, 120";
            halign = "center";
            valign = "center";
          }
        ];

        input-field = [
          {
            size = "200, 50";
            position = "0, 0";
            monitor = "";
            dots_center = true;
            fade_on_empty = false;
            font_color = "rgb(202, 211, 245)";
            inner_color = "rgb(91, 96, 120)";
            outer_color = "rgb(24, 25, 38)";
            outline_thickness = 5;
            placeholder_text = "Password...";
            shadow_passes = 2;
          }
        ];
      };
    };

    wayland.windowManager.hyprland = {
      # Uses package from flake pulling the newest Git version
      package = inputs.hyprland.packages.${pkgs.system}.hyprland;
      enable = true;

      plugins = [
        # This allows for workspaces to be split with multiple monitors, often breaks with Hyprland updates
        inputs.hyprsplit.packages.${pkgs.system}.hyprsplit
        #inputs.Hyprspace.packages.${pkgs.system}.Hyprspace
      ];

      # TODO: Redo comments
      settings = {
        "$mod" = "SUPER";

        bind =
          [
            ", XF86AudioPlay, exec, playerctl play-pause"
            ", XF86AudioNext, exec, playerctl next"
            ", XF86AudioPrev, exec, playerctl previous"
            # Annoyingly my keyboard uses fn + f11 or f12 to control keyboard backlight only if the firmware was open source :/
            "$mod, f11, exec, brightness-ctrl down"
            "$mod, f12, exec, brightness-ctrl up"
            "$mod SHIFT, f12, exec, brightness-ctrl full"
            "CTRL, Print, exec, satty-shot"
            ", Print, exec, hyprshot -m output -o ~/Pictures/Screenshots"
            "$mod, p, exec, wl-copy $(hyprpicker)"
            "$mod, h, movefocus, l"
            "$mod, l, movefocus, r"
            "$mod, k, movefocus, u"
            "$mod, j, movefocus, d"
            "$mod SHIFT, h, movewindow, l"
            "$mod SHIFT, l, movewindow, r"
            "$mod SHIFT, k, movewindow, u"
            "$mod SHIFT, j, movewindow, d"
            "$mod, slash, togglesplit"
            "$mod, mouse_down, split:workspace, e-1"
            "$mod, mouse_up, split:workspace, e+1"
            "alt, tab, exec, rofi -show window"
            "$mod, t, togglefloating"
            "$mod, c, killactive"
            "$mod, q, exec, shutdown-menu"
            "$mod, B, exec, firefox"
            "$mod, y, exec, kitty -e yazi"
            "alt, f4, exec, hyprctl kill"
            "$mod, Return, exec, kitty"
            "$mod, Space, exec, rofi -show drun"
            "$mod, E, exec, rofimoji"
            "$mod, a, exec, kitty -e ollama run mixtral"
            "$mod SHIFT, escape, exec, hyprlock"
            "$mod SHIFT, a, exec, llm-actions"
          ]
          ++ (
            # workspaces
            # binds $mod + [shift +] {1..10} to [move to] workspace {1..10}
            builtins.concatLists (builtins.genList (
                x: let
                  ws = let
                    c = (x + 1) / 10;
                  in
                    builtins.toString (x + 1 - (c * 10));
                in [
                  "$mod, ${ws}, split:workspace, ${toString (x + 1)}"
                  "$mod SHIFT, ${ws}, split:movetoworkspace, ${toString (x + 1)}"
                ]
              )
              10)
          );

        dwindle = {
          preserve_split = true;
        };

        debug = {
          #disable_logs = false;
          #enable_stdout_logs = true;
          #damage_tracking = false;
        };

        binde = [
          ", XF86AudioRaiseVolume, exec, wpctl set-volume -l 1.4 @DEFAULT_AUDIO_SINK@ 1%+"
          ", XF86AudioLowerVolume, exec, wpctl set-volume -l 1.4 @DEFAULT_AUDIO_SINK@ 1%-"
          "$mod CTRL, l, resizeactive, 10 0"
          "$mod CTRL, h, resizeactive, -10 0"
          "$mod CTRL, k, resizeactive, 0 -10"
          "$mod CTRL, j, resizeactive, 0 10"
        ];

        bindm = [
          "$mod, mouse:272, movewindow"
          "$mod, mouse:273, resizewindow"
        ];

        decoration = {
          drop_shadow = true;
          shadow_range = 300;
          shadow_render_power = 4;
          "col.shadow" = "rgba(1a1a1aaf)";
          shadow_scale = 0.9;
          shadow_offset = "0, 40";
          rounding = 12;
          blurls = [
            "bar-0"
            "bar-1"
            "rofi"
            "notifications0"
            "notifications1"
            "mpris"
          ];

          blur = {
            enabled = true;
            #size = 5;
            #passes = 3;
            brightness = 0.7;
          };
        };

        general = {
          gaps_in = 5;
          gaps_out = 10;
          border_size = 2;
          "col.active_border" = "rgba(f38ba8ff)";
          "col.inactive_border" = "rgba(1e1e2eff)";
        };

        cursor = {
          inactive_timeout = 5;
        };

        input = {
          follow_mouse = 1;
          mouse_refocus = false;
          accel_profile = "flat";
        };

        misc = {
          disable_hyprland_logo = true;
        };

        monitor = [
          "DP-2, 1920x1200, 1920x0, 1"
          "DP-1, 1920x1080@165, 0x0, 1, vrr, 1 "
        ];

        device = {
          name = "wacom-intuos-s-pen";
        };

        layerrule = [
          "ignorealpha, bar-0"
          "ignorealpha, bar-1"
          "ignorealpha, notifications0"
          "ignorealpha, notifications1"
          "ignorealpha, mpris"
          "ignorealpha, rofi"
          "noanim,selection"
        ];

        windowrulev2 = [
          "noanim, class:^(com.gabm.satty)$"
          "size 640 360, title:(Picture-in-Picture)"
          "pin, title:^(Picture-in-Picture)$"
          "move 1906 14, title:(Picture-in-Picture)"
          "float, title:^(Picture-in-Picture)$"
          "float, title:^(Authentication Required)$"
        ];

        animation = [
          "layers, 1, 5, default, slide"
        ];

        exec-once = [
          "ags"
          "fcitx5"
          "wpaperd"
          "mpv --no-video --volume=150 ${../misc/sound/start/start.wav}"
          "${pkgs.lxqt.lxqt-policykit}/bin/lxqt-policykit-agent"
        ];
      };
    };
  };
}
