Skip to content

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

feat(domain): add `MonitorService` method for getting the DPI of a monitor

Lars Bergera8a2c340e92b
diff --git a/LarsWM.Domain/Monitors/MonitorService.cs b/LarsWM.Domain/Monitors/MonitorService.cs
index bed319e8..9da9560d 100644
--- a/LarsWM.Domain/Monitors/MonitorService.cs
+++ b/LarsWM.Domain/Monitors/MonitorService.cs
@@ -4,6 +4,7 @@ using System.Windows.Forms;
using LarsWM.Domain.Common.Enums;
using LarsWM.Domain.Containers;
using LarsWM.Domain.Windows;
+using static LarsWM.Infrastructure.WindowsApi.WindowsApiService;
namespace LarsWM.Domain.Monitors
{
@@ -50,6 +51,18 @@ namespace LarsWM.Domain.Monitors
return GetMonitorFromChildContainer(focusedContainer);
}
+ public uint GetMonitorDpi(Screen screen)
+ {
+ // Get a handle to the monitor from a `Screen`.
+ var point = new System.Drawing.Point(screen.Bounds.Left + 1, screen.Bounds.Top + 1);
+ var monitorHandle = MonitorFromPoint(point, MonitorFromPointFlags.MONITOR_DEFAULTTONEAREST);
+
+ uint dpiX, dpiY;
+ GetDpiForMonitor(monitorHandle, DpiType.Effective, out dpiX, out dpiY);
+
+ return dpiX;
+ }
+
/// <summary>
/// Get monitor in a given direction. Use i3wm's algorithm for finding best guess.
/// </summary>