GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
refactor(infra,domain): remove custom `WindowRect` struct; use `Rectangle` from `System.Drawing` instead
Lars Bergerfc2171880258
diff --git a/GlazeWM.Domain/Windows/CommandHandlers/AddWindowHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/AddWindowHandler.csindex 555a9a2b..125fc1c4 100644--- a/GlazeWM.Domain/Windows/CommandHandlers/AddWindowHandler.cs+++ b/GlazeWM.Domain/Windows/CommandHandlers/AddWindowHandler.cs@@ -1,4 +1,5 @@using System.Collections.Generic;+using System.Drawing;using System.Linq;using GlazeWM.Domain.Containers;using GlazeWM.Domain.Containers.Commands;@@ -63,13 +64,13 @@ namespace GlazeWM.Domain.Windows.CommandHandlers// Calculate where window should be placed when floating is enabled. Use the original// width/height of the window, but position it in the center of the workspace.- // TODO: This can be simplified. Add utility methods to `WindowRect` struct?- var floatingPlacement = new WindowRect+ // TODO: This can be simplified. Add utility methods to `Rectangle` struct?+ var floatingPlacement = new Rectangle{- Left = targetWorkspace.X + (targetWorkspace.Width / 2) - (floatingWidth / 2),- Right = targetWorkspace.X + (targetWorkspace.Width / 2) - (floatingWidth / 2) + floatingWidth,- Top = targetWorkspace.Y + (targetWorkspace.Height / 2) - (floatingHeight / 2),- Bottom = targetWorkspace.Y + (targetWorkspace.Height / 2) - (floatingHeight / 2) + floatingHeight,+ X = targetWorkspace.X + (targetWorkspace.Width / 2) - (floatingWidth / 2),+ Width = floatingWidth,+ Y = targetWorkspace.Y + (targetWorkspace.Height / 2) - (floatingHeight / 2),+ Height = floatingHeight,};// Create the window instance.diff --git a/GlazeWM.Domain/Windows/FloatingWindow.cs b/GlazeWM.Domain/Windows/FloatingWindow.csindex 705e1cc0..a9c57b3f 100644--- a/GlazeWM.Domain/Windows/FloatingWindow.cs+++ b/GlazeWM.Domain/Windows/FloatingWindow.cs@@ -1,5 +1,5 @@using System;-using GlazeWM.Infrastructure.WindowsApi;+using System.Drawing;namespace GlazeWM.Domain.Windows{@@ -13,7 +13,7 @@ namespace GlazeWM.Domain.Windowspublic override int Y => FloatingPlacement.Top;- public FloatingWindow(IntPtr hwnd, WindowRect floatingPlacement) : base(hwnd, floatingPlacement)+ public FloatingWindow(IntPtr hwnd, Rectangle floatingPlacement) : base(hwnd, floatingPlacement){}}diff --git a/GlazeWM.Domain/Windows/FullscreenWindow.cs b/GlazeWM.Domain/Windows/FullscreenWindow.csindex 487f676c..f4c1bd42 100644--- a/GlazeWM.Domain/Windows/FullscreenWindow.cs+++ b/GlazeWM.Domain/Windows/FullscreenWindow.cs@@ -1,5 +1,5 @@using System;-using GlazeWM.Infrastructure.WindowsApi;+using System.Drawing;namespace GlazeWM.Domain.Windows{@@ -7,7 +7,7 @@ namespace GlazeWM.Domain.Windows{public FullscreenWindow(IntPtr hwnd,- WindowRect floatingPlacement+ Rectangle floatingPlacement) : base(hwnd, floatingPlacement){}diff --git a/GlazeWM.Domain/Windows/MaximizedWindow.cs b/GlazeWM.Domain/Windows/MaximizedWindow.csindex a5cbac6b..b3a0ba14 100644--- a/GlazeWM.Domain/Windows/MaximizedWindow.cs+++ b/GlazeWM.Domain/Windows/MaximizedWindow.cs@@ -1,5 +1,5 @@using System;-using GlazeWM.Infrastructure.WindowsApi;+using System.Drawing;namespace GlazeWM.Domain.Windows{@@ -7,7 +7,7 @@ namespace GlazeWM.Domain.Windows{public MaximizedWindow(IntPtr hwnd,- WindowRect floatingPlacement+ Rectangle floatingPlacement) : base(hwnd, floatingPlacement){}diff --git a/GlazeWM.Domain/Windows/MinimizedWindow.cs b/GlazeWM.Domain/Windows/MinimizedWindow.csindex 77fe3df5..d68ab0ac 100644--- a/GlazeWM.Domain/Windows/MinimizedWindow.cs+++ b/GlazeWM.Domain/Windows/MinimizedWindow.cs@@ -1,5 +1,5 @@using System;-using GlazeWM.Infrastructure.WindowsApi;+using System.Drawing;namespace GlazeWM.Domain.Windows{@@ -9,7 +9,7 @@ namespace GlazeWM.Domain.Windowspublic MinimizedWindow(IntPtr hwnd,- WindowRect floatingPlacement,+ Rectangle floatingPlacement,WindowType previousState) : base(hwnd, floatingPlacement){diff --git a/GlazeWM.Domain/Windows/TilingWindow.cs b/GlazeWM.Domain/Windows/TilingWindow.csindex 7739fc75..9895694c 100644--- a/GlazeWM.Domain/Windows/TilingWindow.cs+++ b/GlazeWM.Domain/Windows/TilingWindow.cs@@ -1,7 +1,7 @@using System;+using System.Drawing;using GlazeWM.Domain.Containers;using GlazeWM.Infrastructure;-using GlazeWM.Infrastructure.WindowsApi;using Microsoft.Extensions.DependencyInjection;namespace GlazeWM.Domain.Windows@@ -21,7 +21,7 @@ namespace GlazeWM.Domain.Windowspublic override int Y => _containerService.CalculateYOfResizableContainer(this);- public TilingWindow(IntPtr hwnd, WindowRect floatingPlacement) : base(hwnd, floatingPlacement)+ public TilingWindow(IntPtr hwnd, Rectangle floatingPlacement) : base(hwnd, floatingPlacement){}}diff --git a/GlazeWM.Domain/Windows/Window.cs b/GlazeWM.Domain/Windows/Window.csindex dd4119c6..f67aa59f 100644--- a/GlazeWM.Domain/Windows/Window.cs+++ b/GlazeWM.Domain/Windows/Window.cs@@ -1,4 +1,5 @@using System;+using System.Drawing;using GlazeWM.Domain.Containers;using GlazeWM.Domain.Workspaces;using GlazeWM.Infrastructure;@@ -16,7 +17,7 @@ namespace GlazeWM.Domain.Windows/// The placement of the window when floating. Initialized with window's placement on launch/// and updated on resize/move whilst floating./// </summary>- public WindowRect FloatingPlacement { get; set; }+ public Rectangle FloatingPlacement { get; set; }/// <summary>/// Whether adjustments need to be made because of DPI (eg. when moving between monitors).@@ -26,7 +27,7 @@ namespace GlazeWM.Domain.Windowsprivate WindowService _windowService = ServiceLocator.Provider.GetRequiredService<WindowService>();private WorkspaceService _workspaceService = ServiceLocator.Provider.GetRequiredService<WorkspaceService>();- public Window(IntPtr hwnd, WindowRect floatingPlacement)+ public Window(IntPtr hwnd, Rectangle floatingPlacement){Hwnd = hwnd;FloatingPlacement = floatingPlacement;@@ -41,7 +42,7 @@ namespace GlazeWM.Domain.Windowspublic string ClassName => _windowService.GetClassNameOfHandle(Hwnd);- public WindowRect Location => _windowService.GetLocationOfHandle(Hwnd);+ public Rectangle Location => _windowService.GetLocationOfHandle(Hwnd);public string Title => _windowService.GetTitleOfHandle(Hwnd);diff --git a/GlazeWM.Domain/Windows/WindowService.cs b/GlazeWM.Domain/Windows/WindowService.csindex b164e09b..2e70a618 100644--- a/GlazeWM.Domain/Windows/WindowService.cs+++ b/GlazeWM.Domain/Windows/WindowService.cs@@ -1,6 +1,7 @@using System;using System.Collections.Generic;using System.Diagnostics;+using System.Drawing;using System.Linq;using System.Runtime.InteropServices;using System.Text;@@ -51,9 +52,9 @@ namespace GlazeWM.Domain.Windows/// <summary>/// Get dimensions of the bounding rectangle of the specified window./// </summary>- public WindowRect GetLocationOfHandle(IntPtr handle)+ public Rectangle GetLocationOfHandle(IntPtr handle){- var rect = new WindowRect();+ var rect = new Rectangle();GetWindowRect(handle, ref rect);return rect;}diff --git a/GlazeWM.Domain/Workspaces/CommandHandlers/MoveFocusedWindowToWorkspaceHandler.cs b/GlazeWM.Domain/Workspaces/CommandHandlers/MoveFocusedWindowToWorkspaceHandler.csindex 7d697cbd..6fee558c 100644--- a/GlazeWM.Domain/Workspaces/CommandHandlers/MoveFocusedWindowToWorkspaceHandler.cs+++ b/GlazeWM.Domain/Workspaces/CommandHandlers/MoveFocusedWindowToWorkspaceHandler.cs@@ -4,7 +4,7 @@ using GlazeWM.Domain.Containers;using GlazeWM.Domain.Windows;using GlazeWM.Domain.Monitors;using GlazeWM.Domain.Containers.Commands;-using GlazeWM.Infrastructure.WindowsApi;+using System.Drawing;namespace GlazeWM.Domain.Workspaces.CommandHandlers{@@ -76,12 +76,12 @@ namespace GlazeWM.Domain.Workspaces.CommandHandlersvar relativeY = focusedWindow.Y - currentWorkspace.Y + (focusedWindow.Height / 2);// TODO: Clean this up.- var updatedPlacement = new WindowRect+ var updatedPlacement = new Rectangle{- Left = targetWorkspace.X + (relativeX * targetWorkspace.Width / currentWorkspace.Width - (focusedWindow.Width / 2)),- Right = targetWorkspace.X + (relativeX * targetWorkspace.Width / currentWorkspace.Width - (focusedWindow.Width / 2)) + focusedWindow.Width,- Top = targetWorkspace.Y + (relativeY * targetWorkspace.Height / currentWorkspace.Height - (focusedWindow.Height / 2)),- Bottom = targetWorkspace.Y + (relativeY * targetWorkspace.Height / currentWorkspace.Height - (focusedWindow.Height / 2)) + focusedWindow.Height,+ X = targetWorkspace.X + (relativeX * targetWorkspace.Width / currentWorkspace.Width - (focusedWindow.Width / 2)),+ Width = focusedWindow.Width,+ Y = targetWorkspace.Y + (relativeY * targetWorkspace.Height / currentWorkspace.Height - (focusedWindow.Height / 2)),+ Height = focusedWindow.Height,};focusedWindow.FloatingPlacement = updatedPlacement;diff --git a/GlazeWM.Infrastructure/WindowsApi/WindowRect.cs b/GlazeWM.Infrastructure/WindowsApi/WindowRect.csdeleted file mode 100644index e1c82ddc..00000000--- a/GlazeWM.Infrastructure/WindowsApi/WindowRect.cs+++ /dev/null@@ -1,25 +0,0 @@-namespace GlazeWM.Infrastructure.WindowsApi-{- public struct WindowRect- {- /// <summary>- /// The x-coordinate of the upper-left corner of the rectangle.- /// </summary>- public int Left { get; set; }-- /// <summary>- /// The y-coordinate of the upper-left corner of the rectangle.- /// </summary>- public int Top { get; set; }-- /// <summary>- /// The x-coordinate of the lower-right corner of the rectangle.- /// </summary>- public int Right { get; set; }-- /// <summary>- /// The y-coordinate of the lower-right corner of the rectangle.- /// </summary>- public int Bottom { get; set; }- }-}diff --git a/GlazeWM.Infrastructure/WindowsApi/WindowsApiService.cs b/GlazeWM.Infrastructure/WindowsApi/WindowsApiService.csindex 6dc1ac74..0cb105df 100644--- a/GlazeWM.Infrastructure/WindowsApi/WindowsApiService.cs+++ b/GlazeWM.Infrastructure/WindowsApi/WindowsApiService.cs@@ -1,4 +1,4 @@-using GlazeWM.Infrastructure.WindowsApi.Enums;+using GlazeWM.Infrastructure.WindowsApi.Enums;using System;using System.Drawing;using System.Runtime.InteropServices;@@ -206,7 +206,7 @@ namespace GlazeWM.Infrastructure.WindowsApipublic static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);[DllImport("user32.dll")]- public static extern bool GetWindowRect(IntPtr hwnd, ref WindowRect rectangle);+ public static extern bool GetWindowRect(IntPtr hwnd, ref Rectangle rectangle);/// <summary>/// Contains information about the placement of a window on the screen.@@ -242,7 +242,7 @@ namespace GlazeWM.Infrastructure.WindowsApi/// <summary>/// The window's coordinates when the window is in the restored position./// </summary>- public WindowRect NormalPosition;+ public Rectangle NormalPosition;}[DllImport("user32.dll", SetLastError = true)]@@ -358,13 +358,13 @@ namespace GlazeWM.Infrastructure.WindowsApipublic static extern uint GetDpiForWindow(IntPtr hWnd);[DllImport("user32.dll", SetLastError = true)]- public static extern bool AdjustWindowRectEx(ref WindowRect lpRect, WS dwStyle, [MarshalAs(UnmanagedType.Bool)] bool bMenu, WS_EX dwExStyle);+ public static extern bool AdjustWindowRectEx(ref Rectangle lpRect, WS dwStyle, [MarshalAs(UnmanagedType.Bool)] bool bMenu, WS_EX dwExStyle);[DllImport("user32.dll", SetLastError = true)]- public static extern bool AdjustWindowRect(ref WindowRect lpRect, WS dwStyle, [MarshalAs(UnmanagedType.Bool)] bool bMenu);+ public static extern bool AdjustWindowRect(ref Rectangle lpRect, WS dwStyle, [MarshalAs(UnmanagedType.Bool)] bool bMenu);[DllImport("user32.dll", SetLastError = true)]- public static extern bool AdjustWindowRectExForDpi(ref WindowRect lpRect, WS dwStyle, [MarshalAs(UnmanagedType.Bool)] bool bMenu, WS_EX dwExStyle, uint dpi);+ public static extern bool AdjustWindowRectExForDpi(ref Rectangle lpRect, WS dwStyle, [MarshalAs(UnmanagedType.Bool)] bool bMenu, WS_EX dwExStyle, uint dpi);public enum DpiType{