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
Alright I shouldn't be spending time on this :) but here's a version with animating fade capability -- complete with configurable 'Fade Step'

EDIT: now fades in as well as out

;
; 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


#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 

iniread, TransLvl, fadetoblack.ini, Preferences, Transparent, 150
iniread, fadeStep, fadetoblack.ini, Preferences, FadeStep, 10
iniread, delay, fadetoblack.ini, Preferences, Delay, 0

ifexist, %A_Windir%\System32\accessibilitycpl.dll
  menu, tray, icon, %A_Windir%\System32\accessibilitycpl.dll, 15
menu, tray, nostandard
menu, tray, add, &Configure, Configure
menu, tray, default, &Configure
menu, tray, add
menu, tray, add, E&xit, ExitRoutine
menu, tray, tip, Fades Inactive Windows - Please exit properly.


OnExit, ExitRoutine
#Persistent
SetTimer, CheckIfActive, 200
return



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
    
    winget processname,processname, ahk_id %this_id%

    ;Exclusions
    if ( processname = "PSPad.exe" and class = "TApplication" )
      continue

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

    ; if active task, Set vis.
    IfWinActive, ahk_id %id_trans%
    {
        ; if still transparent
        if Trans = %TransLvl%
        {
            fadeTrans := TransLvl

            While, fadeTrans < 255
            {
                fadeTrans += fadeStep

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

            winset, Transparent, Off, ahk_id %id_trans%
        }

        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
    {
        fadeTrans -= fadeStep
        Winset,Transparent, %fadeTrans%, ahk_id %id_trans%
        Sleep, 30
    }

    Winset,Transparent, %TransLvl%, ahk_id %id_trans%
}
return


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
    
    winget processname,processname, ahk_id %this_id%

    ;Exclusions
    if ( processname = "PSPad.exe" and class = "TApplication" )
        continue

    WinGet, id_trans, ID, ahk_id %this_id%

    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
Hello earlsd, not sure which OS you're using, so not sure if you'll be able to test this or not.

However, while running this script, it seems to conflict a bit. e.g., Windows Gadgets have a black box surrounding them. And I use a firefox plugin called Yoono that posts notification windows with updates. The popup windows now show black boxes, and that is all.

Any clue why this is happening, or if it's preventable?

Thanks

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

Alright I shouldn't be spending time on this :) but here's a version with animating fade capability -- complete with configurable 'Fade Step'


Awesome. =]

bruno
  • Members
  • 635 posts
  • Last active: Nov 04 2015 02:26 PM
  • Joined: 07 Mar 2011
Posted Image This script consumes about 3K of memory on my XP! :wink:

; http://www.autohotkey.com/forum/viewtopic.php?p=435226#435226
; Fade Inactive Windows
;
; 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.

#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

iniread, TransLvl, fadetoblack.ini, Preferences, Transparent, 100
iniread, fadeStep, fadetoblack.ini, Preferences, FadeStep, 5
iniread, delay, fadetoblack.ini, Preferences, Delay, 0

ifexist, %A_Windir%\System32\accessibilitycpl.dll
menu, tray, icon, %A_Windir%\System32\accessibilitycpl.dll, 15
menu, tray, nostandard
menu, tray, add, &Configure, Configure
menu, tray, default, &Configure
menu, tray, add
menu, tray, add, E&xit, ExitRoutine
menu, tray, tip, Fades Inactive Windows - please exit properly!

OnExit, ExitRoutine
#Persistent
SetTimer, CheckIfActive, 200
return

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
   
    winget processname,processname, ahk_id %this_id%

    ; Exclusions
    if ( processname = "PSPad.exe" and class = "TApplication" )
      continue

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

    ; If active task, set vis.
    IfWinActive, ahk_id %id_trans%
    {
       winset, Transparent, Off, ahk_id %id_trans%
       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
    {
        fadeTrans -= fadeStep
        Winset,Transparent, %fadeTrans%, ahk_id %id_trans%
        Sleep, 10
    }

    Winset,Transparent, %TransLvl%, ahk_id %id_trans%
}
return

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
   
    winget processname,processname, ahk_id %this_id%

    ; Exclusions
    if ( processname = "PSPad.exe" and class = "TApplication" )
        continue

    WinGet, id_trans, ID, ahk_id %this_id%

    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


jobob
  • Guests
  • Last active:
  • Joined: --

Hello earlsd, not sure which OS you're using, so not sure if you'll be able to test this or not.

However, while running this script, it seems to conflict a bit. e.g., Windows Gadgets have a black box surrounding them. And I use a firefox plugin called Yoono that posts notification windows with updates. The popup windows now show black boxes, and that is all.

Any clue why this is happening, or if it's preventable?

Thanks


Same here with rainmeter items.

mazz0310
  • Guests
  • Last active:
  • Joined: --
Is there anyway to make it exclude certain programs?

Specifically wmplayer.exe

under exclusions would i put wmplayer.exe?

Mazz0310
  • Guests
  • Last active:
  • Joined: --
Sorry, looks like I solved my own question. My bad.

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

Sorry, looks like I solved my own question. My bad.


Would you mind posting your edits?

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

Hello earlsd, not sure which OS you're using, so not sure if you'll be able to test this or not.

However, while running this script, it seems to conflict a bit. e.g., Windows Gadgets have a black box surrounding them. And I use a firefox plugin called Yoono that posts notification windows with updates. The popup windows now show black boxes, and that is all.

Any clue why this is happening, or if it's preventable?

Thanks


Found this in the AutoHotKey Help:

"Setting Transparent to 255 prior to turning it off might avoid window redrawing problems such as a black background. If the window still fails to be redrawn correctly, see Redraw for a possible workaround."

It's worth a shot. I can't test it myself as I can't reproduce the bad behavior... My rainmeter widgets look great :/

jesseelliott
  • Members
  • 26 posts
  • Last active: May 19 2011 07:40 PM
  • Joined: 11 Apr 2011
Meetloaf, I got the standard menu back by removing the line:
menu, tray, nostandard
Then I changed the menu section as follows:
menu, tray, add
menu, tray, add, &Configure, Configure
menu, tray, default, &Configure
menu, tray, tip, Fades Inactive Windows - Please exit properly.
That way you get to keep the nice light bulb icon :)

JonS
  • Members
  • 49 posts
  • Last active: Feb 09 2018 07:45 PM
  • Joined: 10 Sep 2010
I've been experimenting with "Active window" exclusions—that is, if a certain window is active, the script won't fade the previously active window. This is especially appropriate for "Find in Text" dialogs. I added this code near the top of the loop in the CheckIfActive routine.

WinGetTitle, activeTitle, A
;ACTIVE window exclusions
if (activeTitle = "Task Switching") OR (activeTitle = "Find Text") OR (activeTitle = "Find")
	continue

I love the gradual fade animation you added, earl, but there's one thing that bugs me about it. Usually, when you switch to a new window, the script unfades the new window before fading the previously-active window. However, sometimes the script fades the previously-active window before unfading the newly-active window, which adds unnecessary wait-time. I was hoping this was caused by the "alt-tab" window being active for a split moment, so I added it as a "active window exclusion", but it didn't fix the problem. If anyone can come up with a fix, I'd like to hear it.

bruno
  • Members
  • 635 posts
  • Last active: Nov 04 2015 02:26 PM
  • Joined: 07 Mar 2011
Posted Image I added JonS's code, and called it Fade Inactive Windows Plus :lol:, but I am not sure if it is in the correct place or if it is working as expected? Posted Image

; http://www.autohotkey.com/forum/viewtopic.php?p=435226#435226
; Fade Inactive Windows Plus
;
; 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.

#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

iniread, TransLvl, fadetoblack.ini, Preferences, Transparent, 100
iniread, fadeStep, fadetoblack.ini, Preferences, FadeStep, 5
iniread, delay, fadetoblack.ini, Preferences, Delay, 0

ifexist, %A_Windir%\System32\accessibilitycpl.dll
menu, tray, icon, %A_Windir%\System32\accessibilitycpl.dll, 15
menu, tray, nostandard
menu, tray, add, &Configure, Configure
menu, tray, default, &Configure
menu, tray, add
menu, tray, add, E&xit, ExitRoutine
menu, tray, tip, Fades Inactive Windows - please exit properly!

OnExit, ExitRoutine
#Persistent
SetTimer, CheckIfActive, 200
return

CheckIfActive:
WinGet, id, list, , , Program Manager
Loop, %id%
{
    StringTrimRight, this_id, id%a_index%, 0
    WinGetTitle, title, ahk_id %this_id%

WinGetTitle, activeTitle, A ; ACTIVE window exclusions
if (activeTitle = "Task Switching") OR (activeTitle = "Find Text") OR (activeTitle = "Find")
continue
   
    If title =
        continue

    WinGetClass class , ahk_id %this_id%

    if class = Shell_TrayWnd ; Look down!
        continue
    if class = Button ; Start Menu!
        continue
   
    winget processname,processname, ahk_id %this_id%

    ; Exclusions
    if ( processname = "PSPad.exe" and class = "TApplication" )
      continue

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

    ; If active task, set vis.
    IfWinActive, ahk_id %id_trans%
    {
       winset, Transparent, Off, ahk_id %id_trans%
       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
    {
        fadeTrans -= fadeStep
        Winset,Transparent, %fadeTrans%, ahk_id %id_trans%
        Sleep, 10
    }

    Winset,Transparent, %TransLvl%, ahk_id %id_trans%
}
return

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
   
    winget processname,processname, ahk_id %this_id%

    ; Exclusions
    if ( processname = "PSPad.exe" and class = "TApplication" )
        continue

    WinGet, id_trans, ID, ahk_id %this_id%

    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


JonS
  • Members
  • 49 posts
  • Last active: Feb 09 2018 07:45 PM
  • Joined: 10 Sep 2010
Yes I believe that would work.

For example, if you opened your AutoHotkey.chm helpfile and pressed ctrl-F to bring up the "Find in Text" dialogue, both windows should remain 100% unfaded (the dialogue box and the help file).

Aero98
  • Members
  • 112 posts
  • Last active: Mar 29 2013 03:42 PM
  • Joined: 08 Jan 2009
Dragging ICONs on the desktop does not work properly. If I click on an Icon on the desk top and try to drag it, the icon will disappear and gets replaced with a transparent box.

I have tried adding exceptions but cannot gett his to work properly. Has anyone else seen this or have a fix?

Great code by the way. 8)
(\__/) 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 I have also experienced some "ghostly" phenomena with this script. All minor and not significant enough to describe at the moment. Posted Image

Posted Image :lol: