Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Fade Inactive Windows


  • Please log in to reply
118 replies to this topic
jesseelliott
  • Members
  • 26 posts
  • Last active: May 19 2011 07:40 PM
  • Joined: 11 Apr 2011
Lots of Fixes here. Not everything is strictly new -- this is simply as list of changes I've made from the original script:

- Added configurable Fade Step for fade in and fade out
- No longer replace the standard menu, rather 'Configure' is simply added to it
- Added a check to make sure the system tray icon exits
- Loop through windows much more often (every 200 ms) for better responsiveness
- Moved processname code further down to improve performance (6% to 1% CPU)
- Make the active window non-transparent first, before making other windows transparent
- Make all windows in the active process (based on PID) non-transparent (i.e. Find Dialogs, menus, etc.)
- Fixed Drag artifacts (transparent box when dragging Desktop icons)

;
; AutoHotkey Version: 1.x
; Language:       English
; Platform:       WinNT
; Author:         David Earls
;
; Script Function:
;   Ghost inactive Windows like XFCE
;
; Attribution: The code to loop through windows was paraphrased from the AHK forums.
; script of Unambiguous adjusted for use with PSPad
;
; Modified by Jesse Elliott
;
; - Added configurable Fade Step for fade in and fade out
; - No longer replace the standard menu, rather 'Configure' is simply added to it
; - Added a check to make sure the system tray icon exits
; - Loop through windows much more often (every 200 ms) for better responsiveness
; - Moved processname code further down to improve performance (6% to 1% CPU)
; - Make the active window non-transparent first, before making other windows transparent
; - Make all windows in the active process (based on PID) non-transparent (i.e. Find Dialogs, menus, etc.)
; - Fixed Drag artifacts (transparent box when dragging Desktop icons)


#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetTitleMatchMode, 2
#SingleInstance, force
DetectHiddenWindows, Off 


; Configurable Values
iniread, TransLvl, fadetoblack.ini, Preferences, Transparent, 200
iniread, fadeStep, fadetoblack.ini, Preferences, FadeStep, 10
iniread, delay, fadetoblack.ini, Preferences, Delay, 0


; if the icon exists, use it
ifexist, %A_Windir%\System32\accessibilitycpl.dll
  menu, tray, icon, %A_Windir%\System32\accessibilitycpl.dll, 15


; add Configure to the standard menu  
menu, tray, add
menu, tray, add, &Configure, Configure
menu, tray, default, &Configure
menu, tray, tip, Fades Inactive Windows - Please exit properly.


OnExit, ExitRoutine
#Persistent
SetTimer, CheckIfActive, 200  ; check windows every 200 milliseconds
return


; loop through all windows
CheckIfActive:
WinGet, id, list, , , Program Manager
Loop, %id%
{
    StringTrimRight, this_id, id%a_index%, 0
    WinGetTitle, title, ahk_id %this_id%
    
    If title =
        continue

    WinGetClass class , ahk_id %this_id%

    if class = Shell_TrayWnd ; Look down
        continue
    if class = Button ; Start Menu
        continue
    if class = SysDragImage ; Drag Objects
        continue


    ; Exclusions
    winget processname, processname, ahk_id %this_id%

    if ( processname = "PSPad.exe" and class = "TApplication" )
      continue
    if (processname = "devenv.exe") ; Visual Studio doesn't support transparency (WS_EX_LAYERED is not set)
        continue


    ; Set the active window non-transparent first
    WinGet, activeTrans, Transparent, A

    if activeTrans = %TransLvl%
    {
        fadeTrans := TransLvl

        While, fadeTrans < 255
        {
            fadeTrans += fadeStep

            if (fadeTrans < 255)
            {
              Winset, Transparent, %fadeTrans%, A
              Sleep, 5
            }
        }

        ; set to 255 first as suggested in Help to avoid black background issues
        winset, Transparent, 255, ahk_id A
        winset, Transparent, Off, ahk_id A

        ; Debug Code
        ;WinGetTitle activeTitle, A
        ;WinGetClass activeClass, A
        ;winget activeProcessname, processname, A
        ;MsgBox, Activated %activeTitle%   Class: %activeClass%   Process: %activeProcessname%
    }


    ; get the active process ID to make all windows in a single process the same
    WinGet, active_pid, PID, A

    WinGet, pid, PID, ahk_id %this_id%
    WinGet, id_trans, ID, ahk_id %this_id%
    WinGet, Trans, Transparent, ahk_id %this_id%

    ; if this is a window in the active process, Set non-transparent
    if (pid = active_pid)
    {
        ; if transparent
        if Trans = %TransLvl%
        {
            fadeTrans := TransLvl

            While, fadeTrans < 255
            {
                fadeTrans += fadeStep

                if (fadeTrans < 255)
                {
                  Winset,Transparent, %fadeTrans%, ahk_id %id_trans%
                  Sleep, 5
                }
            }

            ; set to 255 first as suggested in Help to avoid black background issues
            winset, Transparent, 255, ahk_id %id_trans%
            winset, Transparent, Off, ahk_id %id_trans%

            ; Debug Code
            ;winget processname,processname, ahk_id %this_id%
            ;MsgBox, Activated %title%   Class: %class%   Process: %processname%
        }

        continue
    }


    If Trans = %TransLvl% ; already Transparent
        continue

    if delay
    {
        if wininactive%ID_trans% < %delay%
        {
            wininactive%ID_trans% += 1
            continue
        }
        else
        {
            wininactive%ID_min% = 0
        }
    }

    fadeTrans = 255

    While, fadeTrans > TransLvl
    {
        if (fadeTrans > TransLvl)
        {
          fadeTrans -= fadeStep
          Winset,Transparent, %fadeTrans%, ahk_id %id_trans%
          Sleep, 30
        }
    }

    Winset, Transparent, %TransLvl%, ahk_id %id_trans%

    ; Debug Code
    ;winget processname,processname, ahk_id %this_id%
    ;MsgBox, Faded %title%   Class: %class%   Process: %processname%
}
return


; on exit, set windows back to non-transparent
ExitRoutine:
WinGet, id, list, , , Program Manager
Loop, %id%
{
    StringTrimRight, this_id, id%a_index%, 0
    WinGetTitle, title, ahk_id %this_id%
    WinGetClass class , ahk_id %this_id%

    If title =
        continue
    if class = Shell_TrayWnd
        continue
    if class = Button ;you get a large square if you remove this.
       continue
    if class = SysDragImage ; Drag Objects
       continue

    winget processname,processname, ahk_id %this_id%

    ; Exclusions
    if ( processname = "PSPad.exe" and class = "TApplication" )
        continue
    if (processname = "devenv.exe") ; Visual Studio doesn't support transparency (WS_EX_LAYERED is not set)
        continue

    WinGet, id_trans, ID, ahk_id %this_id%

    ; set to 255 first as suggested in Help to avoid black background issues
    Winset,Transparent,255, ahk_id %id_trans%
    Winset,Transparent,off, ahk_id %id_trans%
}
ExitApp
return


Configure:
gui, add, text,,Transparency:
gui, add, text,,Ghost
gui, add, slider,x+5 vTransSlider Range20-255 tooltip,%TransLvl%
gui, add, text,x+5,HiDef
gui, add, text,xm,Fade Step:
gui, add, text,,Slow
gui, add, slider,x+5 vFadeSlider Range1-50 tooltip,%fadeStep%
gui, add, text,x+5,Fast
gui, add, text,xm,`nInactivity Delay (Seconds):
gui, add, text,,Zero
gui, add, slider,x+5 tooltip vDelaySlider Range0-90, %delay%
gui, add, text,x+5,Ninety
gui, add, button,xm,&Save
gui, show,,Configure
return ;the gui


buttonSave:
gui, submit
iniwrite, %TransSlider%, fadetoblack.ini, Preferences, Transparent
iniwrite, %FadeSlider%,  fadetoblack.ini, Preferences, FadeStep
iniwrite, %DelaySlider%, fadetoblack.ini, Preferences, Delay
reload
return


GuiEscape:
GuiClose:
gui, destroy
return

return ;configure sub


Meetloaf
  • Members
  • 46 posts
  • Last active: Mar 05 2016 07:57 PM
  • Joined: 02 Jun 2008
Awesome work, I'll going to roll with this today and see how it runs =]

Thanks!

Meetloaf
  • Members
  • 46 posts
  • Last active: Mar 05 2016 07:57 PM
  • Joined: 02 Jun 2008
Allrighty, here's what I got:

Posted Image

As well as this (this is a notification for a Yoono pop-up, Yoono is a Firefox extension):
Posted Image


The Yoono pop-up notification box typically looks something like this (not my photo):
Posted Image

I am going to try and get Window spy to see what the window information is for that pop-up? I would think it possible to exclude that window from being affected by this script, no? Unless it has common identifiers with the Firefox window.

Rainmeter widgets are fine.

jesseelliott
  • Members
  • 26 posts
  • Last active: May 19 2011 07:40 PM
  • Joined: 11 Apr 2011
Meetloaf, there's some Debug code in the script that you can uncomment that will tell you window information whenever a window is faded...

Meetloaf
  • Members
  • 46 posts
  • Last active: Mar 05 2016 07:57 PM
  • Joined: 02 Jun 2008

Meetloaf, there's some Debug code in the script that you can uncomment that will tell you window information whenever a window is faded...


Allright, I'll see if I can play with it. I'm still a rookie ;)

Thanks for all your updates. I'm diggin' your defaults for the fade transition BTW =]

EDIT:
Sweet, I just excluded siderbar.exe and my gadgets are not affected.
with the If...continue code it excludes that process from the ghosting effect.

Can you exclude other things like window classes?

jesseelliott
  • Members
  • 26 posts
  • Last active: May 19 2011 07:40 PM
  • Joined: 11 Apr 2011

Sweet, I just excluded siderbar.exe and my gadgets are not affected.
with the If...continue code it excludes that process from the ghosting effect.

Can you exclude other things like window classes?

Absolutely. That's how I fixed the Drag problem:
if class = SysDragImage ; Drag Objects
    continue


Meetloaf
  • Members
  • 46 posts
  • Last active: Mar 05 2016 07:57 PM
  • Joined: 02 Jun 2008
So, I can't use the ahk_class, b/c it's the same as Firefox,

But, the window title is different. My only problem is that the title name varies as follows:
layer-XXXXXX
layer-XXXX

I was thinking of using an * at the end of my expression, but it would be in quotes, so this won't work right?

Been reading about 'RegExMatch' but not sure how it works exactly.

Essentially I need something like this

if title = "layer-*"
continue



tidbit
  • Administrators
  • 2709 posts
  • Hates playing Janitor
  • Last active: Jan 15 2016 11:37 PM
  • Joined: 09 Mar 2008
if Instr(...)
or
If var in/contains value1,value2,...
or
SetTitleMatchMode

samples:
if (instr(title, "layer"))
  continue
; or
if title contains layer,Pandora,tidbit ; ignore anything with layer or Pandora or tidbit in the title.
  Continue

rawr. be very afraid
*poke*
. Populate the AutoHotkey city. Pointless but somewhat fun. .


Aero98
  • Members
  • 112 posts
  • Last active: Mar 29 2013 03:42 PM
  • Joined: 08 Jan 2009
Has anyone tried locking their computer (Window’s Key + L) with this running? I don't know if it is just coincidence or not, but after I started running this script, if I lock my pc, when I unlock it, I get a black screen and the system is un responsive for like 3 minutes.

I have rebooted and I am going to see if it continues. Has anyone else seen this or does anyone know of a way to detect when the machine is locked and stop the timer until the system is unlocked?
(\__/) This is Bunny.
(='.'=) Copy and paste Bunny onto your signature.
(")_(") Help Bunny gain World Domination.

bruno
  • Members
  • 635 posts
  • Last active: Nov 04 2015 02:26 PM
  • Joined: 07 Mar 2011
Posted Image ...which raises my next question: Could these scripts we are using so casually somehow damage our Windows OS? Posted Image

This is Bunny. Help Bunny gain World Domination. :lol:
Posted Image :shock:

jesseelliott
  • Members
  • 26 posts
  • Last active: May 19 2011 07:40 PM
  • Joined: 11 Apr 2011

Has anyone tried locking their computer (Window’s Key + L) with this running? I don't know if it is just coincidence or not, but after I started running this script, if I lock my pc, when I unlock it, I get a black screen and the system is un responsive for like 3 minutes.

I have rebooted and I am going to see if it continues. Has anyone else seen this or does anyone know of a way to detect when the machine is locked and stop the timer until the system is unlocked?


Hmm, just tried it. It worked fine for me... Are you on Windows 7?

Meetloaf
  • Members
  • 46 posts
  • Last active: Mar 05 2016 07:57 PM
  • Joined: 02 Jun 2008

if Instr(...)
or
If var in/contains value1,value2,...
or
SetTitleMatchMode

samples:

if (instr(title, "layer"))
  continue
; or
if title contains layer,Pandora,tidbit ; ignore anything with layer or Pandora or tidbit in the title.
  Continue


Tidbit, thank you for your help and the examples, one reason I love coming here to AHK forums, always learn something new.


@Aero98, I just tried lock/unlock and no issues.

jesseelliott
  • Members
  • 26 posts
  • Last active: May 19 2011 07:40 PM
  • Joined: 11 Apr 2011
- Now keeps track of currently active process to improve performance (brings CPU to 0%)
- Fixed regression in Inactive Delay (it now works again)
- Added excludes for sidebar.exe and windows with title starting with 'layer-'

;
; AutoHotkey Version: 1.x
; Language:       English
; Platform:       WinNT
; Author:         David Earls
;
; Script Function:
;   Ghost inactive Windows like XFCE
;
; Attribution: The code to loop through windows was paraphrased from the AHK forums.
; script of Unambiguous adjusted for use with PSPad
;
; Modified by Jesse Elliott
;
; - Added configurable Fade Step for fade in and fade out
; - No longer replace the standard menu, rather 'Configure' is simply added to it
; - Added a check to make sure the system tray icon exits
; - Loop through windows much more often (every 200 ms) for better responsiveness
; - Moved processname code further down to improve performance (6% to 1% CPU)
; - Make the active window non-transparent first, before making other windows transparent
; - Make all windows in the active process (based on PID) non-transparent (i.e. Find Dialogs, menus, etc.)
; - Fixed Drag artifacts (transparent box when dragging Desktop icons)
; - Keep track of currently active process (brings CPU to 0%)
; - Fixed regression in Inactive Delay
; - Added excludes for sidebar.exe and windows with title starting with 'layer-'


#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetTitleMatchMode, 2
#SingleInstance, force
DetectHiddenWindows, Off 


; Configurable Values
iniread, TransLvl, fadetoblack.ini, Preferences, Transparent, 200
iniread, fadeStep, fadetoblack.ini, Preferences, FadeStep, 10
iniread, delay,    fadetoblack.ini, Preferences, Delay, 0


; if the icon exists, use it
ifexist, %A_Windir%\System32\accessibilitycpl.dll
  menu, tray, icon, %A_Windir%\System32\accessibilitycpl.dll, 15


; add Configure to the standard menu  
menu, tray, add
menu, tray, add, &Configure, Configure
menu, tray, default, &Configure
menu, tray, tip, Fades Inactive Windows - Please exit properly.


; keep track of the current active PID for performance reasons
curActivePID = -1


OnExit, ExitRoutine
#Persistent
SetTimer, CheckIfActive, 200  ; check windows every 200 ms
return



CheckIfActive:

WinGet, active_pid, PID, A

; if the active process hasn't changed, don't do anything
if (active_pid = curActivePID)
{
    canReturn = 1

    if (delay)
    {
        WinGet, id, list, , , Program Manager
        Loop, %id%
        {
            StringTrimRight, this_id, id%a_index%, 0

            if wininactive%this_id% > 0
            {
                canReturn = 0
                break
            }
        }
    }

    if (canReturn)
        return
}

curActivePID := active_pid


; Set the active window non-transparent first
WinGet, activeTrans, Transparent, A

if activeTrans = %TransLvl%
{
    fadeTrans := TransLvl

    While, fadeTrans < 255
    {
        fadeTrans += fadeStep

        if (fadeTrans < 255)
        {
          Winset, Transparent, %fadeTrans%, A
          Sleep, 5
        }
    }

    ; set to 255 first as suggested in Help to avoid black background issues
    winset, Transparent, 255, A
    winset, Transparent, Off, A

    ; Debug Code
    ;WinGetTitle activeTitle, A
    ;WinGetClass activeClass, A
    ;winget activeProcessname, processname, A
    ;MsgBox, Activated %activeTitle%   Class: %activeClass%   Process: %activeProcessname%
}


; loop through all windows
WinGet, id, list, , , Program Manager
Loop, %id%
{
    StringTrimRight, this_id, id%a_index%, 0
    WinGetTitle, title, ahk_id %this_id%
    
    If title =
        continue

    WinGetClass class , ahk_id %this_id%

    if class = Shell_TrayWnd ; taskbar
        continue
    if class = Button ; Start Menu
        continue
    if class = SysDragImage ; Drag Objects
        continue
    if class = WorkerW ; Desktop
        continue


    ; Exclusions
    winget processname, processname, ahk_id %this_id%

    if (processname = "PSPad.exe" and class = "TApplication" )
        continue
    if (processname = "devenv.exe") ; Visual Studio doesn't support transparency (WS_EX_LAYERED is not set)
        continue
    if (processname = "sidebar.exe")
        continue

    ; if the title starts with 'layer-', continue
    StringGetPos, strPos, title, layer-

    if (strPos = 0)
        continue


    WinGet, pid, PID, ahk_id %this_id%
    WinGet, id_trans, ID, ahk_id %this_id%
    WinGet, Trans, Transparent, ahk_id %this_id%

    ; if this is a window in the active process, Set non-transparent
    if (pid = active_pid)
    {
        ; if transparent
        if Trans = %TransLvl%
        {
            fadeTrans := TransLvl

            While, fadeTrans < 255
            {
                fadeTrans += fadeStep

                if (fadeTrans < 255)
                {
                  Winset,Transparent, %fadeTrans%, ahk_id %id_trans%
                  Sleep, 5
                }
            }

            ; set to 255 first as suggested in Help to avoid black background issues
            winset, Transparent, 255, ahk_id %id_trans%
            winset, Transparent, Off, ahk_id %id_trans%

            ; Debug Code
            ;winget processname,processname, ahk_id %this_id%
            ;MsgBox, Activated* %title%   Class: %class%   Process: %processname%
        }

        continue
    }


    If Trans = %TransLvl% ; already Transparent
        continue

    if delay
    {
        ; scale delay based on loop frequency (200 ms)
        scaledDelay := delay * 4 ; should be 5, but this seems to work :)

        if wininactive%ID_trans% < %scaledDelay%
        {
            wininactive%ID_trans% += 1
            continue
        }
        else
        {
            wininactive%ID_trans% = 0
        }
    }

    fadeTrans = 255

    While, fadeTrans > TransLvl
    {
        fadeTrans -= fadeStep

        if (fadeTrans > TransLvl)
        {
          Winset,Transparent, %fadeTrans%, ahk_id %id_trans%
          Sleep, 30
        }
    }

    Winset, Transparent, %TransLvl%, ahk_id %id_trans%

    ; Debug Code
    ;winget processname,processname, ahk_id %this_id%
    ;MsgBox, Faded %title%   Class: %class%   Process: %processname%
}

return


; on exit, set windows back to non-transparent
ExitRoutine:
WinGet, id, list, , , Program Manager
Loop, %id%
{
    StringTrimRight, this_id, id%a_index%, 0
    WinGetTitle, title, ahk_id %this_id%
    WinGetClass class , ahk_id %this_id%

    If title =
        continue
    if class = Shell_TrayWnd
        continue
    if class = Button ;you get a large square if you remove this.
       continue
    if class = SysDragImage ; Drag Objects
       continue
    if class = WorkerW ; Desktop
        continue

    winget processname,processname, ahk_id %this_id%

    ; Exclusions
    if (processname = "PSPad.exe" and class = "TApplication" )
        continue
    if (processname = "devenv.exe") ; Visual Studio doesn't support transparency (WS_EX_LAYERED is not set)
        continue
    if (processname = "sidebar.exe")
        continue

    WinGet, id_trans, ID, ahk_id %this_id%

    ; set to 255 first as suggested in Help to avoid black background issues
    Winset,Transparent,255, ahk_id %id_trans%
    Winset,Transparent,off, ahk_id %id_trans%
}
ExitApp
return


Configure:
gui, add, text,,Transparency:
gui, add, text,,Ghost
gui, add, slider,x+5 vTransSlider Range20-255 tooltip,%TransLvl%
gui, add, text,x+5,HiDef
gui, add, text,xm,Fade Step:
gui, add, text,,Slow
gui, add, slider,x+5 vFadeSlider Range1-50 tooltip,%fadeStep%
gui, add, text,x+5,Fast
gui, add, text,xm,`nInactivity Delay (Seconds):
gui, add, text,,Zero
gui, add, slider,x+5 tooltip vDelaySlider Range0-90, %delay%
gui, add, text,x+5,Ninety
gui, add, button,xm,&Save
gui, show,,Configure
return ;the gui


buttonSave:
gui, submit
iniwrite, %TransSlider%, fadetoblack.ini, Preferences, Transparent
iniwrite, %FadeSlider%,  fadetoblack.ini, Preferences, FadeStep
iniwrite, %DelaySlider%, fadetoblack.ini, Preferences, Delay
reload
return


GuiEscape:
GuiClose:
gui, destroy
return

return ;configure sub


earlsd
  • Guests
  • Last active:
  • Joined: --
I've been busy at work/home all week and I missed all of this. Even the Lifehacker part. I've created a web page for (my version) of the program located here:

https://sites.google...activewinfader/

It has several bug fixes and the priority of the process is configurable. Judging by all your comments I need to read exclusions from an INI file and consider stealing (:-) the gradual fade effect worked on by y'all.

I'll sign up for an AHK forums account so I'm not so out of the loop in the future.

Meetloaf
  • Members
  • 46 posts
  • Last active: Mar 05 2016 07:57 PM
  • Joined: 02 Jun 2008
Jesse's edits are butter. Running it right now it most of the bugginess is gone.