diff --git a/src/Whim.Tests/Store/MapSector/MapPickersTests.cs b/src/Whim.Tests/Store/MapSector/MapPickersTests.cs index aa84e558d..7be64a8c0 100644 --- a/src/Whim.Tests/Store/MapSector/MapPickersTests.cs +++ b/src/Whim.Tests/Store/MapSector/MapPickersTests.cs @@ -188,18 +188,29 @@ internal void PickAdjacentWorkspace_NoAdjacentWorkspaces(IContext ctx, MutableRo Assert.False(result.IsSuccessful); } + public static TheoryData 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(0, 0, false, false, 1)] - [InlineAutoSubstituteData(0, 0, true, false, 3)] - [InlineAutoSubstituteData(3, 3, false, false, 0)] - [InlineAutoSubstituteData(3, 3, true, false, 2)] - [InlineAutoSubstituteData(0, 1, false, true, 2)] - [InlineAutoSubstituteData(1, 0, true, true, 3)] - [InlineAutoSubstituteData(3, 0, false, true, 1)] - [InlineAutoSubstituteData(3, 2, true, true, 1)] + [MemberAutoSubstituteData(nameof(PickAdjacentWorkspaceData))] internal void PickAdjacentWorkspace_Success( int startIdx, - int activeIdx, + int[] activeIdx, bool reverse, bool skipActive, int expected, @@ -219,11 +230,15 @@ MutableRootSector root ImmutableArray 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)); diff --git a/src/Whim/Store/MapSector/MapPickers.cs b/src/Whim/Store/MapSector/MapPickers.cs index 888030d42..3a721835a 100644 --- a/src/Whim/Store/MapSector/MapPickers.cs +++ b/src/Whim/Store/MapSector/MapPickers.cs @@ -102,8 +102,10 @@ public static PurePicker> PickAdjacentWorkspace( ) => rootSector => { - IWorkspaceSector sector = rootSector.WorkspaceSector; - ImmutableArray order = sector.WorkspaceOrder; + IWorkspaceSector workspaceSector = rootSector.WorkspaceSector; + IMapSector mapSector = rootSector.MapSector; + + ImmutableArray order = workspaceSector.WorkspaceOrder; int idx = order.IndexOf(workspaceId); if (idx == -1) @@ -119,9 +121,11 @@ public static PurePicker> 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);