using System;
using System.Drawing;
// 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
{
private const int SnapDistance = 10;
public static void Run(IntPtr windowHandle)
{
var windowBounds = BFS.Window.GetBounds(windowHandle);
var monitorBounds = BFS.Monitor.GetMonitorWorkAreaByWindow(windowHandle);
var left = SnapTo(windowBounds.Left, monitorBounds.Left);
var right = SnapTo(windowBounds.Right, monitorBounds.Right);
var top = SnapTo(windowBounds.Top, monitorBounds.Top);
var bottom = SnapTo(windowBounds.Bottom, monitorBounds.Bottom);
BFS.Window.SetSizeAndLocation(windowHandle, left, top, right - left, bottom - top);
}
private static int SnapTo(int value, int snapTo)
{
return (Math.Abs(snapTo - value) < SnapDistance) ? snapTo : value;
}
}