This repository has been archived by the owner on Apr 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GridMove.ahk
1753 lines (1551 loc) · 43.1 KB
/
GridMove.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;GridMove
;By jgpaiva
;date: May 2006
;fix, add some functions and translate
;By mirtle
;date: Nov. 2022
;function: Adjusts windows to a predefined or user-defined desktop grid.
;;options:
MButtonDrag := True ;to be able to drag a window using the 3rd mouse button
EdgeDrag := True ;to be able to bring the grid up when dragging a window to the edge
EdgeTime := 500
ShowGroupsFlag := False ;configures the showing or not of the groups
ShowNumbersFlag := True ;configures the showing or not of the numbers
GridName = Grids/3 Part.grid
GridOrder = 3 Part
UseCommand := False
CommandHotkey = !g
UseFastMove := True
FastMoveModifiers = !
Exceptions =
MButtonExceptions =
MButtonTimeout = 0.3
Transparency = 200
SafeMode := True
FastMoveMeta =
SequentialMove := False
DebugMode := False
StartWithWindows := False
DisableTitleButtonsDetection := False
ColorTheme=orange
Language=EN
NoTrayIcon:=False
FirstRun:= False
AltDragToggle := True
AltDragMove :=True
WinDragMove := True
Gap := 1
;Registered=quebec
;;end of options
ScriptVersion = 2.04
if (! A_IsAdmin){
Run *RunAs "%A_ScriptFullPath%"
ExitApp
}
; Detect Windows 10
if % substr(a_osversion, 1, 2) = 10
Windows10:=True
; Hack WinMove for Windows 10
WinSnap(WinTitle, X := "", Y := "", W := "", H := "") {
If ((X . Y . W . H) = "") ;
Return False
WinGet, hWnd, ID, %WinTitle% ; taken from Coco's version
If !(hWnd)
Return False
DL := DT := DR := DB := 0
VarSetCapacity(RC, 16, 0)
DllCall("GetWindowRect", "Ptr", hWnd, "Ptr", &RC)
WL := NumGet(RC, 0, "Int"), WT := NumGet(RC, 4, "Int"), WR := NumGet(RC, 8, "Int"), WB := NumGet(RC, 12, "Int")
If (DllCall("Dwmapi.dll\DwmGetWindowAttribute", "Ptr", hWnd, "UInt", 9, "Ptr", &RC, "UInt", 16) = 0) { ; S_OK = 0
FL := NumGet(RC, 0, "Int"), FT := NumGet(RC, 4, "Int"), FR := NumGet(RC, 8, "Int"), FB := NumGet(RC, 12, "Int")
DL := WL - FL, DT := WT - FT, DR := WR - FR, DB := WB - FB
}
X := X <> "" ? X + DL : WL, Y := Y <> "" ? Y + DT : WT
W := W <> "" ? W - DL + DR : WR - WL, H := H <> "" ? H - DT + DB: WB - WT
Return DllCall("MoveWindow", "Ptr", hWnd, "Int", X, "Int", Y, "Int", W, "Int", H, "UInt", 1)
}
MutexExists("GridMove_XB032")
Sysget, CaptionSize,4 ;get the size of the caption
Sysget, BorderSize, 46 ;get the size of the border
CaptionSize += BorderSize
TitleLeft := CaptionSize
if DebugMode
Traytip,GridMove,Reading INI,10
;goSub, showOptions
GetScreenSize() ;get the size of the monitors
GetMonitorSizes()
RectangleSize := 1
ComputeEdgeRectangles()
OSDcreate()
GoSub,setlanguage
GoSub, ReadIni
AeroEnabled := loadAero()
GoSub,setlanguage
SetWinDelay, 0
SetBatchLines, -1
If 0 = 1
GridName = %1%
createTrayMenus()
if DebugMode
Traytip,GridMove,Reading the grid file,10
GoSub, ApplyGrid
Mutex := False
GroupsShowing := False
EdgeFlag := True
MousePositionLock := False
WM_ENTERSIZEMOVE = 0x231
WM_EXITSIZEMOVE = 0x232
WindowY =
WindowX =
WindowWidth =
WindowHeight=
WindowXBuffer =
WindowYBuffer =
;if DebugMode
; Traytip,GridMove,Creating the grid,10
;GoSub,createGroups NOT NEEDED, GRID IS CREATED IN "APPLY GRID"
if DebugMode
Traytip,GridMove,Registering Hotkeys...,10
;hotkey definitions:
If UseCommand
Hotkey, %CommandHotkey%, Command
If MButtonDrag
Hotkey, MButton, MButtonMove
If UseFastMove
{
GoSub,DefineHotkeys
}
if SequentialMove
{
Hotkey, %FastMoveModifiers%Right,MoveToNext
Hotkey, %FastMoveModifiers%Left,MoveToPrevious
HotKey, %FastMoveModifiers%T,NextGrid
}
MPFlag := True
Settimer, MousePosition, 100
;Settimer, ReloadOnResolutionChange, 1000
HotKey,RButton,NextGrid
HotKey,RButton,off
HotKey,Esc,cancel
HotKey,Esc,off
HotKey,LButton,cancel
HotKey,LButton,off
HotKey,F12,AddCurrentToIgnore
HotKey,F11,AddCurrentToIgnoreCancel
HotKey,F12,off
HotKey,F11,off
#maxthreadsperhotkey,1
#singleinstance,force
#InstallMouseHook
#InstallKeybdHook
#noenv
; GoSub,TitleButtonInitialization
if DebugMode
Traytip,GridMove,Start process completed,10
SetBatchLines, 20ms
return
MutexExists(name) {
mutex := DllCall("CreateMutex", "UInt", 0, "UInt", 0, "str", name)
last_error := A_LastError
; DllCall("CloseHandle", "uint", mutex)
return last_error == 183 ; ERROR_ALREADY_EXISTS
}
;*******************Init
createTrayMenus()
{
global
if DebugMode
Traytip,GridMove,Creating the templates menu,10
;;tray menu:
; Menu,Tray, Add, %tray_help%, AboutHelp
; Menu,Tray, Default, %tray_help%
Menu,Tray, Tip, GridMove V%ScriptVersion%
; Menu,Tray, Add, %tray_updates%, EnableAutoUpdate
Menu,Tray, Add, %tray_ignore%, AddToIgnore
createTemplatesMenu()
Menu,Tray, Add, %tray_templates%, :templates_menu
If(NoTrayIcon){
; msgbox,here
menu, tray, NoIcon
}else{
IfExist %A_ScriptDir%\gridmove.ico
Menu,Tray, Icon,%A_ScriptDir%\gridmove.ico
}
Menu,Tray, NoStandard
if DebugMode
Traytip,GridMove,Creating the options tray menu,10
createOptionsMenu()
Menu,Tray, Add,%tray_options%, :options_menu
createColorsMenu()
Menu,Tray, Add, %tray_colors%, :colors_menu
createHotkeysMenu()
Menu,Tray, Add, %tray_hotkeys%, :hotkeys_menu
Menu,Tray,add,,
if(Registered<>"quebec")
Menu,Tray, Add, %tray_windows%, StartWithWindowsToggle
if(Registered<>"quebec")
if(startWithWindowsQ())
Menu,Tray,Check, %tray_windows%
else
Menu,Tray,UnCheck, %tray_windows%
createLanguageMenu()
Menu,Tray, Add, %tray_lang%, :chooselanguage
Menu,Tray, Add, %tray_restart%, ReloadProgram
Menu,Tray, Add, %tray_exit%, ExitProgram
}
createLanguageMenu()
{
global Language
Menu,chooselanguage, add, zh_CN, setLang
Menu,chooselanguage, add, English, setLang
Menu,chooselanguage, add, French, setLang
if(Language= "zh_CN")
Menu,chooselanguage,check, zh_CN
if(Language= "EN")
Menu,chooselanguage,check, English
if(Language= "FR")
Menu,chooselanguage,check, French
}
setLang:
global Language
if(A_ThisMenuItem="zh_CN")
Language=zh_CN
if(A_ThisMenuItem="English")
Language=EN
if(A_ThisMenuItem="French")
Language=FR
gosub, writeini
reload
return
createTemplatesMenu()
{
global GridName
global tray_refresh
global tray_gridpath
global tray_gridorder
Loop,%A_ScriptDir%\Grids\*.grid
{
StringTrimRight,out_GridName2,A_LoopFileName,5
Menu,templates_menu, add, %out_GridName2%,Template-Grids
}
Menu,templates_menu,add,,
Menu,templates_menu, add,%tray_refresh%, RefreshTemplates
Menu,templates_menu, add, %tray_gridorder%, Options_GridOrder
Menu,templates_menu, add,%tray_gridpath%, OpenGridPath
stringgetpos,out_pos,gridname,\,R1
if out_pos <= 0
stringgetpos,out_pos,gridname,/,R1
if out_pos <= 0
return
stringlen, len, gridname
StringRight,out_GridName,gridname,% len - out_pos -1
StringTrimRight,out_GridName2,out_GridName,5
IfExist %A_ScriptDir%\Grids\%out_GridName2%.grid
menu,templates_menu,check,%out_GridName2%
}
OpenGridPath(){
Run, explorer.exe %A_ScriptDir%\Grids
}
ShowIniFile(){
Run, explorer.exe %A_AppData%\GridMove\
}
createOptionsMenu()
{
global
; Menu,options_menu, add, %tray_safemode%, Options_SafeMode
Menu,options_menu, add, %tray_showgrid%, Options_ShowGrid
Menu,options_menu, add, %tray_shownumbers%, Options_ShowNumbers
Menu,options_menu, add, %tray_mbuttondrag%, Options_MButtonDrag
Menu,options_menu, add, %tray_windragmove%, Options_WinDragMove
Menu,options_menu, add, %tray_altdragmove%, Options_AltDragMove
Menu,options_menu, add, %tray_edgedrag%, Options_EdgeDrag
Menu,options_menu, add, %tray_edgetime%, Options_EdgeTime
Menu,options_menu, add, %tray_ini%, ShowIniFile
if WinDragMove
Menu,options_menu,check, %tray_windragmove%
if AltDragMove
Menu,options_menu,check, %tray_altdragmove%
If MButtonDrag
Menu,options_menu,check, %tray_mbuttondrag%
If EdgeDrag
Menu,options_menu,check, %tray_edgedrag%
else
Menu,options_menu,Disable, %tray_edgetime%
If ShowGroupsFlag
Menu,options_menu, Check, %tray_showgrid%
If ShowNumbersFlag
Menu,options_menu, Check, %tray_shownumbers%
; If SafeMode
; Menu,options_menu, Check, %tray_safemode%
}
createColorsMenu()
{
global tray_color_orange
global tray_color_blue
global tray_color_black
global colortheme
Menu,colors_menu, add, %tray_color_orange%, setColorTheme
Menu,colors_menu, add, %tray_color_blue%, setColorTheme
Menu,colors_menu, add, %tray_color_black%, setColorTheme
if(colortheme="orange")
Menu,colors_menu,check, %tray_color_orange%
if(colortheme="blue")
Menu,colors_menu,check, %tray_color_blue%
if(colortheme="black")
Menu,colors_menu,check, %tray_color_black%
}
setColorTheme:
if(A_ThisMenuItem=tray_color_orange)
colorTheme=orange
if(A_ThisMenuItem=tray_color_blue)
colorTheme=blue
if(A_ThisMenuItem=tray_color_black)
colorTheme=black
gosub, writeini
reload
return
createHotkeysMenu()
{
global
Menu,hotkeys_menu, add, %tray_windrag%, AltDrag
Menu,hotkeys_menu, add, %tray_usecommand%, Hotkeys_UseCommand
Menu,hotkeys_menu, add, %tray_commandhotkey%, Hotkeys_CommandHotkey
Menu,hotkeys_menu, add, %tray_fastmove%, Hotkeys_UseFastMove
Menu,hotkeys_menu, add, %tray_extrahotkey%, Hotkeys_Extrahotkey
Menu,hotkeys_menu, add, %tray_fastmovemodifiers%, Hotkeys_FastMoveModifiers
If UseCommand
Menu,hotkeys_menu,check, %tray_usecommand%
If AltDragToggle
Menu,hotkeys_menu,check, %tray_windrag%
else
Menu,hotkeys_menu,Disable, %tray_commandhotkey%,
If UseFastMove
Menu,hotkeys_menu,check, %tray_fastmove%
else
{
Menu,hotkeys_menu,Disable, %tray_fastmovemodifiers%
Menu,hotkeys_menu,Disable, %tray_extrahotkey%
}
if SequentialMove
Menu,hotkeys_menu,check, %tray_extrahotkey%
}
startWithWindowsQ()
{
loop,%A_startup%\*.lnk
{
if (A_LoopFileName = "GridMove.lnk")
{
return true
}
}
return false
}
;*******************Drop Zone Mode
DropZoneMode:
DropZoneModeFlag := true
gosub,showgroups
Hotkey,RButton,on
Hotkey,Esc,on
Hotkey,LButton,on
Canceled := False
CoordMode,Mouse,Screen
hideGui2()
loop
{
If Canceled
{
Critical, on
Gui,2:Hide
Hotkey,RButton,off
Hotkey,Esc,off
Hotkey,LButton,off
DropZoneModeFlag := false
Critical, off
return
}
GetKeyState,State,%hotkey%,P
If State = U
break
MouseGetPos, MouseX, MouseY, window,
flagLButton:=true
Critical, on
SetBatchLines, 10ms
loop,%NGroups%
{
TriggerTop := %A_Index%TriggerTop
TriggerBottom := %A_Index%TriggerBottom
TriggerRight := %A_Index%TriggerRight
TriggerLeft := %A_Index%TriggerLeft
If (MouseY >= TriggerTop AND MouseY <= TriggerBottom
AND MouseX <= TriggerRight AND MouseX >= TriggerLeft)
{
GetGrid(A_Index)
If (GridTop = "AlwaysOnTop" OR GridTop = "Run")
{
GridTop := TriggerTop
GridLeft := TriggerLeft
GridWidth := TriggerRight - TriggerLeft
GridHeight := TriggerBottom - TriggerTop
}
If (GridTop = "Maximize")
{
GridTop := GetMonitorTop(MouseX,MouseY)
GridLeft := GetMonitorLeft(MouseX,MouseY)
GridWidth := GetMonitorRight(MouseX,MouseY) - GetMonitorLeft(MouseX,MouseY)
GridHeight := GetMonitorBottom(MouseX,MouseY) - GetMonitorTop(MouseX,MouseY)
}
If not canceled
{
if(!AeroEnabled)
WinMove,ahk_id %gui2hwnd%, ,%GridLeft%,%GridTop%,%GridWidth%,%GridHeight%
else
{
left:=GridLeft + 3
top:=GridTop + 3
width:=GridWidth - 6
height:=GridHeight - 6
WinMove,ahk_id %gui2hwnd%, ,%Left%,%Top%,%Width%,%Height%
}
}
flagLButton:=false
break
}
}
Critical, off
if flagLButton
hideGui2()
}
DropZoneModeFlag := false
Gui,2:Hide
Hotkey,RButton,off
Hotkey,Esc,off
Hotkey,LButton,off
GoSub,SnapWindow
Gosub,hidegroups
return
hideGui2()
{
global AeroEnabled
if(!AeroEnabled)
Gui,2: +ToolWindow +AlwaysOnTop -Disabled -SysMenu -Caption
else
Gui,2: +ToolWindow +AlwaysOnTop -Disabled -SysMenu
Gui,2: Show, x-10000 y-10000 w0 h0 NoActivate,% A_SPACE
}
cancel:
if not canceled
{
canceled := True
GoSub, HideGroups
Gui,2:Hide
}
return
;*******************AltDrag method
#if AltDragMove && GetKeyState("Shift", "P")
~LWin & LButton::
CoordMode,Mouse,Screen
MouseGetPos, OldMouseX, OldMouseY, Window,
WinGetTitle,WinTitle,ahk_id %Window%
WinGetClass,WinClass,ahk_id %Window%
WinGetPos,WinLeft,WinTop,WinWidth,WinHeight,ahk_id%Window%
WinGet,WinStyle,Style,ahk_id %Window%
WinGet,WindowId,Id,ahk_id %Window%
WinGet, WindowProcess , ProcessName, ahk_id %Window%
if SafeMode
{
if not (WinStyle & 0x40000) ;0x40000 = WS_SIZEBOX = WS_THICKFRAME
{
sendinput,{LWindown}
Keywait, LButton
sendinput,{Lwinup}
Return
}
}
If Winclass in %Exceptions%
{
sendinput,{LWindown}
Keywait, LButton
sendinput,{Lwinup}
Return
}
If WindowProcess in %MButtonExceptions%
{
sendinput,{LWindown}
Keywait, LButton
sendinput,{Lwinup}
Return
}
KeyWait,LButton,T%MButtonTimeOut%
if errorlevel = 0
{
sendinput,{LButton}
return
}
Winactivate, ahk_id %window%
Hotkey = LButton
GoSub, DropZoneMode
return
#if
; win drag move
#if WinDragMove
~LWin & RButton::
~RWin & RButton::
CoordMode,Mouse,Screen
MouseGetPos, OldMouseX, OldMouseY, Window,
WinGetTitle,WinTitle,ahk_id %Window%
WinGetClass,WinClass,ahk_id %Window%
WinGetPos,WinLeft,WinTop,WinWidth,WinHeight,ahk_id%Window%
WinGet,WinStyle,Style,ahk_id %Window%
WinGet,WindowId,Id,ahk_id %Window%
WinGet, WindowProcess , ProcessName, ahk_id %Window%
if SafeMode
{
if not (WinStyle & 0x40000) ;0x40000 = WS_SIZEBOX = WS_THICKFRAME
{
SendInput, {LWinDown}
Keywait, RButton
SendInput, {LWinUp}
Return
}
}
If Winclass in %Exceptions%
{
SendInput, {LWinDown}
Keywait, RButton
SendInput, {LWinUp}
Return
}
If WindowProcess in %MButtonExceptions%
{
SendInput, {LWinDown}
Keywait, RButton
SendInput, {LWinUp}
Return
}
KeyWait,RButton,T%MButtonTimeOut%
if errorlevel = 0
{
sendinput,{RButton}
return
}
Winactivate, ahk_id %window%
Hotkey = RButton
GoSub, DropZoneMode
return
#if
;*******************Mbutton method
MButtonMove:
CoordMode,Mouse,Screen
MouseGetPos, OldMouseX, OldMouseY, Window,
WinGetTitle,WinTitle,ahk_id %Window%
WinGetClass,WinClass,ahk_id %Window%
WinGetPos,WinLeft,WinTop,WinWidth,WinHeight,ahk_id%Window%
WinGet,WinStyle,Style,ahk_id %Window%
WinGet,WindowId,Id,ahk_id %Window%
WinGet, WindowProcess , ProcessName, ahk_id %Window%
if SafeMode
{
if not (WinStyle & 0x40000) ;0x40000 = WS_SIZEBOX = WS_THICKFRAME
{
sendinput,{MButton down}
Keywait,mbutton
sendinput,{MButton up}
Return
}
}
If Winclass in %Exceptions%
{
sendinput,{MButton down}
Keywait,mbutton
sendinput,{MButton up}
Return
}
If WindowProcess in %MButtonExceptions%
{
sendinput,{MButton down}
Keywait,mbutton
sendinput,{MButton up}
Return
}
KeyWait,MButton,T%MButtonTimeOut%
if errorlevel = 0
{
sendinput,{MButton}
return
}
Winactivate, ahk_id %window%
Hotkey = MButton
GoSub, DropZoneMode
return
;**********************edge/lbutton method
MousePosition:
Settimer, MousePosition,off
if MousePositionLock
return
KeyWait, LButton,U
KeyWait, LButton,D
SetBatchLines, -1
CoordMode,Mouse,Relative
MouseGetPos,OldMouseX,OldMouseY,MouseWin, MouseControl
WinGetTitle,Wintitle,ahk_id %mousewin%
WinGetClass,WinClass,ahk_id %mousewin%
WinGetPos,WinLeft,WinTop,WinWidth,WinHeight,ahk_id%MouseWin%
WinGet,WinStyle,Style,ahk_id %mousewin%
WinGet,WindowId,Id,ahk_id %mousewin%
If Winclass in %Exceptions%
{
Settimer, MousePosition,10
Return
}
if SafeMode
if not (WinStyle & 0x40000) ;0x40000 = WS_SIZEBOX = WS_THICKFRAME
{
Settimer, MousePosition,10
Return
}
If (OldMouseY > CaptionSize OR OldMouseY <= BorderSize + 1 OR WinTitle = "" )
{
Settimer, MousePosition,10
return
}
if not EdgeDrag
{
settimer, MousePosition,10
return
}
SetBatchLines, 10ms
CoordMode,Mouse,Screen
EdgeFlag := true
SetTimer, EdgeMove, Off
loop
{
MouseGetPos, MouseX, MouseY
GetKeyState, State, LButton, P
If (state = "U" or MousePositionLock)
{
SetTimer, EdgeMove, Off
Settimer, MousePosition,10
return
}
EdgeFlagFound := false
loop,%RectangleCount%
{
if(mouseX >= EdgeRectangleXL%A_Index% && mouseX <= EdgeRectangleXR%A_Index%
&& mouseY >= EdgeRectangleYT%A_Index% && mouseY <= EdgeRectangleYB%A_Index%)
{
EdgeFlagFound := true
break
}
}
if EdgeFlagFound
{
if EdgeFlag
{
settimer, EdgeMove, %EdgeTime%
EdgeFlag := False
}
}
else
{
SetTimer, EdgeMove, Off
EdgeFlag := True
}
sleep,100
;eternal loop
}
return
edgemove:
SetTimer, EdgeMove, Off
HotKey = LButton
sendinput, {LButton up}
MousePositionLock := true
SetBatchLines, -1
GoSub,DropZoneMode
MousePositionLock := false
EdgeFlag := True
Settimer, MousePosition,10
return
;**********************Snap Window to Grid
SnapWindow:
sendinput, {LButton up}
CoordMode,Mouse,Screen
Moved := False
loop %NGroups%
{
triggerTop := %A_Index%TriggerTop
triggerBottom := %A_Index%TriggerBottom
triggerRight := %A_Index%TriggerRight
triggerLeft := %A_Index%TriggerLeft
GridBottom :=0
GridRight :=0
GridTop :=0
GridLeft :=0
If (MouseY >= triggerTop AND MouseY <= triggerBottom
AND MouseX <= triggerRight AND MouseX >= triggerLeft)
{
GetGrid(A_Index)
If GridTop = AlwaysOnTop
{
WinSet, AlwaysOnTop, Toggle,A
return
}
If GridTop = Maximize
{
winget,state,minmax,A
if state = 1
WinRestore,A
else
PostMessage, 0x112, 0xF030,,, A,
return
}
If GridTop = Run
{
Run,%GridLeft% ,%GridRight%
return
}
WinRestore,A
Moved := True
if ShouldUseSizeMoveMessage(WinClass)
SendMessage WM_ENTERSIZEMOVE, , , ,ahk_id %windowid%
if Windows10
WinSnap("ahk_id" windowid, GridLeft,GridTop, GridWidth, GridHeight)
else
WinMove, ahk_id %windowid%, ,%GridLeft%,%GridTop%,%GridWidth%,%GridHeight%,
if ShouldUseSizeMoveMessage(WinClass)
SendMessage WM_EXITSIZEMOVE, , , ,ahk_id %windowid%
break
}
}
If Moved
StoreWindowState(WindowID,WinLeft,WinTop,WinWidth,WinHeight)
gosub, hidegroups
return
GetGrid(number)
{
global
MouseGetPos, MouseX, MouseY, window,
GridTop := %number%GridTop
GridBottom := %number%GridBottom
GridRight := %number%GridRight
GridLeft := %number%GridLeft
TriggerTop := %number%TriggerTop
TriggerBottom := %number%TriggerBottom
TriggerRight := %number%TriggerRight
TriggerLeft := %number%TriggerLeft
if GridTop in run,maximize,AlwaysOnTop
return
If GridTop = WindowHeight
{
MonitorBottom := GetMonitorBottom(MouseX, MouseY)
MonitorTop := GetMonitorTop(MouseX, MouseY)
GridTop := MouseY - 0.5 * WinHeight
If (GridTop + WinHeight > MonitorBottom)
GridTop := MonitorBottom - WinHeight
If (GridTop < MonitorTop)
GridTop := MonitorTop
GridBottom := GridTop + WinHeight
}
If GridLeft = WindowWidth
{
MonitorRight := GetMonitorRight(MouseX, MouseY)
MonitorLeft := GetMonitorLeft(MouseX, MouseY)
GridLeft := MouseX - 0.5 * WinWidth
If (GridLeft + WinWidth > MonitorRight)
GridLeft := MonitorRight - WinWidth
If (GridLeft < MonitorLeft)
GridLeft := MonitorLeft
GridRight := GridLeft + WinWidth
}
If GridTop = restore
{
data := GetWindowState(WindowID)
If data
{
GridLeft := WindowX
GridRight := WindowX + WindowWidth
GridTop := WindowY
GridBottom := WindowY + WindowHeight
}
else
{
GridLeft := WinLeft
GridRight := WinLeft + WinWidth
GridTop := WinTop
GridBottom := WinTop + WinHeight
}
}
if (GridTop = "Current")
GridTop := WinTop
else
GridTop := round(GridTop)
if (GridLeft = "Current")
GridLeft := WinLeft
else
GridLeft := round(GridLeft)
if (GridRight = "Current")
GridRight := WinLeft + WinWidth
else
GridRight := round(GridRight)
if(GridBottom = "Current")
GridBottom := WinTop + WinHeight
else
GridBottom := round(GridBottom)
if ( GridTop <> WindowHeight and GridLeft <> WindowWidth){
GridTop := GridTop + Gap
GridBottom := GridBottom - Gap
GridRight := GridRight - Gap
GridLeft := GridLeft + Gap
}
GridWidth := GridRight - GridLeft
GridHeight := GridBottom - GridTop
}
;*************************************************************************Groups
showgroups:
if not ShowGroupsFlag
return
Gui,+ToolWindow +AlwaysOnTop -Disabled -SysMenu -Caption
WinSet, AlwaysOnTop, On,ahk_id %GuiId%
Gui,Show, X%ScreenLeft% Y%ScreenTop% W%ScreenWidth% H%ScreenHeight% noactivate,GridMove Drop Zone
;sleep,100
GroupsShowing := True
return
Hidegroups:
Gui,hide
return
setGuiColors()
{
global shadowcolor
global textcolor
global guicolor
global colortheme
global horizontalGrid
global verticalGrid
if(colortheme="blue")
{
Gui, Font, s15 cBlue, Tahoma
shadowcolor=555555
textcolor=0000FF
guicolor=0000EF
horizontalGrid=Gridh_blue.bmp
verticalGrid=Gridv_blue.bmp
}else if(colortheme="black")
{
Gui, Font, s15 cPink, Tahoma
shadowcolor=333333
textcolor= EB8D8D
guicolor=000000
horizontalGrid=Gridh_black.bmp
verticalGrid=Gridv_black.bmp
}else{
Gui, Font, s15 cRed, Tahoma
shadowcolor=000000
textcolor=FFD300
guicolor=EEAA99
horizontalGrid=Gridh_orange.bmp
verticalGrid=Gridv_orange.bmp
}
}
creategroups:
gui,destroy
setGuiColors()
loop,%NGroups%
{
TriggerTop := %A_Index%TriggerTop - ScreenTop
TriggerBottom := %A_Index%TriggerBottom - ScreenTop
TriggerLeft := %A_Index%TriggerLeft - ScreenLeft
TriggerRight := %A_Index%TriggerRight - ScreenLeft
TriggerHeight := TriggerBottom - TriggerTop
TriggerWidth := TriggerRight - TriggerLeft
GridTop := %A_Index%GridTop
GridLeft := %A_Index%GridLeft
TextTop := %A_Index%TriggerTop - ScreenTop
TextTop += Round((%A_Index%TriggerBottom - %A_Index%TriggerTop) / 2 )- 11
TextLeft := %A_Index%TriggerLeft - ScreenLeft
TextLeft += Round((%A_Index%TriggerRight - %A_Index%TriggerLeft) / 2) - 5
RestoreLeft := TextLeft - 50
tempTop := triggerTop - 1
tempBottom := triggerBottom - 1
tempLeft := triggerLeft - 1
tempRight := triggerRight - 1
tempHeight := tempBottom - tempTop +2
tempWidth := tempRight - tempLeft +2
Gui, add, Picture, Y%tempTop% X%tempLeft% W%tempWidth% H3 ,%A_ScriptDir%\Images\%horizontalGrid%
Gui, add, Picture, Y%tempBottom% X%tempLeft% W%tempWidth% H3 ,%A_ScriptDir%\Images\%horizontalGrid%
Gui, add, Picture, Y%tempTop% X%tempLeft% W3 H%tempHeight% ,%A_ScriptDir%\Images\%verticalGrid%
Gui, add, Picture, Y%tempTop% X%tempRight% W3 H%tempHeight% ,%A_ScriptDir%\Images\%verticalGrid%
shadowleft := textleft + 1
shadowtop := texttop + 1