using System;
using System.Drawing;
// This script is based on Keith Lammers' original script.BFS.
// This script will toggle spanning a custom group of horizontally arranged monitors.
// Specify the monitor IDs from left-to-right in the monitorsToSpan array on line 14.
// Each time the script runs, it spans the window across the specified monitors.
public static class DisplayFusionFunction
{
public static void Run(IntPtr windowHandle)
{
// Specify the monitors you want to span here
// Ensure the monitor IDs are entered from left-to-right.
uint[] monitorsToSpan = { 2, 3 };
// Calculate the total size of the spanned window
// Initialize with the first monitor's work area.
Rectangle leftMonitorWorkArea = BFS.Monitor.GetMonitorWorkAreaByID(monitorsToSpan[0]);
int windowWidth = 0; // Total width of all monitors in the span
int windowHeight = leftMonitorWorkArea.Height; // Height will be the smallest height among the monitors
// Iterate through each specified monitor to sum up the widths and find the smallest height
foreach (uint monitorID in monitorsToSpan)
{
Rectangle monitorWorkArea = BFS.Monitor.GetMonitorWorkAreaByID(monitorID);
windowWidth += monitorWorkArea.Width; // Add the monitor's width to the total
if (monitorWorkArea.Height < windowHeight)
{
windowHeight = monitorWorkArea.Height; // Update to the smallest height encountered
}
}
// Determine the top-left corner position of the spanned window
int windowLocationX = leftMonitorWorkArea.X;
int windowLocationY = leftMonitorWorkArea.Y;
// Define the calculated size and position for the spanned window
Rectangle calculatedSize = new Rectangle(windowLocationX, windowLocationY, windowWidth, windowHeight);
// Always span the window to the calculated size
BFS.Window.SetSizeAndLocation(windowHandle, calculatedSize.X, calculatedSize.Y, calculatedSize.Width, calculatedSize.Height);
}
}