{ lib, config, pkgs, ... }: {
  config = lib.mkIf (config.usercfg.wm == "Wayland") {

    wayland.windowManager.hyprland = {
      enable = true;
      xwayland.enable = true;
      extraConfig = ''
        monitor=,preferred,auto,auto
        env=bitdepth,10
        input {
            kb_layout = us, ru
            kb_variant = intl, phonetic
            kb_options = grp:ctrls_toggle

            follow_mouse = 1

            sensitivity = 0
                        
            touchpad {
                natural_scroll=no
                disable_while_typing=true
                scroll_factor=1
                disable_while_typing=0
                tap-to-click=0
            }
        }
                        
        misc {
            disable_hyprland_logo=true
            animate_mouse_windowdragging=false
            animate_manual_resizes=false
                          
            vrr=1
        }
                        
        general {
            gaps_in = ${config.colorScheme.palette.gaps-window}
            gaps_out = ${config.colorScheme.palette.gaps-screen}
            border_size = ${config.colorScheme.palette.border-width}
                                      
            col.active_border = rgb(${config.colorScheme.palette.base04})
            col.inactive_border = rgb(${config.colorScheme.palette.base03})
                          
            layout = dwindle
        }
                        
        decoration {
            rounding = ${config.colorScheme.palette.border-radius}
                          
            blur {
                enabled = true
                size = 2
                passes = 1
                new_optimizations = true
            }
            #multisample_edges = true

            #opactity
            inactive_opacity = 1.0
            active_opacity = 1.0
            fullscreen_opacity = 1.0
                                      
            # shadow
            # drop_shadow = no
            # shadow_range = 60
            # shadow_offset = 0 5
            # shadow_render_power = 4
            #col.shadow = rgba(00000099)
        }
                        
        animations {
            enabled = true
            bezier = customcurve, 0.0, 0.9, 0.1, 1.0

            animation = windows, 1, 4, customcurve
            animation = windowsOut, 1, 4, customcurve, popin 50%
            animation = border, 1, 10, customcurve
            animation = borderangle, 0, 1, customcurve
            animation = fade, 1, 4, customcurve
            animation = workspaces, 1, 4, customcurve
        }
                        
        dwindle {
            pseudotile = yes
            preserve_split = yes 
        }

        master {
            new_status = master
        }

        gestures {
            workspace_swipe = off
        }
                        
        exec-once = eww open bar
        #exec-once = waybar
        exec-once = dunst

        exec-once = swww init

        exec-once = dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP
        exec-once = /nix/store/$(ls -la /nix/store | grep 'polkit-gnome' | grep '4096' | awk '{print $9}' | sed -n '$p')/libexec/polkit-gnome-authentication-agent-1 & 

        exec-once = wl-paste --type text --watch cliphist store #Stores only text data
        exec-once = wl-paste --type image --watch cliphist store #Stores only image data

        exec-once = swayidle -w timeout 600 'swaylock' before-sleep 'swaylock'


        #windowrules
        windowrule = noshadow, floating:0

        windowrule = float, title:^(flying_kitty)$
        windowrule = size 1100 600, title:^(flying_kitty)$
        windowrule = move center, title:^(flying_kitty)$
        windowrule = animation slide, title:^(flying_kitty)$
        windowrule = float, title:^(Volume Control)$
        windowrule = float, title:^(Picture-in-Picture)$
        windowrule = float, title:^(Steam)$

        windowrulev2 = workspace 2 silent, class:^(org.telegram.desktop)$
        windowrulev2 = workspace 2 silent, class:^(discord)$

        windowrulev2 = workspace 8 silent, class:^(org.keepassxc.KeePassXC)$
        windowrulev2 = workspace 8 silent, title:^(Nextcloud)$
        windowrulev2 = workspace 8 silent, class:^(Tk)$,title:^(Server Configuration)$

        #SPECIAL FLOATERS
        windowrulev2 = float,class:^(org.keepassxc.KeePassXC)$,title:^(KeePassXC -  Access Request)$
        windowrulev2 = pin,class:^(org.keepassxc.KeePassXC)$,title:^(KeePassXC -  Access Request)$
        windowrulev2 = float,class:^(org.keepassxc.KeePassXC)$,title:^(Unlock Database - KeePassXC)$
        windowrulev2 = pin,class:^(org.keepassxc.KeePassXC)$,title:^(Unlock Database - KeePassXC)$
        windowrulev2 = float,title:^(Open)$
        windowrulev2 = float,title:^(Choose Files)$
        windowrulev2 = float,title:^(Save As)$
        windowrulev2 = float,title:^(Confirm to replace files)$
        windowrulev2 = float,title:^(File Operation Progress)$
        windowrulev2 = float,class:^(firefox)$,title:^(Picture-in-Picture)$
        windowrulev2 = pin,class:^(firefox)$,title:^(Picture-in-Picture)$
        windowrulev2 = suppressevent fullscreen,class:^(firefox)$,title:^(Picture-in-Picture)$
        windowrulev2 = float,class:^(firefox)$,title:^(Firefox — Sharing Indicator)$
        windowrulev2 = suppressevent fullscreen,class:^(firefox)$,title:^(Firefox — Sharing Indicator)$
        windowrulev2 = float,class:^(firefox)$,title:^(Extension:.* Mozilla Firefox)$
        windowrulev2 = suppressevent fullscreen,class:^(firefox)$,title:^(Extension:.* Mozilla Firefox)$
        windowrulev2 = float,class:^(org.telegram.desktop)$,title:^(Media viewer)$
        windowrulev2 = center,class:^(org.telegram.desktop)$,title:^(Media viewer)$

        #SPECIAL NO SLEEP
        windowrulev2 = idleinhibit fullscreen, class:^(.*)
        windowrulev2 = idleinhibit focus, class:^(steam_app_.*)$
        windowrulev2 = idleinhibit focus, class:^(mpv)$

        layerrule = blur,^(eww-blur)

        #binds
        bind = SUPER, RETURN, exec, kitty

        bind = SUPER_SHIFT, RETURN,togglespecialworkspace,
        # bind = SUPER_SHIFT, RETURN, exec, kitty --title flying_kitty --single-instance
        bind = SUPER, Q, killactive, 
        bind = SUPER, T, togglefloating, 
        bind = SUPER, F, fullscreen, 

        bind = SUPER, D, exec, wofi -modi --show drun
        bind = SUPER SHIFT,D,exec, ~/.config/hypr/themes/apatheia/eww/launch_bar 

        bind = SUPER, V, exec, cliphist list | wofi -dmenu | cliphist decode | wl-copy
        bind =  , Print, exec, grim -g "$(slurp -d)" - | swappy -f -

        bind = SUPER, L, exec, swaylock 

        bind = SUPER, left, movefocus, l
        bind = SUPER, right, movefocus, r
        bind = SUPER, up, movefocus, u
        bind = SUPER, down, movefocus, d

        bind = SUPER, 1, workspace, 1
        bind = SUPER, 2, workspace, 2
        bind = SUPER, 3, workspace, 3
        bind = SUPER, 4, workspace, 4
        bind = SUPER, 5, workspace, 5
        bind = SUPER, 6, workspace, 6
        bind = SUPER, 7, workspace, 7
        bind = SUPER, 8, workspace, 8
        bind = SUPER, 9, workspace, 9
        bind = SUPER, 0, workspace, 10

        bind = SUPER SHIFT, 1, movetoworkspacesilent, 1
        bind = SUPER SHIFT, 2, movetoworkspacesilent, 2
        bind = SUPER SHIFT, 3, movetoworkspacesilent, 3
        bind = SUPER SHIFT, 4, movetoworkspacesilent, 4
        bind = SUPER SHIFT, 5, movetoworkspacesilent, 5
        bind = SUPER SHIFT, 6, movetoworkspacesilent, 6
        bind = SUPER SHIFT, 7, movetoworkspacesilent, 7
        bind = SUPER SHIFT, 8, movetoworkspacesilent, 8
        bind = SUPER SHIFT, 9, movetoworkspacesilent, 9
        bind = SUPER SHIFT, 0, movetoworkspacesilent, 10

        bind = SUPER, mouse_down, workspace, e+1
        bind = SUPER, mouse_up, workspace, e-1

        bindm = SUPER, mouse:272, movewindow
        bindm = SUPER, mouse:273, resizewindow
        bind = , XF86AudioPlay, exec, playerctl play-pause
        bind = , XF86AudioPrev, exec, playerctl previous
        bind = , XF86AudioNext, exec, playerctl next
        bind = , XF86AudioRaiseVolume, exec, amixer -q sset 'Master' 5%+
        bind = , XF86AudioLowerVolume, exec, amixer -q sset 'Master' 5%-
        bind = , XF86AudioMute, exec, amixer -q sset 'Master' toggle
        bind = , XF86MonBrightnessUp, exec, brightnessctl s 5%+
        bind = , XF86MonBrightnessDown, exec, brightnessctl s 5%-

        exec-once = [workspace special silent] kitty --title flying_kitty
        exec-once = sh ~/.config/startup.sh
      '';
    };

    xdg.configFile."startup.sh".text = ''
      #!/bin/sh
      sleep 2
      keepassxc & 
      firefox & 
      jellyfin-mpv-shim & 
      easyeffects --gapplication-service &

      sleep 2
      nextcloud & 
      #telegram-desktop&
      #discord&
    '';
  };
}