# {{@@ header() @@}}
# LEL
#  _____      ____ _ _   _
# / __\ \ /\ / / _` | | | |
# \__ \\ 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 $suspend    b
    set $kill       x
    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 @@}} 14px

    {%@@ 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)
        xkb_options lv3:lsgt_switch
    # {%@@ elif key.layout == "dvorak" @@%}
    #
        xkb_layout us(dvorak)
    # {%@@ endif @@%}
        xkb_options caps:backspace
        xkb_numlock enabled
    }

# }}}
# Key bindings: {{{
    # Basic {{{

    # Start a terminal
    bindsym $mod+Return exec $term

    #start web browser
    bindsym $mod+b exec qutebrowser

    #start file manager
    bindsym $mod+m exec thunar

    bindsym $mod+j exec emoji

    # Kill focused window
    bindsym $mod+$kill kill

    # Start your launcher
    bindsym $mod+$menu exec launcher

    # Fill passwords
    bindsym $mod+p exec wpass

    # mouse button for dragging.
    floating_modifier $mod normal

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

    # Lock Sway
    bindsym $mod+Control+$suspend exec loginctl suspend || systemctl suspend

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

    bindsym Control+Shift+BackSpace exit

    # }}}
    # Moving around: {{{

    #       Move your focus around
    bindsym $mod+$left  focus left
    bindsym $mod+$down  focus down
    bindsym $mod+$up    focus up
    bindsym $mod+$right focus 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

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

    #}}}
    # Workspaces: {{{

    bindsym $mod+{{@@ key.tabL @@}}  workspace prev
    bindsym $mod+{{@@ key.tabR @@}}  workspace next

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

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

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

    # Make the current focus fullscreen
    bindsym $mod+f fullscreen

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

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

    # }}}
    # Screenshots: {{{
    #

    # Screens to file
    bindsym Print exec screenshotsh def

    # Screen area to file
    bindsym Shift+Print exec screenshotsh area

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

    # Focused monitor to clipboard
    bindsym Control+Print exec screenshotsh clip

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

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

    # Color picker
    bindsym $mod+c exec color-picker

    # show keys being pressed
    bindsym $mod+k exec showkeys

    # }}}
    # Audio: {{{
    #
    bindsym Control+$mod+p exec pulse-sink
    for_window [app_id="pavucontrol"] floating enable

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

    # Media player controls
{%@@ if exists_in_path ( 'playerctl' ) @@%}
    # playerctl for notifications
    bindsym --locked XF86AudioPlay  exec playerctl -p mpd play-pause
    bindsym --locked XF86AudioNext  exec playerctl -p mpd next
    bindsym --locked XF86AudioPrev  exec playerctl -p mpd previous
{%@@ else @@%}
    bindsym --locked XF86AudioPlay  exec mpc toggle
    bindsym --locked XF86AudioNext  exec mpc next
    bindsym --locked XF86AudioPrev  exec mpc prev
{%@@ endif @@%}
    bindsym $mod+Shift+$mus         exec musmenu delete
    bindsym $mod+Control+$mus       exec musmenu search
    bindsym $mod+Control+Shift+$mus exec dzadd

    # }}}
    # Special Keys{{{

    bindsym XF86Calculator  exec $term ipython
    bindsym XF86Mail        exec $term neomutt
    bindsym XF86Explorer    exec thunar
    bindsym XF86HomePage    exec xdg-open http://start.duckduckgo.com

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

    # }}}
# }}}
# Visual: {{{
#
    set $accent     {{@@ color.accent @@}}
    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 @@%}
    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] floating enable
    # 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 to workspaces {{{

    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 {{{
#

    exec 'dbus-daemon --session --address=unix:path=$XDG_RUNTIME_DIR/bus'
    #Notification Daemon
    exec mako
    # Block device Mounter to /run/media/<username>
    exec udiskie
    # gesture daemon
    exec fusuma
    # exec sh -c 'pkill fusuma; fusuma'
    # Blue light filter
    exec pidof redshift || redshift
    # exec_always sh -c 'pkill 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

    # lock screen after a period of inactivity execp for fullscreen
    for_window [class=.*] inhibit_idle fullscreen

    # Lock configuration
    set $lock swaylock -f \
        --image $wallPath \
        --font 'Inter' \

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

    # Idle daemon
    exec_always pkill swayidle && false || \
    exec swayidle -w \
       before-sleep '$lock' \
           after-resume '$screenReload' \
       timeout 1800 '$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
