Skip to content

Commit c756aca

Browse files
committed
Init
1 parent b8f9029 commit c756aca

File tree

11 files changed

+121
-105
lines changed

11 files changed

+121
-105
lines changed

.github/NOTICE.md

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -199,35 +199,6 @@ The above copyright notice and this permission notice shall be included in all c
199199
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
200200
```
201201

202-
## INI File Parser
203-
204-
**Source**: [https://github.com/rickyah/ini-parser](https://github.com/rickyah/ini-parser)
205-
206-
### License
207-
208-
```
209-
The MIT License (MIT)
210-
211-
Copyright (c) 2008 Ricardo Amores Hernández
212-
213-
Permission is hereby granted, free of charge, to any person obtaining a copy of
214-
this software and associated documentation files (the "Software"), to deal in
215-
the Software without restriction, including without limitation the rights to
216-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
217-
the Software, and to permit persons to whom the Software is furnished to do so,
218-
subject to the following conditions:
219-
220-
The above copyright notice and this permission notice shall be included in all
221-
copies or substantial portions of the Software.
222-
223-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
224-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
225-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
226-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
227-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
228-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
229-
```
230-
231202
## SevenZipSharp
232203

233204
**Source**: [https://github.com/files-community/SevenZipSharp](https://github.com/files-community/SevenZipSharp)
@@ -675,36 +646,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
675646
SOFTWARE.
676647
```
677648

678-
## WinUIEx
679-
680-
**Source**: [https://github.com/dotMorten/WinUIEx](https://github.com/dotMorten/WinUIEx)
681-
682-
### License
683-
684-
```
685-
MIT License
686-
687-
Copyright (c) 2021 Morten Nielsen
688-
689-
Permission is hereby granted, free of charge, to any person obtaining a copy
690-
of this software and associated documentation files (the "Software"), to deal
691-
in the Software without restriction, including without limitation the rights
692-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
693-
copies of the Software, and to permit persons to whom the Software is
694-
furnished to do so, subject to the following conditions:
695-
696-
The above copyright notice and this permission notice shall be included in all
697-
copies or substantial portions of the Software.
698-
699-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
700-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
701-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
702-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
703-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
704-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
705-
SOFTWARE.
706-
```
707-
708649
## libgit2sharp
709650

710651
**Source**: [https://github.com/libgit2/libgit2sharp](https://github.com/libgit2/libgit2sharp)
@@ -762,4 +703,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
762703
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
763704
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
764705
DEALINGS IN THE SOFTWARE.
765-
```
706+
```
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) 2024 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4-
using CommunityToolkit.Mvvm.ComponentModel;
54
using Microsoft.UI.Windowing;
65

76
namespace Files.App.Data.Contexts
@@ -13,15 +12,18 @@ internal sealed class WindowContext : ObservableObject, IWindowContext
1312

1413
public WindowContext()
1514
{
16-
MainWindow.Instance.PresenterChanged += Window_PresenterChanged;
15+
MainWindow.Instance.AppWindow.Changed += AppWindow_Changed;
1716
}
1817

19-
private void Window_PresenterChanged(object? sender, AppWindowPresenter e)
18+
private void AppWindow_Changed(AppWindow sender, AppWindowChangedEventArgs args)
2019
{
21-
SetProperty(
22-
ref isCompactOverlay,
23-
e.Kind is AppWindowPresenterKind.CompactOverlay,
24-
nameof(IsCompactOverlay));
20+
if (args.DidPresenterChange)
21+
{
22+
SetProperty(
23+
ref isCompactOverlay,
24+
sender.Presenter.Kind is AppWindowPresenterKind.CompactOverlay,
25+
nameof(IsCompactOverlay));
26+
}
2527
}
2628
}
2729
}

src/Files.App/Data/Items/WindowEx.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) 2024 Files Community
2+
// Licensed under the MIT License. See the LICENSE.
3+
4+
using Microsoft.UI.Xaml;
5+
using System.Runtime.InteropServices;
6+
using Windows.Win32;
7+
using Windows.Win32.Foundation;
8+
using Windows.Win32.UI.WindowsAndMessaging;
9+
10+
namespace Files.App.Data.Items
11+
{
12+
public unsafe class WindowEx : Window
13+
{
14+
private WNDPROC* _oldWndProc = default;
15+
16+
public int MinWidth = 400;
17+
public int MinHeight = 300;
18+
19+
public unsafe WindowEx()
20+
{
21+
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
22+
WNDPROC newWndProc = new(NewWindowProc);
23+
_oldWndProc = (WNDPROC*)PInvoke.SetWindowLongPtr(new(hWnd), WINDOW_LONG_PTR_INDEX.GWL_WNDPROC, new(&newWndProc));
24+
}
25+
26+
private LRESULT NewWindowProc(HWND param0, uint param1, WPARAM param2, LPARAM param3)
27+
{
28+
switch (param1)
29+
{
30+
case 0x0024: /*WM_GETMINMAXINFO*/
31+
{
32+
var dpi = PInvoke.GetDpiForWindow(new(param0));
33+
float scalingFactor = (float)dpi / 96;
34+
35+
MINMAXINFO minMaxInfo = Marshal.PtrToStructure<MINMAXINFO>(param3);
36+
minMaxInfo.ptMinTrackSize.X = (int)(MinWidth * scalingFactor);
37+
minMaxInfo.ptMinTrackSize.Y = (int)(MinHeight * scalingFactor);
38+
Marshal.StructureToPtr(minMaxInfo, param3, true);
39+
break;
40+
}
41+
}
42+
43+
return PInvoke.CallWindowProc(*_oldWndProc, param0, param1, param2, param3);
44+
}
45+
}
46+
}

src/Files.App/Files.App.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@
8585
<PackageReference Include="CommunityToolkit.WinUI.UI.Controls" Version="7.1.2" />
8686
<PackageReference Include="TagLibSharp" Version="2.3.0" />
8787
<PackageReference Include="Tulpep.ActiveDirectoryObjectPicker" Version="3.0.11" />
88-
<PackageReference Include="WinUIEx" Version="2.3.4" />
8988
<PackageReference Include="Vanara.Windows.Extensions" Version="4.0.1" />
9089
<PackageReference Include="Vanara.Windows.Shell" Version="4.0.1" />
9190
<PackageReference Include="Microsoft.Management.Infrastructure" Version="3.0.0" />

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
// Licensed under the MIT License. See the LICENSE.
33

44
using Microsoft.UI.Input;
5+
using Microsoft.UI.Windowing;
56
using Microsoft.UI.Xaml;
67
using System.Reflection;
8+
using System.Runtime.InteropServices;
79
using Vanara.PInvoke;
10+
using Windows.Graphics;
811
using Windows.Win32;
912
using Windows.Win32.UI.WindowsAndMessaging;
1013
using static Vanara.PInvoke.User32;
@@ -75,5 +78,26 @@ public static IntPtr SetWindowLong(HWND hWnd, WindowLongFlags nIndex, IntPtr dwN
7578
? Win32PInvoke.SetWindowLongPtr32(hWnd, nIndex, dwNewLong)
7679
: Win32PInvoke.SetWindowLongPtr64(hWnd, nIndex, dwNewLong);
7780
}
81+
82+
public static void UpdateOverlappedPresenter(Window window, Action<OverlappedPresenter> action)
83+
{
84+
ArgumentNullException.ThrowIfNull(window);
85+
86+
var appWindow = window.AppWindow;
87+
if (appWindow.Presenter is OverlappedPresenter overlapped)
88+
action(overlapped);
89+
else
90+
throw new NotSupportedException($"Not supported with a {appWindow.Presenter.Kind} presenter");
91+
}
92+
93+
public static void SetIsMaximizableWindow(Window window, bool maximizable)
94+
{
95+
UpdateOverlappedPresenter(window, (c) => c.IsMaximizable = maximizable);
96+
}
97+
98+
public static void SetIsMinimizableWindow(Window window, bool minimizable)
99+
{
100+
UpdateOverlappedPresenter(window, (c) => c.IsMinimizable = minimizable);
101+
}
78102
}
79103
}

src/Files.App/Helpers/Win32/Win32PInvoke.Methods.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) 2024 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4+
using Microsoft.UI;
45
using System.IO;
56
using System.Runtime.InteropServices;
67
using System.Runtime.InteropServices.ComTypes;
@@ -511,6 +512,11 @@ static extern int SHGetKnownFolderPath(
511512
out IntPtr pszPath
512513
);
513514

515+
[DllImport("Microsoft.Internal.FrameworkUdk.dll", EntryPoint = "Windowing_GetWindowHandleFromWindowId", CharSet = CharSet.Unicode)]
516+
private static extern IntPtr GetWindowHandleFromWindowId(
517+
WindowId windowId,
518+
out nint result);
519+
514520
public static string GetFolderFromKnownFolderGUID(Guid guid)
515521
{
516522
IntPtr pPath;

src/Files.App/MainWindow.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<!-- Copyright (c) 2024 Files Community. Licensed under the MIT License. See the LICENSE. -->
2-
<winuiex:WindowEx
2+
<items:WindowEx
33
x:Class="Files.App.MainWindow"
44
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
55
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
66
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:items="using:Files.App.Data.Items"
78
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8-
xmlns:winuiex="using:WinUIEx"
99
mc:Ignorable="d" />

src/Files.App/MainWindow.xaml.cs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
// Copyright (c) 2024 Files Community
1+
// Copyright (c) 2024 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

44
using Microsoft.UI;
55
using Microsoft.UI.Windowing;
66
using Microsoft.UI.Xaml.Controls;
77
using Microsoft.UI.Xaml.Media.Animation;
88
using Microsoft.UI.Xaml.Navigation;
9+
using System.Runtime.InteropServices;
910
using Windows.ApplicationModel.Activation;
1011
using Windows.Storage;
11-
using WinUIEx;
12+
using Windows.Win32;
13+
using Windows.Win32.UI.WindowsAndMessaging;
14+
using static Vanara.PInvoke.User32;
1215
using IO = System.IO;
1316

1417
namespace Files.App
@@ -18,38 +21,31 @@ public sealed partial class MainWindow : WindowEx
1821
private static MainWindow? _Instance;
1922
public static MainWindow Instance => _Instance ??= new();
2023

21-
public IntPtr WindowHandle { get; }
24+
public nint WindowHandle { get; }
2225

23-
private MainWindow()
26+
public MainWindow()
2427
{
25-
WindowHandle = this.GetWindowHandle();
26-
2728
InitializeComponent();
2829

29-
EnsureEarlyWindow();
30-
}
31-
32-
private void EnsureEarlyWindow()
33-
{
34-
// Set PersistenceId
35-
PersistenceId = "FilesMainWindow";
36-
37-
// Set minimum sizes
38-
MinHeight = 416;
39-
MinWidth = 516;
30+
WindowHandle = WinRT.Interop.WindowNative.GetWindowHandle(this);
31+
ExtendsContentIntoTitleBar = true;
32+
Title = "Files";
4033

41-
AppWindow.Title = "Files";
42-
AppWindow.SetIcon(AppLifecycleHelper.AppIconPath);
43-
AppWindow.TitleBar.ExtendsContentIntoTitleBar = true;
4434
AppWindow.TitleBar.ButtonBackgroundColor = Colors.Transparent;
4535
AppWindow.TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
36+
AppWindow.TitleBar.ButtonPressedBackgroundColor = Colors.Transparent;
37+
AppWindow.TitleBar.ButtonHoverBackgroundColor = Colors.Transparent;
38+
AppWindow.SetIcon(AppLifecycleHelper.AppIconPath);
39+
40+
MinHeight = 550;
41+
MinWidth = 460;
4642

4743
// Workaround for full screen window messing up the taskbar
4844
// https://github.com/microsoft/microsoft-ui-xaml/issues/8431
4945
// This property should only be set if the "Automatically hide the taskbar" in Windows 11,
5046
// or "Automatically hide the taskbar in desktop mode" in Windows 10 is enabled.
5147
// Setting this property when the setting is disabled will result in the taskbar overlapping the application
52-
if (AppLifecycleHelper.IsAutoHideTaskbarEnabled())
48+
if (AppLifecycleHelper.IsAutoHideTaskbarEnabled())
5349
Win32PInvoke.SetPropW(WindowHandle, "NonRudeHWND", new IntPtr(1));
5450
}
5551

@@ -205,7 +201,7 @@ public async Task InitializeApplicationAsync(object activatedEventArgs)
205201
}
206202

207203
if (Windows.Win32.PInvoke.IsIconic(new(WindowHandle)))
208-
Instance.Restore(); // Restore window if minimized
204+
AppWindow.MoveInZOrderAtTop(); // Restore window if minimized
209205
}
210206

211207
public Frame EnsureWindowIsInitialized()

src/Files.App/NativeMethods.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,8 @@ DesktopWallpaper
9494
SHCreateShellItemArrayFromIDLists
9595
ILCreateFromPath
9696
CLSIDFromString
97+
SetWindowLongPtr
98+
GetDpiForWindow
99+
CallWindowProc
100+
MINMAXINFO
101+
SUBCLASSPROC

src/Files.App/Utils/Storage/Helpers/FilePropertiesHelpers.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using Microsoft.UI.Xaml.Media.Animation;
1010
using Microsoft.Windows.ApplicationModel.Resources;
1111
using System.Collections.Concurrent;
12-
using Windows.ApplicationModel;
1312
using Windows.Graphics;
1413
using Windows.Win32;
1514

@@ -37,7 +36,7 @@ public static nint GetWindowHandle(Window w)
3736
=> WinRT.Interop.WindowNative.GetWindowHandle(w);
3837

3938
private static TaskCompletionSource? PropertiesWindowsClosingTCS;
40-
private static readonly BlockingCollection<WinUIEx.WindowEx> WindowCache = [];
39+
private static readonly BlockingCollection<WindowEx> WindowCache = [];
4140

4241
/// <summary>
4342
/// Open properties window
@@ -99,22 +98,21 @@ public static void OpenPropertiesWindow(object item, IShellPage associatedInstan
9998

10099
var frame = new Frame
101100
{
102-
RequestedTheme = (ElementTheme)AppThemeModeService.AppThemeMode
101+
RequestedTheme = AppThemeModeService.AppThemeMode
103102
};
104103

105-
WinUIEx.WindowEx propertiesWindow;
106-
if (!WindowCache.TryTake(out propertiesWindow!))
104+
if (!WindowCache.TryTake(out var propertiesWindow))
107105
{
108106
propertiesWindow = new();
109107
propertiesWindow.Closed += PropertiesWindow_Closed;
110108
}
111109

112-
propertiesWindow.IsMinimizable = false;
113-
propertiesWindow.IsMaximizable = false;
114-
propertiesWindow.MinWidth = 460;
110+
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(propertiesWindow);
111+
Win32Helper.SetIsMaximizableWindow(propertiesWindow, false);
112+
Win32Helper.SetIsMinimizableWindow(propertiesWindow, false);
115113
propertiesWindow.MinHeight = 550;
116-
propertiesWindow.Width = 800;
117-
propertiesWindow.Height = 550;
114+
propertiesWindow.MinWidth = 460;
115+
propertiesWindow.AppWindow.Resize(new(800, 550));
118116
propertiesWindow.Content = frame;
119117
propertiesWindow.SystemBackdrop = new AppSystemBackdrop(true);
120118

@@ -127,7 +125,7 @@ public static void OpenPropertiesWindow(object item, IShellPage associatedInstan
127125
appWindow.SetIcon(AppLifecycleHelper.AppIconPath);
128126

129127
frame.Navigate(
130-
typeof(Views.Properties.MainPropertiesPage),
128+
typeof(MainPropertiesPage),
131129
new PropertiesPageNavigationParameter
132130
{
133131
Parameter = item,
@@ -160,7 +158,7 @@ public static void OpenPropertiesWindow(object item, IShellPage associatedInstan
160158
// So instead of destroying the Window object, cache it and reuse it as a workaround.
161159
private static void PropertiesWindow_Closed(object sender, WindowEventArgs args)
162160
{
163-
if (!App.AppModel.IsMainWindowClosed && sender is WinUIEx.WindowEx window)
161+
if (!App.AppModel.IsMainWindowClosed && sender is WindowEx window)
164162
{
165163
args.Handled = true;
166164

0 commit comments

Comments
 (0)