# This file is a modified version based on default i3-config-wizard config
# source is available here:
# https://raw.githubusercontent.com/endeavouros-team/endeavouros-i3wm-setup/master/.config/i3/config
# Maintainer: joekamprad [joekamprad@endeavouros.com]
# https://endeavouros.com
#
# iconic font icon search: https://fontawesome.com/v4.7/cheatsheet/
#
# --> to update this run the following command (will backup existing setup file)
# wget --backups=1 https://raw.githubusercontent.com/endeavouros-team/endeavouros-i3wm-setup/main/.config/i3/config -P ~/.config/i3/
#
# Endeavouros-i3 config file
# Source for complete framework of our i3 config and theming here: https://github.com/endeavouros-team/endeavouros-i3wm-setup
# EndeavourOS wiki holds some Information also: https://discovery.endeavouros.com/window-tiling-managers/i3-wm/
# Please see http://i3wm.org/docs/userguide.html for the official i3 reference!

#######################
# config starts here: #
#######################

# Font for window titles. Will also be used by the bar unless a different font
# is used in the bar {} block below.
# 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: Noto Sans Regular 10

# set the mod key to the winkey:
set $mod Mod4

#####################
# workspace layout: #
#####################

# default i3 tiling mode:
workspace_layout default

##############################
# extra options for windows: #
##############################

#border indicator on windows:
new_window pixel 1

# thin borders
# hide_edge_borders both

# Set inner/outer gaps
gaps inner 6
gaps outer 3

# Use Mouse+$mod to drag floating windows to their wanted position
floating_modifier $mod

# switch to workspace with number keys (ws 1 - 10)
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

# switch to workspace with numpad keys (ws 11 - 20)
bindcode $mod+87 workspace 11
bindcode $mod+88 workspace 12
bindcode $mod+89 workspace 13
bindcode $mod+83 workspace 14
bindcode $mod+84 workspace 15
bindcode $mod+85 workspace 16
bindcode $mod+79 workspace 17
bindcode $mod+80 workspace 18
bindcode $mod+81 workspace 19
bindcode $mod+90 workspace 20

# switch to workspace with numlock numpad keys (ws 11 - 20)
bindcode $mod+Mod2+87 workspace $ws11
bindcode $mod+Mod2+88 workspace $ws12
bindcode $mod+Mod2+89 workspace $ws13
bindcode $mod+Mod2+83 workspace $ws14
bindcode $mod+Mod2+84 workspace $ws15
bindcode $mod+Mod2+85 workspace $ws16
bindcode $mod+Mod2+79 workspace $ws17
bindcode $mod+Mod2+80 workspace $ws18
bindcode $mod+Mod2+81 workspace $ws19
bindcode $mod+Mod2+90 workspace $ws20

# move focused container to workspace (ws 1 - 10)
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

# move focused container to workspace with numpad keys (ws 11 - 20)
bindcode $mod+Shift+Mod2+87 	move container to workspace  $ws11
bindcode $mod+Shift+Mod2+88 	move container to workspace  $ws12
bindcode $mod+Shift+Mod2+89 	move container to workspace  $ws13
bindcode $mod+Shift+Mod2+83 	move container to workspace  $ws14
bindcode $mod+Shift+Mod2+84 	move container to workspace  $ws15
bindcode $mod+Shift+Mod2+85 	move container to workspace  $ws16
bindcode $mod+Shift+Mod2+79 	move container to workspace  $ws17
bindcode $mod+Shift+Mod2+80 	move container to workspace  $ws18
bindcode $mod+Shift+Mod2+81 	move container to workspace  $ws19
bindcode $mod+Shift+Mod2+90 	move container to workspace  $ws20

# move focused container to workspace with numpad keys (ws 11 - 20)
bindcode $mod+Shift+87 	 move container to workspace  $ws11
bindcode $mod+Shift+88 	 move container to workspace  $ws21
bindcode $mod+Shift+89 	 move container to workspace  $ws13
bindcode $mod+Shift+83 	 move container to workspace  $ws14
bindcode $mod+Shift+84 	 move container to workspace  $ws15
bindcode $mod+Shift+85 	 move container to workspace  $ws16
bindcode $mod+Shift+79 	 move container to workspace  $ws17
bindcode $mod+Shift+80 	 move container to workspace  $ws18
bindcode $mod+Shift+81 	 move container to workspace  $ws19
bindcode $mod+Shift+90 	 move container to workspace  $ws20

# switch/iterate between workspaces
bindsym $mod+Tab workspace next
bindsym $mod+Shift+Tab workspace prev

# move focused workspace between monitors
bindsym $mod+Ctrl+Right move workspace to output right
bindsym $mod+Ctrl+Left move workspace to output left

######################################
# keybindings for different actions: #
######################################

# start a terminal
bindsym $mod+Return exec xfce4-terminal

# kill focused window
bindsym $mod+Shift+q kill

# exit-menu
bindsym $mod+Shift+e exec "i3-nagbar -t warning -m 'You pressed the exit shortcut. Do you really want to exit i3? This will end your X session.' -B 'Yes, exit i3' 'i3-msg exit'"

# Lock the system
# lock with a picture:
#bindsym $mod+l exec i3lock -i  ~/.config/i3/i3-lock-screen.png -p default|win -t
# lock by blurring the screen:
bindsym $mod+l exec ~/.config/i3/scripts/blur-lock

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

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

# Screen brightness controls
bindsym XF86MonBrightnessUp exec xbacklight -inc 20 # increase screen brightness
bindsym XF86MonBrightnessDown exec xbacklight -dec 20 # decrease screen brightness

# change focus
bindsym $mod+j focus left
bindsym $mod+k focus down
bindsym $mod+b focus up
bindsym $mod+o focus right

# alternatively, you can use the cursor keys:
bindsym $mod+Left focus left
bindsym $mod+Down focus down
bindsym $mod+Up focus up
bindsym $mod+Right focus right

# move focused window
bindsym $mod+Shift+j move left
bindsym $mod+Shift+k move down
bindsym $mod+Shift+b move up
bindsym $mod+Shift+o move right

# alternatively, you can use the cursor keys:
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+h 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+g layout tabbed
bindsym $mod+e layout toggle split

# toggle tiling / floating
bindsym $mod+Shift+space floating toggle

# change focus between tiling / floating windows
bindsym $mod+space focus mode_toggle

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

# open new empty workspace
bindsym $mod+Shift+n exec ~/.config/i3/scripts/empty_workspace

# Multimedia Keys

# volume
bindsym XF86AudioRaiseVolume exec amixer -D pulse sset Master 5%+ && pkill -RTMIN+1 i3blocks
bindsym XF86AudioLowerVolume exec amixer -D pulse sset Master 5%- && pkill -RTMIN+1 i3blocks

# gradular volume control
bindsym $mod+XF86AudioRaiseVolume exec amixer -D pulse sset Master 1%+ && pkill -RTMIN+1 i3blocks
bindsym $mod+XF86AudioLowerVolume exec amixer -D pulse sset Master 1%- && pkill -RTMIN+1 i3blocks

# mute
bindsym XF86AudioMute exec amixer sset Master toggle && killall -USR1 i3blocks

# audio control
bindsym XF86AudioPlay exec playerctl play
bindsym XF86AudioPause exec playerctl pause
bindsym XF86AudioNext exec playerctl next
bindsym XF86AudioPrev exec playerctl previous

# Redirect sound to headphones
bindsym $mod+p exec /usr/local/bin/switch-audio-port

## App shortcuts
bindsym $mod+w exec /usr/bin/firefox
bindsym $mod+n exec /usr/bin/dolphin
bindsym Print exec flameshot gui && notify-send "Screenshot saved to ~/Pictures/$(date +"%Y-%m-%d-%T")-screenshot.png"

# Power Profiles menu switcher (rofi)
bindsym $mod+Shift+p exec ~/.config/i3/scripts/power-profiles

# setup displays
bindsym $mod+Shift+d exec --no-startup-id ~/.config/i3/scripts/displayconfig

##########################################
# configuration for workspace behaviour: #
##########################################

# Define names for default workspaces for which we configure key bindings later on.
# We use variables to avoid repeating the names in multiple places.
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"
set $ws11 "11"
set $ws12 "12"
set $ws13 "13"
set $ws14 "14"
set $ws15 "15"
set $ws16 "16"
set $ws17 "17"
set $ws18 "18"
set $ws19 "19"
set $ws20 "20"

# bind program to workspace and focus to them on startup:
assign [class="Xfce4-terminal"] $ws1
assign [class="(?i)firefox"] $ws2
assign [class="dolphin"] $ws3
assign [class="Thunderbird"] $ws4
assign [class="GitHub Desktop"] $ws4
assign [class="discord"] $ws5
assign [class="Spotify"] &ws6
assign [class="Sublime_text"] $ws7

##############
# compositor #
##############

exec_always --no-startup-id picom #--config  ~/.config/picom/picom.conf

#############################################
# autostart applications/services on login: #
#############################################

#get auth work with polkit-gnome
exec --no-startup-id /usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1

# dex execute .desktop files + apps using /etc/xdg/autostart.
# when second to i3 a DE is installed or mixed usage of i3 + xfce4 or GNOME
# in this cases better disable dex and use manual starting apps using xdg/autostart
# if enabled you should comment welcome app.
# https://github.com/jceb/dex
#exec --no-startup-id dex -a -s /etc/xdg/autostart/:~/.config/autostart/
exec --no-startup-id dex --autostart --environment i3

# num lock activated
exec --no-startup-id numlockx on

# set wallpaper
#exec --no-startup-id feh --bg-fill /usr/share/endeavouros/backgrounds/eos_wallpapers_community/Rockwallaby_EOS_NEO.jpg
exec_always --no-startup-id "nitrogen --restore"

# set powersavings for display:
exec --no-startup-id xset s 480 dpms 600 600 600

# Desktop notifications
exec --no-startup-id dbus-launch dunst --config ~/.config/dunst/dunstrc

# autotiling script
exec_always --no-startup-id autotiling

# display config
exec_always --no-startup-id ~/.config/i3/scripts/displayconfig

# Autostart apps
exec --no-startup-id sleep 2 && xfce4-terminal
exec --no-startup-id sleep 2 && xfce4-terminal -e "neofetch" --hold
exec --no-startup-id sleep 2 && xfce4-terminal -e btop
exec --no-startup-id sleep 7 && firefox
exec --no-startup-id sleep 3 && dolphin
exec --no-startup-id sleep 3 && discord
exec --no-startup-id sleep 3 && spotify
exec --no-startup-id sleep 3 && tmux new-session -d -s streamdeck "/home/jonas_jones/.local/bin/streamdeck -n"
exec --no-startup-id sleep 3 && github-desktop
exec --no-startup-id sleep 3 && syncthing



##################
# floating rules #
##################

# set floating (nontiling) for apps needing it
for_window [class="Yad" instance="yad"] floating enable
for_window [class="Galculator" instance="galculator"] floating enable
for_window [class="Blueberry.py" instance="blueberry.py"] floating enable

# set floating (nontiling) for special apps
for_window [class="Xsane" instance="xsane"] floating enable
for_window [class="Pavucontrol" instance="pavucontrol"] floating enable
for_window [class="qt5ct" instance="qt5ct"] floating enable
for_window [class="Blueberry.py" instance="blueberry.py"] floating enable
for_window [class="Bluetooth-sendto" instance="bluetooth-sendto"] floating enable
for_window [class="Pamac-manager"] floating enable
for_window [window_role="About"] floating enable
for_window [class="Blueman-manager"] floating enable

# set border of floating window
for_window [class="urxvt"] border pixel 1

######################################
# color settings for bar and windows #
######################################

# Define colors variables:
set $darkbluetrans	#08052be6
set $darkblue		#08052b
set $lightblue		#5294e2
set $urgentred		#e53935
set $white		#ffffff
set $black		#000000
set $purple		#e345ff
set $darkgrey		#383c4a
set $grey		#b0b5bd
set $mediumgrey		#8b8b8b
set $yellowbrown	#e1b700

# define colors for windows:
#class		        	border		bground		text		indicator	child_border
client.focused		    	$lightblue	$darkblue	$white		$mediumgrey	$mediumgrey
client.unfocused	    	$darkblue	$darkblue	$grey		$darkgrey	$darkgrey
client.focused_inactive		$darkblue	$darkblue	$grey		$black		$black
client.urgent		    	$urgentred	$urgentred	$white		$yellowbrown	$yellowbrown

############################################
# bar settings (input comes from i3blocks) #
############################################

bar {
		font pango: Noto Sans Regular 10
		status_command i3blocks -c ~/.config/i3/i3blocks.conf
	    	position top
#	    	i3bar_command i3bar --transparency
		    tray_output primary
		    tray_padding 5
strip_workspace_numbers yes

		    colors {
		    separator          $purple
		    background         #2E414B
		    statusline         $white
#                          		border 		        bg		txt		indicator
		focused_workspace	$mediumgrey	   	$grey		$darkgrey	$purple
		active_workspace	$lightblue      	$mediumgrey	$darkgrey	$purple
		inactive_workspace	$darkgrey   		$darkgrey	$grey		$purple
		urgent_workspace	$urgentred	    	$urgentred	$white		$purple
	}
}

#####################################
# Application menu handled by rofi: #
#####################################

## rofi bindings fancy application menu ($mod+d /F9 optional disabled)

bindsym $mod+d exec rofi -modi drun -show drun \
		-config ~/.config/rofi/rofidmenu.rasi

bindsym $mod+t exec rofi -show window \
		-config ~/.config/rofi/rofidmenu.rasi