-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
MoveWindowToMonitorIndexTransform
(#975)
Adds a transform to make it easier to move a window to a monitor with a specific index (#974).
- Loading branch information
Showing
6 changed files
with
141 additions
and
1 deletion.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
src/Whim.Tests/Store/MapSector/Transforms/MoveWindowToMonitorIndexTransformTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace Whim.Tests; | ||
|
||
[SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope")] | ||
public class MoveWindowToMonitorIndexTransformTests | ||
{ | ||
[Theory, AutoSubstituteData<StoreCustomization>] | ||
internal void NoMonitorAtIndex(IContext ctx, MutableRootSector rootSector) | ||
{ | ||
// Given there is no monitor at the index | ||
IWindow window = CreateWindow((HWND)10); | ||
IMonitor originalMonitor = CreateMonitor((HMONITOR)10); | ||
IMonitor newMonitor = CreateMonitor((HMONITOR)11); | ||
|
||
PopulateThreeWayMap(ctx, rootSector, originalMonitor, CreateWorkspace(ctx), window); | ||
PopulateMonitorWorkspaceMap(ctx, rootSector, newMonitor, CreateWorkspace(ctx)); | ||
|
||
MoveWindowToMonitorIndexTransform sut = new(2, window.Handle); | ||
|
||
// When | ||
var result = ctx.Store.Dispatch(sut); | ||
|
||
// Then | ||
Assert.False(result.IsSuccessful); | ||
} | ||
|
||
[Theory, AutoSubstituteData<StoreCustomization>] | ||
internal void Success(IContext ctx, MutableRootSector rootSector) | ||
{ | ||
// Given there is a three way map | ||
IWindow window = CreateWindow((HWND)10); | ||
|
||
IMonitor originalMonitor = CreateMonitor((HMONITOR)10); | ||
IMonitor newMonitor = CreateMonitor((HMONITOR)11); | ||
|
||
Workspace originalWorkspace = CreateWorkspace(ctx); | ||
Workspace newWorkspace = CreateWorkspace(ctx); | ||
|
||
PopulateThreeWayMap(ctx, rootSector, originalMonitor, originalWorkspace, window); | ||
PopulateMonitorWorkspaceMap(ctx, rootSector, newMonitor, newWorkspace); | ||
|
||
MoveWindowToMonitorIndexTransform sut = new(1, window.Handle); | ||
|
||
// When | ||
var result = ctx.Store.Dispatch(sut); | ||
|
||
// Then | ||
Assert.True(result.IsSuccessful); | ||
Assert.Equal(newWorkspace.Id, rootSector.MapSector.WindowWorkspaceMap[window.Handle]); | ||
Assert.Equal(newWorkspace.Id, rootSector.MapSector.MonitorWorkspaceMap[newMonitor.Handle]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/Whim/Store/MapSector/Transforms/MoveWindowToMonitorIndexTransform.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
namespace Whim; | ||
|
||
/// <summary> | ||
/// Move the window with <paramref name="WindowHandle"/> to the monitor at <paramref name="MonitorIndex"/>. | ||
/// </summary> | ||
/// <param name="MonitorIndex"> | ||
/// The 0-based index of the monitor to move the window to. | ||
/// </param> | ||
/// <param name="WindowHandle"> | ||
/// The handle of the window to move. If not provided, this will default to the focused/active window. | ||
/// </param> | ||
public record MoveWindowToMonitorIndexTransform(int MonitorIndex, HWND WindowHandle = default) : Transform | ||
{ | ||
internal override Result<Unit> Execute(IContext ctx, IInternalContext internalCtx, MutableRootSector rootSector) | ||
{ | ||
// Get the monitor at index. | ||
Result<IMonitor> monitorResult = ctx.Store.Pick(PickMonitorByIndex(MonitorIndex)); | ||
if (!monitorResult.TryGet(out IMonitor monitor)) | ||
{ | ||
return Result.FromException<Unit>(monitorResult.Error!); | ||
} | ||
|
||
return ctx.Store.Dispatch(new MoveWindowToMonitorTransform(monitor.Handle, WindowHandle)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters