# Sway config file
#
# Mostly copy-pasted from my i3 config
#

set $mod Mod4

exec --no-startup-id env > ~/.sway.env

# Use monitor names as kernel names can move
output "Iiyama North America X2485 1120023602183" pos 0    0 res 1920x1200
output "Dell Inc. DELL U2722D JDFN6P3" pos 1920 0 res 2560x1440
output "Iiyama North America X2485 1120023602184" pos 4480 0 res 1920x1200

# Keyboard Inputs

input * {
    xkb_layout "gb"
    xkb_options "ctrl:nocaps"
}

# background, screensaver and locking
exec swayidle -w timeout 1800 'swaylock -f -c 000000' timeout 1800 'swaymsg "output * dpms off"' resume 'swaymsg "output * dpms on"' before-sleep 'swaylock -f -c 000000'
bindsym $mod+l exec swaylock -c 334433

# notifications
exec swaync

# Toggle control center
bindsym $mod+Shift+n exec swaync-client -t -sw

# gamma adjustment
exec gammastep-indicator

##### End of start-up apps #####

# font for window titles. ISO 10646 = Unicode
font pango:monospace 10

# Use Mouse+$mod to drag floating windows to their wanted position
floating_modifier $mod

# Disable mouse focus
focus_follows_mouse no

# start a terminal
# My Ubuntu system at work has higher DPI screens and things in a different place
exec foot --server
bindsym $mod+Return exec "~/.config/i3/terminal.sh"
bindsym $mod+Shift+Return exec x-terminal-emulator
bindsym $mod+x exec "~/bin/new-emacs-frame.sh"

# kill focused window
bindsym $mod+Shift+Q kill

# Start program launcher
# (this searches for .desktop files instead of any $PATH)
bindsym $mod+d exec "rofi -combi-modi drun,run -show combi -modi combi -display-combi run:"
bindsym $mod+s exec "rofi -modi ssh -show ssh -display-ssh ssh: -ssh-command '/home/alex/.config/i3/ssh.sh ssh {host}'"
bindsym $mod+m exec "rofi -modi ssh -show ssh -display-ssh mosh: -ssh-command '/home/alex/.config/i3/ssh.sh mosh {host}'"

# window selector
exec env RUST_BACKTRACE=1 ~/.cargo/bin/swayrd > ~/tmp/swayrd.log 2>&1
bindsym $mod+Tab exec "~/.cargo/bin/swayr switch-window"

# screenshots
bindsym Print exec "~/bin/sway-interactive-screenshot"
bindsym Shift+Print exec "~/bin/sway-interactive-screenshot --video"

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

# focus the parent container
bindsym $mod+Home focus parent

# Move window
bindsym $mod+Shift+Left move left
bindsym $mod+Shift+Down move down
bindsym $mod+Shift+Up move up
bindsym $mod+Shift+Right move right

# enter fullscreen mode for the focused container
bindsym $mod+f fullscreen

# change container layout (stacked, tabbed, default)
workspace_layout tabbed
bindsym $mod+w layout tabbed
bindsym $mod+e layout default
bindsym $mod+v split v
bindsym $mod+h split h

# toggle tiling / floating
bindsym $mod+space floating toggle

# Scratchpad operations
# Make the currently focused window a scratchpad
bindsym $mod+Shift+minus move scratchpad
bindsym $mod+Shift+XF86HomePage move scratchpad
bindsym $mod+Shift+XF86Calculator move scratchpad

# Show the first scratchpad window
bindsym $mod+minus scratchpad show
bindsym $mod+XF86HomePage scratchpad show
bindsym $mod+XF86Calculator scratchpad show

# focus the child container
#bindcode $mod+d focus child

# allow us to rename a workspace (mirrors tmux, screen)
#bindsym $mod+a exec i3-input -F 'rename workspace to %s' -P 'New name: '

# switch to workspace
bindsym $mod+0 workspace "0: Main"
bindsym $mod+1 workspace "1: Shells"
bindsym $mod+2 workspace "2: Work"
bindsym $mod+3 workspace "3: The Cloud!"
bindsym $mod+4 workspace "4: Docs"
bindsym $mod+5 workspace number 5
bindsym $mod+6 workspace number 6
bindsym $mod+7 workspace number 7
bindsym $mod+8 workspace "8: Media"
bindsym $mod+9 workspace "9: Admin"


# move focused container to workspace
# not keymap aware....
bindsym $mod+Shift+0 move container to workspace "0: Main"
bindsym $mod+Shift+1 move container to workspace "1: Shells"
bindsym $mod+Shift+2 move container to workspace "2: Work"
bindsym $mod+Shift+3 move container to workspace "3: The Cloud!"
bindsym $mod+Shift+4 move container to workspace "4: Docs"
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 "8: Media"
bindsym $mod+Shift+9 move container to workspace "9: Admin"

bindsym $mod+XF86Launch5 move workspace to output "Iiyama North America X2485 1120023602183"
bindsym $mod+XF86Favorites move workspace to output "Dell Inc. DELL U2722D JDFN6P3"
bindsym $mod+XF86Launch9 move workspace to output "Iiyama North America X2485 1120023602184"

# reload the configuration file
bindsym $mod+Shift+C reload
# restart i3 inplace (preserves your layout/session, can be used to upgrade i3)
bindsym $mod+Shift+R restart
# exit i3 (logs you out of your X session)
bindsym $mod+Shift+E exit

# resize window (you can also use the mouse for that)
bindsym $mod+r mode "resize"
mode "resize" {
        # These bindings trigger as soon as you enter the resize mode
	bindsym Left  resize shrink width 10 px or 10 ppt
        bindsym Up    resize shrink height 10 px or 10 ppt
        bindsym Down  resize grow height 10 px or 10 ppt
        bindsym Right resize grow width 10 px or 10 ppt

        # back to normal: Enter or Escape
        bindsym Return mode "default"
        bindsym Escape mode "default"
}


# Start swaybar to display a workspace bar (plus the system information from i3blocks)
bar {
    id bar-0
    font pango:monospace 12, FontAwesome 6 Brands:style=Regular 12
    position bottom
    status_command /home/alex/.cargo/bin/i3status-rs /home/alex/.config/i3status-rs/config.toml
    colors {
        separator #666666
        background #222222
        statusline #dddddd
        focused_workspace #0088CC #0088CC #ffffff
        active_workspace #333333 #333333 #ffffff
        inactive_workspace #333333 #333333 #888888
        urgent_workspace #2f343a #900000 #ffffff
    }
}

# Applictation dependent mapping
for_window [title="QEMU"] floating enable
for_window [title="TextArea"] floating enable
for_window [title="Atomic Chrome:"] floating enable
for_window [title="Edit with Emacs FRAME"] floating enable

# Multimedia Keys
bindsym XF86AudioRaiseVolume exec --no-startup-id wpctl set-volume -l 1.5 @DEFAULT_AUDIO_SINK@ 5%+ && killall -s 44 i3blocks
bindsym XF86AudioLowerVolume exec --no-startup-id wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%- && killall -s 44 i3blocks
bindsym XF86AudioMute exec --no-startup-id wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle && killall -s 44 i3blocks

# Final things
# ensure environment is correctly set for portals (should be systemd --user)
exec systemctl --user import-environment WAYLAND_DISPLAY XDG_CURRENT_DESKTOP
#exec dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP=sway