using Moli.Desktop.Configuration;
|
using Moli.Desktop.Diagnostics;
|
|
namespace Moli.Desktop.Interop;
|
|
/// <summary>Fallback strategy that keeps the wallpaper window at the bottom of normal Z-order.</summary>
|
public sealed class BottomDesktopLayerStrategy : IDesktopLayerStrategy
|
{
|
private readonly IDiagnosticsService _diagnostics;
|
|
public BottomDesktopLayerStrategy(IDiagnosticsService diagnostics)
|
{
|
_diagnostics = diagnostics;
|
}
|
|
public string Name => "BottomDesktopLayer";
|
|
public bool IsSupported() => true;
|
|
public bool TryAttachWallpaperWindow(IntPtr hwnd, MonitorInfo monitor, out string? error)
|
{
|
error = null;
|
if (!NativeMethods.SetWindowPos(
|
hwnd,
|
NativeMethods.HwndBottom,
|
(int)monitor.Bounds.X,
|
(int)monitor.Bounds.Y,
|
(int)monitor.Bounds.Width,
|
(int)monitor.Bounds.Height,
|
NativeMethods.SwpNoActivate | NativeMethods.SwpShowWindow))
|
{
|
error = $"SetWindowPos failed with {NativeMethods.GetLastError()}";
|
_diagnostics.Record(
|
DiagnosticSeverity.Warning,
|
DiagnosticCodes.DesktopLayerAttachFailed,
|
"Failed to place window at bottom desktop layer.",
|
new Dictionary<string, string> { ["reason"] = error });
|
return false;
|
}
|
|
_diagnostics.Record(
|
DiagnosticSeverity.Info,
|
DiagnosticCodes.DesktopLayerStrategySelected,
|
"Desktop layer strategy selected.",
|
new Dictionary<string, string> { ["strategy"] = Name });
|
return true;
|
}
|
}
|