{
  lib,
  pkgs,
  config,
  theme,
  ...
}: let
  dbus-sway-environment = pkgs.writeTextFile {
    name = "dbus-sway-env";
    executable = true;
    text = ''
      dbus-update-activation-environment --systemd DISPLAY SWAYSOCK WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=sway
      systemctl --user import-environment
      systemctl --user stop pipewire pipewire-media-session xdg-desktop-portal xdg-desktop-portal-wlr
      systemctl --user start pipewire pipewire-media-session xdg-desktop-portal xdg-desktop-portal-wlr
    '';
  };
  brightnessScript = name: change:
    pkgs.writeScript name ''      #!/usr/bin/env fish
          brightnessctl set ${change}
          set val (brightnessctl -m | cut -d',' -f4 | head -c-2)
          notify-send "Brightness $val%" -h int:value:$val -h string:synchronous:brightness
    '';
  brightnessUp = brightnessScript "brightup" "+5%";
  brightnessDown = brightnessScript "brightdown" "5%-";
  volumeScript = name: change:
    pkgs.writeScript name ''      #!/usr/bin/env fish
          pamixer ${change}
          set val (pamixer --get-volume | head -c-1)
          notify-send "Volume $val%" -h int:value:$val -h string:synchronous:volume
    '';
  volumeUp = volumeScript "volup" "-i 5";
  volumeDown = volumeScript "voldown" "-d 5";
in {
  imports = [./foot.nix];

  home.packages = with pkgs; [wofi wl-clipboard grim];

  wayland.windowManager.sway = {
    enable = true;
    config = {
      modifier = "Mod4";
      menu = "wofi -S drun";
      terminal = "foot";
      startup = [
        {command = "${dbus-sway-environment}";}
      ];
      gaps = {
        smartGaps = true;
        smartBorders = "no_gaps";
        inner = 10;
      };
      workspaceAutoBackAndForth = true;
      input = {
        "type:touchpad" = {
          tap = "enabled";
          natural_scroll = "enabled";
        };
        "*" = {
          xkb_layout = "pl";
        };
      };
      colors = {
        focused = rec {
          border = theme.bright.white;
          background = theme.dark.black;
          text = theme.bright.white;
          indicator = theme.bright.white;
          childBorder = border;
        };
        focusedInactive = rec {
          border = theme.bright.black;
          background = theme.dark.black;
          text = theme.bright.white;
          indicator = theme.bright.white;
          childBorder = border;
        };
        unfocused = rec {
          border = theme.dark.black;
          background = theme.dark.black;
          text = theme.bright.white;
          indicator = theme.bright.white;
          childBorder = border;
        };
        urgent = rec {
          border = theme.bright.red;
          background = theme.dark.black;
          text = theme.bright.white;
          indicator = theme.bright.white;
          childBorder = border;
        };
      };

      keybindings = let
        mod = config.wayland.windowManager.sway.config.modifier;
      in
        lib.mkOptionDefault {
          "${mod}+Shift+s" = "exec flameshot gui";

          "XF86MonBrightnessUp" = "exec ${brightnessUp}";
          "XF86MonBrightnessDown" = "exec ${brightnessDown}";

          "XF86AudioRaiseVolume" = "exec ${volumeUp}";
          "XF86AudioLowerVolume" = "exec ${volumeDown}";
        };
    };
  };

  services.kanshi.enable = true;

  home.sessionVariables.WLR_NO_HARDWARE_CURSORS = 1;
}