Skip to content

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

fix: update id when the `Container` type changes (#384)

lars-berger099f61403e5a
diff --git a/GlazeWM.Domain/Containers/CommandHandlers/RedrawContainersHandler.cs b/GlazeWM.Domain/Containers/CommandHandlers/RedrawContainersHandler.cs
index 9a7269fb..aa4f33c7 100644
--- a/GlazeWM.Domain/Containers/CommandHandlers/RedrawContainersHandler.cs
+++ b/GlazeWM.Domain/Containers/CommandHandlers/RedrawContainersHandler.cs
@@ -68,8 +68,7 @@ namespace GlazeWM.Domain.Containers.CommandHandlers
SetWindowPosFlags.FrameChanged |
SetWindowPosFlags.NoActivate |
SetWindowPosFlags.NoCopyBits |
- SetWindowPosFlags.NoSendChanging |
- SetWindowPosFlags.AsyncWindowPos;
+ SetWindowPosFlags.NoSendChanging;
// Show or hide the window depending on whether the workspace is displayed.
if (window.IsDisplayed)
diff --git a/GlazeWM.Domain/Containers/Container.cs b/GlazeWM.Domain/Containers/Container.cs
index cfbb91fd..91943de5 100644
--- a/GlazeWM.Domain/Containers/Container.cs
+++ b/GlazeWM.Domain/Containers/Container.cs
@@ -11,7 +11,7 @@ namespace GlazeWM.Domain.Containers
/// <summary>
/// A unique identifier for the container.
/// </summary>
- public Guid Id { get; } = Guid.NewGuid();
+ public Guid Id { get; set; } = Guid.NewGuid();
/// <summary>
/// Derived container type (eg. `ContainerType.Monitor`).
diff --git a/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs b/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs
index 0090d8f0..e41470a4 100644
--- a/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs
+++ b/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs
@@ -1,7 +1,6 @@
using System;
using System.Linq;
using System.Threading.Tasks;
-using GlazeWM.Domain.Containers;
using GlazeWM.Domain.UserConfigs.Commands;
using GlazeWM.Domain.Windows;
using GlazeWM.Infrastructure.Bussing;
diff --git a/GlazeWM.Domain/UserConfigs/CommandHandlers/RunWithSubjectContainerHandler.cs b/GlazeWM.Domain/UserConfigs/CommandHandlers/RunWithSubjectContainerHandler.cs
index c1ce148b..9a241902 100644
--- a/GlazeWM.Domain/UserConfigs/CommandHandlers/RunWithSubjectContainerHandler.cs
+++ b/GlazeWM.Domain/UserConfigs/CommandHandlers/RunWithSubjectContainerHandler.cs
@@ -2,6 +2,7 @@ using System.Linq;
using GlazeWM.Domain.Containers;
using GlazeWM.Domain.UserConfigs.Commands;
using GlazeWM.Infrastructure.Bussing;
+using GlazeWM.Infrastructure.Utils;
namespace GlazeWM.Domain.UserConfigs.CommandHandlers
{
@@ -24,15 +25,15 @@ namespace GlazeWM.Domain.UserConfigs.CommandHandlers
public CommandResponse Handle(RunWithSubjectContainerCommand command)
{
- var commandStrings = command.CommandStrings;
+ var commandStrings = command.CommandStrings.ToList();
var subjectContainer =
command.SubjectContainer ?? _containerService.FocusedContainer;
var subjectContainerId = subjectContainer.Id;
- // Return early if any of the commands is an ignore command.
+ // Evaluate ignore rules first (avoids jitters if another rule triggers a redraw).
if (commandStrings.Any(command => command == "ignore"))
- return CommandResponse.Ok;
+ commandStrings.MoveToFront("ignore");
// Invoke commands in sequence.
foreach (var commandString in commandStrings)
diff --git a/GlazeWM.Domain/Windows/CommandHandlers/SetFloatingHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/SetFloatingHandler.cs
index 1a84b218..3c4bcf37 100644
--- a/GlazeWM.Domain/Windows/CommandHandlers/SetFloatingHandler.cs
+++ b/GlazeWM.Domain/Windows/CommandHandlers/SetFloatingHandler.cs
@@ -35,7 +35,10 @@ namespace GlazeWM.Domain.Windows.CommandHandlers
window.Handle,
window.FloatingPlacement,
window.BorderDelta
- );
+ )
+ {
+ Id = window.Id
+ };
_bus.Invoke(new ReplaceContainerCommand(floatingWindow, window.Parent, window.Index));
_bus.Invoke(new RedrawContainersCommand());
diff --git a/GlazeWM.Domain/Windows/CommandHandlers/SetTilingHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/SetTilingHandler.cs
index 0abcabab..8ef60753 100644
--- a/GlazeWM.Domain/Windows/CommandHandlers/SetTilingHandler.cs
+++ b/GlazeWM.Domain/Windows/CommandHandlers/SetTilingHandler.cs
@@ -32,7 +32,10 @@ namespace GlazeWM.Domain.Windows.CommandHandlers
window.FloatingPlacement,
window.BorderDelta,
0
- );
+ )
+ {
+ Id = window.Id
+ };
// Replace the original window with the created tiling window.
_bus.Invoke(new ReplaceContainerCommand(tilingWindow, window.Parent, window.Index));
diff --git a/GlazeWM.Domain/Windows/EventHandlers/WindowFocusedHandler.cs b/GlazeWM.Domain/Windows/EventHandlers/WindowFocusedHandler.cs
index e3142a9d..5be8315c 100644
--- a/GlazeWM.Domain/Windows/EventHandlers/WindowFocusedHandler.cs
+++ b/GlazeWM.Domain/Windows/EventHandlers/WindowFocusedHandler.cs
@@ -68,13 +68,8 @@ namespace GlazeWM.Domain.Windows.EventHandlers
var window = _windowService.GetWindows()
.FirstOrDefault(window => window.Handle == @event.WindowHandle);
- if (window is null)
+ if (window is null || window?.IsDisplayed == false)
return;
- if (!window.IsDisplayed)
- {
- var offScreenWorkspace = WorkspaceService.GetWorkspaceFromChildContainer(window);
- _bus.Invoke(new FocusWorkspaceCommand(offScreenWorkspace.Name));
- }
_logger.LogWindowEvent("Window focused", window);
diff --git a/GlazeWM.Domain/Windows/EventHandlers/WindowMinimizeEndedHandler.cs b/GlazeWM.Domain/Windows/EventHandlers/WindowMinimizeEndedHandler.cs
index a9572677..a3a54f6b 100644
--- a/GlazeWM.Domain/Windows/EventHandlers/WindowMinimizeEndedHandler.cs
+++ b/GlazeWM.Domain/Windows/EventHandlers/WindowMinimizeEndedHandler.cs
@@ -68,7 +68,7 @@ namespace GlazeWM.Domain.Windows.EventHandlers
private static Window CreateWindowFromPreviousState(MinimizedWindow window)
{
- return window.PreviousState switch
+ Window restoredWindow = window.PreviousState switch
{
WindowType.Floating => new FloatingWindow(
window.Handle,
@@ -95,6 +95,9 @@ namespace GlazeWM.Domain.Windows.EventHandlers
WindowType.Minimized => throw new ArgumentException(null, nameof(window)),
_ => throw new ArgumentException(null, nameof(window)),
};
+
+ restoredWindow.Id = window.Id;
+ return restoredWindow;
}
}
}
diff --git a/GlazeWM.Domain/Windows/EventHandlers/WindowMinimizedHandler.cs b/GlazeWM.Domain/Windows/EventHandlers/WindowMinimizedHandler.cs
index 07f2dff2..dfdb097c 100644
--- a/GlazeWM.Domain/Windows/EventHandlers/WindowMinimizedHandler.cs
+++ b/GlazeWM.Domain/Windows/EventHandlers/WindowMinimizedHandler.cs
@@ -50,7 +50,10 @@ namespace GlazeWM.Domain.Windows.EventHandlers
window.FloatingPlacement,
window.BorderDelta,
previousState
- );
+ )
+ {
+ Id = window.Id
+ };
// Get container to switch focus to after the window has been minimized.
var focusTarget = WindowService.GetFocusTargetAfterRemoval(window);
diff --git a/GlazeWM.Domain/Workspaces/CommandHandlers/MoveWindowToWorkspaceHandler.cs b/GlazeWM.Domain/Workspaces/CommandHandlers/MoveWindowToWorkspaceHandler.cs
index 3919cc9c..8ff474f8 100644
--- a/GlazeWM.Domain/Workspaces/CommandHandlers/MoveWindowToWorkspaceHandler.cs
+++ b/GlazeWM.Domain/Workspaces/CommandHandlers/MoveWindowToWorkspaceHandler.cs
@@ -54,19 +54,11 @@ namespace GlazeWM.Domain.Workspaces.CommandHandlers
var focusTarget = WindowService.GetFocusTargetAfterRemoval(windowToMove);
- // Since the workspace that gets displayed is the last focused child, focus needs to be
- // reassigned to the displayed workspace.
- var targetMonitor = targetWorkspace.Parent as Monitor;
- var focusResetTarget = targetWorkspace.IsDisplayed ? null : targetMonitor.LastFocusedDescendant;
-
if (windowToMove is TilingWindow)
MoveTilingWindowToWorkspace(windowToMove as TilingWindow, targetWorkspace);
else
_bus.Invoke(new MoveContainerWithinTreeCommand(windowToMove, targetWorkspace, false));
- if (focusResetTarget is not null)
- _bus.Invoke(new SetFocusedDescendantCommand(focusResetTarget));
-
// Reassign focus to descendant within the current workspace. Need to call
// `SetFocusedDescendantCommand` for when commands like `FocusWorkspaceCommand` are called
// immediately afterwards and they should behave as if `focusTarget` is the focused