Skip to content

Commit

Permalink
ActivateAdjacent now skips all active workspaces (#954)
Browse files Browse the repository at this point in the history
Previously, `PickAdjacentWorkspace` only took into account the workspace which is on the active monitor. This has been changed to account for all workspaces which appear on a monitor.
  • Loading branch information
dalyIsaac authored Jul 13, 2024
1 parent 8446a66 commit 185ade1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 18 deletions.
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

0 comments on commit 185ade1

Please sign in to comment.