# dots-hyprland keybindings adapted for quickshell
# Based on /home/celes/.config/hypr/custom/keybinds.conf

# Key definitions
$Primary = Super
$Secondary = Control
$Tertiary = Shift
$Alternate = Alt
$MenuButton = Menu

# ################### It just works™ keybinds ###################
# Volume
bindl = ,XF86AudioMute, exec, pactl set-sink-mute @DEFAULT_SINK@ toggle
bindle = , XF86AudioRaiseVolume, exec, wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+
bindle = , XF86AudioLowerVolume, exec, wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-

# Brightness (adapted for quickshell)
bindle = , XF86MonBrightnessUp, exec, brightnessctl set '12.75+'
bindle = , XF86MonBrightnessDown, exec, brightnessctl set '12.75-'

# ####################################### Applications ########################################
# Core applications
bind = $Primary, Return, exec, foot
bind = $Primary, E, exec, nautilus
bind = $Primary, W, exec, firefox
bind = $Primary, C, exec, code

# Music applications
bind = $Primary$Secondary, M, exec, tidal-hifi
bind = $Primary$Secondary$Tertiary, M, exec, env -u NIXOS_OZONE_WL cider --use-gl=desktop
bind = $Primary$Secondary$Alternate, M, exec, spotify

# Communication
bind = $Primary$Secondary, O, exec, vesktop

# Terminals
bind = $Primary$Secondary, H, exec, foot
bind = $Primary$Secondary$Tertiary, T, exec, foot sleep 0.01 && nmtui

# File managers
bind = $Primary$Secondary, J, exec, thunar
bind = $Primary$Secondary$Tertiary, J, exec, nautilus

# Browsers
bind = $Primary$Secondary, B, exec, firefox
bind = $Primary$Secondary$Tertiary, B, exec, chromium

# Editors
bind = $Primary$Secondary, X, exec, subl
bind = $Primary$Secondary, C, exec, code
bind = $Primary$Secondary$Tertiary, C, exec, jetbrains-toolbox

# Calculator
bind = $Primary$Secondary, 3, exec, ~/.local/bin/wofi-calc
bind = ,XF86Calculator, exec, ~/.local/bin/wofi-calc

# System settings
bind = $Primary$Secondary, I, exec, XDG_CURRENT_DESKTOP="gnome" gnome-control-center
bind = $Primary$Secondary, V, exec, pavucontrol
bind = $Primary$Tertiary, Home, exec, gnome-system-monitor
bind = $Primary$Alternate, Insert, exec, foot -F btop

# Actions
bind = $Primary$Secondary, Period, exec, pkill fuzzel || ~/.local/bin/fuzzel-emoji
bind = $Alternate, F4, killactive,
bind = $Secondary$Alternate, Space, togglefloating,
bind = $Secondary$Alternate, Q, exec, hyprctl kill
bind = $Primary$Tertiary$Alternate, Delete, exec, pkill wlogout || wlogout -p layer-shell
bind = $Primary$Tertiary$Alternate$Secondary, Delete, exec, systemctl poweroff

# Screenshot, Record, OCR, Color picker, Clipboard history
bind = $Secondary$Tertiary, D, exec, ~/.local/bin/rubyshot | wl-copy
bindl = ,Print, exec, grim - | wl-copy
bind = $Secondary$Tertiary, 4, exec, grim -g "$(slurp -d -c D1E5F4BB -b 1B232866 -s 00000000)" - | wl-copy
bind = $Secondary$Tertiary, 5, exec, ~/.config/ags/scripts/record-script.sh
bind = $Secondary$Alternate, 5, exec, ~/.config/ags/scripts/record-script.sh --sound
bind = $Secondary$Tertiary$Alternate, 5, exec, ~/.config/ags/scripts/record-script.sh --fullscreen-sound

bind = $Secondary$Alternate, C, exec, hyprpicker -a
bind = $Primary$Alternate, Space, exec, cliphist list | wofi -Iim --dmenu | cliphist decode | wl-copy && wtype -M ctrl v -M ctrl
bind = $Secondary$Alternate, V, exec, cliphist list | wofi -Iim --dmenu | cliphist decode | wl-copy && wtype -M ctrl v -M ctrl

# Text-to-image OCR
bind = $Primary$Secondary$Tertiary, S, exec, grim -g "$(slurp -d -c D1E5F4BB -b 1B232866 -s 00000000)" "tmp.png" && tesseract "tmp.png" - | wl-copy && rm "tmp.png"
bind = $Secondary$Tertiary, T, exec, grim -g "$(slurp -d -c D1E5F4BB -b 1B232866 -s 00000000)" "tmp.png" && tesseract -l eng "tmp.png" - | wl-copy && rm "tmp.png"
bind = $Secondary$Tertiary, J, exec, grim -g "$(slurp -d -c D1E5F4BB -b 1B232866 -s 00000000)" "tmp.png" && tesseract -l jpn "tmp.png" - | wl-copy && rm "tmp.png"

# Media controls
bind = $Secondary$Tertiary, N, exec, playerctl next || playerctl position `bc <<< "100 * $(playerctl metadata mpris:length) / 1000000 / 100"`
bindl = , XF86AudioNext, exec, playerctl next
bindl = , XF86AudioPrev, exec, playerctl previous
bindl = , XF86AudioPlay, exec, playerctl play-pause
bind = $Secondary$Tertiary, B, exec, playerctl previous
bind = $Secondary$Tertiary, P, exec, playerctl play-pause

# Lock screen
bind = $Primary$Secondary, L, exec, hyprlock

# App launcher
bind = $Primary$Secondary, Slash, exec, pkill anyrun || anyrun

# ##################################### Quickshell keybinds #####################################
# Quickshell reload and reset
bindr = $Primary$Secondary, R, exec, hyprctl reload; pkill quickshell; pkill activewin.sh; pkill activews.sh; pkill gohypr; pkill bash; pkill ydotool; ~/.local/bin/quickshell-reset.sh; /home/celes/sources/celesrenata/end-4-dev/quickshell-wrapper.sh &

# Color generation and theming
bind = $Primary$Secondary, T, exec, /home/celes/sources/celesrenata/end-4-dev/generate-colors.sh

# Quickshell widgets (adapted from AGS)
bind = $Alternate, Tab, exec, quickshell -c overview
bind = $Secondary, Space, exec, quickshell -c overview
bind = $Secondary$Alternate, Slash, exec, quickshell -c cheatsheet
bind = $Secondary, B, exec, quickshell -c sideleft
bind = $Secondary, N, exec, quickshell -c sideright
bind = $Secondary, K, exec, quickshell -c osk
bind = $Primary$Alternate, Delete, exec, quickshell -c session

# Quickshell indicators and popups
bindle = , XF86AudioRaiseVolume, exec, quickshell -c indicator-volume
bindle = , XF86AudioLowerVolume, exec, quickshell -c indicator-volume
bindle = , XF86MonBrightnessUp, exec, quickshell -c indicator-brightness
bindle = , XF86MonBrightnessDown, exec, quickshell -c indicator-brightness

# Close quickshell windows on Super release
bindr = $Primary, $Primary_R, exec, quickshell -c close-all

# ########################### Keybinds for Hyprland ############################
# Swap windows
bind = $Secondary$Tertiary, left, movewindow, l
bind = $Secondary$Tertiary, right, movewindow, r
bind = $Secondary$Tertiary, up, movewindow, u
bind = $Secondary$Tertiary, down, movewindow, d

# Move focus
bind = $Secondary, left, movefocus, l
bind = $Secondary, right, movefocus, r
bind = $Alternate, up, movefocus, u
bind = $Alternate, down, movefocus, d
bind = $Secondary, BracketLeft, movefocus, l
bind = $Secondary, BracketRight, movefocus, r

# Workspace navigation
bind = $Primary$Secondary, right, workspace, +1
bind = $Primary$Secondary, left, workspace, -1
bind = $Primary$Secondary, BracketLeft, workspace, -1
bind = $Primary$Secondary, BracketRight, workspace, +1
bind = $Primary$Secondary, up, workspace, -5
bind = $Primary$Secondary, down, workspace, +5
bind = $Secondary, Page_Down, workspace, +1
bind = $Secondary, Page_Up, workspace, -1

# Move windows to workspaces
bind = $Secondary$Alternate, Page_Down, movetoworkspace, +1
bind = $Secondary$Alternate, Page_Up, movetoworkspace, -1
bind = $Primary$Secondary$Tertiary, Right, movetoworkspace, +1
bind = $Primary$Secondary$Tertiary, Left, movetoworkspace, -1

# Window split ratio
binde = $Primary$Secondary, Minus, splitratio, -0.1
binde = $Primary$Secondary, Equal, splitratio, 0.1
binde = $Secondary, Semicolon, splitratio, -0.1
binde = $Secondary, Apostrophe, splitratio, 0.1

# Fullscreen
bind = $Primary$Secondary, F, fullscreen, 0
bind = $Primary$Secondary, D, fullscreen, 1
bind = $Secondary$Alternate, F, fullscreenstate, 0

# Workspace switching (1-10)
bind = $Secondary, 1, workspace, 1
bind = $Secondary, 2, workspace, 2
bind = $Secondary, 3, workspace, 3
bind = $Secondary, 4, workspace, 4
bind = $Secondary, 5, workspace, 5
bind = $Secondary, 6, workspace, 6
bind = $Secondary, 7, workspace, 7
bind = $Secondary, 8, workspace, 8
bind = $Secondary, 9, workspace, 9
bind = $Secondary, 0, workspace, 10
bind = $Primary$Secondary, S, togglespecialworkspace,

# Move window to workspace silently
bind = $Secondary $Alternate, 1, movetoworkspacesilent, 1
bind = $Secondary $Alternate, 2, movetoworkspacesilent, 2
bind = $Secondary $Alternate, 3, movetoworkspacesilent, 3
bind = $Secondary $Alternate, 4, movetoworkspacesilent, 4
bind = $Secondary $Alternate, 5, movetoworkspacesilent, 5
bind = $Secondary $Alternate, 6, movetoworkspacesilent, 6
bind = $Secondary $Alternate, 7, movetoworkspacesilent, 7
bind = $Secondary $Alternate, 8, movetoworkspacesilent, 8
bind = $Secondary $Alternate, 9, movetoworkspacesilent, 9
bind = $Secondary $Alternate, 0, movetoworkspacesilent, 10
bind = $Secondary$Alternate, S, movetoworkspacesilent, special

# Mouse workspace switching
bind = $Secondary, mouse_up, workspace, +1
bind = $Secondary, mouse_down, workspace, -1
bind = $Primary$Secondary, mouse_up, workspace, +1
bind = $Primary$Secondary, mouse_down, workspace, -1

# Mouse window controls
bindm = $Primary, mouse:273, resizewindow
bindm = $Primary$Secondary, mouse:273, resizewindow
bindm = ,mouse:274, movewindow
bindm = $Secondary, mouse:273, movewindow
bind = $Primary$Secondary, Backslash, resizeactive, exact 640 480

# Alt+Tab window switching
bind = $Alternate, Tab, cyclenext
bind = $Alternate, Tab, bringactivetotop

# Testing and debugging
bind = $Secondary$Alternate, f12, exec, notify-send "Millis since epoch" "$(date +%s%N | cut -b1-13)" -a 'Hyprland keybind'
bind = $Secondary$Alternate, Equal, exec, notify-send "Urgent notification" "Ah hell no" -u critical -a 'Hyprland keybind'
