Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Files.App/Data/Items/WidgetFolderCardItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ public async Task LoadCardThumbnailAsync()
if (string.IsNullOrEmpty(Path))
return;

Item.TryGetThumbnail((int)(Constants.ShellIconSizes.Large * App.AppModel.AppWindowDPI), SIIGBF.SIIGBF_ICONONLY, out var rawThumbnailData);
var thumbnailSize = (int)(Constants.ShellIconSizes.Large * App.AppModel.AppWindowDPI);
// Ensure thumbnail size is at least 1 to prevent layout errors
thumbnailSize = Math.Max(1, thumbnailSize);
Item.TryGetThumbnail(thumbnailSize, SIIGBF.SIIGBF_ICONONLY, out var rawThumbnailData);
if (rawThumbnailData is null)
return;

Expand Down
12 changes: 10 additions & 2 deletions src/Files.App/Data/Models/AppModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,18 @@ public string PCloudDrivePath
/// <summary>
/// Gets or sets a value indicating the AppWindow DPI.
/// </summary>
private float _AppWindowDPI = PInvoke.GetDpiForWindow((HWND)MainWindow.Instance.WindowHandle) / 96f;
private float? _AppWindowDPI = null;
public float AppWindowDPI
{
get => _AppWindowDPI;
get
{
if (_AppWindowDPI is null || _AppWindowDPI == 0f)
{
var dpi = PInvoke.GetDpiForWindow((HWND)MainWindow.Instance.WindowHandle);
_AppWindowDPI = dpi > 0 ? dpi / 96f : 1.0f; // Fallback to 1.0f if invalid DPI
}
return _AppWindowDPI.Value;
}
set => SetProperty(ref _AppWindowDPI, value);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/Utils/Storage/Helpers/FilePropertiesHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ public static void OpenPropertiesWindow(object item, IShellPage associatedInstan
propertiesWindow.Closed += PropertiesWindow_Closed;
}

var width = Convert.ToInt32(800 * App.AppModel.AppWindowDPI);
var height = Convert.ToInt32(500 * App.AppModel.AppWindowDPI);
var width = Math.Max(1, Convert.ToInt32(800 * App.AppModel.AppWindowDPI));
var height = Math.Max(1, Convert.ToInt32(500 * App.AppModel.AppWindowDPI));

propertiesWindow.AppWindow.Resize(new(width, height));
propertiesWindow.IsMinimizable = false;
Expand Down
2 changes: 2 additions & 0 deletions src/Files.App/Utils/Storage/Helpers/FileThumbnailHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public static class FileThumbnailHelper
public static async Task<byte[]?> GetIconAsync(string path, uint requestedSize, bool isFolder, IconOptions iconOptions)
{
var size = iconOptions.HasFlag(IconOptions.UseCurrentScale) ? requestedSize * App.AppModel.AppWindowDPI : requestedSize;
// Ensure size is at least 1 to prevent layout errors
size = Math.Max(1, size);

return await Win32Helper.StartSTATask(() => Win32Helper.GetIcon(path, (int)size, isFolder, iconOptions));
}
Expand Down
Loading