{ pkgs, config, ... }:
{
  wayland.windowManager.hyprland = {
#    enable = true;
   # package = pkgs.hyprland;
    # package = hyprland.packages.stdenv.hostPlatform.system}.hyprland;
#    xwayland.enable = true;
    systemd.enable = true;

    systemd.variables = ["--all"];

    # device {
    #   name = "hanvon-ugee-shortcut-remote key bindings"
    # };
    settings = {
      "$mod" = "SUPER";

      env = [
        "XDG_SESSION_TYPE,wayland"
        "XDG_SESSION_DESKTOP,Hyprland"
        "XDG_CURRENT_DESKTOP,Hyprland"


        "MOZ_ENABLE_WAYLAND,1"
        # "ANKI_WAYLAND,1"

        "QT_AUTO_SCREEN_SCALE_FACTOR,1"
        "QT_WAYLAND_DISABLE_WINDOWDECORATION,1"
        "QT_QPA_PLATFORM=wayland,xcb" # removed ,xcb CGPT
        "QT_QPA_PLATFORMTHEME,qt6ct"
        "QT_QPA_PLATFORMTHEME,qt5ct"

        "GDK_SCALE,1"
        "GDK_BACKEND,wayland,x11,*"

        # "GTK_THEME,FlatColor:dark"
        # "GTK2_RC_FILES,/home/hadi/.local/share/themes/FlatColor/gtk-2.0/gtkrc"

        # "DISABLE_QT5_COMPAT,0"
        # "NIXOS_OZONE_WL,1"
        "OZONE_PLATFORM,wayland"
        "ELECTRON_OZONE_PLATFORM_HINT,wayland"
        # "__GL_GSYNC_ALLOWED,0"
        # "__GL_VRR_ALLOWED,0"
        "__GLX_VENDOR_LIBRARY_NAME,nvidia"
        # "DIRENV_LOG_FORMAT,"

        # "WLR_DRM_NO_ATOMIC,1"
        # "WLR_BACKEND,vulkan"
        # "WLR_RENDERER,vulkan"
        # "WLR_NO_HARDWARE_CURSORS,1"

        # "APPIMAGELAUNCHER_DISABLE,1"
        # "OZONE_PLATFORM,wayland"
        # "SDL_VIDEODRIVER,wayland"
        "CLUTTER_BACKEND,wayland"
        "GBM_BACKEND,nvidia-drm"
        "LIBVA_DRIVER_NAME,nvidia"
        # "AQ_DRM_DEVICES,/dev/dri/card2/" # CHANGEME: Related to the GPU

        # THEMING
        # "HYPRCURSOR_THEME,~/.icons/Nordic-cursors"
        # "HYPRCURSOR_SIZE,24x"
        "HYPRCURSOR_THEME,Nordzy-cursors"
        "HYPRCURSOR_SIZE,24"
        "XCURSOR_THEME,Nordzy-cursors"
        "XCURSOR_SIZE,24"

        "HYPRLAND_TRACE=1"

        "QT_STYLE_OVERRIDE=kvantum-dark"
        # "QT_QPA_PLATFORMTHEME = qt6ct" # qt5ct no display
      ];

      input = {
        kb_layout = "us";
        # kb_variant =;
        # kb_model =;
        # kb_options = grp:alt_shift_toggle,caps:backspace;
        # kb_rules =;

        follow_mouse = 1;
        mouse_refocus = false;

        touchpad = {
          natural_scroll = "no";
          tap_button_map = "lmr";
        };

        sensitivity = 0;
      };

      debug = { disable_logs = false; };

      xwayland = {
        enabled = true;
        force_zero_scaling = true;
      };

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

      bind = [
        "$mod, mouse_down, workspace, e+1" # Scroll workspaces
        "$mod, mouse_up, workspace, e-1" # Scroll workspaces
        "$mod, mouse:275, exec, wl-copy $(wl-paste -p)" # copy selected text
        "$mod, mouse:276, exec, wtype -M ctrl -M shift v -m ctrl -m shift" # paste by Ctrl+Shift+

        "ALTSHIFT, H, movewindow, l"
        "ALTSHIFT, L, movewindow, r"
        "ALTSHIFT, K, movewindow, u"
        "ALTSHIFT, J, movewindow, d"

        "ALT,H,movefocus,l"
        "ALT,L,movefocus,r"
        "ALT,K,movefocus,u"
        "ALT,J,movefocus,d"

        "$mod, Q, killactive"
        "ALT, T, togglefloating"
        "ALT, F, fullscreen"
        "$mod, Prior, exec, pkill -f kitty --class=kitty-logs || kitty --class='kitty-logs' journalctl -f"
        # Minimize window
        "ALT, M, movetoworkspace, special:magic"
        "ALT, M, togglespecialworkspace, magic"

        "Control_R+Shift_R, B, exec, ${config.home.homeDirectory}/bin/restore_minimized.sh Keybase"
        "Control_R+Shift_R, X, exec, ${config.home.homeDirectory}/bin/restore_minimized.sh org.kde.kwalletmanager5"
        "Control_R+Shift_R, N, exec, ${config.home.homeDirectory}/bin/restore_minimized.sh com.nextcloud.desktopclient.nextcloud"
        "Control_R+Shift_R, Z, exec, ${config.home.homeDirectory}/bin/restore_minimized.sh zen-alpha"
        "Control_R+Shift_R, S, exec, ${config.home.homeDirectory}/bin/restore_minimized.sh sublime_text"
        # "$mod, R, exec, ${config.home.homeDirectory}/bin/restore_minimized.sh org.kde.dolphin"


        "$mod, F, exec, firefox"
        "$mod, Z, exec, zen"
        "$mod, k, exec, kitty"
        "$mod, G, exec, ghostty"
        "$mod, Home, exec, firefox-developer-edition --new-tab http://webserver/jose/ --devtools"
        # "$mod+SHIFT_R, k, exec, pypr toggle term"
        "$mod+Shift_R, K, exec, konsole"
        "$mod, S, exec, subl"
        # "CTRLSHIFT, K&B, exec, hyprctl dispatch exec keybase-gui %u"
        # ",XF86Search, exec, wofi --show drun"
        ",XF86Explorer, exec, dolphin"
        ",XF86Search, exec, pkill rofi || rofi -show drun -modi drun,filebrowser,run,window,ssh"
        ",XF86Calculator, exec, qalculate-qt"
        "$mod, V, exec, cliphist list | rofi --dmenu | cliphist decode | wl-copy"
        "$mod, Tab, exec, ${config.home.homeDirectory}/bin/audio_event_listener.sh"

        "ALT, Tab, exec, hyprctl dispatch cyclenext"
        "ALTSHIFT, Tab, exec, hyprctl dispatch cyclenext prev"
        # "ALT, Tab, bringactivetotop"
        # "CONTROL_ALT, L, exec, swaylock" # Need to config locker

        ", XF86AudioMicMute, exec ,swayosd-client --input-volume mute-toggle"
        ", XF86AudioMute, exec, swayosd-client --output-volume mute-toggle && wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle"
        ", XF86AudioRaiseVolume, exec, swayosd-client --output-volume 10 && wpctl set-volume @DEFAULT_AUDIO_SINK@ 0.1+"
        ", XF86AudioLowerVolume, exec, swayosd-client --output-volume -10 && wpctl set-volume @DEFAULT_AUDIO_SINK@ 0.1-"
        ", XF86AudioPrev, exec, playerctl previous"
        ", XF86AudioNext, exec, playerctl next"
        ", XF86AudioPlay, exec, playerctl play-pause"
        # "$mod, XF86AudioRaiseVolume, exec, swayosd-client --output-volume raise --max-volume 120 && wpctl set-volume 46 0.1+"
        # "$mod, XF86AudioLowerVolume, exec, swayosd-client --output-volume lower --max-volume 120 && wpctl set-volume 46 0.1-"
        ", Caps_Lock ,exec, swayosd-client --caps-lock"
        "$mod, --release Caps_Lock, exec, swayosd-client --caps-lock-led input19::capslock"
        "$mod, XF86MonBrightnessUp, exec, swayosd-client --brightness raise"
        "$mod, XF86MonBrightnessDown, exec, swayosd-client --brightness lower"
        # "$mod, XF86MonBrightnessUp  exec swayosd-client --brightness +10"
        # "$mod, XF86MonBrightnessDown exec swayosd-client --brightness -10"

        "$mod+SHIFT, S, exec, hyprshot -m region"

        "$mod, code:10, workspace, 1"
        "$mod, code:11, workspace, 2"
        "$mod, code:12, workspace, 3"
        "$mod, code:13, workspace, 4"
        "$mod, code:14, workspace, 5"
        "$mod, code:15, workspace, 6"
        "$mod, code:16, workspace, 7"
        "$mod, code:17, workspace, 8"
        "$mod, code:18, workspace, 9"
        "$mod, code:19, workspace, 10"

        "ALTSHIFT, code:10, movetoworkspace, 1"
        "ALTSHIFT, code:11, movetoworkspace, 2"
        "ALTSHIFT, code:12, movetoworkspace, 3"
        "ALTSHIFT, code:13, movetoworkspace, 4"
        "ALTSHIFT, code:14, movetoworkspace, 5"
        "ALTSHIFT, code:15, movetoworkspace, 6"
        "ALTSHIFT, code:16, movetoworkspace, 7"
        "ALTSHIFT, code:17, movetoworkspace, 8"
        "ALTSHIFT, code:18, movetoworkspace, 9"
        "ALTSHIFT, code:19, movetoworkspace, 10"
      ];

      cursor = {
        # no_hardware_cursors = true;
        default_monitor = "DP-5";
      };

      dwindle = {
          # See https://wiki.hyprland.org/Configuring/Dwindle-Layout/ for more
          pseudotile = true; # master switch for pseudotiling. Enabling is bound to mainMod + P in the keybinds section below
          preserve_split = true; # you probably want this
          special_scale_factor = 0.60; # Fix for floaters
      };

      monitor = [
        "DP-3, 1920x1080, 0x616, 1"
        "DP-5, 3840x2160, 1920x0, 1"
        "DP-6, 1920x1080, 5760x266, 1, transform, 3" # or 3
      ];

      workspace = [
        "4,monitor:DP-3,default:true"
        "5,monitor:DP-3,persistent:true"
        "6,monitor:DP-3,persistent:true"

        "1,monitor:DP-5,default:true,decorate:true"
        "2,monitor:DP-5,persistent:true"
        "3,monitor:DP-5,persistent:true"
        "10,monitor:DP-5,persistent:true"

        "7,monitor:DP-6,default:true,gapsin:2"
        "8,monitor:DP-6,persistent:true"
        "9,monitor:DP-6,persistent:true"
      ];

      exec-once = [
        "systemctl --user import-environment WAYLAND_DISPLAY XDG_CURRENT_DESKTOP"
        "dbus-daemon --session --address=unix:path=$XDG_RUNTIME_DIR/bus"
        # "dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP"
        "dbus-update-activation-environment --systemd --all"
        "systemctl --user start plasma-polkit-agent"
        "/nix/store/jzak3afif9w9hf0xhqx3mdyayngz9iwa-kwallet-pam-6.2.5/libexec/pam_kwallet_init --no-startup-id" # Find a better path, changes on garbage collection
        "waybar &"
        # "hyprpaper &"
        "hypridle &"
        "swayosd &"
        "udiskie &"
        "blueman-manager && blueman-applet & blueman-applet &"
        "wl-paste --type text --watch cliphist store"
        "wl-paste --type image --watch cliphist store"
        # "${config.home.homeDirectory}/.config/hypr/scripts/start-in-tray.sh &"
        "${config.home.homeDirectory}/.config/hypr/scripts/start-keybase-gui.sh &"
        "input-remapper-control --command autoload &"
        # "/nix/store/yvnjx0qis4qdajc52f4xswhz4g69lcbn-polkit-kde-agent-1-6.2.5/libexec/polkit-kde-authentication-agent-1"

        "[workspace 4 silent] remmina --enable-fullscreen -c /home/wayne/.local/share/remmina/group_rdp_xeon_xeon-local.remmina"
        # rdp://wayne@xeon.local"

        "[workspace 7 silent] sublime3"
        "[workspace 9 silent] keepassxc"
        "[workspace 9 silent] nextcloud --background"
        "[workspace 9 silent] keybase-gui %u"

        # "/nix/store/r3fdp5rlxcihmqhpcgy91sj918wnrmrc-pyprland-2.3.4/bin/pypr --debug ~/tmp/pypr.log"
      ];

      general = {
        border_part_of_window = true;
        layout = "dwindle";
        gaps_in = 5;
        gaps_out = 10;
        border_size = 2;
        resize_on_border = true;
      };

      animations = {
        enabled=1;
        animation = [
          "windows,1,4,default,slide"
          "border,1,5,default"
          "fadeIn,1,5,default"
          "workspaces,1,3,default,slidevert"
        ];
      };

      decoration = {
        rounding = 8;
        blur = {
          enabled = true;
          size = 5;
          passes = 1;
        };
        shadow = {
          enabled = true;
          range = 60;
          color = "0x66000000";
        };
      };

      layerrule = [
        "dimaround,rofi"
        # "unset, rofi"
        # "ignorezero, rofi"
        "blurpopups, notifications"
        "blur, waybar"
      ];

      windowrule = [
        # "opacity 0.9 override 0.5 override 0.8 override, ^(.*)$" # set opacity to 1.0 active, 0.5 inactive and 0.8 fullscreen for kitty
        # "opacity 1 override 0.9 override 0.9 override, ^(zen-alpha)$" # set opacity to 1.0 active, 0.5 inactive and 0.8 fullscreen for kitty
        # "opacity 1.0 override 0.5 override 0.8 override, ^(kitty)$" # set opacity to 1.0 active, 0.5 inactive and 0.8 fullscreen for kitty
        "move -50% -50%, float, ^(org.keepassxc.KeePassXC)$"
        "float, ^(Nextcloud)$"
        # common modals
        ## "center,title:^(Open).*$"
        # "center,title:^(Choose Files)$"
        ## "center,title:^(Save).*$"
        # "center,title:^(Confirm to replace files)$"
        # "center,title:^(File Operation Progress)$"
        # "opacity 1.0 override 1 override 1 override, ^(REAPER)$"
        # "float, title:Open Directory"
        # "center, title:Open Directory"
        # "size 900 500, title:Open Directory"
        # "float, vlc"
        "center, [vV]lc"
      ];

      windowrulev2 = [
        "minsize 1 1, class:^(sublime_text)$"

        # REAPER Rules
        # Drop down menus are very wonly and require special attention
        # They only work in fullscreen but if we initially set fullscreen
        # Reaper floats when we select from the toolbar?!!!
        # We initially tile the window then fullscreen it to make toolbar menus work
        "tile, class:^(REAPER)$"
        "monitor DP-5, class:^(REAPER)$"
        "workspace 3, class:^(REAPER)$"
        # The following 3 lines make Dropdowns work
        "float, title:^(menu)$, class:^(REAPER)$" # Important
        "minsize 1 1, title:^(menu)$, class:^(REAPER)$" # Important
        "move onscreen cursor, title:^(menu)$, class:^(REAPER)$" # Important

        # "focusonactivate, class:(REAPER)"
        # "allowsinput, class:(REAPER)"
        # "focusonactivate, class:(REAPER), title(menu)"
        # "stayfocused, title:^(menu)$, class:^(REAPER)$" # Order is important

        # "float, class:REAPER"
        # "move cursor 5px 15px, class:REAPER"
        # Apply stayfocused only to transient (temporary) windows in Reaper
        # "stayfocused, title:^(.*)$, class:REAPER"
        # "stayfocused, parent:REAPER"
        # "noswallow, class:REAPER"
        # "stayfocused, title:^(.*)$, class:REAPER"
        # "float, title:^(Open|Choose Files|Save As|Confirm to replace files|File Operation Progress)$, class:REAPER"
        # "stayfocused, title:^(Open|Choose Files|Save As|Confirm to replace files|File Operation Progress)$, class:REAPER"
        # "nofocus, class:REAPER"
        # "fullscreen, title:^(File|Edit|View|Options|Help)$, class:REAPER"

        # "float,class:^(google-chrome)$,title:^(Open Files)$"
        # "float,class:^(google-chrome)$,title:^(Open File)$"
        "float,class:^(Typora)$,title:^(Open File)$"
        "float,class:^(com.nextcloud.desktopclient.nextcloud)$"
        "float,class:^(Keybase)$"
        "float,class:^(org.kde.kwalletmanager5)$"
        "float,class:^(org.keepassxc.KeePassXC)$"
        "float,class:^(Typora)$"
        "workspace special:magic, class:^(my-app-class)$"
        "float,title:^(VLC media player)$,"
        "minsize 900 500,class:^([vV]lc)$"
      ];

      input.numlock_by_default = true;

      debug.suppress_errors = true;

      # plugin = {
      #   hyprbars = {
      #     hyprbars-button = [
      #       "rgb(ff4040), 10, 󰖭, hyprctl dispatch killactive"
      #       "rgb(eeee11), 10, , hyprctl dispatch fullscreen 1"
      #       "rgb(00ff00), 10, 󰍈, hyprctl dispatch togglefloating"
      #     ];
      #     bar_height = 20;
      #     bar_blur = 0.5;
      #     bar_button_padding = 10;
      #     icon_on_hover = true;
      #   };
      #   hyprwinwrap = {
      #     class = "kitty-logs";
      #     # || class = "ff-dev";
      #   };
      # };
    };

    # extraConfig = {};
    # plugins = [
    #   pkgs.hyprlandPlugins.hyprbars
    #   pkgs.hyprlandPlugins.hyprwinwrap
    # ];
  };
}
