{ lib, pkgs, config, ... }: {
  home-manager.users.agatha = {
    xsession.windowManager.bspwm = {
      enable = true;
      extraConfigEarly = lib.strings.concatStringsSep "\n" [
        "xsetroot -cursor_name left_ptr"
        "xinput set-prop 'SynPS/2 Synaptics TouchPad' 'libinput Scrolling Pixel Distance' 10"
        "setxkbmap"
      ];
      extraConfig = let
        startOnce = procs:
          map (v: "! pgrep ${builtins.head (lib.splitString " " v)} && ${v} &")
          procs;
        startup = startOnce [
          "firefox"
          "element-desktop"
          "telegram-desktop"
          "spotify"
          "geary"
          "bspm -d"
        ];
      in lib.strings.concatStringsSep "\n" ([
        "nitrogen --set-zoom-fill ${
          config.environment.graphical.colorschemes."${config.environment.graphical.theme.name}".image
        }"
      ] ++ startup);
      monitors = { eDP-1 = [ "I" "II" "III" "IV" "V" "VI" "VII" "VIII" ]; };
      settings = let
        color = n:
          config.environment.graphical.colors."${config.environment.graphical.theme.name}"."${builtins.toString
          n}";
      in {
        border_width = 3;
        window_gap = 15;
        top_padding = 45;
        split_ratio = 0.5;
        borderless_monocle = false;
        gapless_monocle = false;
        normal_border_color = color 0;
        focused_border_color = color 1;
        active_border_color = color 2;
        urgent_border_color = color 2;
        presel_feedback_color = color 2;
      };
      rules = {
        "Gimp" = {
          state = "tiled";
          follow = true;
        };
        "Element".desktop = "II";
        "TelegramDesktop".desktop = "III";
        "Spotify".desktop = "IV";
        "Geary".desktop = "V";
        "firefox" = {
          desktop = "I";
          state = "tiled";
          follow = false;
        };
        "Yubico Authenticator".state = "floating";
        "firefox:Places".state = "floating";
      };
    };

    services.sxhkd = {
      enable = true;
      keybindings = {
        # Terminal
        "super + Return" = "kitty";
        "Caps_Lock" = "kitty";
        # File explorer
        "super + e" = "nautilus";
        # Program launcher
        "super + @space" = "rofi -show drun";
        # Clipboard
        "super + v" = ''
          CM_LAUNCHER=rofi clipmenu \
            -theme-str 'listview \{ spacing: 0; \}' \
            -theme-str 'window \{ width: 30em; \}'
        '';
        # Calculator
        "super + shift + c" = ''
          ROFI_PLUGIN_PATH=${pkgs.rofi-calc}/lib/rofi rofi -show calc -modi calc -calc-command '${pkgs.xdotool}/bin/xdotool type --clearmodifiers "\{result\}'
        '';
        "super + shift + e" = ''
          rofimoji --action clipboard
        '';
        # Media keys
        "XF86Audio{Raise,Lower}Volume" = "pamixer {-i,-d} 5";
        "XF86AudioMute" = "pamixer -t";
        "XF86Audio{Prev,Next}" = "playerctl {previous,next}";
        "XF86AudioPlay" = "playerctl play-pause";
        "XF86MonBrightness{Up,Down}" = ''
          brightnessctl set 10%{+,-} && dunstify -r 98114 -h int:value:$(( $(brightnessctl get) * 100 / $(brightnessctl max) )) "Brightness set to:"
        '';
        # Switch outputs
        "super + o" = ''
          dunstify -r 112119 "Sound output switched to $(${pkgs.pads}/bin/pads next && ${pkgs.pads}/bin/pads list | rg '^\*' | choose 1:)"'';
        # Screenshot
        "Print" = "flameshot gui && bspc desktop --focus focused";
        "shift + Print" =
          "flameshot gui -d 3000 && bspc desktop --focus focused";
        # Pause notifications
        "super + n" = "dunstctl set-paused toggle";
        # Reload WM
        "super + shift + {q,r}" = ''
          pkill -USR1 -x sxhkd \
          ; for p in picom polybar dunst; killall $p; end \
          ; bspc {quit,wm -r}
        '';
        # Close/kill window
        "super + {_,shift + }w" = "bspc node -{c,k}";
        # Monocle layout
        "super + m" = "bspm monocle --toggle";
        "super + shift + m" = "bspm monocle --next";
        # Toggle hide all windows
        "super + d" =
          "bspc query -N -n .window | xargs -I node_id bspc node node_id -g hidden";
        # Change window state
        "super + {t,shift + t,s,f}" =
          "bspc node -t {tiled,pseudo_tiled,floating,fullscreen}";
        # Focus/move window
        "super + {_,shift + }{j,k,i,l}" =
          "bspc node -{f,s} {west,south,north,east}";
        # Focus the next window in the current desktop 
        "super + c" = "bspc node -f next.local.!hidden.window";
        # Focus previous/next desktop on current monitor
        "super + bracket{left,right}" = "bspc desktop -f {prev,next}.local";
        # Switch desktops / Move window to desktop
        "super + {_,shift + }{1-9,0}" = "bspc {desktop -f,node -d} '^{1-9,10}'";
        # Window switcher
        "alt + Tab" = "rofi -show window";
        # Move floating window
        "super + {Left,Down,Up,Right}" = "bspc node -v {-20 0,0 20,0 -20,20 0}";
        # Lock screen
        "super + x" = ''
          betterlockscreen --lock dimblur --time-format "%H:%M"; systemctl --user restart gpg-agent'';
      };
    };
  };
}
