Skip to content

Instantly share code, notes, and snippets.

@emvaized
Last active September 3, 2023 06:46
Show Gist options
  • Save emvaized/fd63582d26a583033f983e0c05f5fcd5 to your computer and use it in GitHub Desktop.
Save emvaized/fd63582d26a583033f983e0c05f5fcd5 to your computer and use it in GitHub Desktop.
Autohotkey script to fade out window of drag/resize
; This AHK script makes dragged or resized windows semi-transparent, with nice fade in and fade out animation
; It is intended to recreate similar Compiz effect on KDE Plasma
; Source of window hook: http://forum.script-coding.com/viewtopic.php?pid=95736#p95736
#NoEnv
#SingleInstance Force
#Persistent
SetBatchLines,-1
HookProcAdr := RegisterCallback( "HookProc", "F" ), hWinEventHook := SetWinEventHook( 0x1, 0x17, 0, HookProcAdr, 0, 0, 0 )
SetWinEventHook(eventMin, eventMax, hmodWinEventProc, lpfnWinEventProc, idProcess, idThread, dwFlags)
{
DllCall("CoInitialize", Uint, 0)
return DllCall("SetWinEventHook", Uint,eventMin , Uint,eventMax , Uint,hmodWinEventProc
, Uint,lpfnWinEventProc, Uint,idProcess, Uint,idThread, Uint,dwFlags)
}
HookProc( hWinEventHook, Event, hWnd, idObject, idChild, dwEventThread, dwmsEventTime )
{
; EVENT_SYSTEM_MOVESIZESTART
if (Event = 10) {
FadeOutWindow(Hwnd, 200, 10)
}
; EVENT_SYSTEM_MOVESIZEEND
else if (Event = 11) {
FadeInWindow(Hwnd, 255, 10)
}
}
FadeOutWindow(windowId = "A", end = 0, speed = 10)
{
WinGet, currentTrans, Transparent, ahk_id %windowId%
If (currentTrans == "")
{
WinSet, Trans, 255, ahk_id %windowId%
WinGet, currentTrans, Transparent, ahk_id %windowId%
}
While, (currentTrans > end)
{
Sleep, % speed / 2
Trans := currentTrans - speed
WinSet, Trans, %Trans%, ahk_id %windowId%
WinGet, currentTrans, Transparent, ahk_id %windowId%
}
}
FadeInWindow(windowId = "A", end = 0, speed = 10)
{
WinGet, currentTrans, Transparent, ahk_id %windowId%
If (currentTrans == "")
{
WinSet, Trans, 255, ahk_id %windowId%
WinGet, currentTrans, Transparent, ahk_id %windowId%
}
While, (currentTrans < end)
{
Sleep, % speed / 2
Trans := currentTrans + speed
WinSet, Trans, %Trans%, ahk_id %windowId%
WinGet, currentTrans, Transparent, ahk_id %windowId%
}
}
return
@emvaized
Copy link
Author

emvaized commented Sep 2, 2023

illustration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment