GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
Revert "refactor(infra,domain): remove custom `WindowRect` struct; use `Rectangle` from `System.Drawing` instead"
Lars Berger2511d7922483
diff --git a/GlazeWM.Domain/Windows/CommandHandlers/AddWindowHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/AddWindowHandler.csindex 125fc1c4..555a9a2b 100644--- a/GlazeWM.Domain/Windows/CommandHandlers/AddWindowHandler.cs+++ b/GlazeWM.Domain/Windows/CommandHandlers/AddWindowHandler.cs@@ -1,5 +1,4 @@using System.Collections.Generic;-using System.Drawing;using System.Linq;using GlazeWM.Domain.Containers;using GlazeWM.Domain.Containers.Commands;@@ -64,13 +63,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 `Rectangle` struct?- var floatingPlacement = new Rectangle+ // TODO: This can be simplified. Add utility methods to `WindowRect` struct?+ var floatingPlacement = new WindowRect{- X = targetWorkspace.X + (targetWorkspace.Width / 2) - (floatingWidth / 2),- Width = floatingWidth,- Y = targetWorkspace.Y + (targetWorkspace.Height / 2) - (floatingHeight / 2),- Height = floatingHeight,+ 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,};// Create the window instance.diff --git a/GlazeWM.Domain/Windows/FloatingWindow.cs b/GlazeWM.Domain/Windows/FloatingWindow.csindex a9c57b3f..705e1cc0 100644--- a/GlazeWM.Domain/Windows/FloatingWindow.cs+++ b/GlazeWM.Domain/Windows/FloatingWindow.cs@@ -1,5 +1,5 @@using System;-using System.Drawing;+using GlazeWM.Infrastructure.WindowsApi;namespace GlazeWM.Domain.Windows{@@ -13,7 +13,7 @@ namespace GlazeWM.Domain.Windowspublic override int Y => FloatingPlacement.Top;- public FloatingWindow(IntPtr hwnd, Rectangle floatingPlacement) : base(hwnd, floatingPlacement)+ public FloatingWindow(IntPtr hwnd, WindowRect floatingPlacement) : base(hwnd, floatingPlacement){}}diff --git a/GlazeWM.Domain/Windows/FullscreenWindow.cs b/GlazeWM.Domain/Windows/FullscreenWindow.csindex f4c1bd42..487f676c 100644--- a/GlazeWM.Domain/Windows/FullscreenWindow.cs+++ b/GlazeWM.Domain/Windows/FullscreenWindow.cs@@ -1,5 +1,5 @@using System;-using System.Drawing;+using GlazeWM.Infrastructure.WindowsApi;namespace GlazeWM.Domain.Windows{@@ -7,7 +7,7 @@ namespace GlazeWM.Domain.Windows{public FullscreenWindow(IntPtr hwnd,- Rectangle floatingPlacement+ WindowRect floatingPlacement) : base(hwnd, floatingPlacement){}diff --git a/GlazeWM.Domain/Windows/MaximizedWindow.cs b/GlazeWM.Domain/Windows/MaximizedWindow.csindex b3a0ba14..a5cbac6b 100644--- a/GlazeWM.Domain/Windows/MaximizedWindow.cs+++ b/GlazeWM.Domain/Windows/MaximizedWindow.cs@@ -1,5 +1,5 @@using System;-using System.Drawing;+using GlazeWM.Infrastructure.WindowsApi;namespace GlazeWM.Domain.Windows{@@ -7,7 +7,7 @@ namespace GlazeWM.Domain.Windows{public MaximizedWindow(IntPtr hwnd,- Rectangle floatingPlacement+ WindowRect floatingPlacement) : base(hwnd, floatingPlacement){}diff --git a/GlazeWM.Domain/Windows/MinimizedWindow.cs b/GlazeWM.Domain/Windows/MinimizedWindow.csindex d68ab0ac..77fe3df5 100644--- a/GlazeWM.Domain/Windows/MinimizedWindow.cs+++ b/GlazeWM.Domain/Windows/MinimizedWindow.cs@@ -1,5 +1,5 @@using System;-using System.Drawing;+using GlazeWM.Infrastructure.WindowsApi;namespace GlazeWM.Domain.Windows{@@ -9,7 +9,7 @@ namespace GlazeWM.Domain.Windowspublic MinimizedWindow(IntPtr hwnd,- Rectangle floatingPlacement,+ WindowRect floatingPlacement,WindowType previousState) : base(hwnd, floatingPlacement){diff --git a/GlazeWM.Domain/Windows/TilingWindow.cs b/GlazeWM.Domain/Windows/TilingWindow.csindex 9895694c..7739fc75 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, Rectangle floatingPlacement) : base(hwnd, floatingPlacement)+ public TilingWindow(IntPtr hwnd, WindowRect floatingPlacement) : base(hwnd, floatingPlacement){}}diff --git a/GlazeWM.Domain/Windows/Window.cs b/GlazeWM.Domain/Windows/Window.csindex f67aa59f..dd4119c6 100644--- a/GlazeWM.Domain/Windows/Window.cs+++ b/GlazeWM.Domain/Windows/Window.cs@@ -1,5 +1,4 @@using System;-using System.Drawing;using GlazeWM.Domain.Containers;using GlazeWM.Domain.Workspaces;using GlazeWM.Infrastructure;@@ -17,7 +16,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 Rectangle FloatingPlacement { get; set; }+ public WindowRect FloatingPlacement { get; set; }/// <summary>/// Whether adjustments need to be made because of DPI (eg. when moving between monitors).@@ -27,7 +26,7 @@ namespace GlazeWM.Domain.Windowsprivate WindowService _windowService = ServiceLocator.Provider.GetRequiredService<WindowService>();private WorkspaceService _workspaceService = ServiceLocator.Provider.GetRequiredService<WorkspaceService>();- public Window(IntPtr hwnd, Rectangle floatingPlacement)+ public Window(IntPtr hwnd, WindowRect floatingPlacement){Hwnd = hwnd;FloatingPlacement = floatingPlacement;@@ -42,7 +41,7 @@ namespace GlazeWM.Domain.Windowspublic string ClassName => _windowService.GetClassNameOfHandle(Hwnd);- public Rectangle Location => _windowService.GetLocationOfHandle(Hwnd);+ public WindowRect Location => _windowService.GetLocationOfHandle(Hwnd);public string Title => _windowService.GetTitleOfHandle(Hwnd);diff --git a/GlazeWM.Domain/Windows/WindowService.cs b/GlazeWM.Domain/Windows/WindowService.csindex 2e70a618..b164e09b 100644--- a/GlazeWM.Domain/Windows/WindowService.cs+++ b/GlazeWM.Domain/Windows/WindowService.cs@@ -1,7 +1,6 @@using System;using System.Collections.Generic;using System.Diagnostics;-using System.Drawing;using System.Linq;using System.Runtime.InteropServices;using System.Text;@@ -52,9 +51,9 @@ namespace GlazeWM.Domain.Windows/// <summary>/// Get dimensions of the bounding rectangle of the specified window./// </summary>- public Rectangle GetLocationOfHandle(IntPtr handle)+ public WindowRect GetLocationOfHandle(IntPtr handle){- var rect = new Rectangle();+ var rect = new WindowRect();GetWindowRect(handle, ref rect);return rect;}diff --git a/GlazeWM.Domain/Workspaces/CommandHandlers/MoveFocusedWindowToWorkspaceHandler.cs b/GlazeWM.Domain/Workspaces/CommandHandlers/MoveFocusedWindowToWorkspaceHandler.csindex 6fee558c..7d697cbd 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 System.Drawing;+using GlazeWM.Infrastructure.WindowsApi;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 Rectangle+ var updatedPlacement = new WindowRect{- 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,+ 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,};focusedWindow.FloatingPlacement = updatedPlacement;diff --git a/GlazeWM.Infrastructure/WindowsApi/WindowRect.cs b/GlazeWM.Infrastructure/WindowsApi/WindowRect.csnew file mode 100644index 00000000..e1c82ddc--- /dev/null+++ b/GlazeWM.Infrastructure/WindowsApi/WindowRect.cs@@ -0,0 +1,25 @@+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 0cb105df..6dc1ac74 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 Rectangle rectangle);+ public static extern bool GetWindowRect(IntPtr hwnd, ref WindowRect 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 Rectangle NormalPosition;+ public WindowRect 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 Rectangle lpRect, WS dwStyle, [MarshalAs(UnmanagedType.Bool)] bool bMenu, WS_EX dwExStyle);+ public static extern bool AdjustWindowRectEx(ref WindowRect lpRect, WS dwStyle, [MarshalAs(UnmanagedType.Bool)] bool bMenu, WS_EX dwExStyle);[DllImport("user32.dll", SetLastError = true)]- public static extern bool AdjustWindowRect(ref Rectangle lpRect, WS dwStyle, [MarshalAs(UnmanagedType.Bool)] bool bMenu);+ public static extern bool AdjustWindowRect(ref WindowRect lpRect, WS dwStyle, [MarshalAs(UnmanagedType.Bool)] bool bMenu);[DllImport("user32.dll", SetLastError = true)]- public static extern bool AdjustWindowRectExForDpi(ref Rectangle lpRect, WS dwStyle, [MarshalAs(UnmanagedType.Bool)] bool bMenu, WS_EX dwExStyle, uint dpi);+ public static extern bool AdjustWindowRectExForDpi(ref WindowRect lpRect, WS dwStyle, [MarshalAs(UnmanagedType.Bool)] bool bMenu, WS_EX dwExStyle, uint dpi);public enum DpiType{