[feature] add padding
This commit is contained in:
parent
d63ed0e737
commit
527a1886f1
70
win/win.ahk
70
win/win.ahk
|
@ -9,9 +9,10 @@ CoordMode, Mouse, Screen ; mouse coordinates relative to the screen
|
||||||
; =========================
|
; =========================
|
||||||
; global RATIO := 0.618
|
; global RATIO := 0.618
|
||||||
global RATIO := 0.382
|
global RATIO := 0.382
|
||||||
global ARRANGEMENT := Object()
|
|
||||||
global ID_SEEN := Object()
|
global ID_SEEN := Object()
|
||||||
|
global ARRANGEMENT := Object()
|
||||||
global ARRANGEMENT_PATH := A_AppData . "\arrangement.json"
|
global ARRANGEMENT_PATH := A_AppData . "\arrangement.json"
|
||||||
|
global PADDING := 10
|
||||||
LoadArrangement()
|
LoadArrangement()
|
||||||
WatchNewWindow()
|
WatchNewWindow()
|
||||||
; =========================
|
; =========================
|
||||||
|
@ -24,8 +25,9 @@ WatchNewWindow()
|
||||||
Send ^a
|
Send ^a
|
||||||
Send {BS}
|
Send {BS}
|
||||||
return
|
return
|
||||||
#=::SoundSet,+5
|
#=::SoundSet, +5
|
||||||
#-::SoundSet,-5
|
#-::SoundSet, -5
|
||||||
|
#\::Send {Volume_Mute}
|
||||||
#BS::#l
|
#BS::#l
|
||||||
#f:: ToggleActiveWinMaximum()
|
#f:: ToggleActiveWinMaximum()
|
||||||
^#p::ShowActiveWinGeometry()
|
^#p::ShowActiveWinGeometry()
|
||||||
|
@ -34,6 +36,8 @@ WatchNewWindow()
|
||||||
#+j::MoveActiveWinByDirection("right")
|
#+j::MoveActiveWinByDirection("right")
|
||||||
#+k::MoveActiveWinByDirection("left")
|
#+k::MoveActiveWinByDirection("left")
|
||||||
#+r::reload
|
#+r::reload
|
||||||
|
#i::IgnoreArrangementForActiveWindow()
|
||||||
|
#+i::UnignoreArrangementForActiveWindow()
|
||||||
#t::ShowDebug()
|
#t::ShowDebug()
|
||||||
|
|
||||||
; Ctrl + Alt + v : paste as plain text
|
; Ctrl + Alt + v : paste as plain text
|
||||||
|
@ -97,7 +101,7 @@ Return
|
||||||
; Capslock & ,:: Send {PgDn}
|
; Capslock & ,:: Send {PgDn}
|
||||||
; Capslock & .:: Send {End}
|
; Capslock & .:: Send {End}
|
||||||
|
|
||||||
; Capslock & Space:: SetCapsLockState % !GetKeyState("CapsLock", "T")
|
; Capslock & Space:: SetCapsLockState % !GetKeyState("CapsLock", "T")
|
||||||
; +CapsLock::
|
; +CapsLock::
|
||||||
; Send {~}
|
; Send {~}
|
||||||
; SetCapsLockState % !GetKeyState("CapsLock", "T")
|
; SetCapsLockState % !GetKeyState("CapsLock", "T")
|
||||||
|
@ -173,6 +177,7 @@ MoveActiveWinByDirection(direction) {
|
||||||
WinRestore, A
|
WinRestore, A
|
||||||
}
|
}
|
||||||
global RATIO
|
global RATIO
|
||||||
|
global PADDING
|
||||||
GetCursorMonGeometry(x, y, w, h)
|
GetCursorMonGeometry(x, y, w, h)
|
||||||
activeWinId := WinExist("A")
|
activeWinId := WinExist("A")
|
||||||
WinGetPosEx(activeWinId, wx, wy, ww, wh, l, t, r, b)
|
WinGetPosEx(activeWinId, wx, wy, ww, wh, l, t, r, b)
|
||||||
|
@ -181,17 +186,16 @@ MoveActiveWinByDirection(direction) {
|
||||||
ww := floor(w * RATIO)
|
ww := floor(w * RATIO)
|
||||||
wh := h
|
wh := h
|
||||||
if (direction = "right") {
|
if (direction = "right") {
|
||||||
wx := ww
|
wx := ww + floor(PADDING / 2)
|
||||||
ww := w - ww
|
ww := w - ww
|
||||||
|
} else {
|
||||||
|
wx := wx + PADDING
|
||||||
}
|
}
|
||||||
pos := [wx - l, wy - t, ww + l + r, wh + t + b]
|
ww := ww - floor(PADDING * 1.5)
|
||||||
; store arrangement
|
wy := wy + PADDING
|
||||||
global ARRANGEMENT
|
wh := wh - PADDING * 2
|
||||||
key := GetActiveWindowClassPath()
|
WinMove, A,, wx - l, wy - t, ww + l + r, wh + t + b
|
||||||
ARRANGEMENT[key] := pos
|
SaveActiveWindowDirection(direction)
|
||||||
SaveArrangement()
|
|
||||||
; end store arrangement
|
|
||||||
WinMove, A,, pos[1], pos[2], pos[3], pos[4]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -215,6 +219,12 @@ LoadArrangement() {
|
||||||
if not IsObject(ARRANGEMENT) {
|
if not IsObject(ARRANGEMENT) {
|
||||||
ARRANGEMENT := Object()
|
ARRANGEMENT := Object()
|
||||||
}
|
}
|
||||||
|
if not IsObject(ARRANGEMENT["windows"]) {
|
||||||
|
ARRANGEMENT["windows"] := Object()
|
||||||
|
}
|
||||||
|
if not IsObject(ARRANGEMENT["ignore"]) {
|
||||||
|
ARRANGEMENT["ignore"] := Object()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GetActiveWindowClassPath() {
|
GetActiveWindowClassPath() {
|
||||||
|
@ -228,18 +238,42 @@ IsActiveWindowSeen() {
|
||||||
WinGet winId, ID, A
|
WinGet winId, ID, A
|
||||||
seen := ID_SEEN.HasKey(winId)
|
seen := ID_SEEN.HasKey(winId)
|
||||||
ID_SEEN[winId] := true
|
ID_SEEN[winId] := true
|
||||||
|
return seen
|
||||||
|
}
|
||||||
|
|
||||||
|
IgnoreArrangementForActiveWindow() {
|
||||||
|
global ARRANGEMENT
|
||||||
|
ARRANGEMENT["ignore"][GetActiveWindowClassPath()] := true
|
||||||
|
SaveArrangement()
|
||||||
|
}
|
||||||
|
|
||||||
|
UnignoreArrangementForActiveWindow() {
|
||||||
|
global ARRANGEMENT
|
||||||
|
ARRANGEMENT["ignore"].Delete(GetActiveWindowClassPath())
|
||||||
|
SaveArrangement()
|
||||||
|
}
|
||||||
|
|
||||||
|
IsActiveWindowIgnore() {
|
||||||
|
global ARRANGEMENT
|
||||||
|
WinGetTitle, title, A
|
||||||
|
return ARRANGEMENT["ignore"].HasKey(GetActiveWindowClassPath()) or title = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
SaveActiveWindowDirection(direction) {
|
||||||
|
global ARRANGEMENT
|
||||||
|
key := GetActiveWindowClassPath()
|
||||||
|
ARRANGEMENT["windows"][key] := direction
|
||||||
|
SaveArrangement()
|
||||||
}
|
}
|
||||||
|
|
||||||
WatchNewWindow() {
|
WatchNewWindow() {
|
||||||
global ARRANGEMENT
|
global ARRANGEMENT
|
||||||
Loop {
|
Loop {
|
||||||
WinWaitActive A ; makes the active window to be the Last Found
|
WinWaitActive A ; makes the active window to be the Last Found
|
||||||
if not IsActiveWindowSeen() {
|
if not IsActiveWindowSeen() and not IsActiveWindowIgnore() {
|
||||||
classPath := GetActiveWindowClassPath()
|
classPath := GetActiveWindowClassPath()
|
||||||
if ARRANGEMENT.HasKey(classPath) {
|
if ARRANGEMENT["windows"].HasKey(classPath) {
|
||||||
pos := ARRANGEMENT[classPath]
|
MoveActiveWinByDirection(ARRANGEMENT["windows"][classPath])
|
||||||
WinRestore, A
|
|
||||||
WinMove, A,, pos[1], pos[2], pos[3], pos[4]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WinWaitNotActive ; waits until the active window changes
|
WinWaitNotActive ; waits until the active window changes
|
||||||
|
|
Loading…
Reference in New Issue
Block a user