
# @reference: man 5 sway
# super for modifier
set $mod Mod4

# define service variables
set $launcher wofi --show=run --lines=5 --prompt=""
set $applauncher wofi --show=drun --lines=5 --prompt=""
set $term alacritty
set $browser brave
set $editor alacritty -e nvim
set $files pcmanfm
set $steam steam -gamepadui

# @note: we use the default wallpaper as a backup
output * bg /usr/share/backgrounds/sway/Sway_Wallpaper_Blue_1920x1080.png fill

# @note: cursor theme and size set env vars; may not apply to all applications
seat seat0 xcursor_theme Vimix-cursors 36

# window manager commands
bindsym $mod+Shift+c reload
bindsym $mod+Shift+q kill
bindsym $mod+x exec "systemctl --user import-environment; systemctl --user stop sway-session.target; swaymsg exit"
bindsym $mod+p focus parent

# split workspace horizontal and vertical
bindsym $mod+v splitv
bindsym $mod+h splith

# change workspace layout
bindsym $mod+Shift+e layout toggle split
bindsym $mod+Shift+s layout stacking
bindsym $mod+Shift+w layout tabbed

# fullscreen toggle
bindsym $mod+f fullscreen

# floating window controls:
#   super+l to toggle floating mode
#   super+_shift+l to switch focus to floating window(s)
#   hold super then use left click to drag and right click to resize
bindsym $mod+l floating toggle
bindsym $mod+Shift+l focus mode_toggle
floating_modifier $mod normal

# Move your focus around
bindsym $mod+Left focus left
bindsym $mod+Down focus down
bindsym $mod+Up focus up
bindsym $mod+Right focus right

# Move the focused window with the same, but add Shift
bindsym $mod+Shift+Left move left
bindsym $mod+Shift+Down move down
bindsym $mod+Shift+Up move up
bindsym $mod+Shift+Right move right

mode "resize" {
    bindsym Left resize shrink width 10px
    bindsym Down resize grow height 10px
    bindsym Up resize shrink height 10px
    bindsym Right resize grow width 10px
    bindsym Return mode "default"
    bindsym Escape mode "default"
}
bindsym $mod+r mode "resize"

# navigate workspaces
bindsym $mod+1 workspace number 1
bindsym $mod+2 workspace number 2
bindsym $mod+3 workspace number 3
bindsym $mod+4 workspace number 4
bindsym $mod+5 workspace number 5
bindsym $mod+6 workspace number 6
bindsym $mod+7 workspace number 7
bindsym $mod+8 workspace number 8
bindsym $mod+9 workspace number 9
bindsym $mod+0 workspace number 10
bindsym Control+Alt+Right workspace next
bindsym Control+Alt+Left workspace prev

# send window to workspace
bindsym $mod+Shift+1 move container to workspace number 1, workspace number 1
bindsym $mod+Shift+2 move container to workspace number 2, workspace number 2
bindsym $mod+Shift+3 move container to workspace number 3, workspace number 3
bindsym $mod+Shift+4 move container to workspace number 4, workspace number 4
bindsym $mod+Shift+5 move container to workspace number 5, workspace number 5
bindsym $mod+Shift+6 move container to workspace number 6, workspace number 6
bindsym $mod+Shift+7 move container to workspace number 7, workspace number 7
bindsym $mod+Shift+8 move container to workspace number 8, workspace number 8
bindsym $mod+Shift+9 move container to workspace number 9, workspace number 9
bindsym $mod+Shift+0 move container to workspace number 10, workspace number 10
bindsym $mod+Control+Right move container to workspace next, workspace next
bindsym $mod+Control+Left move container to workspace prev, workspace prev

# services
bindsym $mod+Space exec $launcher
bindsym $mod+Shift+F2 exec $applauncher
bindsym $mod+t exec $term
bindsym $mod+b exec $files
bindsym $mod+e exec $editor
bindsym $mod+w exec $browser
bindsym $mod+g exec $steam
bindsym $mod+Ctrl+3 exec screenshot
bindsym Print exec screenshot
bindsym $mod+Ctrl+4 exec screenshot-selection
bindsym Shift+Print exec screenshot-selection

# multimedia keys
bindsym XF86AudioRaiseVolume exec pactl set-sink-volume @DEFAULT_SINK@ +5%
bindsym XF86AudioLowerVolume exec pactl set-sink-volume @DEFAULT_SINK@ -5%
bindsym XF86AudioMute exec pactl set-sink-mute @DEFAULT_SINK@ toggle
bindsym XF86AudioMicMute exec pactl set-source-mute @DEFAULT_SOURCE@ toggle
bindsym XF86AudioPlay exec playerctl -p mpv play-pause
bindsym XF86AudioNext exec playerctl -p mpv next
bindsym XF86AudioPrev exec playerctl -p mpv previous
bindsym XF86MonBrightnessUp exec brightnessctl set +5%
bindsym XF86MonBrightnessDown exec brightnessctl set 5%-
bindsym Shift+XF86MonBrightnessUp exec brightnessctl s 100%
bindsym Shift+XF86MonBrightnessDown exec brightnessctl s 0%

# global push-to-talk & toggle
bindsym $mod+m exec pactl set-source-mute @DEFAULT_SOURCE@ 0 # mute mic
bindsym --release $mod+m exec pactl set-source-mute @DEFAULT_SOURCE@ 1 # unmute mic
bindsym $mod+Shift+m exec pactl set-source-mute @DEFAULT_SOURCE@ toggle

# Tag xwayland windows with [X]
# for_window [shell="xwayland"] title_format "<span>[X] %title゜</span>"

# classify sane defaults for window management
for_window [window_role="About"] floating enable
for_window [window_role="pop-up"] floating enable
for_window [window_role="bubble"] floating enable
for_window [window_role="dialog"] floating enable
for_window [window_role="task_dialog"] floating enable
for_window [window_role="Preferences"] floating enable

for_window [window_type="dialog"] floating enable
for_window [window_type="menu"] floating enable

for_window [class="Wine"] floating enable

for_window [app_id="pavucontrol"] floating enable
for_window [app_id="floating"] floating enable

for_window [title="(?i)(?:copying|deleting|moving)"] floating enable
for_window [title="Save File"] floating enable
for_window [title="^Open File$"] floating enable

# https://github.com/ValveSoftware/steam-for-linux/issues/1040
for_window [class="^Steam$" title="^Friends$"] floating enable
for_window [class="^Steam$" title="Steam - News"] floating enable
for_window [class="^Steam$" title=".* - Chat"] floating enable
for_window [class="^Steam$" title="^Settings$"] floating enable
for_window [class="^Steam$" title=".* - event started"] floating enable
for_window [class="^Steam$" title=".* CD key"] floating enable
for_window [class="^Steam$" title="^Steam - Self Updater$"] floating enable
for_window [class="^Steam$" title="^Screenshot Uploader$"] floating enable
for_window [class="^Steam$" title="^Steam Guard - Computer Authorization Required$"] floating enable
for_window [title="^Steam Keyboard$"] floating enable

# @reference: man 5 sway-bar
# @note: we now launch waybar via systemctl --user enable waybar.service
#bar {
#    swaybar_command waybar
#}

# load additional configuration
include /etc/sway/config.d/*

# load user configuration from local sub-directory
#
# @reference: man 5 sway-output
# @reference: swaymsg -t get_outputs
#
# example with custom resolution and dual monitors:
#
#   output HDMI-A-1 mode --custom 2560x1440@60Hz position 0,0 adaptive_sync on
#   output DP-1 mode 3440x1440@144Hz pos 3440 0 adaptive_sync on
#
# @reference: man 5 sway-input
# @reference: swaymsg -t get_inputs
#
# Example configuration:
#
#   input "2:14:SynPS/2_Synaptics_TouchPad" {
#       dwt enabled
#       tap enabled
#       natural_scroll enabled
#       middle_emulation enabled
#   }
include ~/.config/sway/config.d/*

# start sway session in systemd to intialize services
exec_always "systemctl --user import-environment; systemctl --user start sway-session.target"
