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 // - 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 windowHandle) { //get the monitor that the mouse is on uint monitorId = BFS.Monitor.GetMonitorIDByXY(BFS.Input.GetMousePositionX(), BFS.Input.GetMousePositionY()); //this list will hold all of the chrome windows that we find List chromeWindows = new List(); //loop through all windows foreach(IntPtr window in BFS.Window.GetAllWindowHandles()) { //if the window isn't on the monitor we want, ignore it if(BFS.Monitor.GetMonitorIDByWindow(window) != monitorId) continue; //if the window isn't owned by chrome, ignore it if(BFS.Application.GetMainFileByWindow(window).IndexOf("chrome.exe", StringComparison.OrdinalIgnoreCase) == -1) continue; //if the window doesn't have a title, ignore it if(string.IsNullOrEmpty(BFS.Window.GetText(window))) continue; //add the window to our list chromeWindows.Add(window); } //if we only found one window, maximize and exit the script if(chromeWindows.Count == 1) { BFS.Window.Maximize(chromeWindows[0]); return; } //loop through all of the windows we found, restore them, and size them accordingly for(int i = 0; i < chromeWindows.Count; i++) { BFS.Window.Restore(chromeWindows[i]); Rectangle workArea = BFS.Monitor.GetMonitorWorkAreaByID(monitorId); BFS.Window.SetSizeAndLocation(chromeWindows[i], workArea.Width / chromeWindows.Count * i, workArea.Y, workArea.Width / chromeWindows.Count, workArea.Height); } } }