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?

Span Two of Three Splits

Description
This script will span the target window across two of three splits. It will select the left two splits or the right two splits depending on where the window is located when the script is called.
Language
C#.net
Minimum Version
Created By
Dave's Display Fusion
Contributors
-
Date Created
3d ago
Date Last Modified
3d ago

Scripted Function (Macro) Code

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