# [Startup]

exec --no-startup-id feh --bg-scale ~/dotfiles/wallpapers/png/blob.png
exec --no-startup-id setxkbmap -layout 'us,ru' -option 'grp:caps_toggle'
exec --no-startup-id polybar top
exec --no-startup-id unclutter
exec --no-startup-id picom \
  --daemon \
  --backend glx \
  --vsync \
  --shadow \
  --shadow-opacity=0.9 \
  --shadow-radius=12 \
  --shadow-offset-x=-12 \
  --shadow-offset-y=-9 \
  --shadow-exclude='x <= 0 && x2 >= 1920 && y <= 30 && y2 >= 1020' \
  --shadow-exclude='class_g = "i3-frame"' \
  --shadow-exclude='class_g = "TelegramDesktop" && argb' \
  --shadow-exclude='class_g = "net.thunderbird.Thunderbird" && argb' \
  --shadow-exclude='class_g = "org.mozilla.firefox" && argb' \

# [Appearance]

# Class                 Border  Back    Text    Marker  Child_Border
client.focused          #383838 #383838 #cdcdcd #bdbdbd #bdbdbd
client.focused_inactive #222222 #222222 #7d7d7d #222222 #222222
client.unfocused        #222222 #222222 #7d7d7d #222222 #222222
client.urgent           #222222 #222222 #7d7d7d #222222 #222222
client.placeholder      #222222 #222222 #7d7d7d #222222 #222222
client.background       #ffffff

font pango:NotoSans 11

gaps inner 30
hide_edge_borders both

for_window [class=".*"] title_format " ◼ %title"
for_window [class="^.*"] border pixel 3

# [Exceptions]

for_window [title=" is sharing your screen.$"] \
        border none, sticky enable, move position 0 px 0 px

# [Keyboard Shortcuts]

set $mod Mod4

# [Execute]

bindsym $mod+Return exec urxvt

bindsym $mod+d exec rofi -show run
bindsym $mod+Tab exec rofi -show window

# [Utils]

bindsym Print exec xfce4-screenshooter
bindsym XF86Tools exec xfce4-screenshooter --region --delay 0

bindsym $mod+y exec --no-startup-id "pkill gpick; gpick -so | xclip -sel c"

bindsym $mod+g exec --no-startup-id xdotool mousemove 0 1080
bindsym $mod+Shift+g exec --no-startup-id xdotool mousemove 960 540

bindsym $mod+t \
        exec "firefox --new-tab --url about:newtab && i3-msg 'workspace 1'"
bindsym $mod+Shift+o \
        exec "~/dotfiles/i3/scripts/tabToLastWorkspace.sh"

# [Notifications]

bindsym $mod+grave exec --no-startup-id dunstctl history-pop
bindsym $mod+BackSpace exec --no-startup-id dunstctl close-all

# [Volume Controls]

bindsym XF86AudioRaiseVolume exec --no-startup-id \
        pactl set-sink-volume @DEFAULT_SINK@ +5% #increase sound volume
bindsym XF86AudioLowerVolume exec --no-startup-id \
        pactl set-sink-volume @DEFAULT_SINK@ -5% #decrease sound volume
bindsym XF86AudioMute exec --no-startup-id \
        pactl set-sink-mute @DEFAULT_SINK@ toggle # mute sound

# [Screen Brightness Controls]

bindsym XF86MonBrightnessUp exec --no-startup-id \
        "light -A 5 && dunstify Brightness -h int:value:`light`"
bindsym XF86MonBrightnessDown exec --no-startup-id \
        "light -U 5 && dunstify Brightness -h int:value:`light`"

# [i3 Controls]

bindsym $mod+Shift+q kill

# Lock the screen
bindsym $mod+F4 exec "i3lock -c 000000"

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

# Restart i3 inplace (preserves your layout/session, can be used to upgrade i3)
bindsym $mod+Shift+r restart

# Exit i3 (logs you out of your X session)
bindsym $mod+Shift+e exec \
        "i3-nagbar -t warning -m 'Exit i3?' -b 'Yes' 'i3-msg exit'"

# Change the Focus

bindsym $mod+h focus left
bindsym $mod+j focus down
bindsym $mod+k focus up
bindsym $mod+l 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

bindsym $mod+Shift+h move left
bindsym $mod+Shift+j move down
bindsym $mod+Shift+k move up
bindsym $mod+Shift+l move right

bindsym $mod+Shift+Left move left
bindsym $mod+Shift+Down move down
bindsym $mod+Shift+Up move up
bindsym $mod+Shift+Right move right

# Split in Horizontal Orientation
bindsym $mod+b split h

# Split in Vertical Orientation
bindsym $mod+v split v

# Enter Fullscreen Mode for the Focused Container
bindsym $mod+f fullscreen toggle

# Change Container Layout (Stacked, Tabbed, Toggle Split)

bindsym $mod+s layout stacking
bindsym $mod+w layout tabbed
bindsym $mod+e layout toggle split

# Toggle Mode (Tiling / Floating)
bindsym $mod+Shift+space floating toggle

# Change Focus Between Tiling and Floating Windows
bindsym $mod+space focus mode_toggle

# Use Mouse+$mod to Drag Floating Windows to Their Wanted Position
floating_modifier $mod

# Focus the Parent Container
bindsym $mod+a focus parent

# Focus the Child Container
bindsym $mod+z focus child

# [Workspaces]

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"

# Workspace Rules

workspace_auto_back_and_forth yes

workspace 1 gaps inner 0
workspace 2 gaps inner 0
for_window [workspace="2"] layout tabbed
workspace 5 gaps inner 0
workspace 9 gaps inner 0

# Switch to Nearest Workspace

bindsym $mod+Ctrl+h workspace prev
bindsym $mod+Ctrl+j workspace next
bindsym $mod+Ctrl+k workspace prev
bindsym $mod+Ctrl+l workspace next

bindsym $mod+Ctrl+Left workspace prev
bindsym $mod+Ctrl+Down workspace next
bindsym $mod+Ctrl+Up workspace prev
bindsym $mod+Ctrl+Right workspace next

# 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

# [Mods]

bindsym $mod+r mode "resize"
mode "resize" {
        # Resize Current Window
        bindsym h resize shrink width 10 px or 10 ppt
        bindsym j resize grow height 10 px or 10 ppt
        bindsym k resize shrink height 10 px or 10 ppt
        bindsym l resize grow width 10 px or 10 ppt

        bindsym Left resize shrink width 10 px or 10 ppt
        bindsym Down resize grow height 10 px or 10 ppt
        bindsym Up resize shrink height 10 px or 10 ppt
        bindsym Right resize grow width 10 px or 10 ppt

        # Set Gaps Size
        bindsym 0 gaps inner current set 0
        bindsym 1 gaps inner current set 10
        bindsym 2 gaps inner current set 20
        bindsym 3 gaps inner current set 30
        bindsym 4 gaps inner current set 40
        bindsym 5 gaps inner current set 50
        bindsym r exec --no-startup-id \
                "i3-msg mode default && i3-msg gaps inner current set 0"

        # Back to Normal Mode
        bindsym Return mode "default"
        bindsym Escape mode "default"
        bindsym $mod+r mode "default"
}

bindsym $mod+m mode "mouse"
mode "mouse" {
        # Clicks
        bindsym j exec --no-startup-id xdotool click 1
        bindsym k exec --no-startup-id xdotool click 3
        bindsym l exec --no-startup-id xdotool click 2

        # Wheel
        bindsym t exec --no-startup-id xdotool click 4
        bindsym g exec --no-startup-id xdotool click 5

        bindsym y exec --no-startup-id xdotool click 4
        bindsym h exec --no-startup-id xdotool click 5

        # Movement
        bindsym a exec --no-startup-id \
                "~/dotfiles/i3/scripts/binSeekCursor.sh reset"
        bindsym e exec --no-startup-id \
                "~/dotfiles/i3/scripts/binSeekCursor.sh up"
        bindsym s exec --no-startup-id \
                "~/dotfiles/i3/scripts/binSeekCursor.sh left"
        bindsym d exec --no-startup-id \
                "~/dotfiles/i3/scripts/binSeekCursor.sh down"
        bindsym f exec --no-startup-id \
                "~/dotfiles/i3/scripts/binSeekCursor.sh right"

        # Slow Movement
        bindsym Shift+e exec --no-startup-id xdotool mousemove_relative -- 0 -1
        bindsym Shift+s exec --no-startup-id xdotool mousemove_relative -- -1 0
        bindsym Shift+d exec --no-startup-id xdotool mousemove_relative -- 0 1
        bindsym Shift+f exec --no-startup-id xdotool mousemove_relative -- 1 0

        # Back to Normal Mode
        bindsym Return mode "default"
        bindsym Escape mode "default"
        bindsym $mod+m mode "default"
}
