Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.
C# audio-converteravaloniabatch-conversionconvertercsharpdocument-converterdocx-to-pdfdotnetdrag-and-dropfile-conversionfile-converterheic-converterhwphwpximage-converterlinuxmacospdf-convertervideo-converterwindows
fix(windows): treat windows owned by the desktop as the desktop
Cafunwe221d34d8b9e
diff --git a/src/Filee.Platform.Windows/NativeMethods.cs b/src/Filee.Platform.Windows/NativeMethods.csindex a89e7d76..33a17cd0 100644--- a/src/Filee.Platform.Windows/NativeMethods.cs+++ b/src/Filee.Platform.Windows/NativeMethods.cs@@ -8,6 +8,7 @@ internal static partial class NativeMethods{public const int SM_CXDRAG = 68;public const uint GA_ROOT = 2;+ public const uint GA_ROOTOWNER = 3;public const uint SPI_GETCLIENTAREAANIMATION = 0x1042;[StructLayout(LayoutKind.Sequential)]diff --git a/src/Filee.Platform.Windows/WindowsPlatformServices.cs b/src/Filee.Platform.Windows/WindowsPlatformServices.csindex f38b9906..32759b15 100644--- a/src/Filee.Platform.Windows/WindowsPlatformServices.cs+++ b/src/Filee.Platform.Windows/WindowsPlatformServices.cs@@ -82,6 +82,24 @@ public sealed class WindowsPlatformServices : IPlatformServices/// <summary>True for the desktop's window classes: its icons are not among Shell.Application's windows.</summary>internal static bool IsDesktop(string? windowClass) => windowClass is "Progman" or "WorkerW";+ /// <summary>+ /// True when the end of a window's owner chain (<paramref name="rootOwner"/>) is another window and the desktop.+ /// Desktop icon layers (apps that hide Explorer's icon view and draw the icons themselves) cover the screen with a+ /// window owned by the shell's desktop window and keep Explorer's desktop view selected like their own icons, so+ /// over them, or with them in front, gestures and the selection shortcut act as on the desktop.+ /// </summary>+ internal static bool StandsForDesktop(nint window, nint rootOwner, string? rootOwnerClass) =>+ rootOwner != 0 && rootOwner != window && IsDesktop(rootOwnerClass);++ /// <summary>The desktop for a top-level window it owns (see <see cref="StandsForDesktop"/>), else the window.</summary>+ private static nint DesktopOrSelf(nint window)+ {+ if (window == 0)+ return 0;+ var owner = NativeMethods.GetAncestor(window, NativeMethods.GA_ROOTOWNER);+ return StandsForDesktop(window, owner, NativeMethods.ClassNameOf(owner)) ? owner : window;+ }+public string? ShortcutTarget(string path) => ShellLinks.TargetOf(path);public string DownloadsFolder => KnownFolders.Downloads@@ -217,7 +235,7 @@ public sealed class WindowsPlatformServices : IPlatformServicesif (foreground == 0)return 0;var root = NativeMethods.GetAncestor(foreground, NativeMethods.GA_ROOT);- return root == 0 ? foreground : root;+ return DesktopOrSelf(root == 0 ? foreground : root);}public int SystemDragThreshold => Math.Max(2, NativeMethods.GetSystemMetrics(NativeMethods.SM_CXDRAG));@@ -384,7 +402,7 @@ public sealed class WindowsPlatformServices : IPlatformServicesprivate static nint RootWindowAt(int x, int y){var hwnd = NativeMethods.WindowFromPoint(new NativeMethods.POINT { X = x, Y = y });- return hwnd == 0 ? 0 : NativeMethods.GetAncestor(hwnd, NativeMethods.GA_ROOT);+ return hwnd == 0 ? 0 : DesktopOrSelf(NativeMethods.GetAncestor(hwnd, NativeMethods.GA_ROOT));}private static string? ProcessNameOf(nint hwnd)diff --git a/tests/Filee.Platform.Tests/WindowsTriggerSupportTests.cs b/tests/Filee.Platform.Tests/WindowsTriggerSupportTests.csindex d201c253..98a8600e 100644--- a/tests/Filee.Platform.Tests/WindowsTriggerSupportTests.cs+++ b/tests/Filee.Platform.Tests/WindowsTriggerSupportTests.cs@@ -20,6 +20,15 @@ public sealed class WindowsTriggerSupportTestspublic void The_desktop_is_told_from_folder_windows(string? windowClass, bool desktop) =>Assert.Equal(desktop, WindowsPlatformServices.IsDesktop(windowClass));+ [Theory]+ [InlineData(10, 20, "Progman", true)] // a desktop icon layer, owned by the desktop+ [InlineData(10, 20, "WorkerW", true)]+ [InlineData(10, 20, "CabinetWClass", false)] // a dialog owned by a folder window+ [InlineData(20, 20, "Progman", false)] // the desktop itself is its own root owner: nothing to map+ [InlineData(10, 0, null, false)] // no owner+ public void A_window_the_desktop_owns_stands_for_the_desktop(long window, long rootOwner, string? rootOwnerClass, bool desktop) =>+ Assert.Equal(desktop, WindowsPlatformServices.StandsForDesktop((nint)window, (nint)rootOwner, rootOwnerClass));+[Fact]public void The_startup_entry_read_back_must_be_the_one_written(){