From ddd6889459bccf5015cd0c9629cdf4f4ce8fb8e1 Mon Sep 17 00:00:00 2001
From: Moli <13026959681@163.com>
Date: 星期一, 04 五月 2026 11:26:25 +0800
Subject: [PATCH] 优化Win+D隐藏的问题

---
 src/Moli.Desktop/Interop/Win32InteropService.cs |   19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)

diff --git a/src/Moli.Desktop/Interop/Win32InteropService.cs b/src/Moli.Desktop/Interop/Win32InteropService.cs
index ad6a2af..bf066f9 100644
--- a/src/Moli.Desktop/Interop/Win32InteropService.cs
+++ b/src/Moli.Desktop/Interop/Win32InteropService.cs
@@ -45,6 +45,9 @@
     }
 
     public void MoveToDesktopLayer(IntPtr hwnd, DesktopLayerMode mode, MonitorInfo monitor)
+        => MoveToDesktopLayer(hwnd, mode, monitor.Bounds);
+
+    public void MoveToDesktopLayer(IntPtr hwnd, DesktopLayerMode mode, RectD bounds)
     {
         var candidates = mode == DesktopLayerMode.WorkerW
             ? _strategies.OrderBy(strategy => strategy is WorkerWDesktopLayerStrategy ? 0 : 1)
@@ -57,7 +60,7 @@
                 continue;
             }
 
-            if (strategy.TryAttachWallpaperWindow(hwnd, monitor, out var error))
+            if (strategy.TryAttachDesktopWindow(hwnd, bounds, out var error))
             {
                 return;
             }
@@ -74,6 +77,20 @@
         }
     }
 
+    public void RestoreTopLevelWindow(IntPtr hwnd)
+    {
+        NativeMethods.SetParent(hwnd, IntPtr.Zero);
+        var error = NativeMethods.GetLastError();
+        if (error != 0)
+        {
+            _diagnostics.Record(
+                DiagnosticSeverity.Warning,
+                DiagnosticCodes.Win32InteropFailed,
+                "RestoreTopLevelWindow failed.",
+                new Dictionary<string, string> { ["hwnd"] = hwnd.ToString("X"), ["error"] = error.ToString() });
+        }
+    }
+
     public void SetBottomMost(IntPtr hwnd)
     {
         if (!NativeMethods.SetWindowPos(

--
Gitblit v1.9.1