# This file has been auto-generated by i3-config-wizard(1).
# It will not be overwritten, so edit it as you like.
#
# Should you change your keyboard layout some time, delete
# this file and re-run i3-config-wizard(1).
#

# i3 config file (v4)
#
# Please see https://i3wm.org/docs/userguide.html for a complete reference!

set $mod1 Mod4
set $mod2 Mod4+Shift

# Font for window titles. Will also be used by the bar unless a different font
# is used in the bar {} block below.
#font Meslo LG M Regular Nerd Font Complete:monospace 11
font pango:monospace 11

# This font is widely installed, provides lots of unicode glyphs, right-to-left
# text rendering and scalability on retina/hidpi displays (thanks to pango).
#font pango:DejaVu Sans Mono 8

# Pane movement keys - vim
set $pane_left h
set $pane_down j
set $pane_up k
set $pane_right l

# Symmetric keys - mpv
set $left_outer q
set $left_inner w
set $right_inner e
set $right_outer r

# Space movement keys - gaming
set $space_up w
set $space_left a
set $space_down s
set $space_right d

# Resize keys - vim windows
set $size_up   comma
set $size_down period

set $term alacritty
set $menu rlaunch

# Sound effects and additional features
set $volume_command ~/.config/sway/pulse_audio_volume.sh
set $volume_change_sound  ~/.config/sway/volume_change_sound.mp3
set $screenshot_sound ffplay -nodisp -autoexit -v error ~/.config/sway/screenshot_sound.mp3

# Duplicate screenshot path, for quick uploads
set $screenshot_tmp /dev/shm/screenshot_shm.png
set $screenshot_script ~/.configs_pointer/bin/screenshot_wayland.py

#╔─────────────────────────────────────────────────────────────────────────────╗
#│ Pαηεs αηd cδηταiηεrs                                                        |
#╚─────────────────────────────────────────────────────────────────────────────╝
  # Move focus
bindsym $mod1+$pane_left  focus left
bindsym $mod1+$pane_down  focus down
bindsym $mod1+$pane_up    focus up
bindsym $mod1+$pane_right focus right

  # Move focused window
bindsym $mod2+$pane_left  move left
bindsym $mod2+$pane_down  move down
bindsym $mod2+$pane_up    move up
bindsym $mod2+$pane_right move right

  # Layout modifiers
bindsym $mod2+f floating toggle
bindsym $mod2+s layout stacking
bindsym $mod2+t layout tabbed
bindsym $mod2+r layout toggle

  # Binary split container
bindsym $mod1+b split toggle
#bindsym $mod1+v split none  # Does not exist in i3
bindsym $mod1+m fullscreen

  # Switch container layout   Stacking|Tabbed|Rotate-bsp
bindsym $mod1+s layout stacking
bindsym $mod1+t layout tabbed
bindsym $mod1+r layout toggle split

  # Traverse window tree
bindsym $mod1+u focus parent
bindsym $mod1+d focus child

  # Alt-tab cycles windows, like on proprietary systems
bindsym $mod1+tab exec ~/.config/sway/cycle_windows.py next
bindsym $mod2+tab exec ~/.config/sway/cycle_windows.py previous

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

  # Important rust jerk
bindsym $mod1+ctrl+r exec wtype "asExpectedOfRust"
#bindsym $mod1+ctrl+s reload

  # Automatic upload image to discord
bindsym $mod1+ctrl+u exec sudo -u emiliko ~/.configs_pointer/bin/auto_image_upload_discord.sh

  # Paste by typing
bindsym Mod4+Ctrl+v exec ~/.configs_pointer/bin/wpastetype.py

# rEsize containers ====
bindsym $mod1+e mode "resize"

mode "resize" {
    # Horizontal, shift for fine adjust
    bindsym $size_up         resize grow   width  16px
    bindsym $size_down       resize shrink width  16px
    bindsym $size_up+Shift   resize grow   width  4px
    bindsym $size_down+Shift resize shrink width  4px

    # Vertical, shift for fine adjust
    bindsym $mod1+$size_down       resize shrink height 16px
    bindsym $mod1+$size_up         resize grow   height 16px
    bindsym $mod1+$size_down+Shift resize shrink height 4px
    bindsym $mod1+$size_up+Shift   resize grow   height 4px

    # Escaping
    bindsym $mod1+f mode "workspace_tuning"

    bindsym Shift+end mode "default"
    bindsym Ctrl+k mode "default"
    bindsym Ctrl+bracketleft mode "default"
    bindsym Escape mode "default"
}

# Gaps ====
bindsym $mod2+bracketright gaps inner current minus 3
bindsym $mod2+bracketleft  gaps inner current plus 3
#bindsym $mod2+equal gaps toggle
    # Standard outer gapping for 27" screen
bindsym $mod2+c gaps vertical current set 100, \
                gaps horizontal current set 200
    # Same as above, shifted left slightly
bindsym $mod2+g gaps vertical current set 100, \
                gaps left current set 150, \
                gaps right current set 250

bindsym $mod1+g mode "gapping"
mode "gapping" {
    # General resize
    bindsym $mod2+bracketright gaps inner current minus 3
    bindsym $mod2+bracketleft  gaps inner current plus 3

    # Horizontal
    bindsym       q gaps left  current minus 2
    bindsym       w gaps left  current plus  2
    bindsym       e gaps right current plus  2
    bindsym       r gaps right current minus 2

    # Vertical
    bindsym $mod1+q gaps top    current minus 2
    bindsym $mod1+w gaps top    current plus  2
    bindsym $mod1+e gaps bottom current plus  2
    bindsym $mod1+r gaps bottom current minus 2

    # Escaping
    bindsym Shift+end mode "default"
    bindsym Ctrl+k mode "default"
    bindsym Ctrl+bracketleft mode "default"
    bindsym Escape mode "default"
}

#╔─────────────────────────────────────────────────────────────────────────────╗
#│ Wδrksραcεs                                                                  |
#╚─────────────────────────────────────────────────────────────────────────────╝
bindsym $mod1+bracketleft workspace prev
bindsym $mod1+bracketright workspace next

bindsym $mod2+a workspace prev
bindsym $mod2+d workspace next

bindsym $mod1+1 workspace number 1
bindsym $mod1+2 workspace number 2
bindsym $mod1+3 workspace number 3
bindsym $mod1+4 workspace number 4
bindsym $mod1+5 workspace number 5
bindsym $mod1+6 workspace number 6
bindsym $mod1+7 workspace number 7
bindsym $mod1+8 workspace number 8
bindsym $mod1+9 workspace number 9

# Advanced workspace tuning ====
bindsym $mod1+f mode "workspace_tuning"

mode "workspace_tuning" {

      # Move focused container to workspace
    bindsym 1 move container to workspace number 1
    bindsym 2 move container to workspace number 2
    bindsym 3 move container to workspace number 3
    bindsym 4 move container to workspace number 4
    bindsym 5 move container to workspace number 5
    bindsym 6 move container to workspace number 6
    bindsym 7 move container to workspace number 7
    bindsym 8 move container to workspace number 8
    bindsym 9 move container to workspace number 9

    # Swap containers
    bindsym $mod1+$pane_left mark --add "_swap", focus left, swap container with mark "_swap", focus left, unmark "_swap"
    bindsym $mod1+$pane_down mark --add "_swap", focus down, swap container with mark "_swap", focus down, unmark "_swap"
    bindsym $mod1+$pane_up mark --add "_swap", focus up, swap container with mark "_swap", focus up, unmark "_swap"
    bindsym $mod1+$pane_right mark --add "_swap", focus right, swap container with mark "_swap", focus right, unmark "_swap"

    # Stack, Tab, Rotate
    bindsym s layout stacking
    bindsym t layout tabbed
    bindsym r layout toggle split

    bindsym f fullscreen
    bindsym Shift+f fullscreen

    # Escaping
    bindsym $mod1+e mode "resize"

    bindsym Shift+end mode "default"
    bindsym Ctrl+k mode "default"
    bindsym Ctrl+bracketleft mode "default"
    bindsym Escape mode "default"
}

#╔─────────────────────────────────────────────────────────────────────────────╗
#│ Iηρμτ αηd δμτρμτ αdjμsτmεητs                                                |
#╚─────────────────────────────────────────────────────────────────────────────╝
# Volume controls
bindsym XF86AudioRaiseVolume exec $volume_command 4 $volume_change_sound
bindsym XF86AudioLowerVolume exec $volume_command -4 $volume_change_sound
bindsym shift+XF86AudioRaiseVolume exec $volume_command 1 $volume_change_sound
bindsym shift+XF86AudioLowerVolume exec $volume_command -1 $volume_change_sound
bindsym XF86AudioMute exec ~/.config/sway/toggle_mute.sh

# External brightness control
  # For laptops
bindsym XF86MonBrightnessUp   exec light -A 1
bindsym XF86MonBrightnessDown exec light -U 1
  # For external monitors
bindsym XF86AudioNext exec ddcutil setvcp 10 + 4
bindsym XF86AudioPrev exec ddcutil setvcp 10 - 4
bindsym F10 exec ddcutil setvcp 10 + 1
bindsym F8 exec ddcutil setvcp 10 - 1
bindsym XF86Back exec ddcutil setvcp 12 + 2
bindsym Menu exec ddcutil setvcp 12 - 2

#╔─────────────────────────────────────────────────────────────────────────────╗
#│ Hδτkεy dαεmδη                                                               |
#╚─────────────────────────────────────────────────────────────────────────────╝
  # Terminal
bindsym $mod2+Return exec $term
  # Chromium
bindsym $mod2+n exec chromium
  # Firefox
bindsym $mod2+p exec MOZ_ENABLE_WAYLAND=1 firefox --private-window
  # App launcher, like spotlight
bindsym $mod1+space exec $menu
  # Reload sway config
bindsym $mod1+ctrl+s reload
  # Close window
bindsym $mod2+q kill
  # Dragging windows
#floating_modifier $mod1 normal
floating_modifier $mod1
  # Screenlock
bindsym $mod2+i exec ~/.config/i3/brightness_lock.sh
  # Scratchpad
bindsym $mod1+Shift+minus move scratchpad
bindsym $mod1+minus scratchpad show
  # Warpd - Keyboard-driven mouse
bindsym Mod4+Control+j exec warpd --hint
bindsym Mod4+Control+n exec warpd --normal
  # Xremap
exec sudo ~/.configs_pointer/bin/switch_keyboard.sh pc
  # IME Module
bindsym $mod1+i exec ~/.config/sway/toggle_fcitx.sh
  # Mako notifications
exec mako
  # Exit sway (hit 3 times repeatedly to force exit)
bindsym $mod2+Escape exec ~/.config/sway/sway_exit.sh

exec --no-startup-id feh --bg-fill ~/.configs_pointer/sway/default_wallpaper.png

client.focused #F4A66E #F4A66E #000000 #F4A66E #F4A66E

# Screenshots ====
bindsym $mod2+6 mode "screenshots"
bindsym $mod2+5 mode "screenshots"; exec $screenshot_script take select -c $screenshot_tmp && $screenshot_sound
bindsym $mod2+4 mode "screenshots"; exec $screenshot_script take exact "$(~/.config/sway/window_dimensions.py)" && \
      $screenshot_script edit -c -q 100 -d "$(colo.sh -t)" -e png --overwrite $screenshot_tmp && $screenshot_sound

mode "screenshots" {
    # Screenshooting in processing "steps"
    # 1. Get screenshot
    bindsym a exec $screenshot_script take select -c $screenshot_tmp && $screenshot_sound
    bindsym f exec $screenshot_script take full -c $screenshot_tmp && $screenshot_sound
    bindsym m mode "default"; exec $screenshot_script markup -c $screenshot_tmp && $screenshot_sound
    bindsym g mode "default"; exec gimp $($screenshot_script markup --show-latest)

    # 2. Downsize the screenshot, since 4k is too big
    bindsym 1 exec $screenshot_script edit -c -e png -q '40%' -r '50%' $screenshot_tmp && $screenshot_sound
    bindsym 2 exec $screenshot_script edit -c -e png -q '40%' -r '60%' $screenshot_tmp && $screenshot_sound
    bindsym 3 exec $screenshot_script edit -c -e png -q '40%' -r '70%' $screenshot_tmp && $screenshot_sound
    bindsym 4 exec $screenshot_script edit -c -e png -q '40%' -r '80%' $screenshot_tmp && $screenshot_sound
    bindsym 5 exec $screenshot_script edit -c -e png -q '80%' -r '50%' $screenshot_tmp && $screenshot_sound
    bindsym 6 exec $screenshot_script edit -c -e png -q '80%' -r '60%' $screenshot_tmp && $screenshot_sound
    bindsym 7 exec $screenshot_script edit -c -e png -q '80%' -r '70%' $screenshot_tmp && $screenshot_sound
    bindsym 8 exec $screenshot_script edit -c -e png -q '80%' -r '80%' $screenshot_tmp && $screenshot_sound
    bindsym 9 exec $screenshot_script edit -c -e png -q '80%' -r '90%' $screenshot_tmp && $screenshot_sound
    bindsym 0 exec $screenshot_script edit -c -e png -q '80%' -r '100%' $screenshot_tmp && $screenshot_sound

    # OR compress image
    bindsym space mode "shrink_screenshots"

    # 3. Copy the smaller image back to clipboard and return to default
    bindsym return mode "default"
    bindsym Shift+end mode "default"
    bindsym Ctrl+k mode "default"
    bindsym Ctrl+bracketleft mode "default"
    bindsym Escape mode "default"
}

mode "shrink_screenshots" {
    # 2. Compress the screenshot, hard
    bindsym 1 exec $screenshot_script edit -c -e webp -q '40%' -r '50%' $screenshot_tmp && $screenshot_sound
    bindsym 2 exec $screenshot_script edit -c -e webp -q '40%' -r '60%' $screenshot_tmp && $screenshot_sound
    bindsym 3 exec $screenshot_script edit -c -e webp -q '40%' -r '70%' $screenshot_tmp && $screenshot_sound
    bindsym 4 exec $screenshot_script edit -c -e webp -q '40%' -r '80%' $screenshot_tmp && $screenshot_sound
    bindsym 5 exec $screenshot_script edit -c -e webp -q '80%' -r '50%' $screenshot_tmp && $screenshot_sound
    bindsym 6 exec $screenshot_script edit -c -e webp -q '80%' -r '60%' $screenshot_tmp && $screenshot_sound
    bindsym 7 exec $screenshot_script edit -c -e webp -q '80%' -r '70%' $screenshot_tmp && $screenshot_sound
    bindsym 8 exec $screenshot_script edit -c -e webp -q '80%' -r '80%' $screenshot_tmp && $screenshot_sound
    bindsym 9 exec $screenshot_script edit -c -e webp -q '80%' -r '90%' $screenshot_tmp && $screenshot_sound
    bindsym 0 exec $screenshot_script edit -c -e webp -q '80%' -r '100%' $screenshot_tmp && $screenshot_sound

    bindsym space mode "screenshots"

    # 3. Back out
    bindsym return mode "default"
    bindsym Shift+end mode "default"
    bindsym Ctrl+k mode "default"
    bindsym Ctrl+bracketleft mode "default"
    bindsym Escape mode "default"
}

# Global mpv ====
bindsym $mod2+m mode "mpv_global"

mode "mpv_global" {
    bindsym j exec ~/.config/sway/mpv_keys.sh 'j'
    bindsym k exec ~/.config/sway/mpv_keys.sh 'k'
    bindsym l exec ~/.config/sway/mpv_keys.sh 'l'
    bindsym Left exec ~/.config/sway/mpv_keys.sh 'LEFT'
    bindsym Right exec ~/.config/sway/mpv_keys.sh 'RIGHT'
    bindsym space exec ~/.config/sway/mpv_keys.sh 'SPACE'
    bindsym bracketleft exec ~/.config/sway/mpv_keys.sh '['
    bindsym bracketright exec ~/.config/sway/mpv_keys.sh ']'
    bindsym minus exec ~/.config/sway/mpv_keys.sh '-'
    bindsym equal exec ~/.config/sway/mpv_keys.sh '='
    bindsym m exec ~/.config/sway/mpv_keys.sh 'm'
    bindsym A exec ~/.config/sway/mpv_keys.sh 'A'

    bindsym return mode "default"
    bindsym Ctrl+k mode "default"
    bindsym Shift+End mode "default"
    bindsym Escape mode "default"
}

#╔─────────────────────────────────────────────────────────────────────────────╗
#│ Sτylεs                                                                      |
#╚─────────────────────────────────────────────────────────────────────────────╝
bar {
    #status_command i3status
    i3bar_command i3bar --transparency
    position bottom

    binding_mode_indicator yes

      # Vertical horizontal
    #gaps 0 10

    mode dock

    status_command while ~/.config/sway/swaybar_status.sh; do sleep 60; done

    colors {
         # Foreground color
       statusline #e7d6ad
       background #22222200

         # border background text
       focused_workspace #F4B36Eff #F4B36Eff #000000
       inactive_workspace #00000000 #444444 #e7d6ad
       urgent_workspace #fadb2f #fadb2f #000000

       binding_mode #8ec07c #8ec07c #000000
       binding_mode #8ec07c #d3869b #000000
       binding_mode #fadb2f #fadb2f #000000
    }
}