Skip to content

Commit

Permalink
Implemented work around for tray icon corruption on resolution change…
Browse files Browse the repository at this point in the history
… (thanks MS for not fixing this since Windows 95(?).
  • Loading branch information
Aaron Landwehr committed Mar 28, 2021
1 parent 7a3b13d commit dfbe4a6
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions virtual_desktop_enhancer.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,24 @@ I_Icon = app.ico
IfExist, %I_Icon%
Menu, Tray, Icon, %I_Icon%

; Restart script on resolution change to fix tray icon.
; Workaround because autohotkey icon change commands do nothing after resolution changes.
OnMessage(0x7E, "WM_DISPLAYCHANGE")
WM_DISPLAYCHANGE(wParam, lParam)
{
sleep 5000 ; takes ~5 seconds for the resolution change to stabilize.
Reload
}

if (not A_IsAdmin)
{
Run *RunAs "%A_ScriptFullPath%" ; Requires v1.0.92.01+
ExitApp
}

; Remove dead tray icons.
Tray_Refresh()

; initiate splash on start.
gtitle:="Splash123"
gDesktopNum := "" ; Splash variable.
Expand Down Expand Up @@ -91,6 +103,41 @@ Return
}
Return

; Removes dead tray icons.
Tray_Refresh() {
WM_MOUSEMOVE := 0x200
detectHiddenWin := A_DetectHiddenWindows
DetectHiddenWindows, On

allTitles := ["ahk_class Shell_TrayWnd"
, "ahk_class NotifyIconOverflowWindow"]
allControls := ["ToolbarWindow321"
,"ToolbarWindow322"
,"ToolbarWindow323"
,"ToolbarWindow324"]
allIconSizes := [24,32]

for id, title in allTitles {
for id, controlName in allControls {
for id, iconSize in allIconSizes {
ControlGetPos, xTray,yTray,wdTray,htTray,% controlName,% title
y := htTray - 10
While (y > 0) {
x := wdTray - iconSize/2
While (x > 0) {
point := (y << 16) + x
PostMessage,% WM_MOUSEMOVE, 0,% point,% controlName,% title
x -= iconSize/2
}
y -= iconSize/2
}
}
}
}

DetectHiddenWindows, %detectHiddenWin%
}

; Fn to get number of desktops (Windows has no exposed APIs).
NumDesktops() {
RegRead, DesktopList, HKEY_CURRENT_USER, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VirtualDesktops, VirtualDesktopIDs
Expand Down Expand Up @@ -239,6 +286,7 @@ GuiSplash() {
Gui, Show, Center NA, %gtitle%
WinSet, Transparent, 75, %gtitle%
Gui, Hide
return
}

; Update Gui display before starting update thread.
Expand Down

0 comments on commit dfbe4a6

Please sign in to comment.