-
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.
Extract UpdateWindowRectangle from Floating and ProxyFloating layout (#…
…967) Extract shared `UpdateWindowRectangle` logic into a `FloatingUtils` static class, for the ``FloatingLayoutEngine` and `ProxyFloatingLayoutEngine`.
- Loading branch information
Showing
3 changed files
with
70 additions
and
57 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Collections.Immutable; | ||
|
||
namespace Whim.FloatingWindow; | ||
|
||
/// <summary> | ||
/// Provide methods for the floating engines | ||
/// </summary> | ||
internal static class FloatingUtils | ||
{ | ||
/// <summary> | ||
/// Update the position of a <paramref name="window"/> from the <paramref name="dict"/>. | ||
/// </summary> | ||
/// <param name="context"></param> | ||
/// <param name="dict"></param> | ||
/// <param name="window"></param> | ||
/// <returns></returns> | ||
public static ImmutableDictionary<IWindow, IRectangle<double>>? UpdateWindowRectangle( | ||
IContext context, | ||
ImmutableDictionary<IWindow, IRectangle<double>> dict, | ||
IWindow window | ||
) | ||
{ | ||
// Try get the old rectangle. | ||
IRectangle<double>? oldRectangle = dict.TryGetValue(window, out IRectangle<double>? rectangle) | ||
? rectangle | ||
: null; | ||
|
||
// Since the window is floating, we update the rectangle, and return. | ||
IRectangle<int>? newActualRectangle = context.NativeManager.DwmGetWindowRectangle(window.Handle); | ||
if (newActualRectangle == null) | ||
{ | ||
Logger.Error($"Could not obtain rectangle for floating window {window}"); | ||
return null; | ||
} | ||
|
||
IMonitor newMonitor = context.MonitorManager.GetMonitorAtPoint(newActualRectangle); | ||
IRectangle<double> newUnitSquareRectangle = newMonitor.WorkingArea.NormalizeRectangle(newActualRectangle); | ||
if (newUnitSquareRectangle.Equals(oldRectangle)) | ||
{ | ||
Logger.Debug($"Rectangle for window {window} has not changed"); | ||
return dict; | ||
} | ||
|
||
ImmutableDictionary<IWindow, IRectangle<double>> newDict = dict.SetItem(window, newUnitSquareRectangle); | ||
|
||
return newDict; | ||
} | ||
} |
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