Skip to content

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

refactor(domain): change `IsHidden` to a getter based on whether parent workspace is displayed

Lars Bergerc3b42ae2e508
diff --git a/GlazeWM.Domain/Windows/Window.cs b/GlazeWM.Domain/Windows/Window.cs
index aba61c6c..e5203bb0 100644
--- a/GlazeWM.Domain/Windows/Window.cs
+++ b/GlazeWM.Domain/Windows/Window.cs
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics;
using GlazeWM.Domain.Containers;
+using GlazeWM.Domain.Workspaces;
using GlazeWM.Infrastructure;
using GlazeWM.Infrastructure.WindowsApi;
using Microsoft.Extensions.DependencyInjection;
@@ -12,7 +13,6 @@ namespace GlazeWM.Domain.Windows
{
public Guid Id = Guid.NewGuid();
public IntPtr Hwnd { get; }
- public bool IsHidden { get; set; } = false;
/// <summary>
/// Whether adjustments need to be made because of DPI (eg. when moving between monitors).
@@ -20,6 +20,7 @@ namespace GlazeWM.Domain.Windows
public bool HasPendingDpiAdjustment { get; set; } = false;
private WindowService _windowService = ServiceLocator.Provider.GetRequiredService<WindowService>();
+ private WorkspaceService _workspaceService = ServiceLocator.Provider.GetRequiredService<WorkspaceService>();
private ContainerService _containerService = ServiceLocator.Provider.GetRequiredService<ContainerService>();
public Window(IntPtr hwnd)
@@ -27,6 +28,11 @@ namespace GlazeWM.Domain.Windows
Hwnd = hwnd;
}
+ /// <summary>
+ /// Windows are hidden if their parent workspace is not displayed.
+ /// </summary>
+ public bool IsHidden => !_workspaceService.GetWorkspaceFromChildContainer(this).IsDisplayed;
+
public override int Width => _containerService.CalculateWidthOfResizableContainer(this);
public override int Height => _containerService.CalculateHeightOfResizableContainer(this);
diff --git a/GlazeWM.Domain/Workspaces/CommandHandlers/DisplayWorkspaceHandler.cs b/GlazeWM.Domain/Workspaces/CommandHandlers/DisplayWorkspaceHandler.cs
index b81d5cec..c112fce7 100644
--- a/GlazeWM.Domain/Workspaces/CommandHandlers/DisplayWorkspaceHandler.cs
+++ b/GlazeWM.Domain/Workspaces/CommandHandlers/DisplayWorkspaceHandler.cs
@@ -1,8 +1,6 @@
-using System.Linq;
-using GlazeWM.Domain.Containers;
+using GlazeWM.Domain.Containers;
using GlazeWM.Domain.Containers.Commands;
using GlazeWM.Domain.Monitors;
-using GlazeWM.Domain.Windows;
using GlazeWM.Domain.Workspaces.Commands;
using GlazeWM.Infrastructure.Bussing;
@@ -28,7 +26,8 @@ namespace GlazeWM.Domain.Workspaces.CommandHandlers
var monitor = _monitorService.GetMonitorFromChildContainer(command.Workspace);
var currentWorkspace = monitor.DisplayedWorkspace;
- // If DisplayedWorkspace is unassigned, there is no need to show/hide windows.
+ // If `DisplayedWorkspace` is unassigned (ie. on startup), there is no need to show/hide
+ // any windows.
if (currentWorkspace == null)
{
monitor.DisplayedWorkspace = workspaceToDisplay;
@@ -38,22 +37,6 @@ namespace GlazeWM.Domain.Workspaces.CommandHandlers
if (currentWorkspace == workspaceToDisplay)
return CommandResponse.Ok;
- var windowsToHide = currentWorkspace.Children
- .SelectMany(container => container.Flatten())
- .OfType<Window>()
- .ToList();
-
- foreach (var window in windowsToHide)
- window.IsHidden = true;
-
- var windowsToShow = workspaceToDisplay.Children
- .SelectMany(container => container.Flatten())
- .OfType<Window>()
- .ToList();
-
- foreach (var window in windowsToShow)
- window.IsHidden = false;
-
monitor.DisplayedWorkspace = command.Workspace;
_containerService.SplitContainersToRedraw.Add(currentWorkspace);