# Default ─────────────────────────────────────────────────────────────
# Logo key. Use Mod1 for Alt.
set $mod Mod4

# Home row direction keys, like vim
set $left h
set $down j
set $up k
set $right l

# Your preferred terminal emulator
set $term {{ terminal[0] }}
set $term_fallback {{ terminal[1] }}

# Your preferred application launcher
# Note: pass the final command to swaymsg so that the resulting window can be opened
# on the original workspace that the command was run on.
{% if launcher == 'wofi' %}
set $menu wofi --show=drun
set $menu_fallback wofi --show=run
{% elif launcher == 'rofi' %}
set $menu rofi -show drun
set $menu_fallback rofi -show run
{% endif %}

# Workspaces' names
set $ws1 "1"
set $ws2 "2"
set $ws3 "3"
set $ws4 "4"
set $ws5 "5"
set $ws6 "6"
set $ws7 "7"
set $ws8 "8"
set $ws9 "9"
set $ws10 "10"

# Pure Wayland
# xwayland disable

{% include 'by_host/' + ansible_hostname + '/config.j2' ignore missing %}

#input * xkb_numlock enable

# Autostart ─────────────────────────────────────────────────────────────
# Inform dbus about the environment
exec dbus-update-activation-environment DISPLAY SWAYSOCK WAYLAND_DISPLAY XDG_SESSION_TYPE XDG_CURRENT_DESKTOP

exec ~/.local/libexec/wayland/launch_pipewire
exec ~/.local/libexec/wayland/launch_mpd
exec ~/.local/libexec/wayland/launch_waybar \
        -c ~/.config/waybar/sway/config \
        -s ~/.config/waybar/sway/style.css
exec ~/.local/libexec/wayland/launch_notify
exec ~/.local/libexec/wayland/clipboard --start
exec_always ~/.local/libexec/wayland/swaywpp
exec swayidle \
        timeout 300 'swaylock' \
        timeout 600 'swaymsg "output * dpms off"' resume 'swaymsg "output * dpms on"'
exec ~/.local/libexec/wayland/launch_mpdris
exec ~/.local/libexec/wayland/launch_xdg_portal wlr
exec ~/.local/libexec/wayland/launch_xdg_portal gtk

# Looks ─────────────────────────────────────────────────────────────
# gaps
gaps outer 5
gaps inner 5
# smart_gaps on

# title bar
font {{ cjk_font }} {{ (font_size - 2) | float }}
titlebar_border_thickness 0
titlebar_padding 11 1

# border, no title
# for_window [app_id="^.*"] border pixel 2, opacity 1
default_border pixel 2
default_floating_border pixel 2
# smart_borders on
# hide_edge_borders smart

# cursor theme
seat seat0 xcursor_theme {{ cursor_theme }} {{ cursor_size }}

# gtk theme
exec_always {
    gsettings set org.gnome.desktop.interface gtk-theme '{{ gtk_theme }}'
    gsettings set org.gnome.desktop.interface icon-theme '{{ icon_theme }}'
    gsettings set org.gnome.desktop.interface cursor-theme '{{ cursor_theme }}'
    gsettings set org.gnome.desktop.interface cursor-size '{{ cursor_size }}'
}

set $light {{ white2 }}
set $dark {{ background }}
set $focusedborder {{ white2 }}
set $inactiveborder {{ yellow }}
set $unfocusedborder {{ blue }}
set $urgentborder {{ red }}

# class                  border            bg                text    indicator         child_border
client.focused           $focusedborder    $focusedborder    $dark   $focusedborder    $focusedborder
client.focused_inactive  $inactiveborder   $inactiveborder   $dark   $inactiveborder   $inactiveborder
client.unfocused         $unfocusedborder  $unfocusedborder  $light  $unfocusedborder  $unfocusedborder
client.urgent            $urgentborder     $urgentborder     $light  $urgentborder     $urgentborder

# Key bindings ─────────────────────────────────────────────────────────────
# Basics:
#
# Start a terminal
bindsym $mod+Return exec $term
bindsym $mod+Shift+Return exec $term_fallback

# Kill focused window
bindsym $mod+q kill

# Start your launcher
bindsym $mod+d exec $menu
bindsym $mod+Shift+d exec $menu_fallback

# Web search
bindsym $mod+Mod1+s exec ~/.local/libexec/wayland/searchmenu

# Manga
bindsym $mod+Mod1+m exec ~/.local/libexec/wayland/mangamenu

# Browser bookmarks (buku)
bindsym $mod+Mod1+b exec ~/.local/libexec/wayland/bukumenu

# Music (playlist)
bindsym $mod+Mod1+u exec ~/.local/libexec/wayland/musicmenu

{% if launcher == 'wofi' %}
# Wofi comes with a qalc script
bindsym $mod+Mod1+t exec ~/.local/libexec/wayland/wofi-calc
{% elif launcher == 'rofi' %}
# Rofi has qalc and file-browser-extended plugins
bindsym $mod+Mod1+t exec rofi -show calc
bindsym $mod+Mod1+f exec rofi -show file-browser-extended
{% endif %}

# Clipboard manager
bindsym $mod+Mod1+d exec ~/.local/libexec/wayland/clipboard --{{ launcher }}
bindsym $mod+Mod1+c exec ~/.local/libexec/wayland/clipboard --clear
bindsym $mod+c exec ~/.local/libexec/wayland/clipboard --{{ launcher }}-clear

# Media keys
bindsym XF86AudioRaiseVolume exec ~/.local/libexec/wayland/volumecontrol --increase
bindsym XF86AudioLowerVolume exec ~/.local/libexec/wayland/volumecontrol --decrease
bindsym XF86AudioMute exec ~/.local/libexec/wayland/volumecontrol --toggle
bindsym XF86AudioMicMute exec ~/.local/libexec/wayland/volumecontrol --toggle-source
bindsym --locked XF86AudioPlay exec playerctl play-pause
bindsym --locked XF86AudioNext exec playerctl next
bindsym --locked XF86AudioPrev exec playerctl previous

# Brightness
bindsym XF86MonBrightnessDown exec ~/.local/libexec/wayland/brightness down
bindsym XF86MonBrightnessUp exec ~/.local/libexec/wayland/brightness up

# Screenshot
bindsym Print exec ~/.local/libexec/wayland/screenshot --region
bindsym $mod+Print exec ~/.local/libexec/wayland/screenshot --full
bindsym Mod1+Print exec ~/.local/libexec/wayland/screenshot --region-optional
bindsym Control+Print exec ~/.local/libexec/wayland/screenshot --full-optional
bindsym $mod+Mod1+Print exec ~/.local/libexec/wayland/screenshot --region-copy
bindsym $mod+Control+Print exec ~/.local/libexec/wayland/screenshot --full-copy

# Dismiss notifications
bindsym $mod+Mod1+n exec ~/.local/libexec/wayland/dismiss_notify

# Emacs
bindsym $mod+Mod1+e exec emacsclient -c -a emacs

# Lock
bindsym $mod+Shift+x exec swaylock
bindsym --locked $mod+Shift+o output * dpms off
bindsym --locked $mod+Mod1+o output * dpms on

# Drag floating windows by holding down $mod and left mouse button.
# Resize them with right mouse button + $mod.
# Despite the name, also works for non-floating windows.
# Change normal to inverse to use left mouse button for resizing and right
# mouse button for dragging.
floating_modifier $mod normal

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

# Exit sway (logs you out of your Wayland session)
bindsym --to-code $mod+Shift+q exec swaynag -t warning \
    -m 'Exit sway?' -b 'Yes' 'swaymsg 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

# 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

# Move to other outputs
bindsym $mod+p focus output left
bindsym $mod+n focus output right
bindsym $mod+Shift+p move to output left
bindsym $mod+Shift+n move to output right

#
# Layout stuff:
#
# You can "split" the current object of your focus with
# $mod+b or $mod+v, for horizontal and vertical splits
# respectively.
bindsym $mod+b splith
bindsym $mod+v splitv

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

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

# Toggle the current focus between tiling and floating mode
bindsym $mod+space floating toggle

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

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

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

# Make window sticky
bindsym $mod+Shift+s sticky toggle

#
# Scratchpad:
#
# Sway has a "scratchpad", which is a bag of holding for windows.
# You can send windows there and get them back later.
#
# Move the currently focused window to the scratchpad
bindsym $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.
bindsym $mod+minus scratchpad show

#
# Resizing containers:
#
mode "resize" {
    bindsym $left resize shrink width 10px
    bindsym $down resize grow height 10px
    bindsym $up resize shrink height 10px
    bindsym $right resize grow width 10px

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

#
# Workspaces:
#
# Switch to workspace
bindsym $mod+1 workspace $ws1
bindsym $mod+2 workspace $ws2
bindsym $mod+3 workspace $ws3
bindsym $mod+4 workspace $ws4
bindsym $mod+5 workspace $ws5
bindsym $mod+6 workspace $ws6
bindsym $mod+7 workspace $ws7
bindsym $mod+8 workspace $ws8
bindsym $mod+9 workspace $ws9
bindsym $mod+0 workspace $ws10
# Move focused container to workspace
bindsym $mod+Shift+1 move container to workspace $ws1
bindsym $mod+Shift+2 move container to workspace $ws2
bindsym $mod+Shift+3 move container to workspace $ws3
bindsym $mod+Shift+4 move container to workspace $ws4
bindsym $mod+Shift+5 move container to workspace $ws5
bindsym $mod+Shift+6 move container to workspace $ws6
bindsym $mod+Shift+7 move container to workspace $ws7
bindsym $mod+Shift+8 move container to workspace $ws8
bindsym $mod+Shift+9 move container to workspace $ws9
bindsym $mod+Shift+0 move container to workspace $ws10

# Window rules ─────────────────────────────────────────────────────────────
# Floating
for_window [app_id="float"] floating enable
for_window [app_id="popup"] floating enable
for_window [app_id="swappy"] floating enable
for_window [app_id="pinentry-qt"] floating enable
for_window [app_id="pavucontrol-qt"] floating enable
# for_window [title="About *"] floating enable
for_window [title="Picture-in-Picture"] floating enable

# Specify workspaces for applications
assign [app_id="thunderbird"] $ws3
assign [class="Element"] $ws7
