; macOS bindings

SendMode Input
SetWorkingDir %A_ScriptDir%
SetTitleMatchMode 2

GroupAdd, Browser, Firefox
GroupAdd, Browser, Edge
GroupAdd, Browser, Chrome

GroupAdd, WebCatalog, Personal
GroupAdd, WebCatalog, Apple
GroupAdd, WebCatalog, Work
GroupAdd, WebCatalog, Ferdium

; ---------------------------------- Global ----------------------------------
#Space::  ; toggle Windows Terminal quake mode
send #``
return

; ---------------------------------- Editing ---------------------------------
!x::  ; cut
send ^x
return

!c::  ; copy
if WinActive("ahk_exe WindowsTerminal.exe") || WinActive("ahk_exe wezterm-gui.exe")
  send ^+c
else
  send ^c
return

!v::  ; paste
if WinActive("ahk_exe WindowsTerminal.exe") || WinActive("ahk_exe wezterm-gui.exe")
  send ^+v
else
  send ^v
return

!z::  ; undo
send ^z
return

!+z::  ; redo
send ^y
return

!a::  ; select all
send ^a
return

$!r::  ; reload
if WinActive("ahk_group Browser") || WinActive("ahk_group WebCatalog")
  send ^r
else if WinActive("ahk_exe explorer.exe")
  send {F5}
else
  send !r
return

; -------------------------------- Navigation --------------------------------

$![::     ; back from Alt+[
$<^>![::  ;      from AltGr+[
if WinActive("ahk_group Browser") || WinActive("ahk_group WebCatalog") || WinActive("ahk_exe explorer.exe")
  send !{Left}
else
  send ![
return

$!]::     ; forward from Atl+]
$<^>!]::  ;         from AltGr+]
if WinActive("ahk_group Browser") || WinActive("ahk_group WebCatalog") || WinActive("ahk_exe explorer.exe")
  send !{Right}
else
  send !]
return

$!+r::  ; reload (override cache)
if WinActive("ahk_group Browser")
  send ^+r
else
  send !+r
return

; ------------------------------- Current Page -------------------------------
$!Down::  ; go to bottom of page
if WinActive("ahk_group Browser")
  send ^{Down}
else
  send !{Down}
return

$!Up::  ; go to top of page
if WinActive("ahk_group Browser")
  send ^{Up}
else
  send !{Up}
return

$!p::  ; print
if WinActive("ahk_group Browser")
  send ^p
else
  send !p
return

$!=::  ; zoom in
if WinActive("ahk_group Browser")
  send ^+=
else
  send !+=
return

$!-::  ; zoom out
if WinActive("ahk_group Browser")
  send ^-
else
  send !-
return

$!0::  ; zoom reset
if WinActive("ahk_group Browser")
  send ^0
else
  send !0
return

; ---------------------------------- Search ----------------------------------
$!f::  ; find
if WinActive("ahk_group Browser")
  send ^f
else
  send !f
return

$!l::  ; focus address bar
if WinActive("ahk_group Browser")
  send ^l
else
  send !l
return

; ------------------------------ Windows & Tabs ------------------------------
$!w::  ; close tab
if WinActive("ahk_group Browser")
  send ^w
else if WinActive("ahk_exe wezterm-gui.exe")
  send ^+w
else
  send !w
return

!<#w::  ; close window - the fuck is this?
if WinActive("ahk_group Browser")
  send ^+w
; TODO: else
return

!q::  ; quit
if WinActive("ahk_group Browser")
  send ^+q
else
  send !{F4}
return

$!+[::  ; go one tab left
if WinActive("ahk_group Browser") || WinActive("ahk_exe wezterm-gui.exe")
  send ^{PgUp}
else
  send !+[
return

$!+]::  ; go one tab right
if WinActive("ahk_group Browser") || WinActive("ahk_exe wezterm-gui.exe")
  send ^{PgDn}
else
  send !+]
return

$^!+[::  ; move one tab left
if WinActive("ahk_group Browser") || WinActive("ahk_exe wezterm-gui.exe")
  send ^+{PgUp}
else
  send ^!+[
return

$^!+]::  ; move one tab right
if WinActive("ahk_group Browser") || WinActive("ahk_exe wezterm-gui.exe")
  send ^+{PgDn}
else
  send ^!+]
return

$!t::  ; new tab
if WinActive("ahk_group Browser")
  send ^t
else
  send !t
return

$!n::  ; new window
if WinActive("ahk_group Browser")
  send ^n
else
  send !n
return

$!+n::  ; new private window
if WinActive("ahk_group Browser")
  send ^+p
else
  send !+n
return

$!+t::  ; undo closed tab
if WinActive("ahk_group Browser")
  send ^+t
else
  send !+t
return

$!1::  ; select tab 1
if WinActive("ahk_group Browser") || WinActive("ahk_group WebCatalog")
  send ^1
else
  send !1
return

$!2::  ; select tab 2
if WinActive("ahk_group Browser") || WinActive("ahk_group WebCatalog")
  send ^2
else
  send !2
return

$!3::  ; select tab 3
if WinActive("ahk_group Browser") || WinActive("ahk_group WebCatalog")
  send ^3
else
  send !3
return

$!4::  ; select tab 4
if WinActive("ahk_group Browser") || WinActive("ahk_group WebCatalog")
  send ^4
else
  send !4
return

$!5::  ; select tab 5
if WinActive("ahk_group Browser") || WinActive("ahk_group WebCatalog")
  send ^5
else
  send !5
return

$!6::  ; select tab 6
if WinActive("ahk_group Browser") || WinActive("ahk_group WebCatalog")
  send ^6
else
  send !6
return

$!7::  ; select tab 7
if WinActive("ahk_group Browser") || WinActive("ahk_group WebCatalog")
  send ^7
else
  send !7
return

$!8::  ; select tab 8
if WinActive("ahk_group Browser") || WinActive("ahk_group WebCatalog")
  send ^8
else
  send !8
return

$!9::  ; select tab 9
if WinActive("ahk_group Browser") || WinActive("ahk_group WebCatalog")
  send ^9
else
  send !9
return

; TODO: Firefox History
; TODO: Firefox Bookmarks
; TODO: Firefox Tools
; TODO: Firefox PDF Viewer
; TODO: Firefox Miscellaneous
; TODO: Firefox Media shortcuts
; TODO: Firefox Selection of Multiple Tabs