Processing Ajax...

Title

Message

Confirm

Confirm

Confirm

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure?

Toggle Maximize (Ignore Splits) and Restore

Description
This script will toggle a window between maximized (ignoring splits) and its previous size/location.
Language
C#.net
Minimum Version
Created By
Ronaldo A.
Contributors
-
Date Created
5d ago
Date Last Modified
5d ago

Scripted Function (Macro) Code

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);
    }
}