mirror of
https://github.com/ryujinx-mirror/ryujinx.git
synced 2024-12-05 04:57:55 +01:00
57d3296ba4
* infra: Migrate to .NET 6 * Rollback version naming change * Workaround .NET 6 ZipArchive API issues * ci: Switch to VS 2022 for AppVeyor CI is now ready for .NET 6 * Suppress WebClient warning in DoUpdateWithMultipleThreads * Attempt to workaround System.Drawing.Common changes on 6.0.0 * Change keyboard rendering from System.Drawing to ImageSharp * Make the software keyboard renderer multithreaded * Bump ImageSharp version to 1.0.4 to fix a bug in Image.Load * Add fallback fonts to the keyboard renderer * Fix warnings * Address caian's comment * Clean up linux workaround as it's uneeded now * Update readme Co-authored-by: Caian Benedicto <caianbene@gmail.com>
53 lines
1.5 KiB
C#
53 lines
1.5 KiB
C#
using Ryujinx.Common.Logging;
|
|
using System;
|
|
using System.Drawing;
|
|
using System.Runtime.InteropServices;
|
|
using System.Runtime.Versioning;
|
|
|
|
namespace Ryujinx.Common.System
|
|
{
|
|
public static class ForceDpiAware
|
|
{
|
|
[DllImport("user32.dll")]
|
|
private static extern bool SetProcessDPIAware();
|
|
|
|
private static readonly double _standardDpiScale = 96.0;
|
|
private static readonly double _maxScaleFactor = 1.25;
|
|
|
|
/// <summary>
|
|
/// Marks the application as DPI-Aware when running on the Windows operating system.
|
|
/// </summary>
|
|
public static void Windows()
|
|
{
|
|
// Make process DPI aware for proper window sizing on high-res screens.
|
|
if (OperatingSystem.IsWindowsVersionAtLeast(6))
|
|
{
|
|
SetProcessDPIAware();
|
|
}
|
|
}
|
|
|
|
public static double GetWindowScaleFactor()
|
|
{
|
|
double userDpiScale = 96.0;
|
|
|
|
try
|
|
{
|
|
if (OperatingSystem.IsWindows())
|
|
{
|
|
userDpiScale = Graphics.FromHwnd(IntPtr.Zero).DpiX;
|
|
}
|
|
else
|
|
{
|
|
// TODO: Linux support
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Logger.Warning?.Print(LogClass.Application, $"Couldn't determine monitor DPI: {e.Message}");
|
|
}
|
|
|
|
return Math.Min(userDpiScale / _standardDpiScale, _maxScaleFactor);
|
|
}
|
|
}
|
|
}
|