Also, to go with that, I can post the newest version of my Aero Snap Window Management where you can use #Left, #Right, #End etc. to snap your windows into neat positions (supports rotating between positions).
Code: Select all
; AERO SNAP WINDOW MANAGEMENT (2017-01-05)
; -----------------------------------------------------------------------------------------------------
; --- Aero window management auto-execute part starts ----------------- ;
WinGetPos,,,, aeroTaskBarHeight, ahk_class Shell_TrayWnd
global aeroWin10margin := 10 ; In Windows 7 and 8 put here 0! In Win10 there is an invisible border margin (and margin's size probably depends on settings, a typical value is 10)!
global aeroTaskBarHeight := aeroTaskBarHeight-aeroWin10margin ; Taskbar also has the same invisible margin in Win10
; --- Aero window management auto-execute part ends ----------------- ;
#End::
<^>!End::GoSub, AeroEndMaxHeight ; <^>! = AltGr, or more precisely left^ right! (which is same as AltGr)
^#End::
^<^>!End::GoSub, AeroEnd800 ; Change width to 800px
+#End::
+<^>!End::GoSub, AeroEnd ; Just center horizontally
#Left::
<^>!Left::GoSub, AeroLeft
#Right::
<^>!Right::GoSub, AeroRight
#Up::
<^>!Up::GoSub, AeroUpHeight ; for some reason AltGr+Up is interpreted as !AltGr+Up???
#Down::
<^>!Down::GoSub, AeroDownHeight
#+Left::
<^>!+Left::GoSub, AeroLeftNoResize
#+Right::
<^>!+Right::GoSub, AeroRightNoResize
<^>!+Down:: ; AltGr+RShift+Down
!#Left::GoSub, AeroLeftWidth ; AltGr+^ is not possible (that's why it's not here)
<^>!+Up:: ; AltGr+RShift+Up
!#Right::GoSub, AeroRightWidth ; AltGr+^ is not possible (that's why it's not here)
!#Up::GoSub, AeroUp
!#Down::GoSub, AeroDown
AeroLeft:
WinGetTitle, currentWindow, A ; get the active window title
WinGetPos, aeroX, aeroY, aeroWidth, aeroHeight, A ; get active window x,y,W,H
WinGet, active_id, ID, A ; get active window ID (like 0xc00dc)
; / if window is already exactly at left
if (aeroX=0-aeroWin10margin && aeroY=0 && aeroWidth=(A_ScreenWidth/2)+aeroWin10margin*2 && aeroHeight=(A_ScreenHeight-aeroTaskBarHeight))
WinMove, %currentWindow%,, (A_ScreenWidth/2)-aeroWin10margin, 0, (A_ScreenWidth/2)+aeroWin10margin*2, (A_ScreenHeight-aeroTaskBarHeight)
; / if window is exactly at right
else if (aeroX=(A_ScreenWidth/2)-aeroWin10margin && aeroY=0 && aeroWidth=(A_ScreenWidth/2)+aeroWin10margin*2 && aeroHeight=(A_ScreenHeight-aeroTaskBarHeight))
{
; / let's check if we have the center position memorized..
aeroAlreadyMemorizedAt := 0 ; reset (not found memorized anywhere yet)
loop
if aeroAllMemorized%A_Index% ; we have to check if active ID already has a memory slot
{ ; FYI: aeroAllMemorized[1..n] = "ID x y W H"
stringsplit, tempArray, aeroAllMemorized%A_Index%, %A_Space%
if (tempArray1=active_id)
{
aeroAlreadyMemorizedAt := %A_Index%
break
}
} else break
if (aeroAlreadyMemorizedAt=0) ; we didn't find center memorized, so let's just move the window to x-center
{
WinMove, %currentWindow%,, A_ScreenWidth/2 - aeroWidth/2, 0
}
else ; we found the center, so let's put the window at memorized center
{
stringsplit, tempArray, aeroAllMemorized%aeroAlreadyMemorizedAt%, %A_Space%
WinMove, %currentWindow%,, tempArray2, tempArray3, tempArray4, tempArray5
}
}
else ; we have to memorize this "center" position
{
aeroAlreadyMemorizedAt := 0 ; reset (not found memorized anywhere yet)
memoryBankSize = 0 ; reset
loop
if aeroAllMemorized%A_Index% ; we have to check if active ID already has a memory slot
{
memoryBankSize++
stringsplit, tempArray, aeroAllMemorized%A_Index%, %A_Space%
if (tempArray1=active_id)
{
aeroAlreadyMemorizedAt := %A_Index%
aeroAllMemorized%A_Index% := active_id . " " . aeroX . " " . aeroY . " " . aeroWidth . " " . aeroHeight
break
}
} else break
if (aeroAlreadyMemorizedAt=0) ; if we didn't find an old memory slot for this ID
{
memoryBankSize++ ; let's create a new memory slot
aeroAllMemorized%memoryBankSize% := active_id . " " . aeroX . " " . aeroY . " " . aeroWidth . " " . aeroHeight
}
WinMove, %currentWindow%,, 0-aeroWin10margin, 0, (A_ScreenWidth/2)+aeroWin10margin*2, (A_ScreenHeight-aeroTaskBarHeight)
}
Return
AeroRight:
WinGetTitle, currentWindow, A ; get the active window title
WinGetPos, aeroX, aeroY, aeroWidth, aeroHeight, A ; get active window x,y,W,H
WinGet, active_id, ID, A ; get active window ID (like 0xc00dc)
; / if window is already exactly at left
if (aeroX=0-aeroWin10margin && aeroY=0 && aeroWidth=(A_ScreenWidth/2)+aeroWin10margin*2 && aeroHeight=(A_ScreenHeight-aeroTaskBarHeight))
{
; / let's check if we have the center position memorized..
aeroAlreadyMemorizedAt := 0 ; reset (not found memorized anywhere yet)
loop
if aeroAllMemorized%A_Index% ; we have to check if active ID already has a memory slot
{ ; FYI: aeroAllMemorized[1..n] = "ID x y W H"
stringsplit, tempArray, aeroAllMemorized%A_Index%, %A_Space%
if (tempArray1=active_id)
{
aeroAlreadyMemorizedAt := %A_Index%
break
}
} else break
if (aeroAlreadyMemorizedAt=0) ; we didn't find center memorized, so let's just move the window to x-center
WinMove, %currentWindow%,, aeroWidth/2, 0
else ; we found the center, so let's put the window at memorized center
{
stringsplit, tempArray, aeroAllMemorized%aeroAlreadyMemorizedAt%, %A_Space%
WinMove, %currentWindow%,, tempArray2, tempArray3, tempArray4, tempArray5
}
}
; / if window is exactly at right
else if (aeroX=(A_ScreenWidth/2)-aeroWin10margin && aeroY=0 && aeroWidth=(A_ScreenWidth/2)+aeroWin10margin*2 && aeroHeight=(A_ScreenHeight-aeroTaskBarHeight))
WinMove, %currentWindow%,, 0-aeroWin10margin, 0, (A_ScreenWidth/2)+aeroWin10margin*2, (A_ScreenHeight-aeroTaskBarHeight)
else ; we have to memorize this "center" position
{
aeroAlreadyMemorizedAt := 0 ; reset (not found memorized anywhere yet)
memoryBankSize = 0 ; reset
loop
if aeroAllMemorized%A_Index% ; we have to check if active ID already has a memory slot
{
memoryBankSize++
stringsplit, tempArray, aeroAllMemorized%A_Index%, %A_Space%
if (tempArray1=active_id)
{
aeroAlreadyMemorizedAt := %A_Index%
aeroAllMemorized%A_Index% := active_id . " " . aeroX . " " . aeroY . " " . aeroWidth . " " . aeroHeight
break
}
} else break
if (aeroAlreadyMemorizedAt=0) ; if we didn't find an old memory slot for this ID
{
memoryBankSize++ ; let's create a new memory slot
aeroAllMemorized%memoryBankSize% := active_id . " " . aeroX . " " . aeroY . " " . aeroWidth . " " . aeroHeight
}
WinMove, %currentWindow%,, (A_ScreenWidth/2)-aeroWin10margin, 0, (A_ScreenWidth/2)+aeroWin10margin*2, (A_ScreenHeight-aeroTaskBarHeight)
}
Return
AeroUpHeight:
; just maximize (current window) vertically
WinGetTitle, currentWindow, A ; get the active window title
WinGetPos, aeroX, aeroY, aeroWidth, aeroHeight, A ; get active window x,y,W,H
WinMove, %currentWindow%,, aeroX, 0, aeroWidth, A_ScreenHeight-aeroTaskBarHeight
Return
AeroDownHeight:
; vertically reduce (current window) size by 200px if its current height is more than 300px
WinGetTitle, currentWindow, A ; get the active window title
WinGetPos, aeroX, aeroY, aeroWidth, aeroHeight, A ; get active window x,y,W,H
if aeroHeight >299
WinMove, %currentWindow%,, aeroX, aeroY+100, aeroWidth, aeroHeight-200
Return
AeroEnd:
; #End CURRENT WINDOW LOCATION TO CENTER
WinGetTitle, WinTitleHere, A
WinGetPos,,, Width, Height, %WinTitleHere%
WinMove, %WinTitleHere%,, (A_ScreenWidth/2)-(Width/2), ((A_ScreenHeight-%aeroTaskBarHeight%)/2)-(Height/2)
Return
AeroEnd800:
; #End CURRENT WINDOW LOCATION TO CENTER AND WIDTH 800
WinGetTitle, WinTitleHere, A
WinGetPos,,, Width, Height, %WinTitleHere%
WinMove, %WinTitleHere%,, (A_ScreenWidth/2)-(800/2), ((A_ScreenHeight-%aeroTaskBarHeight%)/2)-(Height/2), 800
Return
AeroEndMaxHeight:
; #End CURRENT WINDOW LOCATION TO CENTER AND FIT VERTICALLY
WinGetTitle, WinTitleHere, A
WinGetPos,,, Width, Height, %WinTitleHere%
WinMove, %WinTitleHere%,, (A_ScreenWidth/2)-(Width/2), 0,, A_ScreenHeight-aeroTaskBarHeight
Return
AeroLeftNoResize:
WinGetTitle, currentWindow, A ; get the active window title
WinGetPos, aeroX, aeroY, aeroWidth, aeroHeight, A ; get active window x,y,W,H
WinGet, active_id, ID, A ; get active window ID (like 0xc00dc)
; / if window is horizontally already at left
if (aeroX=0-aeroWin10margin)
WinMove, %currentWindow%,, (A_ScreenWidth-aeroWidth)+aeroWin10margin
; / if window is horizontally already at right
else if (aeroX=(A_ScreenWidth-aeroWidth)+aeroWin10margin)
{
; / let's check if we have the center position memorized..
aeroAlreadyMemorizedAt := 0 ; reset (not found memorized anywhere yet)
loop
if aeroAllMemorized%A_Index% ; we have to check if active ID already has a memory slot
{ ; FYI: aeroAllMemorized[1..n] = "ID x y W H"
stringsplit, tempArray, aeroAllMemorized%A_Index%, %A_Space%
if (tempArray1=active_id)
{
aeroAlreadyMemorizedAt := %A_Index%
break
}
} else break
stringsplit, tempArray, aeroAllMemorized%aeroAlreadyMemorizedAt%, %A_Space%
if ((aeroAlreadyMemorizedAt=0) || (tempArray2=0 && tempArray3=aeroY && tempArray4=aeroWidth && tempArray5=aeroHeight) || (tempArray2=A_ScreenWidth-aeroWidth+aeroWin10margin && tempArray3=aeroY && tempArray4=aeroWidth && tempArray5=aeroHeight))
; we didn't find center memorized, so let's just move the window to X-center
; ..also if the memorized center position happens to be identical to left/right position
WinMove, %currentWindow%,, A_ScreenWidth/2 - aeroWidth/2, 0 ; move to X-center
else ; we found the center, so let's put the window at memorized center X (but current Y)
{
stringsplit, tempArray, aeroAllMemorized%aeroAlreadyMemorizedAt%, %A_Space%
WinMove, %currentWindow%,, tempArray2, aeroY, aeroWidth, aeroHeight
}
}
else ; we have to memorize this "center" position
{
aeroAlreadyMemorizedAt := 0 ; reset (not found memorized anywhere yet)
memoryBankSize = 0 ; reset
loop
if aeroAllMemorized%A_Index% ; we have to check if active ID already has a memory slot
{
memoryBankSize++
stringsplit, tempArray, aeroAllMemorized%A_Index%, %A_Space%
if (tempArray1=active_id)
{
aeroAlreadyMemorizedAt := %A_Index%
aeroAllMemorized%A_Index% := active_id . " " . aeroX . " " . aeroY . " " . aeroWidth . " " . aeroHeight
break
}
} else break
if (aeroAlreadyMemorizedAt=0) ; if we didn't find an old memory slot for this ID
{
memoryBankSize++ ; let's create a new memory slot
aeroAllMemorized%memoryBankSize% := active_id . " " . aeroX . " " . aeroY . " " . aeroWidth . " " . aeroHeight
}
WinMove, %currentWindow%,, 0-aeroWin10margin
}
Return
AeroRightNoResize:
WinGetTitle, currentWindow, A ; get the active window title
WinGetPos, aeroX, aeroY, aeroWidth, aeroHeight, A ; get active window x,y,W,H
WinGet, active_id, ID, A ; get active window ID (like 0xc00dc)
; / if window is horizontally already at left
if (aeroX=0-aeroWin10margin)
{
; / let's check if we have the center position memorized..
aeroAlreadyMemorizedAt := 0 ; reset (not found memorized anywhere yet)
loop
if aeroAllMemorized%A_Index% ; we have to check if active ID already has a memory slot
{ ; FYI: aeroAllMemorized[1..n] = "ID x y W H"
stringsplit, tempArray, aeroAllMemorized%A_Index%, %A_Space%
if (tempArray1=active_id)
{
aeroAlreadyMemorizedAt := %A_Index%
break
}
} else break
if ((aeroAlreadyMemorizedAt=0) || (tempArray2=0 && tempArray3=aeroY && tempArray4=aeroWidth && tempArray5=aeroHeight) || (tempArray2=A_ScreenWidth-aeroWidth+aeroWin10margin && tempArray3=aeroY && tempArray4=aeroWidth && tempArray5=aeroHeight))
; we didn't find center memorized, so let's just move the window to X-center
; ..also if the memorized center position happens to be identical to left/right position
WinMove, %currentWindow%,, A_ScreenWidth/2-aeroWidth/2, 0 ; move to X-center
else ; we found the center, so let's put the window at memorized center X (but current Y)
{
stringsplit, tempArray, aeroAllMemorized%aeroAlreadyMemorizedAt%, %A_Space%
WinMove, %currentWindow%,, tempArray2, aeroY, aeroWidth, aeroHeight
}
}
; / if window is horizontally already at right
else if (aeroX=(A_ScreenWidth-aeroWidth)+aeroWin10margin)
WinMove, %currentWindow%,, 0-aeroWin10margin
else ; we have to memorize this "center" position
{
aeroAlreadyMemorizedAt := 0 ; reset (not found memorized anywhere yet)
memoryBankSize = 0 ; reset
loop
if aeroAllMemorized%A_Index% ; we have to check if active ID already has a memory slot
{
memoryBankSize++
stringsplit, tempArray, aeroAllMemorized%A_Index%, %A_Space%
if (tempArray1=active_id)
{
aeroAlreadyMemorizedAt := %A_Index%
aeroAllMemorized%A_Index% := active_id . " " . aeroX . " " . aeroY . " " . aeroWidth . " " . aeroHeight
break
}
} else break
if (aeroAlreadyMemorizedAt=0) ; if we didn't find an old memory slot for this ID
{
memoryBankSize++ ; let's create a new memory slot
aeroAllMemorized%memoryBankSize% := active_id . " " . aeroX . " " . aeroY . " " . aeroWidth . " " . aeroHeight
}
WinMove, %currentWindow%,, (A_ScreenWidth-aeroWidth)+aeroWin10margin
}
Return
AeroLeftWidth:
WinGetTitle, currentWindow, A ; get the active window title
WinGetPos, aeroX, aeroY, aeroWidth, aeroHeight, A ; get active window x,y,W,H
if (aeroX=0-aeroWin10margin)
; if window is at the left edge (0% space at the left) then narrow down to the left until 20%
{
if (aeroWidth+aeroWin10margin*2 > (Floor(A_ScreenWidth*0.20)+200))
{
WinMove, %currentWindow%,, aeroX, aeroY, (aeroWidth-200)+aeroWin10margin*2, aeroHeight
}
}
else
if (aeroX < Floor((A_ScreenWidth-aeroWidth)/2)) ; if empty space at the left is less than at the right
{
WinMove, %currentWindow%,, 0-aeroWin10margin, aeroY, aeroWidth, aeroHeight
}
else ; space at the right was less, so let's max to 80% and leave 0% at the right
{
WinMove, %currentWindow%,, Floor(A_ScreenWidth*0.20)+aeroWin10margin, aeroY, Floor(A_ScreenWidth*0.80), aeroHeight
}
Return
AeroRightWidth:
WinGetTitle, currentWindow, A ; get the active window title
WinGetPos, aeroX, aeroY, aeroWidth, aeroHeight, A ; get active window x,y,W,H
if (aeroX=A_ScreenWidth+aeroWin10margin-aeroWidth)
; if window is at the right edge (0% space at the right) then narrow down to the right until 20%
{
if (aeroWidth+aeroWin10margin*2 > (Floor(A_ScreenWidth*0.20)+200))
WinMove, %currentWindow%,, A_ScreenWidth-aeroWidth+200-aeroWin10margin, aeroY, aeroWidth-200+aeroWin10margin*2, aeroHeight
}
else
if (aeroX > Floor((A_ScreenWidth-aeroWidth)/2)) ; if empty space at the left is more than at the right
{
WinMove, %currentWindow%,, A_ScreenWidth-aeroWidth+aeroWin10margin, aeroY, aeroWidth, aeroHeight
}
else
; ..or else horizontally 80%-maximize window so that there is 0% space at the left and 20% space at the right
{
WinMove, %currentWindow%,, 0-aeroWin10margin, aeroY, Floor(A_ScreenWidth*0.80), aeroHeight
}
Return
AeroUp:
WinGetTitle, currentWindow, A ; get the active window title
WinGetPos, aeroX, aeroY, aeroWidth, aeroHeight, A ; get active window x,y,W,H
WinMove, %currentWindow%,, aeroX, 0, aeroWidth, aeroHeight
Return
AeroDown:
WinGetTitle, currentWindow, A ; get the active window title
WinGetPos, aeroX, aeroY, aeroWidth, aeroHeight, A ; get active window x,y,W,H
WinMove, %currentWindow%,, aeroX, A_ScreenHeight-aeroHeight-aeroTaskBarHeight, aeroWidth, aeroHeight
Return