;GridMove ;By jgpaiva ;date: May 2006 ;function: adjusts windows to a predefined desktop grid ;;options: MButtonDrag := False ;to be able to drag a window using the 3rd mouse button LButtonDrag := False ;to be able to drag a window by it's title EdgeActivation := True ;to be able to bring the grid up when dragging a window to the edge EdgeTime := 100 ShowGroupsFlag := True ;configures the showing or not of the groups ShowGroupsTime := 2000 CaptionSize := 25 WindowPercentage := 0.05 ScreenWidth := A_ScreenWidth ;if you have a dual screen layout, please adjust. otherwise, it should be A_ScreenWidth. ScreenHeight := A_ScreenHeight ;if you have a dual screen layout, please adjust. otherwise, it should be A_ScreenHeight. ;;end of options ScriptVersion = Beta 4.5 Menu, Tray, Tip, GridMove %ScriptVersion% GoSub, AssignGroups GoSub, ReadIni Mutex := False GroupsShowing := False EdgeFlag := True If MButtonDrag Hotkey, MButton, MButtonMove If LButtonDrag Hotkey, ~LButton, LButtonMove If EdgeActivation Settimer, Edge, 200 GoSub,createGroups Hotkey,RButton,RightButton Hotkey,RButton,off #maxthreadsperhotkey 1 #singleinstance,force LButtonMove: CoordMode,Mouse,Relative MouseGetPos, OldMouseX, OldMouseY, MouseWin, WinGetPos,,,winwidth,,ahk_id %mousewin% WinGetTitle,Wintitle,ahk_id %mousewin% WinGetClass,WinClass,ahk_id %mousewin% If OldMouseY > %CaptionSize% return If (OldMouseX > WinWidth * WindowPercentage) return If WinTitle = return If WinClass = Shell_TrayWnd return LButtonGrid: send {LButton up} gosub,showgroups Hotkey,RButton,on CoordMode,Mouse,Screen loop { KeyWait,LButton,D T0.1 If errorlevel = 1 break WinGetPos, WinLeft, WinTop, WinWidth, WinHeight,A MouseGetPos, MouseX, MouseY, window, flagLButton:=true loop,%NGroups% { TriggerTop= %A_Index%TriggerTop TriggerBottom = %A_Index%TriggerBottom TriggerRight = %A_Index%TriggerRight TriggerLeft = %A_Index%TriggerLeft Triggertop=% %Triggertop% Triggerbottom=% %Triggerbottom% Triggerright=% %Triggerright% Triggerleft=% %Triggerleft% GridTop= %A_Index%GridTop GridBottom = %A_Index%GridBottom GridRight = %A_Index%GridRight GridLeft = %A_Index%GridLeft GridTop=% %Gridtop% GridBottom=% %Gridbottom% GridRight=% %Gridright% GridLeft=% %Gridleft% If GridTop = WindowHeight { GridTop := WinTop GridBottom := WinTop + WinHeight } If GridLeft = WindowWidth { GridLeft := WinLeft GridRight := WinLeft + WinWidth } GridHeight=% GridBottom - GridTop GridWidth=% GridRight - GridLeft If (MouseY >= TriggerTop) If (MouseY <= TriggerBottom) If (MouseX <= TriggerRight) If (MouseX >= TriggerLeft) { Gui, 2:show, x%GridLeft% y%GridTop% w%GridWidth% h%GridHeight% NoActivate flagLButton:=false break } } if flagLButton Gui,2:Hide } Gui,2:Hide Hotkey,RButton,off if GroupsShowing { GoSub,SnapWindow } settimer,showgroups, off gosub,hidegroups GroupsShowing := False return RightButton: if GroupsShowing { GroupsShowing := false GoSub, HideGroups } else GoSub SnapWindow return MButtonMove: CoordMode,Mouse,Screen MouseGetPos, OldMouseX, OldMouseY, window, KeyWait,MButton,T0.2 if errorlevel = 0 { send,{MButton} return } GoSub,ShowGroups Winactivate, ahk_id %window% loop { KeyWait,MButton,D T0.1 if errorlevel <> 0 { gui, 2:hide gosub,SnapWindow break } WinGetPos, WinLeft, WinTop, WinWidth, WinHeight,A MouseGetPos, MouseX, MouseY, window, flagMButton:=true loop,%NGroups% { TriggerTop= %A_Index%TriggerTop TriggerBottom = %A_Index%TriggerBottom TriggerRight = %A_Index%TriggerRight TriggerLeft = %A_Index%TriggerLeft Triggertop=% %Triggertop% Triggerbottom=% %Triggerbottom% Triggerright=% %Triggerright% Triggerleft=% %Triggerleft% GridTop= %A_Index%GridTop GridBottom = %A_Index%GridBottom GridRight = %A_Index%GridRight GridLeft = %A_Index%GridLeft GridTop=% %Gridtop% GridBottom=% %Gridbottom% GridRight=% %Gridright% GridLeft=% %Gridleft% If GridTop = WindowHeight { GridTop := WinTop GridBottom := WinTop + WinHeight } If GridLeft = WindowWidth { GridLeft := WinLeft GridRight := WinLeft + WinWidth } GridHeight=% GridBottom - GridTop GridWidth=% GridRight - GridLeft If (MouseY >= TriggerTop) If (MouseY <= TriggerBottom) If (MouseX <= TriggerRight) If (MouseX >= TriggerLeft) { Gui, 2:show, x%GridLeft% y%GridTop% w%GridWidth% h%GridHeight% NoActivate flagMButton:=false break } } if flagMButton Gui,2:Hide } GoSub,HideGroups return edge: loop { KeyWait,LButton,D T0.01 If errorlevel = 1 { SetTimer, EdgeMove, Off continue } CoordMode,Mouse,Relative MouseGetPos, OldMouseX, OldMouseY, MouseWin, If OldMouseY > %CaptionSize% continue If WinTitle = continue If WinClass = Shell_TrayWnd continue CoordMode, Mouse, Screen MouseGetPos, MouseX, MouseY, MouseWin If (MouseY <= 2 OR MouseX <= 2 OR MouseY >= ScreenHeight -2 OR MouseX >= ScreenWidth -2) If EdgeFlag { settimer, EdgeMove, %EdgeTime% EdgeFlag := False continue } else continue SetTimer, EdgeMove, Off EdgeFlag := True } return edgemove: SetTimer, EdgeMove, Off GoSub,LButtonGrid return #g:: gosub,showgroups WinId := WinExist("a") WinGettitle, WinTitle,ahk_id %winid% inputbox,number, Grid to move,Please input the number of the grid are you'd like to move the following window: %WinTitle% if errorlevel <> 0 { gosub,hidegroups return } if number is not number { winget,state,minmax,ahk_id %winid% if number = m if state = 1 WinRestore,ahk_id %winid% else PostMessage, 0x112, 0xF030,,, ahk_id %winid%, if number = r reload if number = e exitapp if number = mbutton { If MButtonDrag { Hotkey, MButton, off MButtonDrag := False } else { Hotkey, MButton, on MButtonDrag := true } } gosub,hidegroups return } if number not between 1 and %NGroups% { PostMessage, 0x112, 0xF020,,, ahk_id %winid%, gosub,hidegroups return } GridTop= %number%GridTop GridBottom = %number%GridBottom GridRight = %number%GridRight GridLeft = %number%GridLeft Gridtop=% %Gridtop% Gridbottom=% %Gridbottom% Gridright=% %Gridright% Gridleft=% %Gridleft% WinMove, ahk_id %winid%, ,%GridLeft%,%GridTop%, % GridRight - GridLeft,% GridBottom - GridTop, gosub,hidegroups return SnapWindow: send, {LButton up} CoordMode,Mouse,Screen MouseGetPos, MouseX, MouseY, MouseWin, WinGetPos, WinLeft, WinTop, WinWidth, WinHeight,A loop %NGroups% { triggerTop= %A_Index%TriggerTop triggerBottom = %A_Index%TriggerBottom triggerRight = %A_Index%TriggerRight triggerLeft = %A_Index%TriggerLeft triggertop=% %triggertop% triggerbottom=% %triggerbottom% triggerright=% %triggerright% triggerleft=% %triggerleft% GridTop= %A_Index%GridTop GridBottom = %A_Index%GridBottom GridRight = %A_Index%GridRight GridLeft = %A_Index%GridLeft Gridtop=% %Gridtop% Gridbottom=% %Gridbottom% Gridright=% %Gridright% Gridleft=% %Gridleft% If GridTop = WindowHeight { GridTop := WinTop GridBottom := WinTop + WinHeight } If GridLeft = WindowWidth { GridLeft := WinLeft GridRight := WinLeft + WinWidth } If (MouseY >= triggerTop) If (MouseY <= triggerBottom) If (MouseX <= triggerRight) If (MouseX >= triggerLeft) { WinRestore,A WinMove, A, ,%GridLeft%,%GridTop%, % GridRight - GridLeft,% GridBottom - GridTop, break } } gosub, hidegroups return ;*************************************************************************Groups showgroups: if not ShowGroupsFlag return settimer,showgroups, off Gui,Show, X0 Y0 W%ScreenWidth% H%ScreenHeight% NoActivate sleep,100 GroupsShowing := True return Hidegroups: Gui,hide return creategroups: gui,destroy Gui, Font, s16 cRed Bold, Verdana loop,%NGroups% { TriggerTop = %A_Index%TriggerTop TriggerBottom = %A_Index%TriggerBottom TriggerRight = %A_Index%TriggerRight TriggerLeft = %A_Index%TriggerLeft Triggertop =% %Triggertop% - 12 Triggerbottom =% %Triggerbottom% Triggerright =% %Triggerright% Triggerleft =% %Triggerleft% TriggerHeight =% TriggerBottom - TriggerTop +1 TriggerWidth =% TriggerRight - TriggerLeft +1 HalfTriggerTop := Triggertop HalfTriggerTop += TriggerHeight / 2 HalfTriggerLeft := TriggerWidth / 2 HalfTriggerLeft += TriggerLeft -12 Gui, add, Groupbox, Y%TriggerTop% X%TriggerLeft% W%TriggerWidth% H%TriggerHeight%, Gui, add, text, Y%HalfTriggerTop% X%HalfTriggerLeft%, %A_Index% } Gui,+ToolWindow +AlwaysOnTop -Disabled -SysMenu -Caption Gui,Margin,0,0 Gui,color,ffffff Gui,+lastfound Gui,show,x0 y0 w0 h0, WinGet,guiid,Id,A WinSet, TransColor, ffffff,ahk_id %guiid% Gui,hide Gui,2: +ToolWindow +AlwaysOnTop -Disabled -SysMenu -Caption Gui,2: Margin,0,0 guilabel: Gui,2: +lastfound WinSet, transparent, 200, return ;************************************************************************ini i/o ReadIni: IfExist,%A_ScriptName%.ini { IniRead,NGroups ,%A_ScriptName%.ini,Groups,NumberOfGroups,%NGroups% loop,%ngroups% { triggerTop= %A_Index%TriggerTop triggerBottom = %A_Index%TriggerBottom triggerRight = %A_Index%TriggerRight triggerLeft = %A_Index%TriggerLeft GridTop= %A_Index%GridTop GridBottom = %A_Index%GridBottom GridRight = %A_Index%GridRight GridLeft = %A_Index%GridLeft IniRead,%TriggerTop% ,%A_ScriptName%.ini,Groups,%TriggerTop%,Error IniRead,%TriggerBottom% ,%A_ScriptName%.ini,Groups,%TriggerBottom%,Error IniRead,%TriggerLeft% ,%A_ScriptName%.ini,Groups,%TriggerLeft%,Error IniRead,%TriggerRight% ,%A_ScriptName%.ini,Groups,%TriggerRight%,Error IniRead,%GridTop% ,%A_ScriptName%.ini,Groups,%GridTop%,Error IniRead,%GridBottom% ,%A_ScriptName%.ini,Groups,%GridBottom%,Error IniRead,%GridLeft% ,%A_ScriptName%.ini,Groups,%GridLeft%,Error IniRead,%GridRight% ,%A_ScriptName%.ini,Groups,%GridRight%,Error } } else GoSub,WriteIni return WriteIni: IfNotExist,%A_ScriptName%.ini FileAppend, ( ;the next section defines how groups are positioned in the screen. ;the key "NumberOfGroups" repesents how many groups there are. ;each of the groups is represented by a "trigger" zone, and a ;"grid" zone. The number at the beggining of each line represents ;the group number that particular statement is related to. ;the 4 elements starting by trigger represent the are where the ;window has to be dropped for that specific group to be used ;and the 4 elements starting by grid represent the square where ;the window will be moved too. ;Attention! ;the coordinates of every element start counting from the top left of the screen. ),%A_ScriptName%.ini IniWrite,%NGroups% ,%A_ScriptName%.ini,Groups,NumberOfGroups loop,%NGroups% { triggerTop= %A_Index%TriggerTop triggerBottom = %A_Index%TriggerBottom triggerRight = %A_Index%TriggerRight triggerLeft = %A_Index%TriggerLeft triggerTopt =% %TriggerTop% triggerBottomt = % %TriggerBottom% triggerRightt = % %TriggerRight% triggerLeftt = % %TriggerLeft% GridTop= %A_Index%GridTop GridBottom = %A_Index%GridBottom GridRight = %A_Index%GridRight GridLeft = %A_Index%GridLeft GridTopt =% %GridTop% GridBottomt = % %GridBottom% GridRightt = % %GridRight% GridLeftt = % %GridLeft% IniWrite,%TriggerTopt% ,%A_ScriptName%.ini,Groups,%TriggerTop% IniWrite,%TriggerBottomt% ,%A_ScriptName%.ini,Groups,%TriggerBottom% IniWrite,%TriggerLeftt% ,%A_ScriptName%.ini,Groups,%TriggerLeft% IniWrite,%TriggerRightt% ,%A_ScriptName%.ini,Groups,%TriggerRight% IniWrite,%GridTopt% ,%A_ScriptName%.ini,Groups,%GridTop% IniWrite,%GridBottomt% ,%A_ScriptName%.ini,Groups,%GridBottom% IniWrite,%GridLeftt% ,%A_ScriptName%.ini,Groups,%GridLeft% IniWrite,%GridRightt% ,%A_ScriptName%.ini,Groups,%GridRight% } Return AssignGroups: NGroups=8 ;;if you use the taskbar on the top of the screen ;;uncomment the commented lines, and comment the ;;line below each of them ;UPPER LEFT TRIGGER -> SCREEN LEFT HALF 1Triggertop := 0 1TriggerRight := a_screenwidth * 0.3 1TriggerLeft := 0 1TriggerBottom := 5 1Gridtop := 0 1GridRight := a_screenwidth / 2 1GridLeft := 0 1GridBottom := a_screenheight ;UPPER LEFT CORNER TRIGGER -> SCREEN UPPER LEFT QUARTER 2Triggertop := 0 2TriggerRight := 5 2TriggerLeft := 0 2TriggerBottom := a_screenheight / 2 2Gridtop := 0 2GridRight := a_screenwidth / 2 2GridLeft := 0 2GridBottom := a_screenheight / 2 ;LOWER LEFT CORNER TRIGGER -> SCREEN LOWER LEFT QUARTER 3TriggerTop := a_screenheight / 2 3TriggerRight := 5 3TriggerLeft := 0 3TriggerBottom := a_screenheight 3GridTop := a_screenheight / 2 3GridRight := a_screenwidth / 2 3GridLeft := 0 3GridBottom := a_screenheight ;UPPER RIGHT TRIGGER -> SCREEN RIGHT HALF 4TriggerTop := 0 4TriggerRight := a_screenwidth 4TriggerLeft := a_screenwidth * 0.7 4TriggerBottom := 5 4GridTop := 0 4GridRight := a_screenwidth 4GridLeft := a_screenwidth / 2 4GridBottom := a_screenheight ;UPPER RIGHT CORNER TRIGGER -> SCREEN UPPER RIGHT QUARTER 5Triggertop := 0 5TriggerRight := a_screenwidth 5TriggerLeft := a_screenwidth - 5 5TriggerBottom := a_screenheight / 2 5GridTop := 0 5GridRight := a_screenwidth 5GridLeft := a_screenwidth / 2 5GridBottom := a_screenheight / 2 ;LOWER RIGHT CORNER TRIGGER -> SCREEN LOWER RIGHT QUARTER 6Triggertop := a_screenheight / 2 6TriggerRight := a_screenwidth 6TriggerLeft := a_screenwidth - 5 6TriggerBottom := a_screenheight 6GridTop := a_screenheight / 2 6GridRight := a_screenwidth 6GridLeft := a_screenwidth / 2 6GridBottom := a_screenheight ;TOP CENTER TRIGGER -> SCREEN CENTER WITH BLANK BORDER 7Triggertop := 0 7TriggerRight := a_screenwidth * 0.7 7TriggerLeft := a_screenwidth * 0.3 7TriggerBottom := 5 7GridTop := 65 7GridRight := a_screenwidth * 0.85 7GridLeft := a_screenwidth * 0.15 7GridBottom := a_screenheight * 0.97 ;BOTTOM CENTER TRIGGER -> SCREEN BOTTOM HALF 8Triggertop := a_screenheight - 5 8TriggerRight := a_screenwidth * 0.7 8TriggerLeft := a_screenwidth * 0.3 8TriggerBottom := a_screenheight 8GridTop := a_screenheight / 2 8GridRight := a_screenwidth 8GridLeft := 0 8GridBottom := a_screenheight return