{ config, lib, ... }:

let
  cfg = config.wayland.windowManager.hyprland;

  nonCenterFloatingClasses = [
    "Gimp"
    "steam"
    "KiCad"
  ];

  nonCenterFloatingClassesRegex = concatStringsSep "|" nonCenterFloatingClasses;

  inherit (builtins) concatStringsSep toString;
  inherit (lib) mkDefault;
in
{
  # Do not add binds here. Use `./binds/default.nix` instead.
  "$mod" = cfg.modifier;

  exec-once = [
    "dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP" # dbus package comes from NixOS module option `services.dbus.dbusPackage` [1]
    "gnome-keyring-daemon --start --components=secrets" # gnome-keyring package comes from NixOS module `services.gnome.gnome-keyring` [1]
  ];
  # 1: see Hyprland NixOS module

  windowrule = [
    # "float, class:^(${nonCenterFloatingClassesRegex})$"
    "center, floating:1, class:^(?!.*(${nonCenterFloatingClassesRegex})).*$"
    "float, title:^(Open|Save) Files?$"
    "noborder, onworkspace:w[t1]"
    "bordersize ${toString cfg.settings.general.border_size}, floating:1"

    # https://wiki.hyprland.org/Useful-Utilities/Screen-Sharing/#xwayland
    "opacity 0.0 override, class:^(xwaylandvideobridge)$"
    "noanim, class:^(xwaylandvideobridge)$"
    "noinitialfocus, class:^(xwaylandvideobridge)$"
    "maxsize 1 1, class:^(xwaylandvideobridge)$"
    "noblur, class:^(xwaylandvideobridge)$"
  ];

  gesture = [
    "3, horizontal, workspace"
    "3, up, dispatcher, exec, bemenu-run" # TODO: move to hyprland.applications
    "4, swipe, move"
  ];

  # Layouts
  general.layout = mkDefault "master";
  master = {
    mfact = mkDefault 0.5;
    new_status = mkDefault "master";
    new_on_top = mkDefault true;
  };

  input.kb_layout = mkDefault "de";

  xwayland = {
    force_zero_scaling = mkDefault true;
  };

  misc = {
    disable_hyprland_logo = mkDefault true;
    force_default_wallpaper = mkDefault 0;
  };

  # Styling
  animations.enabled = mkDefault false;
  decoration = {
    blur.enabled = mkDefault false;
    shadow.enabled = mkDefault false;
  };
  general = {
    resize_on_border = mkDefault true;
    border_size = mkDefault 2;
  };
}
