-
Notifications
You must be signed in to change notification settings - Fork 5
/
winSizer.ahk
73 lines (63 loc) · 2.84 KB
/
winSizer.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
class winSizer {
__new(){
this.action:=objBindmethod(this,"run"), act:=this.action, this.running:=False
, this.toastObj:=new toast({life:0,margin:{x:1,y:1}, title:{size:10}, message:{def_size:8,offset:[4],def_offset:1}})
setTimer, % act, 100 ;, 10
setTimer, % act, Off
}
start(endOnKeyRelease:="", force:=False){
if (!force && this.running)
return false
this.endOnKeyRelease:=endOnKeyRelease
MouseGetPos, mx, my, Win
WinGetClass, winclass, ahk_id %win%
if (winclass="WorkerW" OR winclass="Shell_TrayWnd" OR !winexist("ahk_id " win))
return false
WinGetPos, wx, wy, w, h, ahk_id %win%
; Winget, isMax, MinMax, % win ; Can't be minimized
this.win:=win, this.mx:=mx, this.my:=my, this.wx:=wx, this.wy:=wy, this.ww:=w, this.wh:=h
, this.mode:={ x:3*(mx-wx)//w -1 , y:3*(my-wy)//h -1} ;, this.isMax:=isMax
; | -1-1 dw dh dx dy | 0-1 dh dy | +1-1 dw dh dy |
; | -1 0 dw dx | 0 0 dx dy | +1 0 dw |
; | -1+1 dw dh dx | 0+1 dh | +1+1 dw dh |
act:=this.action
setTimer, % act, On
this.show(mx,my,wx,wy,w,h, this.mode)
return true
}
end(){
act:=this.action, r:=this.running, this.running:=False
setTimer, % act, Off
this.toastObj.close()
return r
}
run(){
MouseGetPos, x, y
mode:=this.mode, dx0:=x-this.mx, dy0:=y-this.my, win:= "ahk_id " this.win
if ( this.running OR abs(dx0)>64 OR abs(dy0)>64 OR getKeyState("Shift","P") ) {
this.running:=True, dx:=0, dy:=0
if (mode.x<0) OR (!mode.x and !mode.y)
dx:=dx0
if (mode.y<0) OR (!mode.x and !mode.y)
dy:=dy0
WinRestore, % win ;Fixes problem of window being detected as maximized, but causes a slight flickering
WinMove, % win,, % this.wx+dx, % this.wy+dy, % this.ww+dx0*mode.x, % this.wh+dy0*mode.y
WinSet, Redraw,, % win
WinGetPos, wx, wy, w, h, % win
this.show(x,y,wx,wy,w,h,mode)
}
if (this.endOnKeyRelease AND !GetKeyState(this.endOnKeyRelease,"P"))
return this.end()
return
}
show(mx,my,wx,wy,ww,wh,mode){
static pad:=" ", mxOld:=-100, myOld:=-100
if (abs(mxOld-mx)<4) AND (abs(myOld-my)<4) ;Minimize flickering
return
mxOld:=mx, myOld:=my
e:= (mode.x OR mode.y)? "Resize " (!mode.x?"|":!mode.y?"--":mode.x*mode.y>0?"\":"/") : "Move"
return this.toastObj.show({title:{text:e}, pos:{x:mx,y:my}
,message:{text:["Mouse : (" substr(pad mx,-4) "," substr(pad my,-4) ")"
,"Window:(" substr(pad wx,-4) "," substr(pad wy,-4) ") " substr(pad ww,-4) " x" substr(pad wh,-4) ]} })
}
}