let
  lock-command = "swaylock";
in {
  wayland.windowManager.river = {
    enable = true;
    extraConfig = ''
      rivertile -view-padding 0 -outer-padding 0 &
      pkill waybar
      waybar &
      mako --height 700 --width 700 &
      wlr-randr --output DP-1 --pos 1280,0 --output HDMI-A-1 --pos 0,56 # void desktop double monitor setup
      wlr-randr --output DP-5 --pos 3840,1192 --output DP-4 --pos 5120,1136 --output eDP-1 --pos 5120,2216 # t470 triple monitor setup
      # audio volume control
      riverctl map -repeat normal None XF86AudioLowerVolume spawn 'wpctl set-volume @DEFAULT_SINK@ 1%-'
      riverctl map -repeat normal None XF86AudioRaiseVolume spawn 'wpctl set-volume @DEFAULT_SINK@ 1%+'

      # screen backlight brightness control
      riverctl map -repeat normal None XF86MonBrightnessDown spawn 'brightnessctl set 1%-'
      riverctl map -repeat normal None XF86MonBrightnessUp spawn 'brightnessctl set 1%+'
      riverctl map -repeat normal Super 'Prior' spawn 'ddcutil setvcp 10 + 10'
      riverctl map -repeat normal Super 'Next' spawn 'ddcutil setvcp 10 - 10'

      # layout management
      riverctl map -repeat normal Super+Alt H send-layout-cmd rivertile 'main-ratio -0.05'
      riverctl map -repeat normal Super+Alt L send-layout-cmd rivertile 'main-ratio +0.05'
    '';
    settings = {
      border-width = 2;
      keyboard-layout = "-variant altgr-intl -options ctrl:nocaps us";
      default-layout = "rivertile";
      focus-follows-cursor = "normal";
      map = {
        normal = {
          # transcription
          "None Insert" = "spawn ~/whisper_tests/script.fish";
          # screen lock & suspend
          "Control+Alt L" = "spawn '${lock-command}'";
          "Control+Alt+Shift L" = "spawn '${lock-command} & systemctl suspend'";
          # terminal
          "Super Return" = "spawn kitty";
          # frequent programs
          "Super Q" = "spawn firefox";
          "Super A" = "spawn emacs";
          "Super D" = "spawn discord";
          "Super G" = "spawn dolphin";
          # program launcher
          "Super R" = "spawn fuzzel";
          # quit river
          "Super+Alt+Control Q" = "exit";
          # manipulate current view
          "Super W" = "close";
          "Super M" = "toggle-fullscreen";
          "Super S" = "toggle-float";
          "Super F" = "toggle-fullscreen";
          # view focus
          "Super H" = "focus-view left";
          "Super J" = "focus-view down";
          "Super K" = "focus-view up";
          "Super L" = "focus-view right";
          "Super O" = "send-to-output -current-tags next";
          # view movement
          "Super+Shift H" = "swap left";
          "Super+Shift J" = "swap down";
          "Super+Shift K" = "swap up";
          "Super+Shift L" = "swap right";
          # layout management
          "Super+Alt J" = "send-layout-cmd rivertile 'main-count -1'";
          "Super+Alt K" = "send-layout-cmd rivertile 'main-count +1'";
          # tag (workspace) management
          ## rotate workspace
          "Super Right" = "spawn 'river-shifttags --num-tags 10 --shifts 1'";
          "Super Left" = "spawn 'river-shifttags --num-tags 10 --shifts -1'";
          ##### fr layout
          ## switch to workspace
          "Super ampersand" = "set-focused-tags 1";
          "Super eacute" = "set-focused-tags 2";
          "Super quotedbl" = "set-focused-tags 4";
          "Super apostrophe" = "set-focused-tags 8";
          "Super parenleft" = "set-focused-tags 16";
          "Super minus" = "set-focused-tags 32";
          "Super egrave" = "set-focused-tags 64";
          "Super underscore" = "set-focused-tags 128";
          "Super ccedilla" = "set-focused-tags 256";
          "Super agrave" = "set-focused-tags 512";
          ## toggle workspace display
          "Super+Alt ampersand" = "toggle-focused-tags 1";
          "Super+Alt eacute" = "toggle-focused-tags 2";
          "Super+Alt quotedbl" = "toggle-focused-tags 4";
          "Super+Alt apostrophe" = "toggle-focused-tags 8";
          "Super+Alt parenleft" = "toggle-focused-tags 16";
          "Super+Alt minus" = "toggle-focused-tags 32";
          "Super+Alt egrave" = "toggle-focused-tags 64";
          "Super+Alt underscore" = "toggle-focused-tags 128";
          "Super+Alt ccedilla" = "toggle-focused-tags 256";
          "Super+Alt agrave" = "toggle-focused-tags 512";
          ## send to workspace
          "Super+Shift ampersand" = "set-view-tags 1";
          "Super+Shift eacute" = "set-view-tags 2";
          "Super+Shift quotedbl" = "set-view-tags 4";
          "Super+Shift apostrophe" = "set-view-tags 8";
          "Super+Shift parenleft" = "set-view-tags 16";
          "Super+Shift minus" = "set-view-tags 32";
          "Super+Shift egrave" = "set-view-tags 64";
          "Super+Shift underscore" = "set-view-tags 128";
          "Super+Shift ccedilla" = "set-view-tags 256";
          "Super+Shift agrave" = "set-view-tags 512";
          ## toggle visibility of window in workspace
          "Super+Alt+Shift ampersand" = "toggle-view-tags 1";
          "Super+Alt+Shift eacute" = "toggle-view-tags 2";
          "Super+Alt+Shift quotedbl" = "toggle-view-tags 4";
          "Super+Alt+Shift apostrophe" = "toggle-view-tags 8";
          "Super+Alt+Shift parenleft" = "toggle-view-tags 16";
          "Super+Alt+Shift minus" = "toggle-view-tags 32";
          "Super+Alt+Shift egrave" = "toggle-view-tags 64";
          "Super+Alt+Shift underscore" = "toggle-view-tags 128";
          "Super+Alt+Shift ccedilla" = "toggle-view-tags 256";
          "Super+Alt+Shift agrave" = "toggle-view-tags 512";

          #### us layout
          ## switch to workspace
          "Super 1" = "set-focused-tags 1";
          "Super 2" = "set-focused-tags 2";
          "Super 3" = "set-focused-tags 4";
          "Super 4" = "set-focused-tags 8";
          "Super 5" = "set-focused-tags 16";
          "Super 6" = "set-focused-tags 32";
          "Super 7" = "set-focused-tags 64";
          "Super 8" = "set-focused-tags 128";
          "Super 9" = "set-focused-tags 256";
          "Super 0" = "set-focused-tags 512";
          ## toggle workspace display
          "Super+Alt 1" = "toggle-focused-tags 1";
          "Super+Alt 2" = "toggle-focused-tags 2";
          "Super+Alt 3" = "toggle-focused-tags 4";
          "Super+Alt 4" = "toggle-focused-tags 8";
          "Super+Alt 5" = "toggle-focused-tags 16";
          "Super+Alt 6" = "toggle-focused-tags 32";
          "Super+Alt 7" = "toggle-focused-tags 64";
          "Super+Alt 8" = "toggle-focused-tags 128";
          "Super+Alt 9" = "toggle-focused-tags 256";
          "Super+Alt 0" = "toggle-focused-tags 512";
          ## send to workspace
          "Super+Shift 1" = "set-view-tags 1";
          "Super+Shift 2" = "set-view-tags 2";
          "Super+Shift 3" = "set-view-tags 4";
          "Super+Shift 4" = "set-view-tags 8";
          "Super+Shift 5" = "set-view-tags 16";
          "Super+Shift 6" = "set-view-tags 32";
          "Super+Shift 7" = "set-view-tags 64";
          "Super+Shift 8" = "set-view-tags 128";
          "Super+Shift 9" = "set-view-tags 256";
          "Super+Shift 0" = "set-view-tags 512";
          ## toggle visibility of window in workspace
          "Super+Alt+Shift 1" = "toggle-view-tags 1";
          "Super+Alt+Shift 2" = "toggle-view-tags 2";
          "Super+Alt+Shift 3" = "toggle-view-tags 4";
          "Super+Alt+Shift 4" = "toggle-view-tags 8";
          "Super+Alt+Shift 5" = "toggle-view-tags 16";
          "Super+Alt+Shift 6" = "toggle-view-tags 32";
          "Super+Alt+Shift 7" = "toggle-view-tags 64";
          "Super+Alt+Shift 8" = "toggle-view-tags 128";
          "Super+Alt+Shift 9" = "toggle-view-tags 256";
          "Super+Alt+Shift 0" = "toggle-view-tags 512";

          # music player control
          # We have to specify None as the modifier, else riverctl complains that XF86Etc is not a valid modifier
          "None XF86AudioPlay" = "spawn 'playerctl play-pause'";
          "None Scroll_Lock" = "spawn 'playerctl previous'";
          "None XF86AudioNext" = "spawn 'playerctl next'";
          "None Pause" = "spawn 'cmus-remote -C player-next-album'";

          "None XF86Bluetooth" = "spawn 'playerctl play-pause'";
          "None XF86Tools" = "spawn 'playerctl previous'";
          "None XF86Keyboard" = "spawn 'playerctl next'";
          "None XF86Favorites" = "spawn 'cmus-remote -C player-next-album'";

          "None XF86AudioMute" = "spawn 'wpctl set-mute @DEFAULT_SINK@ toggle'";
        };
      };
      map-pointer = {
        normal = {
          "Super BTN_LEFT" = "move-view";
          "Super BTN_RIGHT" = "resize-view";
          "Super BTN_MIDDLE" = "toggle-float";
        };
      };
    };
  };
}
