Skip to content

Commit

Permalink
fix: update id when the Container type changes (glzr-io#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-berger authored and AryanSolanki637 committed Sep 9, 2023
1 parent a93e58a commit fd37dc0
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ private void SetWindowPosition(Window window)
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)
Expand Down
2 changes: 1 addition & 1 deletion GlazeWM.Domain/Containers/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public abstract class Container
/// <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`).
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using GlazeWM.Domain.Containers;
using GlazeWM.Domain.UserConfigs.Commands;
using GlazeWM.Infrastructure.Bussing;
using GlazeWM.Infrastructure.Utils;

namespace GlazeWM.Domain.UserConfigs.CommandHandlers
{
Expand All @@ -24,15 +25,15 @@ public RunWithSubjectContainerHandler(

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)
Expand Down
5 changes: 4 additions & 1 deletion GlazeWM.Domain/Windows/CommandHandlers/SetFloatingHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ public CommandResponse Handle(SetFloatingCommand command)
window.Handle,
window.FloatingPlacement,
window.BorderDelta
);
)
{
Id = window.Id
};

_bus.Invoke(new ReplaceContainerCommand(floatingWindow, window.Parent, window.Index));
_bus.Invoke(new RedrawContainersCommand());
Expand Down
5 changes: 4 additions & 1 deletion GlazeWM.Domain/Windows/CommandHandlers/SetTilingHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ public CommandResponse Handle(SetTilingCommand command)
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));
Expand Down
7 changes: 1 addition & 6 deletions GlazeWM.Domain/Windows/EventHandlers/WindowFocusedHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,8 @@ public void Handle(WindowFocusedEvent @event)
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void Handle(WindowMinimizeEndedEvent @event)

private static Window CreateWindowFromPreviousState(MinimizedWindow window)
{
return window.PreviousState switch
Window restoredWindow = window.PreviousState switch
{
WindowType.Floating => new FloatingWindow(
window.Handle,
Expand All @@ -95,6 +95,9 @@ private static Window CreateWindowFromPreviousState(MinimizedWindow window)
WindowType.Minimized => throw new ArgumentException(null, nameof(window)),
_ => throw new ArgumentException(null, nameof(window)),
};

restoredWindow.Id = window.Id;
return restoredWindow;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ public void Handle(WindowMinimizedEvent @event)
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,11 @@ public CommandResponse Handle(MoveWindowToWorkspaceCommand command)

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
Expand Down

0 comments on commit fd37dc0

Please sign in to comment.