using Moli.Desktop.Diagnostics; using Moli.Desktop.Layout; namespace Moli.Desktop.Interop; /// Fallback strategy that keeps the wallpaper window at the bottom of normal Z-order. 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 TryAttachDesktopWindow(IntPtr hwnd, RectD bounds, out string? error) { error = null; if (!NativeMethods.SetWindowPos( hwnd, NativeMethods.HwndBottom, (int)bounds.X, (int)bounds.Y, (int)bounds.Width, (int)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 { ["reason"] = error }); return false; } _diagnostics.Record( DiagnosticSeverity.Info, DiagnosticCodes.DesktopLayerStrategySelected, "Desktop layer strategy selected.", new Dictionary { ["strategy"] = Name }); return true; } }