GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat(domain): add `Monitor` properties to ctor; remove getters with `Screen` instance
Lars Berger823f46833d61
diff --git a/GlazeWM.Domain/Monitors/CommandHandlers/AddMonitorHandler.cs b/GlazeWM.Domain/Monitors/CommandHandlers/AddMonitorHandler.csindex ec5fab94..a6786bf3 100644--- a/GlazeWM.Domain/Monitors/CommandHandlers/AddMonitorHandler.cs+++ b/GlazeWM.Domain/Monitors/CommandHandlers/AddMonitorHandler.cs@@ -24,9 +24,20 @@ namespace GlazeWM.Domain.Monitors.CommandHandlerspublic CommandResponse Handle(AddMonitorCommand command){- var newMonitor = new Monitor(command.Screen);- var rootContainer = _containerService.ContainerTree;+ var screen = command.Screen;++ // Create a `Monitor` instance. Use the working area of the monitor instead of the bounds of+ // the display. The working area excludes taskbars and other reserved display space.+ var newMonitor = new Monitor(+ screen.DeviceName,+ screen.WorkingArea.Width,+ screen.WorkingArea.Height,+ screen.WorkingArea.X,+ screen.WorkingArea.Y,+ screen.Primary+ );+ var rootContainer = _containerService.ContainerTree;_bus.Invoke(new AttachContainerCommand(newMonitor, rootContainer));ActivateWorkspaceOnMonitor(newMonitor);diff --git a/GlazeWM.Domain/Monitors/Monitor.cs b/GlazeWM.Domain/Monitors/Monitor.csindex 726f8167..ee986b50 100644--- a/GlazeWM.Domain/Monitors/Monitor.cs+++ b/GlazeWM.Domain/Monitors/Monitor.cs@@ -2,31 +2,39 @@using GlazeWM.Domain.Workspaces;using GlazeWM.Infrastructure;using Microsoft.Extensions.DependencyInjection;-using System.Windows.Forms;namespace GlazeWM.Domain.Monitors{public class Monitor : Container{- public string Name => Screen.DeviceName;- public override int Width => Screen.WorkingArea.Width;- public override int Height => Screen.WorkingArea.Height;- public override int X => Screen.WorkingArea.X;- public override int Y => Screen.WorkingArea.Y;- public bool IsPrimary => Screen.Primary;- public Workspace DisplayedWorkspace;-- public Screen Screen { get; }-- private MonitorService _monitorService = ServiceLocator.Provider.GetRequiredService<MonitorService>();-- public uint Dpi => _monitorService.GetMonitorDpi(Screen);+ public string DeviceName { get; set; }+ public override int Width { get; set; }+ public override int Height { get; set; }+ public override int X { get; set; }+ public override int Y { get; set; }+ public bool IsPrimary { get; set; }+ public Workspace DisplayedWorkspace { get; set; }+ private MonitorService _monitorService =+ ServiceLocator.Provider.GetRequiredService<MonitorService>();+ public uint Dpi => _monitorService.GetMonitorDpi(this);public decimal ScaleFactor => decimal.Divide(Dpi, 96);- public Monitor(Screen screen)+ public Monitor(+ string deviceName,+ int width,+ int height,+ int x,+ int y,+ bool isPrimary+ ){- Screen = screen;+ DeviceName = deviceName;+ Width = width;+ Height = height;+ X = x;+ Y = y;+ IsPrimary = isPrimary;}}}diff --git a/GlazeWM.Domain/Monitors/MonitorService.cs b/GlazeWM.Domain/Monitors/MonitorService.csindex 3b4fb1bc..2eae2f69 100644--- a/GlazeWM.Domain/Monitors/MonitorService.cs+++ b/GlazeWM.Domain/Monitors/MonitorService.cs@@ -38,7 +38,7 @@ namespace GlazeWM.Domain.Monitors{var screen = Screen.FromHandle(windowHandle);- return GetMonitors().FirstOrDefault(monitor => monitor.Screen.DeviceName == screen.DeviceName)+ return GetMonitors().FirstOrDefault(monitor => monitor.DeviceName == screen.DeviceName)?? GetMonitors().First();}@@ -47,20 +47,23 @@ namespace GlazeWM.Domain.Monitorsreturn GetMonitorFromChildContainer(_containerService.FocusedContainer);}- public uint GetMonitorDpi(Screen screen)+ public uint GetMonitorDpi(Monitor monitor){+ // Create a point within the monitor's dimensions.var point = new Point{- X = screen.Bounds.Left + 1,- Y = screen.Bounds.Top + 1+ X = monitor.X + 1,+ Y = monitor.Y + 1};- // Get a handle to the monitor from a `Screen`.+ // Get a handle to the monitor.+ // TODO: Consider adding a `Monitor` getter for a monitor's handle.var monitorHandle = MonitorFromPoint(point, MonitorFromPointFlags.MONITOR_DEFAULTTONEAREST);uint dpiX, dpiY;GetDpiForMonitor(monitorHandle, DpiType.Effective, out dpiX, out dpiY);+ // DPI X and Y should be equivalent, so it's arbitrary which to return.return dpiX;}