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
// - Trigger target when run by a Trigger 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)
{
// Set the X, Y, Width, Height of the positions here
List<Rectangle> positions = new List<Rectangle>();
positions.Add(new Rectangle(-1, 0, 963, 521));
positions.Add(new Rectangle(960, 0, 963, 521));
positions.Add(new Rectangle(-1, 521, 963, 521));
positions.Add(new Rectangle(960, 520, 963, 521));
positions.Add(new Rectangle(-964, 0, 963, 521));
positions.Add(new Rectangle(-1927, 0, 963, 521));
positions.Add(new Rectangle(-964, 520, 963, 521));
positions.Add(new Rectangle(-1927, 520, 963, 521));
// Set the process name of the application here
String processName = "notepad.exe";
// Check if there are any open windows at either position
bool[] positionsOccupied = new bool[positions.Count];
for (int i = 0; i < positions.Count; i++)
{
positionsOccupied[i] = false;
}
foreach (IntPtr window in BFS.Window.GetVisibleWindowHandles())
{
if (BFS.Application.GetMainFileByWindow(window).ToLower().Contains(processName.ToLower()))
{
Rectangle bounds = BFS.Window.GetBounds(window);
int j = 0;
foreach (Rectangle position in positions)
{
if (bounds == position)
{
positionsOccupied[j] = true;
}
j++;
}
}
}
// Place the new window depending on where the open ones are
int k = 0;
foreach (bool positionOccupied in positionsOccupied)
{
if (!positionOccupied)
{
BFS.Window.SetSizeAndLocation(windowHandle, positions[k].X, positions[k].Y, positions[k].Width, positions[k].Height);
break;
}
k++;
}
}
}