Skip to content

armgit / Filee

Public Imported from GitHub
0

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.

Keep the donut on top after other apps reorder the windows

KnifeLemonca9b295f1da0
diff --git a/src/Filee.App/Services/RadialController.cs b/src/Filee.App/Services/RadialController.cs
index 4c887ab6..cc4e7519 100644
--- a/src/Filee.App/Services/RadialController.cs
+++ b/src/Filee.App/Services/RadialController.cs
@@ -18,6 +18,7 @@ using Filee.App.Controls;
using Filee.App.ViewModels;
using Filee.App.Views;
using Filee.Core.Conversion;
+using Filee.Core.Platform;
using Filee.Core.Settings;
using Microsoft.Extensions.Logging;
@@ -28,6 +29,7 @@ public sealed class RadialController(
ConversionService conversions,
WindowService windows,
UserDataStore store,
+ IPlatformServices platform,
ILogger<RadialController> log)
{
/// <summary>
@@ -290,6 +292,11 @@ public sealed class RadialController(
if (!window.IsVisible)
window.Show();
window.Position = position; // again, in case showing changed the DPI scale
+ // Showing a window that is already marked topmost does not move it in the z-order, and Windows can push it
+ // below normal windows while it keeps the mark (after the Photos app opened, for one). Then Explorer stays on
+ // top of the donut and the drop never reaches it, so put it back on top every time.
+ if (window.TryGetPlatformHandle()?.Handle is { } handle)
+ platform.RaiseTopmost(handle);
_visible = true;
if (activate)
window.Activate();
diff --git a/src/Filee.Core/Platform/IPlatformServices.cs b/src/Filee.Core/Platform/IPlatformServices.cs
index e9b4f4a4..c68b5311 100644
--- a/src/Filee.Core/Platform/IPlatformServices.cs
+++ b/src/Filee.Core/Platform/IPlatformServices.cs
@@ -38,6 +38,12 @@ public interface IPlatformServices
/// <summary>Opens a folder in the file manager and selects the file, if given.</summary>
void RevealInFileManager(string path);
+
+ /// <summary>
+ /// Puts an always-on-top window back at the top of the z-order without activating it. Windows can push such a
+ /// window below normal ones (seen after the Photos app opened) while it still reports itself as topmost.
+ /// </summary>
+ void RaiseTopmost(nint windowHandle);
}
/// <summary>Whether "Convert with Filee" is in the top-level Windows 11 File Explorer menu (not just "Show more options").</summary>
@@ -77,6 +83,8 @@ public sealed class NullPlatformServices : IPlatformServices
public Task<ModernContextMenuResult> SetModernContextMenuAsync(bool enabled, string executablePath) =>
Task.FromResult(new ModernContextMenuResult(false, Error: "Not supported on this platform."));
+ public void RaiseTopmost(nint windowHandle) { }
+
public void RevealInFileManager(string path)
{
var target = Directory.Exists(path) ? path : Path.GetDirectoryName(path);
diff --git a/src/Filee.Platform.Windows/NativeMethods.cs b/src/Filee.Platform.Windows/NativeMethods.cs
index 1e360bb6..40f061f0 100644
--- a/src/Filee.Platform.Windows/NativeMethods.cs
+++ b/src/Filee.Platform.Windows/NativeMethods.cs
@@ -26,6 +26,13 @@ internal static partial class NativeMethods
[LibraryImport("user32.dll")]
public static partial nint GetForegroundWindow();
+ public const nint HWND_TOPMOST = -1;
+ public const uint SWP_NOSIZE = 0x0001, SWP_NOMOVE = 0x0002, SWP_NOACTIVATE = 0x0010, SWP_NOOWNERZORDER = 0x0200;
+
+ [LibraryImport("user32.dll", SetLastError = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ public static partial bool SetWindowPos(nint hWnd, nint hWndInsertAfter, int x, int y, int cx, int cy, uint flags);
+
[LibraryImport("user32.dll")]
public static partial uint GetWindowThreadProcessId(nint hwnd, out uint processId);
diff --git a/src/Filee.Platform.Windows/WindowsPlatformServices.cs b/src/Filee.Platform.Windows/WindowsPlatformServices.cs
index 5efb4239..103f2558 100644
--- a/src/Filee.Platform.Windows/WindowsPlatformServices.cs
+++ b/src/Filee.Platform.Windows/WindowsPlatformServices.cs
@@ -25,6 +25,13 @@ public sealed class WindowsPlatformServices : IPlatformServices
"WorkerW", // desktop (when wallpaper slideshow / Win+Tab created a WorkerW)
};
+ public void RaiseTopmost(nint windowHandle)
+ {
+ if (windowHandle != 0)
+ NativeMethods.SetWindowPos(windowHandle, NativeMethods.HWND_TOPMOST, 0, 0, 0, 0,
+ NativeMethods.SWP_NOMOVE | NativeMethods.SWP_NOSIZE | NativeMethods.SWP_NOACTIVATE | NativeMethods.SWP_NOOWNERZORDER);
+ }
+
public bool IsFileManagerAt(int x, int y)
{
var root = RootWindowAt(x, y);