# {{@@ header() @@}}
#  _____      ____ _ _   _
# / __\ \ /\ / / _` | | | |
# \__ \\ V  V / (_| | |_| |
# |___/ \_/\_/ \__,_|\__, |
#                    |___/

# Variables {{{
#
    # Logo key.
    set $mod Mod4
    # Home row direction keys, like vim
    set $left       {{@@ key.left @@}}
    set $down       {{@@ key.down @@}}
    set $up         {{@@ key.up @@}}
    set $right      {{@@ key.right @@}}
    set $menu       s
    set $mus        r

    set $term terminal
    # set $menu wofi --show drun --allow-images --insensitive --term $term -p'Iniciar: '
    # set $menu  bmenu run $term
    font {{@@ font.interface @@}}  {{@@ font.size.medium @@}}px

    #{%@@ if color.type == 'dark' @@%}#
    set $wallPath ~/.local/share/wallpapers/assembly.png
    #{%@@ else @@%}#
    set $wallPath ~/.local/share/wallpapers/austria.jpg
    #{%@@ endif @@%}#

# }}}
# Output configuration {{{
#
    # output * bg '#252525' solid_color
    output * bg $wallPath fill
    # Output HDMI-A-1 resolution 1280x720

    # Disable laptop screen if closed, --reload is important
    # set $laptop eDP-1
    # bindswitch --reload lid:on output $laptop disable
    # bindswitch --reload lid:off output $laptop enable

    # output $laptop disable
    # bindsym $mod+o output eDP-1 toggle
    # exec_always swaymsg -t get_outputs | grep HDMI || swaymsg 'output eDP-1 enable'

    # Backlight settings for laptops
    exec light -N 1
    bindsym XF86MonBrightnessUp   exec light -A 5
    bindsym XF86MonBrightnessDown exec light -U 5

# }}}
# Input configuration {{{

    #hide the mouse after 10 seconds
    seat * hide_cursor 10000
    seat * xcursor_theme {{@@ cursor_theme @@}} {{@@ cursor_size @@}}

    input "type:touchpad" {
        #disable while typing
        dwt disabled
        natural_scroll enabled
        tap enabled
    }

    input * {
    # {%@@ if key_layout == "colemak" @@%}
    #
        xkb_layout "us(colemak),br"
        xkb_options "lv3:lsgt_switch,grp:shifts_toggle"
    # {%@@ elif key_layout == "dvorak" @@%}
    #
        xkb_layout us(dvorak)
    # {%@@ endif @@%}
        xkb_options caps:backspace
        xkb_numlock enabled
    }

# }}}
# Key bindings: {{{

# mouse button for dragging.
floating_modifier $mod normal

bindsym {
# Basic {{{

# Start a terminal
$mod+Return exec $term

#start web browser
$mod+b exec qutebrowser

#start file manager
$mod+Control+Return exec {{@@ file_manager @@}}

$mod+g exec emoji

# Kill focused window
$mod+x kill

# Start your launcher
$mod+$menu exec launcher

# Fill passwords
$mod+p exec wpass

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

# Lock Sway
--locked $mod+Control+z exec loginctl suspend || systemctl suspend

# Exit sway (logs you out of your Wayland session)
$mod+Shift+q exec swaynag -t warning -m 'Do you really want to exit sway?' -b 'Yes, exit sway' 'swaymsg exit'

Control+Alt+delete exit

# }}}
# Moving around: {{{

#       Move your focus around
#{%@@ for d in "up,down,left,right".split(',') @@%}#
$mod+${{@@ d @@}} focus {{@@ d @@}}
$mod+{{@@ d.capitalize() @@}} focus {{@@ d @@}}
$mod+Shift+${{@@ d @@}} move  {{@@ d @@}}
#{%@@ endfor @@%}#

#       Resizing containers:
$mod+Control+$left  resize shrink width  20px
$mod+Control+$down  resize grow   height 20px
$mod+Control+$up    resize shrink height 20px
$mod+Control+$right resize grow   width  20px

#}}}
# Workspaces: {{{

# Mouse prev/next button
--whole-window $mod+button8 workspace next_on_output
--whole-window $mod+button9 workspace prev_on_output

$mod+{{@@ key.tabL @@}}  workspace prev_on_output
$mod+{{@@ key.tabR @@}}  workspace next_on_output

$mod+Shift+{{@@ key.tabL @@}}  move workspace prev_on_output
$mod+Shift+{{@@ key.tabR @@}}  move workspace next_on_output

#       Switch to workspace
#       Move focused container to workspace
#{%@@ for i in range(1,11) @@%}#
$mod+{{@@ i % 10 @@}}       workspace {{@@ i @@}}
$mod+Shift+{{@@ i % 10 @@}} move container to workspace {{@@ i @@}}
#{%@@ endfor @@%}#

# }}}
# Layout stuff: {{{
#
# Splits
# bindsym $mod+b splith
$mod+v splitv

# Layout styles
$mod+t layout tabbed
$mod+r layout toggle split

# Make the current focus fullscreen
$mod+f fullscreen

# Floating
$mod+Shift+space floating toggle
$mod+space focus mode_toggle

# Move focus to the parent container
$mod+a focus parent
$mod+z focus child

# }}}
# Screenshots: {{{

# Screens to file
Print exec screenshotsh def

# Screen area to file
Shift+Print exec screenshotsh area

# Screen area to clipboard
Control+Shift+Print exec screenshotsh area-clip

# Focused monitor to clipboard
Control+Print exec screenshotsh clip

# Screen recorder
Control+Alt+Shift+r exec wf-recorder -a

# Mirror selection as window
$mod+Alt+r exec sssway

# Color picker
$mod+c exec color-picker

# show keys being pressed
$mod+k exec showkeys

# }}}
# Audio: {{{

# Volume controll
# script in dotfiles
--locked    XF86AudioRaiseVolume exec  volumesh -i 10
--locked    XF86AudioLowerVolume exec  volumesh -d 10
--locked    XF86AudioMute        exec  volumesh -t

# Media player controls
--locked XF86AudioPlay  exec mpc toggle
--locked XF86AudioNext  exec mpc next
--locked XF86AudioPrev  exec mpc prev

# }}}
# Special Keys{{{

XF86Calculator  exec $term ipython
XF86Mail        exec $term neomutt
XF86Explorer    exec {{@@ file_manager @@}}
XF86HomePage    exec xdg-open http://start.duckduckgo.com


# }}}
}
# Modes  {{{

set $dexec mode default;exec

# Music {{{
bindsym $mod+m mode Music
mode Music bindsym {

        m                   exec volumesh -t
        {{@@ key.tabL  @@}} exec volumesh -d 10
        {{@@ key.tabR  @@}} exec volumesh -i 10

        {{@@ key.right @@}} exec mpc next
        {{@@ key.left  @@}} exec mpc prev
        {{@@ key.up    @@}} exec volumesh --mpd -i 10
        {{@@ key.down  @@}} exec volumesh --mpd -d 10

        space $dexec mpc toggle
        p     $dexec mpc toggle

        d $dexec musmenu delete
        f $dexec musmenu search
        a $dexec dzadd
        s $dexec pulse-sink

        escape mode default
        q      mode default

}
# }}}

mode Passthrough {
    bindsym $mod+escape mode default
}
bindsym $mod+escape mode Passthrough

# }}}
# }}}
# Visual: {{{
#
    set $accent     {{@@ accent_color @@}}
    set $fg_color   {{@@ color.txt @@}}
    set $bg_color   {{@@ color.bg_dark @@}}
    set $alert      #000000

    #                       border      background  text        indicator   child_border
    client.focused          $accent     $accent     $fg_color   $accent     $accent
    client.focused_inactive $bg_color   $bg_color   $fg_color   $bg_color   $bg_color
    client.unfocused        $bg_color   $bg_color   $fg_color   $bg_color   $bg_color
    client.urgent           $alert      $alert      $fg_color   $alert      $alert

{%@@ if bar == "waybar" @@%}
    # Wake up pulseaudio
    exec pactl set-sink-volume @DEFAULT_SINK@ +0%

    bar swaybar_command waybar
{%@@ else @@%}
    # I rarely use this
    bar {
        position {{@@ bar_pos @@}}
        # status_command i3blocks

        # gaps 5px
        icon_theme {{@@ icon_theme @@}}

        font {{@@ font.interface @@}} 14px

        colors {
            statusline $fg_color
            background $bg_color
            focused_workspace $accent $bg_color $fg_color
        }
    }
{%@@ endif @@%}

    default_border pixel 2px
    default_floating_border normal 2px
    gaps inner 5px

    smart_gaps on
    smart_borders on

    # for_window [app_id=mpv] floating enable
    for_window [app_id=weather] fullscreen
    # for_window [app_id=weather] resize set 635px 700px
    # for_window [app_id=weather] resize set 1500px 750px

    # set theme
    set $gnome-schema org.gnome.desktop.interface
    exec_always {
        kvantummanager --set '{{@@ kvantum_theme @@}}'
        gsettings set $gnome-schema gtk-theme '{{@@ gtk_theme @@}}'
        gsettings set $gnome-schema icon-theme '{{@@ icon_theme @@}}'
        gsettings set $gnome-schema cursor-theme '{{@@ cursor_theme @@}}'
    }

# }}}
# Assigns {{{

    for_window [app_id=pavucontrol] floating enable

    assign [app_id=qutebrowser] workspace 2
    assign [class=qutebrowser] workspace 2
    assign [class=Steam] workspace 9

    assign [app_id=telegram.?desktop] workspace 10
    assign [class=TelegramDesktop] workspace 10

    assign [class=discord] workspace 10

#}}}
# Daemons {{{
#

    # start dbusd just in case
    exec 'dbus-daemon --session --address=unix:path=$XDG_RUNTIME_DIR/bus'

    #Notification Daemon
    exec_always pidof mako || mako
    # Block device Mounter to /run/media/<username>
    exec udiskie
    # gesture daemon
    exec fusuma
    # exec sh -c 'pkill fusuma; fusuma'
    # Blue light filter
    exec_always pidof redshift || redshift

    # kde connect
    exec /usr/lib/kdeconnectd
    exec kdeconnect-indicator
    # Telegram
    exec telegram-desktop-bin || telegram-desktop
    # Music Player Daemon
    exec pidof mpd || mpd
    exec pgrep -f mpDris2|| mpDris2

    # Prevent the screen from locking if fullscreen
    for_window [title=.*] inhibit_idle fullscreen

    # Lock configuration
    set $lock swaylock -f \
        --image $wallPath \
        --font '{{@@ font.interface @@}}' \

    set $screenReload \
        pkill kanshi; \
        kanshi & disown\

    # Idle daemon
    exec_always pkill swayidle && false || \
    exec swayidle -w \
       before-sleep '$lock' \
           after-resume '$screenReload' \
       timeout 360 '$lock' \
           resume '$screenReload' \
       timeout 1800 'swaymsg "output * dpms off"' \
            resume 'swaymsg "output * dpms on";$screenReload' \

    # Screen manager
    exec_always $screenReload

    include /etc/sway/config.d/
#}}}
# vim:filetype=sh:foldmethod=marker
