{ "name": "Toggle Window to Center of Monitor (ignore splits)", "language": 0, "code": "using System;\r\nusing System.Drawing;\r\nusing System.Runtime.InteropServices;\r\nusing System.Windows.Forms;\r\n\r\n// The 'windowHandle' parameter will contain the window handle for the:\r\n// - Active window when run by hotkey\r\n// - Trigger target when run by a Trigger rule\r\n// - TitleBar Button owner when run by a TitleBar Button\r\n// - Jump List owner when run from a Taskbar Jump List\r\n// - Currently focused window if none of these match\r\npublic static class DisplayFusionFunction\r\n{\r\n\tpublic static void Run(IntPtr windowHandle)\r\n\t{\r\n\t\t/////////////////////////////////////////////////////////////////////////////////////////////\r\n\t\t// Monitor index from left to right. -1 = primary, 0 = leftmost, 1 = one to the right, etc //\r\n\t\t/////////////////////////////////////////////////////////////////////////////////////////////\r\n int targetMonitor = -1; \r\n\t\t\r\n\t\t/////////////////////////////////////////////////////////////////////////////////////////////////\r\n\t\t// The target width of the window when it moves to the center of the target. 0 = keep the same //\r\n\t\t/////////////////////////////////////////////////////////////////////////////////////////////////\r\n int targetWidth = 0;\r\n \t\t\r\n\t\t// A constant value to easily refer to the property we're saving\r\n const string PropertyName = \"CenterScript_OriginalBounds\";\t\t\r\n\t\t\r\n\t\t// Try and get the window property\r\n\t\tIntPtr raw = BFS.Window.GetWindowProperty(windowHandle, PropertyName);\r\n\t\t\r\n\t\t// If it's IntPtr.Zero, there isn't one. Save the window position and move the window to the center of the screen\r\n\t\tif(raw == IntPtr.Zero)\r\n\t\t{\r\n // Get and save original window location\r\n raw = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Rectangle)));\r\n Rectangle bounds = BFS.Window.GetBounds(windowHandle);\r\n Marshal.StructureToPtr(bounds, raw, false);\r\n BFS.Window.SetWindowProperty(windowHandle, PropertyName, raw);\r\n \r\n // If we're changing the width, do it now\r\n if(targetWidth != 0)\r\n {\r\n BFS.Window.SetSize(windowHandle, targetWidth, bounds.Height);\r\n bounds = BFS.Window.GetBounds(windowHandle);\r\n }\r\n \r\n // Get the bounds of our target monitor\r\n Rectangle monitorBounds = (targetMonitor == -1) ? Screen.PrimaryScreen.Bounds : BFS.Monitor.GetMonitorBoundsNoSplits()[targetMonitor];\r\n\t\t\t\r\n\t\t\t// Move the window\r\n BFS.Window.SetLocation(\r\n windowHandle,\r\n monitorBounds.X + monitorBounds.Width / 2 - bounds.Width / 2,\r\n monitorBounds.Y + monitorBounds.Height / 2 - bounds.Height / 2);\r\n\t\t}\r\n\t\telse // Otherwise, move the window back and clear the property\r\n\t\t{\r\n // Get the saved rectangle\r\n Rectangle bounds = Marshal.PtrToStructure(raw);\r\n BFS.Window.SetSizeAndLocation(windowHandle, bounds.X, bounds.Y, bounds.Width, bounds.Height);\r\n \r\n // Clean up\r\n BFS.Window.RemoveWindowProperty(windowHandle, PropertyName);\r\n Marshal.FreeHGlobal(raw);\r\n\t\t}\r\n\t}\r\n}", "description": "", "references": "System.Core.dll|System.Data.dll|System.dll|System.Drawing.dll|System.Management.dll|System.Web.dll|System.Windows.Forms.dll|System.Xml.dll" }