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
{
public static void Run(IntPtr w)
{
if (w == 0) return;
var isMaximized = BFS.Window.IsMaximized(w);
var wasMaximizedBefore = BFS.Window.GetWindowProperty(w, "wasMaximizedBefore") == 1;
if (isMaximized)
{
if (isSuperMaximized(w))
{
BFS.Window.Restore(w);
if (wasMaximizedBefore) BFS.Window.Maximize(w);
} else
{
superMaximize(w);
}
} else
{
superMaximize(w);
}
BFS.Window.SetWindowProperty(w, "wasMaximizedBefore", isMaximized ? 1 : 0);
}
public static bool isSuperMaximized(IntPtr w)
{
var wSize = BFS.Window.GetBounds(w);
Rectangle mSize = BFS.Monitor.GetScreens()[0].WorkArea;
return wSize.Width == mSize.Width && wSize.Height == mSize.Height;
}
public static void superMaximize(IntPtr w)
{
BFS.DisplayFusion.RunFunctionWithWindowHandle("Maximize Window (ignore monitor splits)", w);
}
}