This script will fade windows that are [not maximized/minimized, under the mouse, active or system windows].
What may be unique to this fade script is that it uses sendmessage for interprocess communication to make the fade effect multithreaded/multiprocess
place both files in same directory and run winfade, it will launch 2 copies of _fade_effect, 1 for fadein, 1 for fadeout.
winfade.ahk
Code: Select all
#NoEnv
;#NoTrayIcon
#SingleInstance, force
#Persistent
CoordMode, Mouse, Screen
SetWinDelay, -1
SetWorkingDir, %A_ScriptDir%
SetTitleMatchMode, 2
DetectHiddenWindows, On
OnExit("Shutdown", -1)
exclusions := {}
Startup()
Main_Loop()
return
IsExcluded(win) {
global exclusions
if(exclusions[win])
return true
if(DllCall("GetParent", UInt, win))
return true
WinGetTitle, wtitle, ahk_id %win%
if(!wtitle)
return true
WinGet, mm, MinMax, ahk_id %win%
if(mm <> 0)
return true
return false
}
UpdateWindows() {
global AllWindows
newWindows := {}
DetectHiddenWindows, Off
GroupAdd, allwins
WinGet, WINDS, List, ahk_group allwins
DetectHiddenWindows, On
Loop, %WINDS% {
cWind := WINDS%A_Index%
if(IsExcluded(cWind))
Continue
newWindows[cWind] := 1
}
AllWindows := newWindows
}
IsPopup(win) {
WinGet, ss, Style, ahk_id %win%
winGet, sx, ExStyle, ahk_id %win%
if(ss & 0x80000000 and sx & 0x00000080)
return true
return false
}
Startup() {
global exclusions, _FadeIn_pid, _FadeOut_pid, fadein_id, fadeout_id, AllWindows
bad_classes := Array("Progman", "WorkerW", "Shell_SecondaryTrayWnd", "Shell_TrayWnd", "ClassicShell.CMenuContainer", "TaskManagerWindow", "Windows.UI.Core.CoreWindow")
for i, v in bad_classes {
WinGet, wid, ID, ahk_class %v%
exclusions[wid] := 1
}
exclusions[DllCall("GetDesktopWindow")] := 1
Run, % ".\_fade_effect.ahk",, Hide, _FadeIn_pid
WinWait, % "_fade_effect.ahk ahk_pid " . _FadeIn_pid
fadein_id := WinExist("_fade_effect.ahk ahk_pid " . _FadeIn_pid)
Run, % ".\_fade_effect.ahk",, Hide, _FadeOut_pid
WinWait, % "_fade_effect.ahk ahk_pid " . _FadeOut_pid
fadeout_id := WinExist("_fade_effect.ahk ahk_pid " . _FadeOut_pid)
UpdateWindows()
}
Shutdown() {
global _FadeOut_pid, _FadeIn_pid, AllWindows
UpdateWindows()
For win, v in AllWindows
Sync_FadeIn(win)
Sleep, 250
Process, Close, %_FadeIn_pid%
Process, Close, %_FadeOut_pid%
}
Main_Loop() {
prior_active := 0, prior_mouseover := 0
trigger_event := true
Loop {
Sleep, 50
trigger_event := !trigger_event
if(trigger_event) {
ProcessWindowUnderMouse(ProcessActiveWindow())
} else {
UpdateWindows()
}
}
}
ProcessActiveWindow() {
static prev_active := WinActive("A")
current_active := WinActive("A")
if(current_active != prev_active) {
FadeIn(current_active)
FadeOut(prev_active)
prev_active := current_active
}
return current_active
}
ProcessWindowUnderMouse(exclude) {
static prev_mwin
MouseGetPos,,, current_mwin,,
; if(IsExcluded(current_mwin))
; return
if(current_mwin != prev_mwin) {
if(!IsPopup(current_mwin)) {
FadeIn(current_mwin)
}
if(prev_mwin != exclude) {
FadeOut(prev_mwin)
}
prev_mwin := current_mwin
}
}
Sync_FadeIn(win) {
global fadein_id
SendMessage, 0x9005, -1, win,, ahk_id %fadein_id%
}
FadeIn(win) {
global fadein_id
PostMessage, 0x9005, -1, win,, ahk_id %fadein_id%
}
FadeOut(win) {
global fadeout_id, AllWindows
if(!AllWindows[win] or IsExcluded(win))
return
PostMessage, 0x9005, 1, win,, ahk_id %fadeout_id%
}
Code: Select all
#NoEnv
#NoTrayIcon
#SingleInstance, off
#Persistent
Thread, NoTimers
SetWinDelay, -1
SetWorkingDir %A_ScriptDir%
OnMessage(0x9005, "FadeEffect")
Return
FadeEffect(wParam, lParam, Msg) {
window_id := WinExist("ahk_id " . lParam)
TransitionTrans(window_id, (wParam == -1 ? 255 : 150))
return 0x9005
}
TransitionTrans(window, needed) {
WinGet, cTrans, Transparent, ahk_id %window%
if(cTrans == needed)
return
cTrans := !cTrans ? 255 : cTrans
steps := 5
step_size := (needed - cTrans) / steps
Loop, %steps% {
cTrans += step_size
WinSet, Transparent, %cTrans%, ahk_id %window%
;WinGet, cTrans, Transparent, ahk_id %window%
Sleep, % (150 / steps)
}
WinSet, Redraw,, ahk_id %window%
;DllCall("User32\ShowWindow", UInt, window, Int, 4, Int)
if(needed == 255) {
WinSet, Transparent, Off, ahk_id %window%
}
}