steam-deck-tools/PowerControl/Options/Resolution.cs

90 lines
3.5 KiB
C#
Raw Permalink Normal View History

using PowerControl.Helpers;
using PowerControl.Helpers.AMD;
namespace PowerControl.Options
{
public static class Resolution
{
public static Menu.MenuItemWithOptions Instance = new Menu.MenuItemWithOptions()
{
Name = "Resolution",
PersistentKey = "Resolution",
ApplyDelay = 1000,
ResetValue = () =>
{
if (!GPUScaling.SafeResolutionChange && !Settings.Default.EnableExperimentalFeatures)
return null;
return DisplayResolutionController.GetAllResolutions().Last().ToString();
},
OptionsValues = delegate ()
{
2023-02-09 11:03:41 +01:00
var resolutions = DisplayResolutionController.GetAllResolutions().ToList();
var currentResolution = DisplayResolutionController.GetResolution();
2023-02-09 11:42:50 +01:00
if (currentResolution is not null)
2023-02-09 11:03:41 +01:00
resolutions.Add(currentResolution.Value);
2023-02-09 11:42:50 +01:00
if (ExternalHelpers.DisplayConfig.IsInternalConnected == true)
{
foreach (var displayModeInfo in ModeTiming.AllDetailedTimings())
{
if (currentResolution?.Rotated == true)
{
resolutions.Add(new DisplayResolutionController.DisplayResolution(
displayModeInfo.iPelsHeight, displayModeInfo.iPelsWidth));
}
else
{
resolutions.Add(new DisplayResolutionController.DisplayResolution(
displayModeInfo.iPelsWidth, displayModeInfo.iPelsHeight));
}
}
2023-02-09 11:03:41 +01:00
}
2023-02-09 11:42:50 +01:00
resolutions = resolutions.Distinct().ToList();
resolutions.Sort();
if (resolutions.Count() > 1)
return resolutions.Select(item => item.ToString()).ToArray();
2023-02-09 11:03:41 +01:00
return null;
},
CurrentValue = delegate ()
{
if (!GPUScaling.SafeResolutionChange && !Settings.Default.EnableExperimentalFeatures)
return null;
return DisplayResolutionController.GetResolution().ToString();
},
ApplyValue = (selected) =>
{
var selectedResolution = new DisplayResolutionController.DisplayResolution(selected);
2023-02-09 11:42:50 +01:00
selectedResolution.Rotated = DisplayResolutionController.GetResolution()?.Rotated;
2023-02-08 23:41:08 +01:00
if (ExternalHelpers.DisplayConfig.IsInternalConnected == true)
{
2023-02-09 11:42:50 +01:00
var normalizedResolution = selectedResolution.Normalize();
bool result = ModeTiming.AddTiming(new Helpers.AMD.ADLDisplayModeX2()
2023-02-08 23:41:08 +01:00
{
2023-02-09 11:42:50 +01:00
PelsWidth = normalizedResolution.Width,
PelsHeight = normalizedResolution.Height,
2023-02-08 23:41:08 +01:00
RefreshRate = DisplayResolutionController.GetRefreshRate(),
2023-02-09 11:42:50 +01:00
TimingStandard = Helpers.AMD.ADL.ADL_DL_MODETIMING_STANDARD_CUSTOM,
2023-02-08 23:41:08 +01:00
});
2023-02-09 11:42:50 +01:00
if (result)
Thread.Sleep(500);
2023-02-08 23:41:08 +01:00
}
2023-02-09 00:24:32 +01:00
DisplayResolutionController.SetResolution(selectedResolution);
return DisplayResolutionController.GetResolution().ToString();
},
Impacts =
{
RefreshRate.Instance,
FPSLimit.Instance
}
};
}
}