Skip to content

Commit

Permalink
- Fix memory leak.
Browse files Browse the repository at this point in the history
- Fix assignment operators used in place of comparison operators.
- Fix accidently double loop of GUI updater.
  • Loading branch information
snaphat committed Apr 16, 2021
1 parent b4a32ce commit c9ba35e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 30 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.0.7
v0.0.8
54 changes: 25 additions & 29 deletions virtual_desktop_enhancer.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ DesktopPtrFromIdx(index) {
line := A_LineNumber - 2
MsgBox,,, Error in function '%A_ThisFunc%' on line %line%!`n`nError: '%A_LastError%'
}
ObjRelease(IObjectArray) ; Clear comm object memory.
return ptr
}

Expand All @@ -357,7 +358,7 @@ DesktopIdxFromPtr(ptr) {
count := NumDesktops()
loop %count% {
GUID := DesktopGUIDFromPtr(DesktopPtrFromIdx(A_Index))
if (curGUID = GUID)
if (curGUID == GUID)
return A_Index
}
return 1 ; if failed assume first desktop.
Expand Down Expand Up @@ -472,7 +473,7 @@ IsValidWindow(hwnd) {
return False ; Tool Window.

WinGetClass, szClass, ahk_id %hwnd%
if (szClass = "TApplication")
if (szClass == "TApplication")
return False ; Some delphi class window type.

WinGetTitle, title, ahk_id %hwnd%
Expand Down Expand Up @@ -540,33 +541,28 @@ ForkGuiSplashLoop() {
WinSet, Transparent, 75, %title%
Gui, Hide

; Start thread that will update splash (Don't stall this thread).
SetTimer, guiUpdater, % 10 ; trigger next gui at 10ms interval.

; Thread for updating the GUI.
guiUpdater:
loop {
mSleep(20)
static sec := 0 ; counter for hiding GUI.
static idx_store := 0 ; store the last known state.
sec := sec + 20 ; increment the time for hiding the splash.

; Check if the desktop number has changed then update (Avoids Visual blinking).
idx := CurDesktopIdx()
if (idx != idx_store && idx is number) {
sec := 0 ; Reset Counter.
idx_store := idx
GuiControl,,gDesktopNum, %idx%
GuiControlGet, hwnd, Hwnd, gDesktopNum
SetTextAndResize(hwnd, idx)
Gui, Show, NA AutoSize, %title%
}
; Loop to update the GUI forever.
loop {
mSleep(10)
static sec := 0 ; counter for hiding GUI.
static idx_store := 0 ; store the last known state.
sec := sec + 10 ; increment the time for hiding the splash.

; Check if the desktop number has changed then update (Avoids Visual blinking).
idx := CurDesktopIdx()
if (idx != idx_store && idx is number) {
sec := 0 ; Reset Counter.
idx_store := idx
GuiControl,,gDesktopNum, %idx%
GuiControlGet, hwnd, Hwnd, gDesktopNum
SetTextAndResize(hwnd, idx)
Gui, Show, NA AutoSize, %title%
}

; Hide the splash after 1000ms.
if (sec >= 650) {
sec := 0 ; Reset counter.
Gui, Hide
}
; Hide the splash after 1000ms.
if (sec >= 650) {
sec := 0 ; Reset counter.
Gui, Hide
}
Return
}
}

0 comments on commit c9ba35e

Please sign in to comment.