Skip to content

GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.

feat(infra): add `WindowRect` method for translating to center of another `WindowRect`

Lars Berger7521816ff691
diff --git a/GlazeWM.Infrastructure/WindowsApi/WindowRect.cs b/GlazeWM.Infrastructure/WindowsApi/WindowRect.cs
index e1c82ddc..4db357fa 100644
--- a/GlazeWM.Infrastructure/WindowsApi/WindowRect.cs
+++ b/GlazeWM.Infrastructure/WindowsApi/WindowRect.cs
@@ -21,5 +21,26 @@
/// The y-coordinate of the lower-right corner of the rectangle.
/// </summary>
public int Bottom { get; set; }
+
+ public int X => Left;
+
+ public int Y => Top;
+
+ public int Width => Right - Left;
+
+ public int Height => Bottom - Top;
+
+ public static WindowRect TranslateToCenter(WindowRect rect, WindowRect outerRect)
+ {
+ var translatedRect = new WindowRect();
+
+ translatedRect.Left = outerRect.X + (outerRect.Width / 2) - (rect.Width / 2);
+ translatedRect.Right = translatedRect.Left + rect.Width;
+
+ translatedRect.Top = outerRect.Y + (outerRect.Height / 2) - (rect.Height / 2);
+ translatedRect.Bottom = translatedRect.Top + rect.Height;
+
+ return translatedRect;
+ }
}
}