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

ActivateAdjacent now skips all active workspaces #954

Merged
merged 1 commit into from
Jul 13, 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
43 changes: 29 additions & 14 deletions src/Whim.Tests/Store/MapSector/MapPickersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,29 @@ internal void PickAdjacentWorkspace_NoAdjacentWorkspaces(IContext ctx, MutableRo
Assert.False(result.IsSuccessful);
}

public static TheoryData<int, int[], bool, bool, int> PickAdjacentWorkspaceData =>
new()
{
{ 0, new[] { 0 }, false, false, 1 },
{ 0, new[] { 0 }, true, false, 3 },
{ 3, new[] { 3 }, false, false, 0 },
{ 3, new[] { 3 }, true, false, 2 },
{ 0, new[] { 1 }, false, true, 2 },
{ 1, new[] { 0 }, true, true, 3 },
{ 3, new[] { 0 }, false, true, 1 },
{ 3, new[] { 2 }, true, true, 1 },
// Multiple active, skip active.
{ 0, new[] { 0, 1 }, false, true, 2 },
{ 1, new[] { 0, 1 }, true, true, 3 },
{ 3, new[] { 0, 2 }, false, true, 1 },
{ 3, new[] { 2, 3 }, true, true, 1 }
};

[Theory]
[InlineAutoSubstituteData<StoreCustomization>(0, 0, false, false, 1)]
[InlineAutoSubstituteData<StoreCustomization>(0, 0, true, false, 3)]
[InlineAutoSubstituteData<StoreCustomization>(3, 3, false, false, 0)]
[InlineAutoSubstituteData<StoreCustomization>(3, 3, true, false, 2)]
[InlineAutoSubstituteData<StoreCustomization>(0, 1, false, true, 2)]
[InlineAutoSubstituteData<StoreCustomization>(1, 0, true, true, 3)]
[InlineAutoSubstituteData<StoreCustomization>(3, 0, false, true, 1)]
[InlineAutoSubstituteData<StoreCustomization>(3, 2, true, true, 1)]
[MemberAutoSubstituteData<StoreCustomization>(nameof(PickAdjacentWorkspaceData))]
internal void PickAdjacentWorkspace_Success(
int startIdx,
int activeIdx,
int[] activeIdx,
bool reverse,
bool skipActive,
int expected,
Expand All @@ -219,11 +230,15 @@ MutableRootSector root

ImmutableArray<Guid> workspaceOrder = root.WorkspaceSector.WorkspaceOrder;
Guid startId = workspaceOrder[startIdx];

root.MapSector.MonitorWorkspaceMap = root.MapSector.MonitorWorkspaceMap.SetItem(
root.MonitorSector.ActiveMonitorHandle,
workspaceOrder[activeIdx]
);
Random gen = new();

for (int idx = 0; idx < activeIdx.Length; idx++)
{
root.MapSector.MonitorWorkspaceMap = root.MapSector.MonitorWorkspaceMap.SetItem(
(HMONITOR)idx,
workspaceOrder[activeIdx[idx]]
);
}

// When we get the workspace
var result = ctx.Store.Pick(Pickers.PickAdjacentWorkspace(startId, reverse, skipActive));
Expand Down
12 changes: 8 additions & 4 deletions src/Whim/Store/MapSector/MapPickers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ public static PurePicker<Result<IWorkspace>> PickAdjacentWorkspace(
) =>
rootSector =>
{
IWorkspaceSector sector = rootSector.WorkspaceSector;
ImmutableArray<WorkspaceId> order = sector.WorkspaceOrder;
IWorkspaceSector workspaceSector = rootSector.WorkspaceSector;
IMapSector mapSector = rootSector.MapSector;

ImmutableArray<WorkspaceId> order = workspaceSector.WorkspaceOrder;
int idx = order.IndexOf(workspaceId);

if (idx == -1)
Expand All @@ -119,9 +121,11 @@ public static PurePicker<Result<IWorkspace>> PickAdjacentWorkspace(
{
WorkspaceId nextWorkspaceId = order[nextIdx];

if (!skipActive || nextWorkspaceId != activeWorkspaceId)
bool isActive = mapSector.MonitorWorkspaceMap.ContainsValue(nextWorkspaceId);

if (!skipActive || !isActive)
{
return sector.Workspaces[nextWorkspaceId];
return workspaceSector.Workspaces[nextWorkspaceId];
}

nextIdx = (nextIdx + delta).Mod(order.Length);
Expand Down