# Sway Configuration

# Variables
# User Variables
set $mod Mod1 
set $menu "rofi -show"
set $term "kitty"
set $browser librewolf 
set $browser-backup "chromium --incognito --high-dpi-support=1.15 --force-device-scale-factor=1.15 --enable-features=WebRTCPipeWireCapturer </dev/null &>/dev/null &"
set $docu zathura 
set $notes "rnote"
set $office "libreoffice"
set $obs "obs"
set $multimc "multimc"
set $tasks "flatpak run io.github.alainm23.planify"
set $lockscreen "swaylock -e -F -f -l --indicator-idle-visible"

# Personal Scripts
set $nightlight "~/.scripts/sunset"
set $shot "~/.scripts/screenshot -s -c ~/Documents/Screenshots"

## Information Scripts
set $time "~/.scripts/notifs/time"
set $battinfo "~/.scripts/notifs/battery-status"
set $otherinfo "~/.scripts/notifs/info"
set $window_switch "~/.scripts/notifs/window"

## Volume Scripts
set $volinc "wpctl set-volume -l 1.0 @DEFAULT_AUDIO_SINK@ 5%+ && ~/.scripts/notifs/volume inc"
set $voldec "wpctl set-volume -l 1.0 @DEFAULT_AUDIO_SINK@ 5%- && ~/.scripts/notifs/volume dec"
set $volmute_toggle "wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle && ~/.scripts/notifs/volume mute-toggle"

## Microphone Scripts
set $micInc "wpctl set-volume -l 1.0 @DEFAULT_AUDIO_SOURCE@ 5%+ && ~/.scripts/notifs/volume micInc"
set $micDec "wpctl set-volume -l 1.0 @DEFAULT_AUDIO_SOURCE@ 5%- && ~/.scripts/notifs/volume micDec"
set $micMute "wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle && ~/.scripts/notifs/volume micMute"

## Brightness Scripts
set $brightup "xbacklight -inc 5 && ~/.scripts/notifs/brightness inc"
set $brightdown "xbacklight -dec 5 && ~/.scripts/notifs/brightness dec"


# Directions
set $left h
set $down j
set $up k
set $right l

# Monitors
set $laptop "eDP-1"
set $external "HDMI-A-2"

# Workspaces
workspace 1 output $laptop
workspace 2 output $laptop
workspace 3 output $laptop
workspace 4 output $laptop
workspace 5 output $laptop
workspace 6 output $laptop
workspace 7 output $laptop
workspace 8 output $laptop
workspace 9 output $laptop
workspace 10 output $laptop

# Bindings
# Applicantions
bindsym Print exec $shot
bindsym Shift+Super+S exec $shot
bindsym $mod+Return exec $term 
bindsym $mod+Ctrl+2 exec $browser 
bindsym $mod+Ctrl+3 exec $docu 
bindsym $mod+Ctrl+4 exec $tasks
bindsym $mod+Ctrl+5 exec $notes 
bindsym $mod+Ctrl+6 exec $office
bindsym $mod+Ctrl+7 exec $obs
bindsym $mod+Ctrl+8 exec $browser-backup
bindsym $mod+Ctrl+0 exec $nightlight
bindsym $mod+Ctrl+Grave exec $menu
bindsym Shift+Ctrl+L exec $lockscreen

# Scripts
bindsym $mod+t exec $time
bindsym $mod+y exec $battinfo
bindsym $mod+u exec $otherinfo


# Thinkpad Keys (Volume, Brightness, etc)
# Volume / Mute
bindsym XF86AudioRaiseVolume exec $volinc
bindsym XF86AudioLowerVolume exec $voldec
bindsym XF86AudioMute exec $volmute_toggle
# Microphone
bindsym XF86_AudioMicMute exec $micMute
## For External Keyboard
bindsym Shift+XF86_AudioMute exec $micMute
bindsym Shift+XF86AudioRaiseVolume exec $micInc
bindsym Shift+XF86AudioLowerVolume exec $micDec

# Brightness
bindsym XF86MonBrightnessUp exec $brightup
bindsym XF86MonBrightnessDown exec $brightdown

# Brightness (Ext. Keyboard)
bindsym XF86AudioNext exec $brightup
bindsym XF86AudioPrev exec $brightdown

# Monitor Toggle
bindsym XF86Display exec swaymsg output $laptop toggle
bindsym $mod+n exec swaymsg output $laptop toggle # if on the HDMI Monitor
bindsym $mod+i exec swaymsg output $external pos 0 0 transform 270
bindsym $mod+o exec swaymsg output $external pos 0 0 transform 0

## Mirror Laptop Display
bindsym $mod+Shift+m exec wl-mirror eDP-1
bindsym $mod+Shift+b exec wl-mirror HDMI-A-2

# Containers
bindsym $mod+F4 kill
bindsym $mod+f fullscreen
bindsym $mod+Shift+$left move left
bindsym $mod+Shift+$down move down
bindsym $mod+Shift+$up move up
bindsym $mod+Shift+$right move right
# Container Split
bindsym $mod+b split horizontal
bindsym $mod+v split vertical

# Floating Containers
bindsym $mod+Space floating toggle
floating_modifier $mod normal

# Switching to Workspaces
bindsym $mod+1 exec "$window_switch 1"
bindsym $mod+2 exec "$window_switch 2"
bindsym $mod+3 exec "$window_switch 3"
bindsym $mod+4 exec "$window_switch 4"
bindsym $mod+5 exec "$window_switch 5"
bindsym $mod+6 exec "$window_switch 6"
bindsym $mod+7 exec "$window_switch 7"
bindsym $mod+8 exec "$window_switch 8"
bindsym $mod+9 exec "$window_switch 9"
bindsym $mod+0 exec "$window_switch 10"

bindsym $mod+Tab workspace back_and_forth


# Moving Focused Container to Workspaces
bindsym $mod+Shift+1 move container to workspace number 1
bindsym $mod+Shift+2 move container to workspace number 2
bindsym $mod+Shift+3 move container to workspace number 3
bindsym $mod+Shift+4 move container to workspace number 4
bindsym $mod+Shift+5 move container to workspace number 5
bindsym $mod+Shift+6 move container to workspace number 6
bindsym $mod+Shift+7 move container to workspace number 7
bindsym $mod+Shift+8 move container to workspace number 8
bindsym $mod+Shift+9 move container to workspace number 9
bindsym $mod+Shift+0 move container to workspace number 10

# Changing Focus Between Containers
bindsym $mod+$left focus left
bindsym $mod+$down focus down
bindsym $mod+$up   focus up
bindsym $mod+$right focus right

# Reload Configuration
bindsym $mod+Shift+c exec swaymsg reload 

# Exit Sway
bindsym $mod+Shift+e exec swaynag -t warning -m 'Do you really want to exit sway?' -B 'Yes, exit sway' 'swaymsg exit' 

## Laptop Lid
bindswitch lid:on output eDP-1 disable # Display turns off when lid is closed
bindswitch lid:off output eDP-1 enable # Display turns on when lid is open


# Sway Configuration
# Wallpaper
output * bg $HOME/.config/wallpaper/morning fog.jpg fill

# Enable xwayland
xwayland enable

# Disable Title Bar for all containers
default_border pixel 3
default_floating_border pixel 3

# Hardware Devices (note: use swaymsg -t get_inputs for identifiers)
# Touchpad Configuration
input "1267:32:Elan_Touchpad" {
	accel_profile flat
	pointer_accel 0.4
	tap enabled
	natural_scroll enabled
	scroll_factor 0.25
}

# Mouse Configuration
# Old Wireless Mouse
input "1133:16471:Logitech_B330/M330/M3" {
		accel_profile flat
		pointer_accel -0.4
}

# Logitech G304 (not really, knockoff)
input "12625:4128:YICHIP_2.4G_Receiver_Mouse" {
		accel_profile "flat"
		#pointer_accel -0.6
		pointer_accel -0.3
}

input "1133:49295:Logitech_G403_HERO_Gaming_Mouse" {
		accel_profile "flat"
		pointer_accel -0.7
}

input "5215:761:YICHIP_JLab_Work_Mouse" {
	accel_profile "flat"
	pointer_accel 0.0
}

# Container Tweaks
for_window [app_id = "librewolf" title = "About"] floating enable
for_window [app_id = "librewolf" title = "Library"] floating enable, border pixel 1,
for_window [app_id = "qbittorrent"] floating enable
for_window [app_id = "localsend"] floating enable

for_window [app_id="looking-glass-client"] max_render_time 10

#client.<class>         <border>  <background>    <text>      <indicator>   <child_border> 

client.focused  #2c2c2c #dddfe2 #000000 #000000 #095837 

#client.focused_inactive "#23242a" "#000000"  "#666666"   "#000000"     "#999999"

#client.unfocused        "#666666" "#fff5e5"      "#666666"   "#000000"     "#999999"


# Extra Configurations
include monitor.swayconfig

# GTK Configuration (More specifically: Cursor Configuration)
# Giving my thanks to: https://www.reddit.com/r/swaywm/comments/zmn263/comment/lweur89/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button
set $gnome_interface_schema "org.gnome.desktop.interface"
exec_always {
	gsettings set $gnome_interface_schema cursor-theme Adwaita
	gsettings set $gnome_interface_schema cursor-size 40
	gsettings set $gnome_interface_schema color-scheme prefer-dark
	gsettings set $gnome_interface_schema scaling-factor 1.5
}

seat seat0 xcursor_theme Adwaita 30

# Programs to always execute
exec_always {
	"~/.scripts/daemons/battery-daemon"
}

# Execute Once
exec swayidle -w \
	timeout 300 'swaylock -f' \
	timeout 3600 'systemctl suspend' \
	timeout 1800 'swaymsg "output * power off"' \
	resume 'swaymsg "output * power on"' \
	before-sleep 'swaylock -f'

exec wayland-pipewire-idle-inhibit -w -q
exec /usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1

seat * idle_inhibit keyboard pointer

include /etc/sway/config.d/*
