Skip to content

Commit 42e0fa6

Browse files
authored
Fix: Use correct DPI settings when requesting icons (#14779)
1 parent cc32782 commit 42e0fa6

File tree

21 files changed

+40
-31
lines changed

21 files changed

+40
-31
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ public int CompareTo(INavigationControlItem other)
317317
public async Task LoadThumbnailAsync()
318318
{
319319
if (!string.IsNullOrEmpty(DeviceID) && !string.Equals(DeviceID, "network-folder"))
320-
IconData ??= await FileThumbnailHelper.LoadIconWithoutOverlayAsync(DeviceID, Constants.ShellIconSizes.Large, false, false, true);
320+
IconData ??= await FileThumbnailHelper.LoadIconWithoutOverlayAsync(DeviceID, Constants.ShellIconSizes.Small, false, false, true, true);
321321

322322
if (Root is not null)
323323
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public async Task<bool> CheckDefaultSaveFolderAccess()
4646

4747
public async Task LoadLibraryIconAsync()
4848
{
49-
IconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Path, Constants.ShellIconSizes.Large, false, false, true);
49+
IconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Path, Constants.ShellIconSizes.Small, false, false, true, true);
5050

5151
if (IconData is not null)
5252
Icon = await IconData.ToBitmapAsync();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public WidgetDriveCardItem(DriveItem item)
2626

2727
public async Task LoadCardThumbnailAsync()
2828
{
29-
thumbnailData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Item.Path, Constants.ShellIconSizes.Jumbo, true, false, true);
29+
thumbnailData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Item.Path, Constants.ShellIconSizes.Large, true, false, true, true);
3030

3131
// Thumbnail data is valid, set the item icon
3232
if (thumbnailData is not null && thumbnailData.Length > 0)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public WidgetFolderCardItem(LocationItem item, string text, bool isPinned)
5050

5151
public async Task LoadCardThumbnailAsync()
5252
{
53-
_thumbnailData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Path, Constants.ShellIconSizes.Jumbo, true, false, true);
53+
_thumbnailData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Path, Constants.ShellIconSizes.Large, true, false, true, true);
5454

5555
if (_thumbnailData is not null && _thumbnailData.Length > 0)
5656
Thumbnail = await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(() => _thumbnailData.ToBitmapAsync(), Microsoft.UI.Dispatching.DispatcherQueuePriority.Low);

src/Files.App/Data/Models/AppModel.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,13 @@ public string PCloudDrivePath
116116
get => pCloudDrivePath;
117117
set => SetProperty(ref pCloudDrivePath, value);
118118
}
119+
120+
/// <summary>
121+
/// Gets or sets a value indicating the AppWindow DPI.
122+
/// </summary>
123+
public float AppWindowDpi
124+
{
125+
get => InteropHelpers.GetDpiForWindow(MainWindow.Instance.WindowHandle) / 96f;
126+
}
119127
}
120128
}

src/Files.App/Data/Models/ItemViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,7 @@ await SafetyExtensions.IgnoreExceptions(() =>
12881288
ImageSource? groupImage = null;
12891289
if (item.PrimaryItemAttribute != StorageItemTypes.Folder || item.IsArchive)
12901290
{
1291-
var headerIconInfo = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(item.ItemPath, Constants.ShellIconSizes.ExtraLarge, false, false, true);
1291+
var headerIconInfo = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(item.ItemPath, Constants.ShellIconSizes.Large, false, false, true, true);
12921292

12931293
if (headerIconInfo is not null && !item.IsShortcut)
12941294
groupImage = await dispatcherQueue.EnqueueOrInvokeAsync(() => headerIconInfo.ToBitmapAsync(), Microsoft.UI.Dispatching.DispatcherQueuePriority.Low);

src/Files.App/Data/Models/SidebarPinnedModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public async Task<LocationItem> CreateLocationItemFromPathAsync(string path)
102102
locationItem.IsInvalid = false;
103103
if (res && res.Result is not null)
104104
{
105-
var iconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(res.Result.Path, 28u, true, false, true);
105+
var iconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(res.Result.Path, Constants.ShellIconSizes.Small, true, false, true, true);
106106
locationItem.IconData = iconData;
107107

108108
if (locationItem.IconData is not null)

src/Files.App/Helpers/Interop/InteropHelpers.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public static class InteropHelpers
3232
[DllImport("user32.dll", SetLastError = true)]
3333
public static extern void SwitchToThisWindow(IntPtr hWnd, bool altTab);
3434

35+
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
36+
public static extern int GetDpiForWindow(IntPtr hwnd);
37+
3538
[DllImport("ole32.dll")]
3639
public static extern uint CoWaitForMultipleObjects(uint dwFlags, uint dwMilliseconds, ulong nHandles, IntPtr[] pHandles, out uint dwIndex);
3740

src/Files.App/Helpers/Navigation/NavigationHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ private static async Task UpdateTabInfoAsync(TabBarItem tabItem, object navigati
188188

189189
if (iconSource.ImageSource is null)
190190
{
191-
var iconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(currentPath, 28u, true, false, true);
191+
var iconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(currentPath, Constants.ShellIconSizes.Small, true, false, true, true);
192192
if (iconData is not null)
193193
iconSource.ImageSource = await iconData.ToBitmapAsync();
194194
}

src/Files.App/UserControls/Widgets/DrivesWidget.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
<Image
6363
Grid.RowSpan="3"
6464
Grid.Column="0"
65+
Width="32"
66+
Height="32"
6567
HorizontalAlignment="Center"
6668
VerticalAlignment="Center"
6769
x:Phase="1"

0 commit comments

Comments
 (0)