## Copyright (C) 2020-2023 Aditya Shakya <adi1090x@gmail.com>config.d
##
## Keybindings

##-- Key Bindings ------------------------

## A keysym (key symbol) is a description for a specific symbol, like "a" or "b", 
## but also more strange ones like "underscore" instead of "_".
## These are the ones you use in Xmodmap to remap your keys. 
## To get the current mapping of your keys, use `xmodmap -pke`.
## To interactively enter a key and see what keysym it is configured to, use `xev`.
##
## Keycodes do not need to have a symbol assigned (handy for custom vendor hotkeys on some notebooks)
## and they will not change their meaning as you switch to a different keyboard layout (when using `xmodmap`). 
##
## If you often switch keyboard layouts but you want to keep your bindings in the 
## same physical location on the keyboard, use keycodes.
## If you don’t switch layouts, and want a clean and simple config file, use keysyms.
##
## Available Modifiers: Mod1-Mod5, Shift, Control
##
## Syntax:
# bindsym [--release] [<Group>+][<Modifiers>+]<keysym> command
# bindcode [--release] [<Group>+][<Modifiers>+]<keycode> command

##-- Variables ---------------------------
set $terminal ~/.config/i3/scripts/i3_term
set $music_player ~/.config/i3/scripts/i3_music
set $color_picker ~/.config/i3/scripts/i3_colorpicker
set $brightness ~/.config/i3/scripts/i3_brightness
set $volume ~/.config/i3/scripts/i3_volume
set $screenshot ~/.config/i3/scripts/i3_screenshot
set $alacritty alacritty --config-file ~/.config/i3/alacritty/alacritty.yml
set $rofi_applets ~/.config/i3/scripts
set $file_manager nemo
set $text_editor nvim
set $web_browser firefox

## -- Terminal --
bindsym $MOD+Return 			exec --no-startup-id $terminal
bindsym $MOD+Shift+Return 		exec --no-startup-id $terminal --float
bindsym $MOD+$ALT+Return 		exec --no-startup-id $terminal --full

## -- GUI Apps --
bindsym $MOD+Shift+f 			exec --no-startup-id $file_manager
bindsym $MOD+Shift+e 			exec --no-startup-id $text_editor
bindsym $MOD+Shift+w 			exec --no-startup-id $web_browser

## -- CLI Apps --
bindsym $ALT+Control+v 			exec --no-startup-id "$alacritty -e vim"
bindsym $ALT+Control+r 			exec --no-startup-id "$alacritty -e ranger"
bindsym $ALT+Control+h 			exec --no-startup-id "$alacritty -e htop"
bindsym $ALT+Control+m 			exec --no-startup-id $music_player

## -- Rofi Applets --
bindsym $MOD+p   				exec --no-startup-id $rofi_applets/rofi_launcher -dpi 1
bindsym $MOD+n 					exec --no-startup-id $rofi_applets/network_menu -dpi 1
bindsym $MOD+r 					exec --no-startup-id $rofi_applets/rofi_powermenu -dpi 1
bindsym $MOD+q 					exec --no-startup-id $rofi_applets/rofi_windows -dpi 1
bindsym $MOD+m 					exec --no-startup-id $rofi_applets/rofi_music -dpi 1
# bindsym $MOD+r 					exec --no-startup-id $rofi_applets/rofi_asroot
# bindsym $MOD+s 					exec --no-startup-id $rofi_applets/rofi_screenshot
bindsym $MOD+t 					exec --no-startup-id $rofi_applets/rofi_themes -dpi 1

## -- Function keys --
bindsym XF86MonBrightnessUp 	exec --no-startup-id "$brightness --inc"
bindsym XF86MonBrightnessDown 	exec --no-startup-id "$brightness --dec"
bindsym XF86AudioRaiseVolume 	exec --no-startup-id "$volume --inc"
bindsym XF86AudioLowerVolume 	exec --no-startup-id "$volume --dec"
bindsym XF86AudioMute 			exec --no-startup-id "$volume --toggle"
bindsym XF86AudioMicMute 		exec --no-startup-id "$volume --toggle-mic"
bindsym XF86AudioNext 			exec --no-startup-id "mpc next"
bindsym XF86AudioPrev 			exec --no-startup-id "mpc prev"
bindsym XF86AudioPlay 			exec --no-startup-id "mpc toggle"
bindsym XF86AudioStop 			exec --no-startup-id "mpc stop"

## -- Screenshots --
bindsym Print 					exec --no-startup-id "$screenshot --now"
bindsym Control+Print 			exec --no-startup-id "$screenshot --in5"
# bindsym Shift+Print 			exec --no-startup-id "$screenshot --in10"
bindsym Shift+Print 					exec --no-startup-id $rofi_applets/rofi_screenshot
bindsym Control+Shift+Print 	exec --no-startup-id "$screenshot --win"
bindsym $MOD+Print 				exec --no-startup-id "$screenshot --area"

## -- Misc --
# bindsym --release $MOD+p 		exec --no-startup-id $color_picker
bindsym $ALT+Control+l 			exec --no-startup-id "betterlockscreen --lock"

##-- WM Specific -------------------------

## Kill focused window
##
bindsym $MOD+w kill
bindsym $MOD+c kill

#------

## Send Notification
##
set $send-notify exec --no-startup-id dunstify -u low -h string:x-dunst-stack-tag:i3config

## Splitting containers
##
## split in horizontal orientation
bindsym $MOD+h split horizontal, $send-notify 'Split Horizontally'
## split in vertical orientation
bindsym $MOD+v split vertical, $send-notify 'Split Vertically'
## toggle split
#bindsym $MOD+g split toggle, $send-notify 'Split Mode'

#------

## Manipulating layout
##
## change container layout (stacked, tabbed, toggle split)
## Set stacking layout
bindsym $MOD+Shift+s layout stacking, $send-notify 'Layout - Stacking'
## Set tabbed layout
bindsym $MOD+Shift+t layout tabbed, $send-notify 'Layout - Tabbed'
## Set default layout
bindsym $MOD+Shift+d layout default, $send-notify 'Layout - Default'
## Toggle between stacking/tabbed/split:
bindsym $MOD+Shift+l layout toggle, $send-notify 'Cycling Layouts'
## Toggle between horizontal/vertical:
bindsym $MOD+Shift+v layout toggle split, $send-notify 'Layout - Hor/Vert'
## Toggle fullscreen
bindsym $MOD+f fullscreen toggle, $send-notify 'Toggled Fullscreen'
## Toggle floating/tiling
bindsym $MOD+space floating toggle, $send-notify 'Toggled Floating Mode'

#------

## Focusing containers
##
## Sets focus to the nearest container in the given direction.
bindsym $MOD+Left focus left
bindsym $MOD+Down focus down
bindsym $MOD+Up focus up
bindsym $MOD+Right focus right
## Sets focus to the parent container of the current container.
bindsym $MOD+a focus parent
## The opposite of `focus parent`, sets the focus to the last focused child container.
bindsym $MOD+d focus child
## Automatically sets focus to the adjacent container.
bindsym $MOD+Tab focus next
## Toggles focus between floating/tiling containers.
bindsym $MOD+Shift+space focus mode_toggle

#------

## Moving containers
##
## move focused window in the given direction.
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 floating container to the center of all outputs (floating only)
bindsym $MOD+$ALT+c move absolute position center
## Move container to the current position of the cursor (floating only)
bindsym $MOD+$ALT+p move position mouse

#------

## Resizing containers/windows
##
bindsym $MOD+$ALT+Left resize shrink width 50 px or 10 ppt
bindsym $MOD+$ALT+Down resize grow height 50 px or 10 ppt
bindsym $MOD+$ALT+Up resize shrink height 50 px or 10 ppt
bindsym $MOD+$ALT+Right resize grow width 50 px or 10 ppt

#------

## Sticky floating windows (floating only)
##
bindsym $MOD+Shift+o sticky toggle, $send-notify 'Toggled Sticky'

#------

## Changing border style
##
bindsym $MOD+y border toggle, $send-notify 'Toggled Borders'

#------

## Scratchpad
##
## Make the currently focused window a scratchpad
bindsym $MOD+Shift+minus move scratchpad, $send-notify 'Scratchpad'
## Show the first scratchpad window
bindsym $MOD+minus scratchpad show

#------

## restart i3 inplace (preserves your layout/session, can be used to upgrade i3)
bindsym Ctrl+Shift+r restart, $send-notify 'i3wm Restarted!'
## reload the configuration file
bindsym $MOD+Shift+c reload, $send-notify 'Configuration Reloaded!'
## quit i3 session
bindsym $MOD+Shift+q exit

#------

## Changing (named) workspaces/moving to workspaces
##
## 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"

## switch to workspace
bindsym $MOD+1 workspace number $ws1
bindsym $MOD+2 workspace number $ws2
bindsym $MOD+3 workspace number $ws3
bindsym $MOD+4 workspace number $ws4
bindsym $MOD+5 workspace number $ws5
bindsym $MOD+6 workspace number $ws6
bindsym $MOD+7 workspace number $ws7
bindsym $MOD+8 workspace number $ws8
bindsym $MOD+9 workspace number $ws9
bindsym $MOD+0 workspace number $ws10

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

## move a container to the next/previous workspace
bindsym $MOD+Control+Right "move container to workspace next, workspace next"
bindsym $MOD+Control+Left "move container to workspace prev, workspace prev"

## switch between the current and the previously focused one
bindsym $MOD+b workspace back_and_forth
bindsym $MOD+Shift+b "move container to workspace back_and_forth, workspace back_and_forth"
