#!/bin/sh

mod="Super"

riverctl spawn kanshi
riverctl spawn "swaybg -i $HOME/.local/share/wallpapers/07.jpg -m fill"
riverctl spawn "$HOME/.config/river/scripts/waybar.sh"

riverctl spawn "systemctl --user import-environment WAYLAND_DISPLAY XDG_CURRENT_DESKTOP"
riverctl spawn "dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=river"

riverctl map normal "$mod"+Shift Return spawn kitty
riverctl map normal "$mod" P spawn "rofi -show drun"
riverctl map normal "$mod" S spawn "flameshot gui"
riverctl map normal "$mod" Q close
riverctl map normal "$mod"+Shift E exit
riverctl map normal "$mod"+Shift C spawn "$HOME/.config/river/init"
riverctl map normal "$mod" J focus-view next
riverctl map normal "$mod" K focus-view previous
riverctl map normal "$mod"+Shift J swap next
riverctl map normal "$mod"+Shift K swap previous
riverctl map normal "$mod" Period focus-output next
riverctl map normal "$mod" Comma focus-output previous
riverctl map normal "$mod"+Shift Period send-to-output next
riverctl map normal "$mod"+Shift Comma send-to-output previous
riverctl map normal "$mod" Return zoom
riverctl map normal "$mod" H send-layout-cmd rivercarro "main-ratio -0.05"
riverctl map normal "$mod" L send-layout-cmd rivercarro "main-ratio +0.05"
riverctl map normal "$mod"+Shift H send-layout-cmd rivercarro "main-count +1"
riverctl map normal "$mod"+Shift L send-layout-cmd rivercarro "main-count -1"
riverctl map normal "$mod"+Alt H move left 100
riverctl map normal "$mod"+Alt J move down 100
riverctl map normal "$mod"+Alt K move up 100
riverctl map normal "$mod"+Alt L move right 100
riverctl map normal "$mod"+Alt+Control H snap left
riverctl map normal "$mod"+Alt+Control J snap down
riverctl map normal "$mod"+Alt+Control K snap up
riverctl map normal "$mod"+Alt+Control L snap right
riverctl map normal "$mod"+Alt+Shift H resize horizontal -100
riverctl map normal "$mod"+Alt+Shift J resize vertical 100
riverctl map normal "$mod"+Alt+Shift K resize vertical -100
riverctl map normal "$mod"+Alt+Shift L resize horizontal 100
riverctl map-pointer normal "$mod" BTN_LEFT move-view
riverctl map-pointer normal "$mod" BTN_RIGHT resize-view
riverctl map-pointer normal "$mod" BTN_MIDDLE toggle-float

for i in $(seq 1 9); do
	tags=$((1 << (i - 1)))
	riverctl map normal "$mod" "$i" set-focused-tags "$tags"
	riverctl map normal "$mod"+Shift "$i" set-view-tags "$tags"
	riverctl map normal "$mod"+Control "$i" toggle-focused-tags "$tags"
	riverctl map normal "$mod"+Shift+Control "$i" toggle-view-tags "$tags"
done

all_tags=$(((1 << 32) - 1))
riverctl map normal "$mod" 0 set-focused-tags "$all_tags"
riverctl map normal "$mod"+Shift 0 set-view-tags "$all_tags"
riverctl map normal "$mod" Space toggle-float
riverctl map normal "$mod" F toggle-fullscreen
riverctl map normal "$mod" Up send-layout-cmd rivercarro "main-location top"
riverctl map normal "$mod" Right send-layout-cmd rivercarro "main-location right"
riverctl map normal "$mod" Down send-layout-cmd rivercarro "main-location bottom"
riverctl map normal "$mod" Left send-layout-cmd rivercarro "main-location left"
riverctl declare-mode passthrough
riverctl map normal "$mod" F11 enter-mode passthrough
riverctl map passthrough "$mod" F11 enter-mode normal

for mode in normal locked; do
	riverctl map "$mode" None XF86Eject spawn 'eject -T'
	riverctl map "$mode" None XF86AudioRaiseVolume spawn 'pamixer -i 5'
	riverctl map "$mode" None XF86AudioLowerVolume spawn 'pamixer -d 5'
	riverctl map "$mode" None XF86AudioMute spawn 'pamixer --toggle-mute'
	riverctl map "$mode" None XF86AudioMedia spawn 'playerctl play-pause'
	riverctl map "$mode" None XF86AudioPlay spawn 'playerctl play-pause'
	riverctl map "$mode" None XF86AudioPrev spawn 'playerctl previous'
	riverctl map "$mode" None XF86AudioNext spawn 'playerctl next'
	riverctl map "$mode" None XF86MonBrightnessUp spawn 'brightnessctl set +5%'
	riverctl map "$mode" None XF86MonBrightnessDown spawn 'brightnessctl set 5%-'
done

# hacky way of making everything have borders
riverctl rule-add ssd

riverctl background-color 0x00000000
riverctl border-color-focused 0xbe95ffff
riverctl border-color-unfocused 0x00000000

riverctl keyboard-layout -options compose:ralt us
riverctl set-repeat 50 300

riverctl xcursor-theme "Simp1e-Adw-Dark"

riverctl default-layout rivercarro
rivercarro -inner-gaps 8 -outer-gaps 10 -no-smart-gaps &
