{
    pkgs,
    lib,
    env,
    ...
}:

let
    mod = "Mod4";
    displays = if env ? displays then env.displays else null;
in
{
    xsession.windowManager.i3 = {
        enable = true;

        config = {
            modifier = mod;

            fonts = {
                names = [ "Monaco" ];
                size = 8.0;
            };

            keybindings = lib.mkOptionDefault {
                "${mod}+q" = "kill";
                "${mod}+n" = "exec \"${
                    lib.concatStringsSep " " [
                        "${lib.getExe pkgs.rofi}"
                        "-show combi"
                        "-modes combi"
                        "-combi-modes drun,run"
                        "-combi-display-format {text}"
                    ]
                }\"";
                "${mod}+Return" = "exec ${lib.getExe pkgs.kitty}";

                "${mod}+Left" = "focus left";
                "${mod}+Right" = "focus right";
                "${mod}+Up" = "focus up";
                "${mod}+Down" = "focus down";

                "${mod}+Shift+Left" = "move left";
                "${mod}+Shift+Right" = "move right";
                "${mod}+Shift+Up" = "move up";
                "${mod}+Shift+Down" = "move down";

                "${mod}+Ctrl+Left" = "move workspace to output left";
                "${mod}+Ctrl+Right" = "move workspace to output right";

                "Print" = "exec ${lib.getExe pkgs.flameshot} gui";
            };
        };

        extraConfig =
            let
                background = lib.concatStringsSep " " [
                    "exec --no-startup-id"
                    (lib.concatStringsSep " " [
                        (lib.getExe pkgs.xwinwrap)
                        "-g 3820x1080"
                        "-s"
                        "-b"
                        "-ni"
                        "-sp"
                        "-ov"
                        "-nf"
                    ])
                    "--"
                    (lib.concatStringsSep " " [
                        (lib.getExe pkgs.mpv)
                        "${pkgs.wallpaper}/wallpaper.mov"
                        "-wid WID"
                        "--loop"
                        "--no-audio"
                        "--no-osc"
                        "--no-input-default-bindings"
                        "--no-input-cursor"
                        "--gpu-api=vulkan"
                        "--vo=gpu-next"
                        "--framedrop=vo"
                        "--profile=low-latency"
                        "--hwdec=auto"
                    ])
                ];
                displayConf =
                    if displays != null then
                        lib.concatStringsSep "\n" [
                            "workspace 1 output ${displays.primary}"
                            (if (displays ? secondary) then "workspace 2 output ${displays.secondary}" else "")
                            "exec i3-msg focus output ${displays.primary}"
                            (if (displays ? xrandr) then "exec \"${lib.getExe pkgs.xrandr} ${displays.xrandr}\"" else "")
                        ]
                    else
                        "";
            in
            lib.concatStringsSep "\n" [
                background
                displayConf
            ];
    };
}
