exec dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=sway
exec_always autotiling -l 2
exec_always ~/.config/sway/scripts/workspace-colors.py
exec_always eww daemon && (eww open bar0 || true) && (eww open bar1 || true)
exec_always mako

exec /usr/libexec/polkit-mate-authentication-agent-1

exec swayidle -w \
      timeout 900 '~/.local/bin/smart-dim.sh' \
      resume 'brightnessctl -r'

exec sh -c 'sleep 1 && timeout 0.05 speaker-test -t sine -f 800 >/dev/null 2>&1 & sleep 0.2 && wpctl set-volume @DEFAULT_AUDIO_SINK@ 0.2'


mouse_warping container
focus_on_window_activation focus

include $HOME/.config/sway/windowrules
include $HOME/.config/sway/look
include $HOME/.config/sway/monitors
include $HOME/.config/sway/input

### Variables
set $mod Mod4
set $alt Mod1
# Home row direction keys, like vim
set $left h
set $down j
set $up k
set $right l

set $term wezterm
set $menu fuzzel
set $browser firefox

### Key bindings
# Basics:
bindsym $mod+Return exec $term
bindsym $mod+Shift+Return exec ~/.config/sway/scripts/smart-term.sh
bindsym $mod+q kill
bindsym $mod+space exec "pkill fuzzel || fuzzel"
bindsym $mod+b exec $browser
bindsym $mod+Shift+g exec ~/.config/sway/scripts/gif-record.sh

# Screenshots
bindsym $mod+p exec grim /tmp/screenshot-$(date +%Y%m%d-%H%M%S).png && wl-copy < $(ls -t /tmp/screenshot-*.png | head -1)
bindsym $mod+Shift+p exec grim -g "$(slurp)" /tmp/screenshot-$(date +%Y%m%d-%H%M%S).png && wl-copy < $(ls -t /tmp/screenshot-*.png | head -1)

# Screen recording
bindsym $mod+o exec wf-recorder -g "$(slurp)" -f /tmp/recording-$(date +%Y%m%d-%H%M%S).mp4
bindsym $mod+Shift+o exec pkill --euid "$USER" --signal SIGINT wf-recorder

# mouse button for dragging.
floating_modifier $mod normal

# Reload the configuration file
bindsym $mod+Shift+c reload

# Exit sway (logs you out of your Wayland session)
bindsym $mod+Shift+e exec swaynag -t warning -m 'You pressed the exit shortcut. Do you really want to exit sway? This will end your Wayland session.' -B 'Yes, exit sway' 'swaymsg exit'

bindsym $mod+$left focus left
bindsym $mod+$down focus down
bindsym $mod+$up focus up
bindsym $mod+$right focus right
# Or use $mod+[up|down|left|right]
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
# Ditto, with arrow keys
bindsym $mod+Shift+Left move left
bindsym $mod+Shift+Down move down
bindsym $mod+Shift+Up move up
bindsym $mod+Shift+Right move right

# Workspaces:
# Switch to workspace
bindsym $mod+1 workspace number 1
bindsym $mod+a workspace number 1
bindsym $mod+2 workspace number 2
bindsym $mod+s workspace number 2
bindsym $mod+3 workspace number 3
bindsym $mod+d workspace number 3
bindsym $mod+4 workspace number 4
bindsym $mod+z workspace number 4
bindsym $mod+5 workspace number 5
bindsym $mod+x 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
# Move focused container to workspace
bindsym $mod+Shift+1 move container to workspace number 1
bindsym $mod+Shift+a move container to workspace number 1
bindsym $mod+Shift+2 move container to workspace number 2
bindsym $mod+Shift+s move container to workspace number 2
bindsym $mod+Shift+3 move container to workspace number 3
bindsym $mod+Shift+d move container to workspace number 3
bindsym $mod+Shift+4 move container to workspace number 4
bindsym $mod+Shift+z move container to workspace number 4
bindsym $mod+Shift+5 move container to workspace number 5
bindsym $mod+Shift+x 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
# Note: workspaces can have any name you want, not just numbers.
# We just use 1-10 as the default.
#
# Layout stuff:

# bindsym $mod+s layout stacking
# bindsym $mod+w layout tabbed
bindsym $mod+t toggle split

bindsym $mod+f fullscreen

bindsym $mod+Shift+space floating toggle

mode "resize" {
    # left will shrink the containers width
    # right will grow the containers width
    # up will shrink the containers height
    # down will grow the containers height
    bindsym $left resize shrink width 50px
    bindsym $down resize grow height 50px
    bindsym $up resize shrink height 50px
    bindsym $right resize grow width 50px

    # Ditto, with arrow keys
    bindsym Left resize shrink width 50px
    bindsym Down resize grow height 50px
    bindsym Up resize shrink height 50px
    bindsym Right resize grow width 50px

    # Return to default mode
    bindsym Return mode "default"
    bindsym Escape mode "default"
}
bindsym $mod+r mode "resize"
#
# Toggle dark/light theme
bindsym $mod+y exec ~/.config/sway/scripts/toggle-theme.sh

# Utilities:
#
    # Special keys to adjust volume via PulseAudio
    bindsym --locked XF86AudioMute exec pactl set-sink-mute \@DEFAULT_SINK@ toggle
    bindsym --locked XF86AudioLowerVolume exec pactl set-sink-volume \@DEFAULT_SINK@ -5%
    bindsym --locked XF86AudioRaiseVolume exec pactl set-sink-volume \@DEFAULT_SINK@ +5%
    bindsym --locked XF86AudioMicMute exec pactl set-source-mute \@DEFAULT_SOURCE@ toggle
    # Special keys to adjust brightness via brightnessctl
    bindsym --locked XF86MonBrightnessDown exec brightnessctl set 1%-
    bindsym --locked XF86MonBrightnessUp exec brightnessctl set 1%+
    bindsym --locked Shift+XF86MonBrightnessUp exec brightnessctl --device=kbd_backlight set 1%+
    bindsym --locked Shift+XF86MonBrightnessDown exec brightnessctl --device=kbd_backlight set 1%-

include /etc/sway/config.d/*
# Machine-local overrides (not tracked in dotfiles)
include $HOME/.config/sway/local.d/*
