using System;
using System.Drawing;
public static class DisplayFusionFunction
{
public static void Run(IntPtr windowHandle)
{
if (windowHandle == IntPtr.Zero)
return;
// Get current window bounds and its centre point
Rectangle win = BFS.Window.GetBounds(windowHandle);
int centerX = win.X + (win.Width / 2);
int centerY = win.Y + (win.Height / 2);
// Get the bounds of all *physical* monitors (ignores splits)
Rectangle[] physicalMons = BFS.Monitor.GetMonitorBoundsNoSplits();
Rectangle monitorRect = Rectangle.Empty;
// Find which physical monitor the window centre is on
foreach (Rectangle m in physicalMons)
{
if (centerX >= m.X && centerX < m.Right &&
centerY >= m.Y && centerY < m.Bottom)
{
monitorRect = m;
break;
}
}
if (monitorRect == Rectangle.Empty)
return;
// Divide that physical monitor into 3 equal vertical thirds
int thirdWidth = monitorRect.Width / 3;
if (thirdWidth <= 0)
return;
// Position of window centre relative to that monitor
int relX = centerX - monitorRect.X;
Rectangle targetRect;
if (relX < thirdWidth)
{
// Window is in LEFT third -> span LEFT + MIDDLE (splits 1 + 2)
targetRect = new Rectangle(
monitorRect.X,
monitorRect.Y,
thirdWidth * 2,
monitorRect.Height
);
}
else
{
// Window is in MIDDLE or RIGHT third -> span MIDDLE + RIGHT (splits 2 + 3)
targetRect = new Rectangle(
monitorRect.X + thirdWidth,
monitorRect.Y,
thirdWidth * 2,
monitorRect.Height
);
}
// Resize/move the window to fill exactly 2/3 of the physical monitor
BFS.Window.SetSizeAndLocation(
windowHandle,
targetRect.X,
targetRect.Y,
targetRect.Width,
targetRect.Height
);
}
}