Skip to content

Commit 1039616

Browse files
authored
Merge branch 'main' into d2/f_compress
2 parents 5e80b43 + 2a343ee commit 1039616

File tree

7 files changed

+96
-6
lines changed

7 files changed

+96
-6
lines changed

src/Files.App.CsWin32/NativeMethods.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,6 @@ COMPRESSION_FORMAT
170170
FSCTL_SET_COMPRESSION
171171
FSCTL_DISMOUNT_VOLUME
172172
FSCTL_LOCK_VOLUME
173-
FILE_FILE_COMPRESSION
173+
FILE_FILE_COMPRESSION
174+
WM_WINDOWPOSCHANGING
175+
WINDOWPOS

src/Files.App/Helpers/Win32/Win32Helper.WindowManagement.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Microsoft.UI.Input;
55
using Microsoft.UI.Xaml;
66
using System.Reflection;
7+
using System.Runtime.InteropServices;
78
using Windows.Win32;
89
using Windows.Win32.UI.WindowsAndMessaging;
910

@@ -58,5 +59,16 @@ public static void ChangeCursor(this UIElement uiElement, InputCursor cursor)
5859
[cursor]
5960
);
6061
}
62+
63+
/// <summary>
64+
/// Force window to stay at bottom of other upper windows.
65+
/// </summary>
66+
/// <param name="lParam">The lParam of the message.</param>
67+
public static void ForceWindowPosition(nint lParam)
68+
{
69+
var windowPos = Marshal.PtrToStructure<WINDOWPOS>(lParam);
70+
windowPos.flags |= SET_WINDOW_POS_FLAGS.SWP_NOZORDER;
71+
Marshal.StructureToPtr(windowPos, lParam, false);
72+
}
6173
}
6274
}

src/Files.App/MainWindow.xaml.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public sealed partial class MainWindow : WinUIEx.WindowEx
1919
public static MainWindow Instance => _Instance ??= new();
2020

2121
public nint WindowHandle { get; }
22+
private bool CanWindowToFront { get; set; } = true;
23+
private readonly object _canWindowToFrontLock = new();
2224

2325
public MainWindow()
2426
{
@@ -35,6 +37,8 @@ public MainWindow()
3537
AppWindow.TitleBar.ButtonPressedBackgroundColor = Colors.Transparent;
3638
AppWindow.TitleBar.ButtonHoverBackgroundColor = Colors.Transparent;
3739
AppWindow.SetIcon(AppLifecycleHelper.AppIconPath);
40+
41+
WinUIEx.WindowManager.Get(this).WindowMessageReceived += WindowManager_WindowMessageReceived;
3842
}
3943

4044
public void ShowSplashScreen()
@@ -339,5 +343,27 @@ x.tabItem.NavigationParameter.NavigationParameter is PaneNavigationArguments pan
339343
}
340344
}
341345
}
346+
347+
public bool SetCanWindowToFront(bool canWindowToFront)
348+
{
349+
lock (_canWindowToFrontLock)
350+
{
351+
if (CanWindowToFront != canWindowToFront)
352+
{
353+
CanWindowToFront = canWindowToFront;
354+
return true;
355+
}
356+
return false;
357+
}
358+
}
359+
360+
private void WindowManager_WindowMessageReceived(object? sender, WinUIEx.Messaging.WindowMessageEventArgs e)
361+
{
362+
if ((!CanWindowToFront) && e.Message.MessageId == Windows.Win32.PInvoke.WM_WINDOWPOSCHANGING)
363+
{
364+
Win32Helper.ForceWindowPosition(e.Message.LParam);
365+
e.Handled = true;
366+
}
367+
}
342368
}
343369
}

src/Files.App/Views/Layouts/BaseLayoutPage.cs

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public abstract class BaseLayoutPage : Page, IBaseLayoutPage, INotifyPropertyCha
6666
private CancellationTokenSource? groupingCancellationToken;
6767

6868
private bool shiftPressed;
69+
private bool itemDragging;
6970

7071
private ListedItem? dragOverItem = null;
7172
private ListedItem? hoveredItem = null;
@@ -1012,13 +1013,24 @@ protected virtual void FileList_DragItemsStarting(object sender, DragItemsStarti
10121013
var storageItemList = orderedItems.Where(x => !(x.IsHiddenItem && x.IsLinkItem && x.IsRecycleBinItem && x.IsShortcut)).Select(x => VirtualStorageItem.FromListedItem(x));
10131014
e.Data.SetStorageItems(storageItemList, false);
10141015
}
1016+
1017+
// Set can window to front (#13255)
1018+
MainWindow.Instance.SetCanWindowToFront(false);
1019+
itemDragging = true;
10151020
}
10161021
catch (Exception)
10171022
{
10181023
e.Cancel = true;
10191024
}
10201025
}
10211026

1027+
protected virtual void FileList_DragItemsCompleted(ListViewBase sender, DragItemsCompletedEventArgs args)
1028+
{
1029+
// Set can window to front (#13255)
1030+
itemDragging = false;
1031+
MainWindow.Instance.SetCanWindowToFront(true);
1032+
}
1033+
10221034
private void Item_DragLeave(object sender, DragEventArgs e)
10231035
{
10241036
var item = GetItemFromElement(sender);
@@ -1147,13 +1159,19 @@ protected void FileList_ContainerContentChanging(ListViewBase sender, ContainerC
11471159
{
11481160
RefreshContainer(args.ItemContainer, args.InRecycleQueue);
11491161
RefreshItem(args.ItemContainer, args.Item, args.InRecycleQueue, args);
1162+
1163+
// Set can window to front (#13255)
1164+
itemDragging = false;
1165+
MainWindow.Instance.SetCanWindowToFront(true);
11501166
}
11511167

11521168
private void RefreshContainer(SelectorItem container, bool inRecycleQueue)
11531169
{
11541170
container.PointerPressed -= FileListItem_PointerPressed;
11551171
container.PointerEntered -= FileListItem_PointerEntered;
11561172
container.PointerExited -= FileListItem_PointerExited;
1173+
container.Tapped -= FileListItem_Tapped;
1174+
container.DoubleTapped -= FileListItem_DoubleTapped;
11571175
container.RightTapped -= FileListItem_RightTapped;
11581176

11591177
if (inRecycleQueue)
@@ -1163,12 +1181,11 @@ private void RefreshContainer(SelectorItem container, bool inRecycleQueue)
11631181
else
11641182
{
11651183
container.PointerPressed += FileListItem_PointerPressed;
1184+
container.PointerEntered += FileListItem_PointerEntered;
1185+
container.PointerExited += FileListItem_PointerExited;
1186+
container.Tapped += FileListItem_Tapped;
1187+
container.DoubleTapped += FileListItem_DoubleTapped;
11661188
container.RightTapped += FileListItem_RightTapped;
1167-
if (UserSettingsService.FoldersSettingsService.SelectFilesOnHover)
1168-
{
1169-
container.PointerEntered += FileListItem_PointerEntered;
1170-
container.PointerExited += FileListItem_PointerExited;
1171-
}
11721189
}
11731190
}
11741191

@@ -1200,6 +1217,10 @@ private void RefreshItem(SelectorItem container, object item, bool inRecycleQueu
12001217

12011218
protected internal void FileListItem_PointerPressed(object sender, PointerRoutedEventArgs e)
12021219
{
1220+
// Set can window to front and bring the window to the front if necessary (#13255)
1221+
if ((!itemDragging) && MainWindow.Instance.SetCanWindowToFront(true))
1222+
Win32Helper.BringToForegroundEx(new(MainWindow.Instance.WindowHandle));
1223+
12031224
if (sender is not SelectorItem selectorItem)
12041225
return;
12051226

@@ -1225,6 +1246,10 @@ protected internal void FileListItem_PointerPressed(object sender, PointerRouted
12251246

12261247
protected internal void FileListItem_PointerEntered(object sender, PointerRoutedEventArgs e)
12271248
{
1249+
// Set can window to front (#13255)
1250+
if (sender is SelectorItem selectorItem && selectorItem.IsSelected)
1251+
MainWindow.Instance.SetCanWindowToFront(false);
1252+
12281253
if (!UserSettingsService.FoldersSettingsService.SelectFilesOnHover)
12291254
return;
12301255

@@ -1271,15 +1296,37 @@ selectedItems is not null &&
12711296

12721297
protected internal void FileListItem_PointerExited(object sender, PointerRoutedEventArgs e)
12731298
{
1299+
// Set can window to front (#13255)
1300+
if (!itemDragging)
1301+
MainWindow.Instance.SetCanWindowToFront(true);
1302+
12741303
if (!UserSettingsService.FoldersSettingsService.SelectFilesOnHover)
12751304
return;
12761305

12771306
hoverTimer.Stop();
12781307
hoveredItem = null;
12791308
}
12801309

1310+
protected void FileListItem_Tapped(object sender, TappedRoutedEventArgs e)
1311+
{
1312+
// Set can window to front and bring the window to the front if necessary (#13255)
1313+
if ((!itemDragging) && MainWindow.Instance.SetCanWindowToFront(true))
1314+
Win32Helper.BringToForegroundEx(new(MainWindow.Instance.WindowHandle));
1315+
}
1316+
1317+
protected void FileListItem_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
1318+
{
1319+
// Set can window to front and bring the window to the front if necessary (#13255)
1320+
if ((!itemDragging) && MainWindow.Instance.SetCanWindowToFront(true))
1321+
Win32Helper.BringToForegroundEx(new(MainWindow.Instance.WindowHandle));
1322+
}
1323+
12811324
protected void FileListItem_RightTapped(object sender, RightTappedRoutedEventArgs e)
12821325
{
1326+
// Set can window to front and bring the window to the front if necessary (#13255)
1327+
if ((!itemDragging) && MainWindow.Instance.SetCanWindowToFront(true))
1328+
Win32Helper.BringToForegroundEx(new(MainWindow.Instance.WindowHandle));
1329+
12831330
var rightClickedItem = GetItemFromElement(sender);
12841331

12851332
if (rightClickedItem is not null && !((SelectorItem)sender).IsSelected)

src/Files.App/Views/Layouts/ColumnLayoutPage.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
CanDragItems="{x:Bind AllowItemDrag, Mode=OneWay}"
184184
ContainerContentChanging="FileList_ContainerContentChanging"
185185
DoubleTapped="FileList_DoubleTapped"
186+
DragItemsCompleted="FileList_DragItemsCompleted"
186187
DragItemsStarting="FileList_DragItemsStarting"
187188
DragOver="ItemsLayout_DragOver"
188189
Drop="ItemsLayout_Drop"

src/Files.App/Views/Layouts/DetailsLayoutPage.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@
229229
CanDragItems="{x:Bind AllowItemDrag, Mode=OneWay}"
230230
ContainerContentChanging="FileList_ContainerContentChanging"
231231
DoubleTapped="FileList_DoubleTapped"
232+
DragItemsCompleted="FileList_DragItemsCompleted"
232233
DragItemsStarting="FileList_DragItemsStarting"
233234
DragOver="ItemsLayout_DragOver"
234235
Drop="ItemsLayout_Drop"

src/Files.App/Views/Layouts/GridLayoutPage.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,7 @@
787787
ContainerContentChanging="FileList_ContainerContentChanging"
788788
DoubleTapped="FileList_DoubleTapped"
789789
DragEnter="ItemsLayout_DragEnter"
790+
DragItemsCompleted="FileList_DragItemsCompleted"
790791
DragItemsStarting="FileList_DragItemsStarting"
791792
DragLeave="ItemsLayout_DragLeave"
792793
DragOver="ItemsLayout_DragOver"

0 commit comments

Comments
 (0)