using System;
using System.Drawing;
using System.Collections.Generic;
// The 'windowHandle' parameter will contain the window handle for the:
// - Active window when run by hotkey
// - Window Location target when run by a Window Location rule
// - TitleBar Button owner when run by a TitleBar Button
// - Jump List owner when run from a Taskbar Jump List
// - Currently focused window if none of these match
public static class DisplayFusionFunction
{
public static void Run(IntPtr windowHandle)
{
//a dictionary type to store the window handle and an approximate time
Dictionary<IntPtr, int> watchedWindows = new Dictionary<IntPtr, int>();
while(true)
{
//store the currently focused window
IntPtr focusedWindow = BFS.Window.GetFocusedWindow();
//if the focused window is in the watched windows, reset the timer
if(watchedWindows.ContainsKey(focusedWindow))
watchedWindows[focusedWindow] = 0;
//get a list of all of the visible window handles
List<IntPtr> windows = new List<IntPtr>(BFS.Window.GetVisibleWindowHandles());
//loop though all of the visible windows
foreach(IntPtr window in windows)
{
//check if this window is already rolled up
if(BFS.Window.IsWindowRolledUpToTitleBar(window))
continue;
//if this is a new window, add it to the list and continue
if(!watchedWindows.ContainsKey(window))
{
watchedWindows.Add(window, 0);
continue;
}
//increment the time by 1
watchedWindows[window]++;
//if the time is greater or equal to 30, roll up the window and remove it from the list
if(watchedWindows[window] >= 30)
{
BFS.Window.RollupWindowToTitleBar(window);
watchedWindows.Remove(window);
}
}
//make a list to store windows that have been closed/minimized
List<IntPtr> windowsToRemove = new List<IntPtr>();
//look for windows that aren't visible anymore
foreach(IntPtr key in watchedWindows.Keys)
{
//sequencial lookup, but the list size shouldn't ever be very big (>500)
if(!windows.Contains(key))
windowsToRemove.Add(key);
}
foreach(IntPtr window in windowsToRemove)
watchedWindows.Remove(window);
//pause for one second
BFS.General.Sleep(1000);
}
}
}