### Declare variables
set {
    # Primary mod key.
    # Mod4 is Meta key, Mod1 is Alt.
    $mod Mod4

    # Add Vim key support
    $left h
    $down j
    $up k
    $right l

    # Default terminal emulator
    $term footclient

    # Application launcher
    $launcher fuzzel
    
    # Power Menu
    $powermenu ~/.config/sway/scripts/power_menu.sh

    # Application menu
    $menu nwg-drawer
}

### Key bindings
#
# Basics:
#
bindsym {
    # Launch the terminal
    $mod+Return exec $term

    # Open the power menu
    Ctrl+Alt+Delete exec $powermenu

    # Kill focused window
	$mod+Backspace kill
	$mod+q kill

    # Start your launcher
    $mod+d exec $launcher

    # Menu
    $mod+Shift+d exec $menu

    # Switch to the last recently used window
    Alt+Tab exec swayr switch-to-urgent-or-lru-window

    # Lock screen
    $mod+f1 exec gtklock

    # Activities
    $mod+Tab exec swayr switch-window

    # Activities and workspaces
    $mod+Shift+Tab exec swayr switch-workspace-or-window

    # Open this file in a floating window
    $mod+Shift+i exec $term -T sway_config -e micro ~/.config/sway/config.d/default

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

#
# Moving around:
#
bindsym {
    # Change window focus
    $mod+Left focus left
    $mod+Down focus down
    $mod+Up focus up
    $mod+Right focus right
    # Vim key support
    $mod+$left focus left
    $mod+$down focus down
    $mod+$up focus up
    $mod+$right focus right

    # Move the focused window
    $mod+Shift+Left move left
    $mod+Shift+Down move down
    $mod+Shift+Up move up
    $mod+Shift+Right move right
    # Vim key support
    $mod+Shift+$left move left
    $mod+Shift+$down move down
    $mod+Shift+$up move up
    $mod+Shift+$right move right
}

#
# Workspaces:
#
bindsym {
    # Switch to workspace
    $mod+1 workspace number 1
    $mod+2 workspace number 2
    $mod+3 workspace number 3
    $mod+4 workspace number 4
    $mod+5 workspace number 5
    $mod+6 workspace number 6
    $mod+7 workspace number 7
    $mod+8 workspace number 8
    $mod+9 workspace number 9
    $mod+0 workspace number 10
    # Move focused container to workspace
    $mod+Shift+1 move container to workspace number 1
    $mod+Shift+2 move container to workspace number 2
    $mod+Shift+3 move container to workspace number 3
    $mod+Shift+4 move container to workspace number 4
    $mod+Shift+5 move container to workspace number 5
    $mod+Shift+6 move container to workspace number 6
    $mod+Shift+7 move container to workspace number 7
    $mod+Shift+8 move container to workspace number 8
    $mod+Shift+9 move container to workspace number 9
    $mod+Shift+0 move container to workspace number 10
}

#
# Layout stuff:
#
bindsym {
    # Set how the current window will be split
    # Split the window vertically
    $mod+v splitv
    # Split the window horizontally
    $mod+Shift+v splith

    # Switch the current container between different layout styles
    $mod+Shift+s layout stacking
    $mod+Shift+w layout tabbed
    $mod+Shift+e layout toggle split

    # Make the current focus fullscreen
    $mod+f fullscreen

    # Toggle between tiling and floating mode
    $mod+space floating toggle

    # Swap focus between the tiling area and the floating area
    $mod+Shift+space focus mode_toggle

    # Move focus to the parent container
    $mod+a focus parent
}

#
# Scratchpad:
#
# Sway has a "scratchpad", which is a bag of holding for windows.
# You can send windows there and get them back later.

bindsym {
    # Move the currently focused window to the scratchpad
    $mod+Shift+minus move scratchpad

    # Show the next scratchpad window or hide the focused scratchpad window.
    # If there are multiple scratchpad windows, this command cycles through them.
    $mod+minus scratchpad show
}

#
# Resizing containers:
#
bindsym {
    # Resize with arrow keys
    $mod+ctrl+Right resize shrink width 10 px
    $mod+ctrl+Up resize grow height 10 px
    $mod+ctrl+Down resize shrink height 10 px
    $mod+ctrl+Left resize grow width 10 px
    # Resize with Vim keys
    $mod+ctrl+l resize shrink width 10 px
    $mod+ctrl+k resize grow height 10 px
    $mod+ctrl+j resize shrink height 10 px
    $mod+ctrl+h resize grow width 10 px
}

# Resize floating windows with mouse scroll:
bindsym --whole-window --border {
    # Resize vertically
    $mod+button4 resize shrink height 5 px or 5 ppt
    $mod+button5 resize grow height 5 px or 5 ppt
    # Resize horizontally
    $mod+Shift+button4 resize shrink width 5 px or 5 ppt
    $mod+Shift+button5 resize grow width 5 px or 5 ppt
}

# Move windows by holding down $mod and left mouse button.
# Resize them with right mouse button + $mod.
# Change "normal" to "inverse" to switch left and right
floating_modifier $mod normal

#
# Media Keys
#
bindsym {
    # Volume
    XF86AudioRaiseVolume exec pamixer -ui 2
    XF86AudioLowerVolume exec pamixer -ud 2
    XF86AudioMute exec pamixer --toggle-mute

    # Player
    XF86AudioPlay exec playerctl play-pause
    XF86AudioNext exec playerctl next
    XF86AudioPrev exec playerctl previous

    # Backlight
    XF86MonBrightnessUp exec brightnessctl -c backlight set +5%
    XF86MonBrightnessDown exec brightnessctl -c backlight set 5%-
}

#
# App shortcuts
#
bindsym {
    # Launch the file explorer
    $mod+e exec thunar
    # Launch the browser
    $mod+b exec firedragon
    # Launch the text editor
    $mod+t exec mousepad
    # Launch the calculator
    $mod+c exec galculator
    # Launch the clipboard manager
    $mod+Ctrl+v exec cliphist list | fuzzel -d -w 90 -l 30 -p "Select an entry to copy it to your clipboard buffer:"| cliphist decode | wl-copy
    # Delete an entry from the clipboard manager
    $mod+Ctrl+x exec cliphist list | fuzzel -d -w 90 -l 30 -t cc9393ff -S cc9393ff -p "Select an entry to delete it from cliphist:"| cliphist delete
    # Note: you can clear all cliphist entries by running `cliphist wipe`
}

#
# Screenshots
#
bindsym {
    # Snip a selection and pipe to swappy
    print exec grim -g "$(slurp)" - | swappy -f -
    # Screenshot a window and pipe to swappy
    Ctrl+Print exec ~/.config/sway/scripts/screenshot_window.sh
    # Screenshot the current display and pipe to swappy
    Shift+Print exec ~/.config/sway/scripts/screenshot_display.sh
}

