using System; using System.Collections.Generic; using System.Drawing; // The 'windowHandle' parameter will contain the window handle for the: // - Active window when run by hotkey // - Window Location target when run by a Window Location 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 windowHandle) { //get the work area of the current monitor Rectangle monitorBounds = BFS.Monitor.GetMonitorWorkAreaByWindow(windowHandle); //set up the window position array //the order is top-left, bottom-left, top-right, bottom-right Rectangle[] windowPositions = { new Rectangle(monitorBounds.X, monitorBounds.Y, monitorBounds.Width / 2, monitorBounds.Height / 2), new Rectangle(monitorBounds.X, monitorBounds.Y + monitorBounds.Height / 2, monitorBounds.Width / 2, monitorBounds.Height / 2), new Rectangle(monitorBounds.X + monitorBounds.Width / 2, monitorBounds.Y, monitorBounds.Width / 2, monitorBounds.Height / 2), new Rectangle(monitorBounds.X + monitorBounds.Width / 2, monitorBounds.Y + monitorBounds.Height / 2, monitorBounds.Width / 2, monitorBounds.Height / 2), }; //get a list of all the visible windows, but only include windows that we want to tile List windows = new List(); foreach(IntPtr window in BFS.Window.GetVisibleWindowHandlesByMonitor(BFS.Monitor.GetMonitorIDByWindow(windowHandle))) { //ignore any DisplayFusion windows (title bar buttons, etc.) //ignore pesky hidden explorer.exe windows if((BFS.Window.GetClass(window).StartsWith("DF", StringComparison.OrdinalIgnoreCase)) || (BFS.Window.GetClass(window).Equals("EdgeUiInputTopWndClass", StringComparison.OrdinalIgnoreCase)) || (BFS.Window.GetClass(window).Equals("Shell_TrayWnd", StringComparison.OrdinalIgnoreCase)) || (BFS.Window.GetClass(window).Equals("WorkerW", StringComparison.OrdinalIgnoreCase)) || (BFS.Window.GetClass(window).Equals("Progman", StringComparison.OrdinalIgnoreCase)) || (BFS.Window.GetClass(window).Equals("SearchPane", StringComparison.OrdinalIgnoreCase))) { continue; } //add the window to the list windows.Add(window); } //loop through the list of windows for(int i = 0; i < windows.Count; i++) { //check to see if this is the last window in the list bool isLastWindow = (i == windows.Count - 1); //get the index of windowPositions we should use int index = i % windowPositions.Length; //if it's the last window in the list and we're on the top-left position, put the window on the left side of the monitor if((isLastWindow) && (index == 0)) BFS.Window.MoveToLeftMonitorHalf(windows[i]); //if it's the last window in the list and we're on the top-right position, put the window on the right side of the monitor else if((isLastWindow) && (index == 2)) BFS.Window.MoveToRightMonitorHalf(windows[i]); //position the window according to the windowPositions array else BFS.Window.SetSizeAndLocation(windows[i], windowPositions[index].X, windowPositions[index].Y, windowPositions[index].Width, windowPositions[index].Height); } } }