# Common settings for most systems.

# GENERAL SETTINGS
# ~~~~~~~~~~~~~~~~

# Use Mouse+$mod to drag and resize windows
floating_modifier $mod

# No auto focussing via mouseover
focus_follows_mouse no


# APPEARANCE
# ~~~~~~~~~~

# Define font
font pango:Liberation Sans 12

# Define colors
client.focused          #880044 #bb0066 #ffffff #9933dd #880044
client.focused_inactive #333333 #5f676a #ffffff #484e50 #5f676a
client.unfocused        #333333 #222222 #888888 #292d2e #222222
client.urgent           #2f343a #c00000 #ffffff #900000 #900000

# Reduce padding in titlebar
titlebar_padding 3

# Hide window borders on workspaces with only one window
hide_edge_borders smart_no_gaps


# XWAYLAND
# ~~~~~~~~

# Add indicator to window title if running on XWayland
for_window [shell="xwayland"] title_format "%title [XWayland]"

# Load X resources
exec "[[ -f ~/.Xresources ]] && xrdb -merge ~/.Xresources"
exec "[[ -f ~/.Xresources.local ]] && xrdb -merge ~/.Xresources.local"


# GENERAL KEYBINDINGS
# ~~~~~~~~~~~~~~~~~~~

# Start a terminal (in default or in floating mode)
bindsym $mod+Return exec $terminal
bindsym $mod+Shift+Return exec $terminal_floating

# Start application launcher
bindsym $mod+d       exec $app_launcher
bindsym $mod+Shift+d exec $app_launcher_alt

# Reload sway config file
bindsym $mod+Shift+c reload

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


# WINDOW MANAGEMENT
# ~~~~~~~~~~~~~~~~~

# Kill focused window
bindsym $mod+q kill

# Change window focus with [hjkl]
bindsym $mod+h focus left
bindsym $mod+j focus down
bindsym $mod+k focus up
bindsym $mod+l focus right

# Move focused window with [hjkl]
bindsym $mod+Shift+h move left
bindsym $mod+Shift+j move down
bindsym $mod+Shift+k move up
bindsym $mod+Shift+l move right

# Split container in horizontal or vertical orientation or undo split
bindsym $mod+s split toggle
bindsym $mod+Shift+s split none

# Change container layout (toggle split orientation, tabbed)
bindsym $mod+e layout toggle split
bindsym $mod+t layout toggle tabbed split

# Focus the parent or child container
bindsym $mod+a focus parent
bindsym $mod+shift+a focus child

# Toggle floating mode for focused window
# TODO: Try different bindings?
bindsym $mod+Shift+space floating toggle
#bindsym $mod+Shift+slash floating toggle

# Switch focus between floating / tiling windows
# TODO: Try different bindings?
bindsym $mod+space focus mode_toggle
#bindsym $mod+slash focus mode_toggle

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

# Switch back and forth between the current and the previous workspace
bindsym $mod+Tab workspace back_and_forth

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

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

# Define resize mode
mode "move & resize" {
    # Set move and resize rates
    set $MOVE_NORMAL    40 px
    set $MOVE_SLOW      10 px
    set $MOVE_FAST     120 px
    set $RESIZE_NORMAL  40 px or  5 ppt
    set $RESIZE_SLOW    10 px or  1 ppt
    set $RESIZE_FAST   120 px or 10 ppt

    # Exit to default mode
    bindsym Return mode "default"
    bindsym Escape mode "default"
    bindsym $mod+r mode "default"

    # Change window focus with mod key (like in regular mode)
    bindsym $mod+h focus left
    bindsym $mod+j focus down
    bindsym $mod+k focus up
    bindsym $mod+l focus right

    # Switch focus between floating / tiling windows
    bindsym $mod+space focus mode_toggle

    # Move focused window with Alt + [hjkl]
    bindsym Mod1+h move left  $MOVE_NORMAL
    bindsym Mod1+j move down  $MOVE_NORMAL
    bindsym Mod1+k move up    $MOVE_NORMAL
    bindsym Mod1+l move right $MOVE_NORMAL

    # Move focused window faster with Shift + Alt + [hjkl]
    bindsym Mod1+Shift+h move left  $MOVE_FAST
    bindsym Mod1+Shift+j move down  $MOVE_FAST
    bindsym Mod1+Shift+k move up    $MOVE_FAST
    bindsym Mod1+Shift+l move right $MOVE_FAST

    # Move focused window slower with Ctrl + Alt + [hjkl]
    bindsym Mod1+Ctrl+h move left  $MOVE_SLOW
    bindsym Mod1+Ctrl+j move down  $MOVE_SLOW
    bindsym Mod1+Ctrl+k move up    $MOVE_SLOW
    bindsym Mod1+Ctrl+l move right $MOVE_SLOW

    # Resize window with [hjkl]
    bindsym h resize shrink width  $RESIZE_NORMAL
    bindsym j resize grow   height $RESIZE_NORMAL
    bindsym k resize shrink height $RESIZE_NORMAL
    bindsym l resize grow   width  $RESIZE_NORMAL

    # Resize window faster with Shift + [hjkl]
    bindsym Shift+h resize shrink width  $RESIZE_FAST
    bindsym Shift+j resize grow   height $RESIZE_FAST
    bindsym Shift+k resize shrink height $RESIZE_FAST
    bindsym Shift+l resize grow   width  $RESIZE_FAST

    # Resize window more precisely with Ctrl + [hjkl]
    bindsym Ctrl+h resize shrink width  $RESIZE_SLOW
    bindsym Ctrl+j resize grow   height $RESIZE_SLOW
    bindsym Ctrl+k resize shrink height $RESIZE_SLOW
    bindsym Ctrl+l resize grow   width  $RESIZE_SLOW

    # Set defined sizes for windows
    bindsym 1 resize set width 25 ppt
    bindsym 2 resize set width 33 ppt
    bindsym 3 resize set width 50 ppt
    bindsym 4 resize set width 67 ppt
    bindsym 5 resize set width 75 ppt
    bindsym 6 resize set width 100 ppt

    bindsym Shift+1 resize set height 25 ppt
    bindsym Shift+2 resize set height 33 ppt
    bindsym Shift+3 resize set height 50 ppt
    bindsym Shift+4 resize set height 67 ppt
    bindsym Shift+5 resize set height 75 ppt
    bindsym Shift+6 resize set height 100 ppt

    bindsym $mod+1 resize set 25 ppt 25 ppt; move position center
    bindsym $mod+2 resize set 33 ppt 33 ppt; move position center
    bindsym $mod+3 resize set 50 ppt 50 ppt; move position center
    bindsym $mod+4 resize set 67 ppt 67 ppt; move position center
    bindsym $mod+5 resize set 75 ppt 75 ppt; move position center
    bindsym $mod+6 resize set 95 ppt 95 ppt; move position center

    # Center floating window with c
    bindsym      c move position center
    bindsym $mod+c move position center
}

# Switch to resize mode
bindsym $mod+r mode "move & resize"


# KEYBINDINGS FOR SYSTEM CONTROL
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# Lock screen
bindsym $mod+Delete exec "swaylock"
bindsym $mod+Shift+Pause exec "swaylock"

# Suspend system
bindsym --locked $mod+Pause exec "systemctl suspend"

# Volume keys (allow on lock screen)
bindsym --locked XF86AudioRaiseVolume exec "volctl up"
bindsym --locked XF86AudioLowerVolume exec "volctl down"
bindsym --locked XF86AudioMute        exec "volctl mute toggle"
