{ pkgs, lib, ... }@inputs:
let
  rofi = pkgs.rofi.override { plugins = [ pkgs.rofi-emoji ]; };
  scripts = ((import ./scripts.nix) inputs); 
in
{
  imports = [ ./swayidle.nix ];
  wayland.windowManager.sway = rec {
    enable = true;
    config = {
      terminal = "${pkgs.alacritty}/bin/alacritty";
      menu = "${rofi}/bin/rofi -show combi";
      modifier = "Mod4";
      output = {
        "*" = {
          bg = "${./wallpaper.png} fill";
        };
      };
      input = {
        "*" = {
          xkb_layout = "pl";
          accel_profile = "flat";
          dwt = "disabled";
          pointer_accel = "0.0";
        };
      };
      bars = [{
        id = "top";
        statusCommand = "${pkgs.i3status-rust}/bin/i3status-rs";
        position = "top";
        trayOutput = "*";
      }];
      floating.criteria = [{ title = "Steam - Update News"; }];
      startup = [
        # Copied from https://git.sr.ht/~sumner/home-manager-config/tree/master/item/modules/window-manager/wayland.nix#L64
        # See https://github.com/nix-community/home-manager/issues/2028
        # Make all the pinentry stuff work
        # See: https://github.com/NixOS/nixpkgs/issues/119445#issuecomment-820507505
        # and: https://github.com/NixOS/nixpkgs/issues/57602#issuecomment-820512097
        { command = "dbus-update-activation-environment WAYLAND_DISPLAY"; }
      ];
      keybindings = lib.mkOptionDefault {
        "XF86PowerOff" =  "exec systemctl suspend";
      };
    };
    wrapperFeatures.gtk = true;
    systemdIntegration = true;
    extraSessionCommands = ''
      #export SDL_VIDEODRIVER=wayland
      # needs qt5.qtwayland in systemPackages
      export QT_QPA_PLATFORM=wayland
      export QT_WAYLAND_DISABLE_WINDOWDECORATION="1"
      # Fix for some Java AWT applications (e.g. Android Studio),
      # use this if they aren't displayed properly:
      export _JAVA_AWT_WM_NONREPARENTING=1
    '';
  };

  programs.rofi = {
    enable = true;
    package = rofi;
    theme = "purple";
    extraConfig = {
      modi = "combi";
      combi-modi = "drun,emoji";
    };
  };

  programs.mako = {
    enable = true;
    defaultTimeout = 2000;
  };

  programs.i3status-rust = {
    enable = true;
    bars.bar_0 = {
      blocks = [
        {
          block = "disk_space";
          path = "/";
          info_type = "available";
          unit = "GB";
          interval = 60;
          warning = 20.0;
          alert = 10.0;
        }
        {
          block = "memory";
          display_type = "memory";
          format_mem = "{mem_used}/{mem_total}({mem_used_percents})";
          format_swap = "{swap_used}/{swap_total}({swap_used_percents})";
        }
        {
          block = "cpu";
          interval = 1;
        }
        { block = "sound"; }
        {
          block = "time";
          interval = 60;
          format = "%a %d/%m %R";
        }
      ];
    };
  };
  home.packages = [ scripts.lockscreen ];
}