using System; using System.Drawing; using System.Collections.Generic; // 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 monitor of the window where the script was run uint monitor = BFS.Monitor.GetMonitorIDByWindow(windowHandle); //store the windows to be moved here List windows = new List(); //a fix for chrome windows Dictionary chromeWindowTitlesAdded = new Dictionary(); //loop through all visible windows on the monitor foreach(IntPtr window in BFS.Window.GetVisibleWindowHandlesByMonitor(monitor)) { //ignore DisplayFusion windows (titlebar buttons, etc) if(BFS.Window.GetClass(window).IndexOf("DF", StringComparison.Ordinal) == 0) continue; //check to see if this is a chrome window if(BFS.Application.GetMainFileByWindow(window).EndsWith("chrome.exe", StringComparison.OrdinalIgnoreCase)) { //if the chrome windows have the same window text, it is just a tab string text = BFS.Window.GetText(window); if(chromeWindowTitlesAdded.ContainsKey(text)) continue; else chromeWindowTitlesAdded.Add(text, 0); } //add the window to the list to be moved windows.Add(window); //if we found 4 windows, exit the loop if(windows.Count == 4) break; } //get the work area of the monitor Rectangle bounds = BFS.Monitor.GetMonitorWorkAreaByID(monitor); //position the windows with full height and quarter width, stacked next to each other int quarter = bounds.Width / 4; for(int i = 0; i < windows.Count; i++) BFS.Window.SetSizeAndLocation(windows[i], bounds.X + (quarter * i), bounds.Y, quarter, bounds.Height); } }