{ lib, nixosConfig, ... }:
let
  cfg = nixosConfig.my.desktop;
in
{
  wayland.windowManager.hyprland = lib.mkIf (cfg.enable && cfg.hyprland.enable) {
    settings = {
      "$games" = "^(steam_app_.*|gamescope|starrail.exe|.*\.exe)$";
      "$launch_on_second_monitor" = "^(vesktop|spotify)$";
      "$utility_workspace" = 10;

      windowrule = [

        # Windows to launch silently on secondary monitor

        "match:class $launch_on_second_monitor, workspace $altscreenworkspace silent"
        "match:class steam, match:title Steam, workspace 4 silent, tile on"

        # Launch Steam Friends List as floating window on workspace 4

        "match:class steam, match:title (Friends List), workspace 4 silent, tile on"

        "match:class $games, content game"
        "match:class $games, tag +game"
        "match:class $games, workspace 3"

        # Disable VRR for Where Winds meet
        "match:class (steam_app_3564740), no_vrr on"

        # Game Stuff
        "match:class (starrail\.exe), render_unfocused on"

        # Utilities to silently launch on the last workspace
        "match:class (com.github.wwmm.easyeffects), workspace $utility_workspace silent"
        "match:class (org.openrgb.OpenRGB), workspace $utility_workspace silent"
        "match:class (com.core447.StreamController), match:title StreamController, workspace $utility_workspace silent"
        "match:class (opendeck), workspace $utility_workspace silent"
        "match:class (Artemis.UI.Linux), match:title (Artemis 2.0), workspace $utility_workspace silent"

        # Focus popups in the center
        # Floating
        "match:title ^(Open File)(.*)$, center on"
        "match:title ^(Open File)(.*)$, float on"
        "match:title ^(Select a File)(.*)$, center on"
        "match:title ^(Select folder)(.*)$, float on"
        "match:title ^(Select folder)(.*)$, center on"
        "match:title ^(Select a File)(.*)$, float on"
        "match:title ^(Choose wallpaper)(.*)$, center on"
        "match:title ^(Choose wallpaper)(.*)$, float on"
        "match:title ^(Choose wallpaper)(.*)$, size 60% 65%"
        "match:title ^(Open Folder)(.*)$, center on"
        "match:title ^(Open Folder)(.*)$, float on"
        "match:title ^(Save As)(.*)$, center on"
        "match:title ^(Save As)(.*)$, float on"
        "match:title ^(Enter name of file to save to)(.*)$, center on"
        "match:title ^(Enter name of file to save to)(.*)$, float on"
        "match:title ^(Library)(.*)$, center on"
        "match:title ^(Library)(.*)$, float on"
        "match:title ^(File Upload)(.*)$, center on"
        "match:title ^(File Upload)(.*)$, float on"
        "match:title ^(.*)(wants to save)$, center on"
        "match:title ^(.*)(wants to save)$, float on"
        "match:title ^(.*)(wants to open)$, center on"
        "match:title ^(.*)(wants to open)$, float on"
        "match:class ^(blueberry\.py)$, float on"
        "match:class ^(guifetch)$, float on"
        "match:class ^(pwvucontrol)$, float on"
        "match:class ^(pwvucontrol)$, size 45%"
        "match:class ^(pwvucontrol)$, center on"
        "match:class ^(com.saivert.pwvucontrol)$, float on"
        "match:class ^(com.saivert.pwvucontrol)$, size 45%"
        "match:class ^(com.saivert.pwvucontrol)$, center on"
        "match:class .*plasmawindowed.*, float on"
        "match:class kcm_.*, float on"
        "match:class .*bluedevilwizard, float on"
        "match:title .*Welcome, float on"
        "match:title .*Shell conflicts.*, float on"
        "match:class org.freedesktop.impl.portal.desktop.kde, float on"
        "match:class org.freedesktop.impl.portal.desktop.kde, size 60% 65%"
        "match:class ^(Zotero)$, float on"
        "match:class ^(Zotero)$, size 45%"

        # stupid dolphin copy
        "match:title ^(Copying — Dolphin)$, move 40 80"

        # Picture-in-Picture
        "match:title ^([Pp]icture[-\s]?[Ii]n[-\s]?[Pp]icture)(.*)$, float on"
        "match:title ^([Pp]icture[-\s]?[Ii]n[-\s]?[Pp]icture)(.*)$, keep_aspect_ratio on"
        "match:title ^([Pp]icture[-\s]?[Ii]n[-\s]?[Pp]icture)(.*)$, move 73% 72%"
        "match:title ^([Pp]icture[-\s]?[Ii]n[-\s]?[Pp]icture)(.*)$, size 25%"
        "match:title ^([Pp]icture[-\s]?[Ii]n[-\s]?[Pp]icture)(.*)$, pin on"

        # --- Tearing ---
        "match:class $games, immediate on"

        # No shadow for tiled windows (matches windows that are not floating).
        "match:float 0, no_shadow on"

        # Prevent Idle while fullscreen
        "match:class (.*), idle_inhibit fullscreen"
      ];
    };
  };
}

