##############################
### HYPRLAND - KEYBINDINGS ###
##############################

# See https://wiki.hyprland.org/Configuring/Keywords/
$mainMod = SUPER                # "Command/Windows" key as main modifier
$windowMod = ALT                # Option for window controls.
$MEH = ALT SHIFT CTRL
$HYPER = ALT SHIFT SUPER CTRL

# See https://wiki.hyprland.org/Configuring/Keywords/

$terminal = uwsm app -- ghostty
$browser = uwsm app -- brave
$fileManager = $terminal -e yazi
$fileBrowser = uwsm app -- nautilus
$menu = hyprlauncher
$scripts = ~/.local/scripts/hypr
$pwa = $scripts/launch-webapp
$tmuxSessionator = ~/.local/scripts/tmux-sessionator
$clipboardHistory = com.ghostty.clipse $terminal --class=com.ghostty.clipse -e clipse
$uninstallDesktop = $terminal --class=com.ghostty.float -e $scripts/uninstall-desktop-app
$utilsLauncher = com.ghostty.utils-launcher $scripts/utils-launcher --launch
$housecallPro = https://pro.housecallpro.com/app/calendar_new

# Example binds, see https://wiki.hyprland.org/Configuring/Binds/ for more

##############################################################################################
# Apps / hyprland controls
#
# These should in general use the $mainMod prefix
##############################################################################################
#       MOD            # KEY  #     DESC                                #  Action            # 
##############################################################################################

bindd = $mainMod,       SPACE,  Application launcher,                     exec, $menu
bindd = $mainMod,       RETURN, New terminal,                             exec, $terminal
bindd = $mainMod SHIFT, RETURN, New floating terminal,                    exec, $terminal --class=com.ghostty.float
bindd = $mainMod,       TAB,    Focus previous workspace,                 exec, $scripts/workspacectl switch --to previous
bindd = $mainMod,       A,      [A]i - launch / focus,                    exec, $pwa --or-focus "https://ollama.housh.dev"
bindd = $mainMod SHIFT, A,      [A]i - new window,                        exec, $pwa "https://ollama.housh.dev"
bindd = $mainMod,       B,      New [b]rowser,                            exec, $browser
bindd = $mainMod SHIFT, B,      New private [b]rowser,                    exec, $browser --incognito
bindd = $mainMod,       C,      [C]alendar,                               exec, $pwa --or-focus "https://www.icloud.com/calendar"
bindd = $mainMod SHIFT, C,      [C]onfig folder in tmux session,          exec, $terminal -e $tmuxSessionator ~/.config
bindd = $mainMod,       D,      [D]ispatch app - special workspace,       exec, $pwa --special dispatch $housecallPro
bindd = $mainMod SHIFT, D,      [D]ispatch app - new window,              exec, $pwa --new $housecallPro
bindd = $mainMod,       E,      [E]mail - personal,                       exec, $pwa --or-focus "https://mail.proton.me"
bindd = $mainMod SHIFT, E,      [E]mail - work,                           exec, $scripts/launch --or-focus thunderbird uwsm app -- thunderbird
bindd = $mainMod,       F,      [F]ile manager - terminal,                exec, $fileManager
bindd = $mainMod SHIFT, F,      [F]ile manager - application,             exec, $fileBrowser
bindd = $mainMod,       G,      [G]itea,                                  exec, $pwa --or-focus "https://git.housh.dev"
bindd = $mainMod SHIFT, G,      [G]ithub,                                 exec, $pwa --or-focus "https://github.com"
bindd = $mainMod,       H,      Focus window - left,                      movefocus, l # move window focus using vim keys
bindd = $mainMod SHIFT, H,      Workspace - back,                         workspace, -1
bindd = $mainMod,       J,      Focus window - down,                      movefocus, d # move window focus using vim keys
bindd = $mainMod,       K,      Focus window - up,                        movefocus, u # move window focus using vim keys
bindd = $mainMod,       L,      Focus window - right,                     movefocus, r # move window focus using vim keys
bindd = $mainMod SHIFT, L,      Workspace - forward,                      workspace, +1
bindd = $mainMod,       M,      [M]usic - apple,                          exec, $pwa --special music "https://music.apple.com"
bindd = $mainMod SHIFT, M,      [M]enu bar - toggle visible,              exec, $scripts/waybarctl --toggle
bindd = $mainMod,       O,      Purchase [o]rders,                        exec, $pwa --special dispatch "https://po.housh.dev"
bindd = $mainMod,       P,      [P]assword manager,                       exec, $pwa --special pass "https://pass.proton.me"
bindd = $mainMod SHIFT, P,      [P]hotos,                                 exec, $pwa --or-focus "https://photos.housh.dev"
bindd = $mainMod SHIFT, R,      [R]estart menu bar,                       exec, $scripts/waybarctl --restart
bindd = $mainMod,       S,      Toggle [s]pecial workspace,               togglespecialworkspace, magic  # use $windowMod S to send window to the special workspace
bindd = $mainMod,       Y,      [Y]ouTube,                                exec, $pwa --or-focus "https://youtube.com"
bindd = $mainMod,       U,      [U]nifi,                                  exec, $pwa "https://unifi.ui.com"
bindd = $mainMod SHIFT, U,      [U]tility launcher,                       exec, $scripts/launch --or-close $utilsLauncher
bindd = $mainMod,       V,      Clipboard history,                        exec, $scripts/launch --or-close $clipboardHistory
bindd = $mainMod,       W,      Close current window,                     killactive,
bindd = $mainMod SHIFT, W,      Close all windows in active workspace,    exec, $scripts/windowctl close --active-workspace

# Switch to workspaces with mainMod + [0-9]
bindd = $mainMod, 1, Switch to workspace [1],  exec, $scripts/workspacectl switch --to 1
bindd = $mainMod, 2, Switch to workspace [2],  exec, $scripts/workspacectl switch --to 2
bindd = $mainMod, 3, Switch to workspace [3],  exec, $scripts/workspacectl switch --to 3
bindd = $mainMod, 4, Switch to workspace [4],  exec, $scripts/workspacectl switch --to 4
bindd = $mainMod, 5, Switch to workspace [5],  exec, $scripts/workspacectl switch --to 5
bindd = $mainMod, 6, Switch to workspace [6],  exec, $scripts/workspacectl switch --to 6
bindd = $mainMod, 7, Switch to workspace [7],  exec, $scripts/workspacectl switch --to 7
bindd = $mainMod, 8, Switch to workspace [8],  exec, $scripts/workspacectl switch --to 8
bindd = $mainMod, 9, Switch to workspace [9],  exec, $scripts/workspacectl switch --to 9
bindd = $mainMod, 0, Switch to workspace 1[0], exec, $scripts/workspacectl switch --to 10

# Move all workspaces to a monitor
bindd = $mainMod SHIFT, 1, Switch all workspaces to monitor [1], exec, $scripts/mv-all-workspaces-to-monitor 1
bindd = $mainMod SHIFT, 0, Switch all workspaces to monitor [0], exec, $scripts/mv-all-workspaces-to-monitor 0

# Screen Shots
bindd = $mainMod SHIFT, 3, Screenshot a monitor,      exec, hyprshot --mode output --output-folder ~/Pictures
bindd = $mainMod SHIFT, 4, Screenshot a selection,    exec, hyprshot --mode region --output-folder ~/Pictures
bindd = $mainMod SHIFT, 5, Screenshot a window,       exec, hyprshot --mode window --output-folder ~/Pictures

# Scroll through existing workspaces with mainMod + scroll
bind = $mainMod, mouse_down, workspace, e+1
bind = $mainMod, mouse_up, workspace, e-1

# Move/resize windows with mainMod + LMB/RMB and dragging
bindm = $mainMod, mouse:272, movewindow
bindm = $mainMod, mouse:273, resizewindow
bindm = $mainMod SHIFT, mouse_down, resizewindow

#######################################################################################
# Window controls
#
# These should in general use the $windowMod prefix
##########################################################################################
#       MOD             # KEY  #     DESC                         # Action               # 
##########################################################################################
# TODO: Decide which is prefered to switch to fullscreen.
bindd = CTRL,             F,     Toggle [f]ullscreen,                 fullscreen,
bindd = $windowMod,       F,     Toggle [f]loating,                   exec, $scripts/windowctl toggle-floating --active --width 80% --height 80%
bindd = $windowMod SHIFT, F,     Toggle [f]loating,                   exec, $scripts/windowctl toggle-floating --active
bindd = $windowMod,       H,     Move window - left,                  movewindow, l     # move windows with windowMod + vim keys
bindd = $windowMod,       J,     Move window - down,                  movewindow, d     # move windows with windowMod + vim keys
bindd = $windowMod,       K,     Move window - up,                    movewindow, u     # move windows with windowMod + vim keys
bindd = $windowMod,       L,     Move window - right ,                movewindow, r     # move windows with windowMod + vim keys
bindd = $windowMod,       M,     Move window to [m]usic workspace,    movetoworkspace, special:music
bindd = $windowMod SHIFT, P,     Toggle [p]seudo window mode,         pseudo, # dwindle
bindd = $windowMod,       S,     Move window to [s]pecial workspace,  movetoworkspacesilent, special:magic
bindd = $windowMod,       W,     [W]indow actions,                    exec, $scripts/windowctl launch action --active
# FIX: Changes size of window, this works a different depending on if
# the window is on the right or left of the screen.
#
# Resize horizontally
bindd = $windowMod, EQUAL, Increase window size - horizontal,     resizeactive, 20 0
bindd = $windowMod, MINUS, Decrease window size - horizontal,     resizeactive, -20 0
# Resize vertically
bindd = $windowMod SHIFT, EQUAL, Increase window size - vertical, resizeactive, 0 20
bindd = $windowMod SHIFT, MINUS, Decrease window size - vertical, resizeactive, 0 -20

# Move active window to a workspace with windowMod + [0-9]
bindd = $windowMod, 1, Move window to workspace [1], movetoworkspace, 1
bindd = $windowMod, 2, Move window to workspace [2], movetoworkspace, 2
bindd = $windowMod, 3, Move window to workspace [3], movetoworkspace, 3
bindd = $windowMod, 4, Move window to workspace [4], movetoworkspace, 4
bindd = $windowMod, 5, Move window to workspace [5], movetoworkspace, 5
bindd = $windowMod, 6, Move window to workspace [6], movetoworkspace, 6
bindd = $windowMod, 7, Move window to workspace [7], movetoworkspace, 7
bindd = $windowMod, 8, Move window to workspace [8], movetoworkspace, 8
bindd = $windowMod, 9, Move window to workspace [9], movetoworkspace, 9
bindd = $windowMod, 0, Move window to workspace 1[0], movetoworkspace, 10

#######################################################################################
# HYPER (Alt + Shift + Super + Ctrl) controls
#
# These should in general use the $HYPER prefix
#######################################################################################
#       MOD          # KEY  #     DESC                         # Action               # 
#######################################################################################

bindd = $HYPER,       H,     [H]ide / show windows,              exec, $scripts/workspacectl toggle
bindd = $HYPER,       J,     Toggle split orientation,           togglesplit           # dwindle
bindd = $HYPER,       L,     [L]ock computer,                    exec, hyprlock
bindd = $HYPER,       W,     Close all windows,                  exec, $scripts/windowctl close --all

# Move active window to a workspace silently with HYPER + [0-9]
bindd = $HYPER, 1, Move window to workspace silent [1], movetoworkspacesilent, 1
bindd = $HYPER, 2, Move window to workspace silent [2], movetoworkspacesilent, 2
bindd = $HYPER, 3, Move window to workspace silent [3], movetoworkspacesilent, 3
bindd = $HYPER, 4, Move window to workspace silent [4], movetoworkspacesilent, 4
bindd = $HYPER, 5, Move window to workspace silent [5], movetoworkspacesilent, 5
bindd = $HYPER, 6, Move window to workspace silent [6], movetoworkspacesilent, 6
bindd = $HYPER, 7, Move window to workspace silent [7], movetoworkspacesilent, 7
bindd = $HYPER, 8, Move window to workspace silent [8], movetoworkspacesilent, 8
bindd = $HYPER, 9, Move window to workspace silent [9], movetoworkspacesilent, 9
bindd = $HYPER, 0, Move window to workspace silent 1[0], movetoworkspacesilent, 10


#######################################################################################
# MEH (Alt + Shift + Ctrl) controls
#
# These should in general use the $MEH prefix
#######################################################################################
#       MOD          # KEY  #     DESC                         # Action               # 
#######################################################################################
bindd = $MEH,         L,     [L]ogs picker / viewer,            exec, $terminal --class=com.ghostty.float -e $scripts/utils/logs/logs-picker

##################################################
# Multi-media keys
##################################################
# Laptop multimedia keys for volume and LCD brightness
bindel = ,XF86AudioRaiseVolume, exec, wpctl set-volume -l 1 @DEFAULT_AUDIO_SINK@ 5%+
bindel = ,XF86AudioLowerVolume, exec, wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-
bindel = ,XF86AudioMute, exec, wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle
bindel = ,XF86AudioMicMute, exec, wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle
bindel = ,XF86MonBrightnessUp, exec, brightnessctl -e4 -n2 set 5%+
bindel = ,XF86MonBrightnessDown, exec, brightnessctl -e4 -n2 set 5%-

# Requires playerctl
bindl = , XF86AudioNext, exec, playerctl next
bindl = , XF86AudioPause, exec, playerctl play-pause
bindl = , XF86AudioPlay, exec, playerctl play-pause
bindl = , XF86AudioPrev, exec, playerctl previous

