Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent additional layouts when focusing a window #922

Merged
merged 1 commit into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.Diagnostics.CodeAnalysis;

namespace Whim.Tests;

[SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope")]
public class SetLastFocusedWindowTransformTests
{
[Theory, AutoSubstituteData<StoreCustomization>]
internal void NoChanges(IContext ctx, MutableRootSector root)
{
// Given the last focused window is the same as the window we're setting.
IWindow window = CreateWindow((HWND)123);
Workspace workspace = CreateWorkspace(ctx) with { LastFocusedWindowHandle = window.Handle };

workspace = PopulateWindowWorkspaceMap(ctx, root, window, workspace);

SetLastFocusedWindowTransform sut = new(workspace.Id, window.Handle);

// When we execute the transform
Result<bool> result = ctx.Store.Dispatch(sut);

// Then there are no changes
Assert.True(result.IsSuccessful);
Assert.False(result.Value);

Workspace resultWorkspace = root.WorkspaceSector.Workspaces[workspace.Id];
Assert.Equal(window.Handle, resultWorkspace.LastFocusedWindowHandle);
}

[Theory, AutoSubstituteData<StoreCustomization>]
internal void Success(IContext ctx, MutableRootSector root)
{
// Given the last focused window is not the same as the window we're setting.
IWindow window = CreateWindow((HWND)123);
Workspace workspace = CreateWorkspace(ctx) with { LastFocusedWindowHandle = (HWND)456 };

workspace = PopulateWindowWorkspaceMap(ctx, root, window, workspace);

SetLastFocusedWindowTransform sut = new(workspace.Id, window.Handle);

// When we execute the transform
Result<bool> result = ctx.Store.Dispatch(sut);

// Then there are changes
Assert.True(result.IsSuccessful);
Assert.True(result.Value);

Workspace resultWorkspace = root.WorkspaceSector.Workspaces[workspace.Id];
Assert.Equal(window.Handle, resultWorkspace.LastFocusedWindowHandle);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ namespace Whim;
/// </summary>
/// <param name="WorkspaceId"></param>
/// <param name="WindowHandle"></param>
internal record SetLastFocusedWindowTransform(Guid WorkspaceId, HWND WindowHandle)
internal record SetLastFocusedWindowTransform(WorkspaceId WorkspaceId, HWND WindowHandle)
: BaseWorkspaceWindowTransform(
WorkspaceId,
WindowHandle,
DefaultToLastFocusedWindow: false,
IsWindowRequiredInWorkspace: true,
SkipDoLayout: false
SkipDoLayout: true
)
{
private protected override Result<Workspace> WindowOperation(
Expand Down
Loading