Skip to content

Instantly share code, notes, and snippets.

@oryon-dominik
Last active October 17, 2023 17:06
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oryon-dominik/562970f77f2ad4d9bd57bea58ddc8ef5 to your computer and use it in GitHub Desktop.
Save oryon-dominik/562970f77f2ad4d9bd57bea58ddc8ef5 to your computer and use it in GitHub Desktop.
AutoHotkey script to emulate Quake-Windows-Terminal behaviour
;; Quake-Windows-Terminal AutoHotkey.
;; Inspired from https://github.com/ehpc/quake-windows-bash
;; and https://github.com/rengler33/dotfiles/blob/master/C/Users/Rub/wt-quake-like.ahk
#SingleInstance force
WindowsTerminal = C:\Users\%A_UserName%\AppData\Local\Microsoft\WindowsApps\wt.exe
GetActiveMonitor()
{
Coordmode, Mouse, Screen
MouseGetPos, MouseX, MouseY
SysGet, numberOfMonitors, MonitorCount
Loop, %numberOfMonitors%
{
SysGet, monitor%A_Index%, Monitor, %A_Index%
if ( MouseX >= monitor%A_Index%left ) && ( MouseX < monitor%A_Index%right ) && ( MouseY >= monitor%A_Index%top ) && ( MouseY < monitor%A_Index%bottom )
{
ActiveMonitor := A_Index
break
}
}
ActiveMonitor--
return ActiveMonitor
}
GetTerminalMonitor()
{
WinActivate, ahk_exe Terminal
WinGetPos, WindowXpos, WindowYpos
SysGet, farLeftMonitorX, 76
if ( WindowXpos >= farLeftMonitorX + 2 * A_ScreenWidth)
{
position := 2 ; right monitor
}
else if ( WindowXpos >= farLeftMonitorX + A_ScreenWidth)
{
position := 1 ; central monitor
}
else if ( WindowXpos <= (farLeftMonitorX + A_ScreenWidth))
{
position := 0 ; left monitor
}
return position
}
CalcNewXPosition(activeMonitor, terminalMonitor, window)
{
WinActivate, ahk_exe Terminal
WinGetPos, WindowXpos, WindowYpos
;; this forumla determines where the terminal will spawn, you may have to change order here, if your monitor configuration is different
;;
relativeDistance := (terminalMonitor - activeMonitor)
distance := A_ScreenWidth * relativeDistance
;; MsgBox, "Move to" "x:" %WindowXpos% "d:" %distance% "t:" %terminalMonitor% "a:" %activeMonitor% "r:" %relativeDistance%
moveToX := WindowXpos - distance
return moveToX
}
^^:: ; On CTRL+^ press
WinGet, windows, List,
SetTitleMatchMode RegEx
if WinExist("ahk_exe Terminal")
if WinActive("ahk_exe Terminal")
{
WinMinimize, ahk_exe Terminal
}
else
{
activeMonitor := GetActiveMonitor()
terminalMonitor := GetTerminalMonitor()
moveToX := CalcNewXPosition(activeMonitor, terminalMonitor, ahk_exe Terminal)
WinMove %moveToX%, %Ypos%
}
else
Run, %WindowsTerminal%
Return
@Navidda
Copy link

Navidda commented Oct 17, 2023

I changed the shortcut and removed the move window functionality because I had some issues with it. Now it works perfectly!

;; Quake-Windows-Terminal AutoHotkey.

;; Inspired from https://github.com/ehpc/quake-windows-bash
;; and https://github.com/rengler33/dotfiles/blob/master/C/Users/Rub/wt-quake-like.ahk

#SingleInstance force

WindowsTerminal = C:\Users\%A_UserName%\AppData\Local\Microsoft\WindowsApps\wt.exe

#`:: ; On Win+`


    WinGet, windows, List,
    SetTitleMatchMode RegEx

    if WinExist("ahk_exe Terminal")
        if WinActive("ahk_exe Terminal")
            {
                WinMinimize, ahk_exe Terminal
            }
        else
            {
                WinActivate, ahk_exe Terminal
            }
    else
        Run, %WindowsTerminal%

Return


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment