# vim: filetype=i3
#  _          _          ____            _ _   _     _       _ _____    ____             __ _
# | |   _   _| | _____  / ___| _ __ ___ (_) |_| |__ ( )___  (_)___ /   / ___|___  _ __  / _(_) __ _
# | |  | | | | |/ / _ \ \___ \| '_ ` _ \| | __| '_ \|// __| | | |_ \  | |   / _ \| '_ \| |_| |/ _` |
# | |__| |_| |   <  __/  ___) | | | | | | | |_| | | | \__ \ | |___) | | |__| (_) | | | |  _| | (_| |
# |_____\__,_|_|\_\___| |____/|_| |_| |_|_|\__|_| |_| |___/ |_|____/   \____\___/|_| |_|_| |_|\__, |
                                                                                            # |___/

# This is Luke Smith's i3-gaps configuration file.
# Me: http://lukesmith.xyz
# Email: luke@lukesmith.xyz
# YouTube: https://youtube.com/c/LukeSmithxyz
# Github: https://github.com/LukeSmithxyz

# Be sure that you have your $BROWSER environmental variable set to your favorite browser.
# E.g., put `export BROWSER="firefox"` into your bash_profile

# #---Basic Definitions---# #
#Needed for i3-gaps
for_window [class="^.*"] border pixel 3
gaps inner 15
gaps outer 15
font pango:mono 12
set $mod Mod4
set $term --no-startup-id st
set $stoprec --no-startup-id killrecording
exec --no-startup-id rm -f ~/.larbs/.recording

# #---Starting External Scripts---# #
#Setting the background:
exec_always --no-startup-id feh --bg-scale ~/.config/wall.png
#Starts dunst for notifications:
exec --no-startup-id dunst
#Music player daemon:
exec --no-startup-id mpd
#Torrent daemon:
exec --no-startup-id transmission-daemon
#Composite manager:
exec --no-startup-id compton --xrender-sync-fence
#Launch Polybar where appropriate:
#exec_always --no-startup-id ~/.scripts/polybar_launch
#Runs the key remapping scripts
exec --no-startup-id ~/.scripts/remaps
#Unclutter makes the mouse invisible after a brief period
exec --no-startup-id unclutter
#Network Manager applet
exec --no-startup-id nm-applet

bar {
	status_command i3blocks
	position top
	mode dock
	modifier None
}
# Run the script to update the mpd i3block on change.
exec --no-startup-id "pgrep i3mpdupdate || i3mpdupdate"

#OPENRC
#set $shutdown sudo openrc-shutdown -p
#set $reboot sudo openrc-shutdown -r
#set $netrefresh --no-startup-id sudo rc-service NetworkManager restart

#RUNIT
#set $shutdown sudo shutdown -h now
#set $reboot sudo reboot
#set $netrefresh --no-startup-id sudo sv restart NetworkManager

#SYSTEMD
set $shutdown sudo shutdown -h now
set $reboot sudo reboot
set $netrefresh --no-startup-id sudo systemctl restart NetworkManager
set $hibernate sudo systemctl suspend

# #---Basic Bindings---# #
bindsym $mod+Return 		exec $term
##bindsym $mod+Shift+Return

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

bindsym $mod+Escape		workspace prev
bindsym $mod+Shift+Escape 	exec --no-startup-id prompt "Are you sure you want to leave i3?" "i3-msg exit"

# bindsym $mod+BackSpace
bindsym $mod+Shift+BackSpace	exec --no-startup-id prompt "Are you sure you want to reboot?" "$reboot"

##bindsym $mod+grave
##bindsym $mod+asciitilde

#STOP/HIDE EVERYTHING:
bindsym $mod+Shift+Delete	exec --no-startup-id lmc truemute ; exec $truepause ; workspace lmao ; exec $term -e htop ; exec $term -e ranger

# #---Letter Key Bindings---# #
bindsym $mod+q			kill
bindsym $mod+Shift+q		kill

bindsym $mod+w			exec --no-startup-id $BROWSER
bindsym $mod+Shift+w		exec --no-startup-id $BROWSER

bindsym $mod+e			exec $term -e neomutt
##bindsym $mod+Shift+e

bindsym $mod+r 			exec $term -e ranger
bindsym $mod+Shift+r		exec $term -e sudo ranger /

bindsym $mod+t			split toggle
bindsym $mod+Shift+t		gaps inner current set 15; gaps outer current set 15

bindsym $mod+y			exec $term -e calcurse
bindsym $mod+Shift+y		exec --no-startup-id "bash ~/.scripts/i3resize left"

bindsym $mod+u			[instance="dropdown"] scratchpad show; [instance="dropdown"] move position center
bindsym $mod+Shift+u		exec --no-startup-id "bash ~/.scripts/i3resize down"

bindsym $mod+i 			exec $term -e htop
bindsym $mod+Shift+i		exec --no-startup-id "bash ~/.scripts/i3resize up"

bindsym $mod+o			sticky toggle
bindsym $mod+Shift+o		exec --no-startup-id "bash ~/.scripts/i3resize right"


bindsym $mod+p			exec --no-startup-id lmc toggle
#bindsym $mod+Shift+p

bindsym $mod+a			[instance="math"] scratchpad show; [instance="math"] move position center
bindsym $mod+Shift+a		exec $term -e ncpamixer

bindsym $mod+s			gaps inner current plus 5
bindsym $mod+Shift+s		gaps inner current minus 5

bindsym $mod+d			exec --no-startup-id dmenu_run
bindsym $mod+Shift+d		gaps inner current set 0; gaps outer current set 0

bindsym $mod+f			fullscreen toggle
##bindsym $mod+Shift+f

bindsym $mod+g			workspace prev
bindsym $mod+Shift+g		exec --no-startup-id gimp; workspace $ws5

bindsym $mod+h			focus left
bindsym $mod+Shift+h		move left 30

bindsym $mod+j			focus down
bindsym $mod+Shift+j		move down 30

bindsym $mod+k			focus up
bindsym $mod+Shift+k		move up 30

bindsym $mod+l			focus right
bindsym $mod+Shift+l		move right 30

bindsym $mod+z			gaps outer current plus 5
bindsym $mod+Shift+z		gaps outer current minus 5

bindsym $mod+x			exec --no-startup-id ~/.config/i3/lock.sh
bindsym $mod+Shift+x		exec --no-startup-id prompt "Are you sure you want to shutdown?" "$shutdown"

bindsym $mod+c			exec --no-startup-id camtoggle
##bindsym $mod+Shift+c

bindsym $mod+v			exec $term -e ncmpcpp -s visualizer
bindsym $mod+Shift+v		exec projectM-pulseaudio

bindsym $mod+b			bar mode toggle
bindsym $mod+Shift+b		floating toggle; sticky toggle; exec --no-startup-id bottomleft

bindsym $mod+n			exec $term -e newsboat
##bindsym $mod+Shift+n

bindsym $mod+m 			exec --no-startup-id st -e ncmpcpp
bindsym $mod+Shift+m		exec --no-startup-id lmc mute


# #---Workspace Bindings---# #
bindsym $mod+Home		workspace $ws1
bindsym $mod+Shift+Home		move container to workspace $ws1
bindsym $mod+End		workspace $ws10
bindsym $mod+Shift+End		move container to workspace $ws10
bindsym $mod+Prior		workspace prev
bindsym $mod+Shift+Prior	move container to workspace prev
bindsym $mod+Next		workspace next
bindsym $mod+Shift+Next		move container to workspace next
bindsym $mod+Tab		workspace back_and_forth
bindsym $mod+XF86Back		workspace prev
##bindsym $mod+Shift+XF86Back
bindsym $mod+XF86Forward	workspace next
##bindsym $mod+Shift+XF86Forward
bindsym $mod+semicolon		workspace next
bindsym $mod+apostrophe		split horizontal ;; exec $term
bindsym $mod+slash		split vertical ;; exec $term
bindsym $mod+Shift+slash	kill
bindsym $mod+backslash		workspace back_and_forth

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"

# 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

for_window [class="Pinentry"] sticky enable
for_window [class="sent"] border pixel 0px
for_window [class="Blender"] move to workspace $ws6
workspace $ws6 gaps inner 0
workspace $ws6 gaps outer 0
for_window [class="marble"] move to workspace $ws7
for_window [title="GIMP Startup"] move workspace $ws5
for_window [class="Gimp"] move workspace $ws5
workspace $ws5 gaps inner 0
workspace $ws5 gaps outer 0
for_window [window_role="gimp-dock"] floating disable; move left; resize shrink width 50 px or 50ppt
for_window [window_role="gimp-toolbox"] floating disable; move right; resize grow width 30 px or 30ppt
for_window [window_role="GtkFileChooserDialog"] resize shrink height 10 px
for_window [instance="dl"] move workspace $ws10

# First I have a tmux window used for background scripts.
# I'll later bind this to mod+u.
for_window [instance="dropdown"] floating enable
for_window [instance="dropdown"] resize set 625 400
for_window [instance="dropdown"] move scratchpad
for_window [instance="dropdown"] border pixel 5
# Runs the tmuxinit script, which searches for an earlier tmux instance,
# otherwise starts a new one (to prevent multiple dropdown sessions).
exec --no-startup-id $term -n dropdown -e tmuxinit
# Runs neofetch on first tmux screen if installed.
exec_always --no-startup-id "tmux send-keys -t 0:0 'clear && neofetch 2>/dev/null' Enter"

# Then I have a window running R I use for basic arithmetic
# I'll later bind this to mod+a.
for_window [instance="math"] floating enable
for_window [instance="math"] resize set 800 300
for_window [instance="math"] move scratchpad
for_window [instance="math"] border pixel 5
exec --no-startup-id $term -n math -f mono:pixelsize=24 -e dropdowncalc

# Bindings to make the webcam float and stick.
for_window [title="mpvfloat"] floating enable
for_window [title="mpvfloat"] sticky enable
for_window [title="mpvfloat"] border pixel 0
no_focus [title="mpvfloat"]

for_window [title="Default - Wine desktop"] floating enable

# #---Function Buttons---# #
bindsym $mod+F1		exec --no-startup-id zathura ~/.config/i3/i3_guide.pdf
bindsym $mod+F2		restart
bindsym $mod+F3		exec --no-startup-id displayselect
bindsym $mod+F4		exec --no-startup-id $hibernate
bindsym $mod+F5		exec --no-startup-id $netrefresh
bindsym $mod+F6		exec --no-startup-id $term -e transmission-remote-cli
##bindsym $mod+F7
##bindsym $mod+F8
bindsym $mod+F9		exec --no-startup-id dmenumount
bindsym $mod+F10	exec --no-startup-id dmenuumount
##bindsym $mod+F11
##bindsym $mod+F12


# #---Arrow Keys---# #
bindsym $mod+Left		focus left
bindsym $mod+Down		focus down
bindsym $mod+Up			focus up
bindsym $mod+Right 		focus 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


# #---Media Keys---# #

# Volume keys
bindsym $mod+plus		exec --no-startup-id lmc up 5
bindsym $mod+Shift+plus		exec --no-startup-id lmc up 15
bindsym $mod+minus 		exec --no-startup-id lmc down 5
bindsym $mod+Shift+minus	exec --no-startup-id lmc down 15
bindsym $mod+less 		exec --no-startup-id lmc prev
bindsym $mod+Shift+less		exec --no-startup-id lmc replay
bindsym $mod+greater		exec --no-startup-id lmc next
bindsym $mod+Shift+greater	exec --no-startup-id lmc next

# For advancing forward/backward in an mpd song
bindsym $mod+bracketleft 	exec --no-startup-id lmc back 10
bindsym $mod+Shift+bracketleft 	exec --no-startup-id lmc back 120
bindsym $mod+bracketright 	exec --no-startup-id lmc forward 10
bindsym $mod+Shift+bracketright exec --no-startup-id lmc forward 120

# For screenshots and recording
bindsym Print 			exec --no-startup-id scrot
bindsym Shift+Print 		exec --no-startup-id scrot -u
bindsym $mod+Print		exec --no-startup-id dmenurecord
bindsym $mod+Scroll_Lock	exec --no-startup-id "killall screenkey || screenkey"
bindsym $mod+Delete		exec $stoprec
bindsym XF86Launch1		exec $stoprec & xset dpms force off

# #---Extra XF86 Keys---# #
# These are the extra media keys that some keyboards have.
bindsym XF86AudioMute		exec --no-startup-id lmc mute
bindsym XF86AudioLowerVolume	exec --no-startup-id lmc down 5
bindsym XF86AudioRaiseVolume	exec --no-startup-id lmc up 5
bindsym XF86PowerOff		exec --no-startup-id prompt "Are you sure you want to shutdown?" "$shutdown"
##bindsym XF86Copy		exec
##bindsym XF86Open		exec
##bindsym XF86Paste		exec
##bindsym XF86Cut		exec
##bindsym XF86MenuKB		exec
bindsym XF86Calculator		exec $term -e R -q
bindsym XF86Sleep		exec sudo zzz
##bindsym XF86WakeUp		exec
bindsym XF86Explorer		exec $term -e ranger
##bindsym XF86Send		exec
##bindsym XF86Xfer		exec
bindsym XF86WWW			exec --no-startup-id $BROWSER
##bindsym XF86DOS		exec
bindsym XF86ScreenSaver		exec exec --no-startup-id ~/.config/i3/lock.sh
##bindsym XF86RotateWindows	exec
##bindsym XF86TaskPane		exec
##bindsym XF86Favorites		exec
bindsym XF86MyComputer		exec $term -e ranger
##bindsym XF86Back		exec
##bindsym XF86Forward		exec
bindsym XF86Eject		exec sudo umount -R /mnt
bindsym XF86AudioNext		exec --no-startup-id lmc next
bindsym XF86AudioPlay		exec --no-startup-id lmc toggle
bindsym XF86AudioPrev		exec --no-startup-id lmc prev
bindsym XF86AudioStop		exec --no-startup-id lmc toggle
##bindsym XF86AudioRecord
bindsym XF86AudioRewind		exec --no-startup-id lmc back 10
bindsym XF86AudioForward	exec --no-startup-id lmc forward 10
##bindsym XF86Phone		exec
##bindsym XF86Tools		exec
bindsym XF86HomePage		exec $BROWSER https://lukesmith.xyz
bindsym XF86Reload		restart
##bindsym XF86ScrollUp		exec
##bindsym XF86ScrollDown		exec
##bindsym XF86New		exec
##bindsym XF86LaunchA		exec
##bindsym XF86LaunchB		exec
##bindsym XF86Launch2		exec
##bindsym XF86Launch3		exec
##bindsym XF86Launch4		exec
##bindsym XF86Launch5		exec
##bindsym XF86Launch6		exec
##bindsym XF86Launch7		exec
##bindsym XF86Launch8		exec
##bindsym XF86Launch9		exec
#bindsym XF86AudioMicMute	exec $micmute
##bindsym XF86TouchpadToggle	exec
bindsym XF86TouchpadOn		exec --no-startup-id exec synclient TouchpadOff=0
bindsym XF86TouchpadOff		exec --no-startup-id exec synclient TouchpadOff=1
bindsym XF86Suspend		exec --no-startup-id ~/.config/i3/lock.sh
bindsym XF86Close		kill
bindsym XF86WebCam		exec --no-startup-id camtoggle
bindsym XF86Mail		exec $term -e neomutt
bindsym XF86Messenger		exec $term -e weechat
bindsym XF86Search		exec $BROWSER https://duckduckgo.com
##bindsym XF86Go			exec
##bindsym XF86Finance		exec
##bindsym XF86Game		exec
bindsym XF86Shop		exec $BROWSER https://ebay.com
bindsym XF86MonBrightnessDown	exec --no-startup-id xbacklight -dec 15
bindsym XF86MonBrightnessUp	exec --no-startup-id xbacklight -inc 15
bindsym XF86AudioMedia		exec --no-startup-id st -e ncmpcpp
bindsym XF86Display		exec --no-startup-id arandr
#bindsym XF86KbdLightOnOff	exec
bindsym XF86KbdBrightnessDown	exec --no-startup-id python3.6 ~/.i3/kb-lights.py -
bindsym XF86KbdBrightnessUp	exec --no-startup-id python3.6 ~/.i3/kb-lights.py +
##bindsym XF86Reply		exec
##bindsym XF86MailForward	exec
##bindsym XF86Save		exec
bindsym XF86Documents		exec $term -e ranger ~/Documents
##bindsym XF86Battery		exec
##bindsym XF86Bluetooth		exec
bindsym XF86WLAN		exec $netrefresh