diff --git a/PowerControl/Menu/MenuItemWithOptions.cs b/PowerControl/Menu/MenuItemWithOptions.cs index bb2a55a..5a8485a 100644 --- a/PowerControl/Menu/MenuItemWithOptions.cs +++ b/PowerControl/Menu/MenuItemWithOptions.cs @@ -16,6 +16,7 @@ public class MenuItemWithOptions : MenuItem public Func? CurrentValue { get; set; } public Func? OptionsValues { get; set; } public Func? ApplyValue { get; set; } + public Action? ImpactedBy { get; set; } public Action? AfterApply { get; set; } public Func? ResetValue { get; set; } @@ -114,9 +115,6 @@ private void FinalizeSet() CommonHelpers.Log.TraceException("FinalizeSet", Name, e); Update(); } - - if (AfterApply != null && runAfterApply) - AfterApply(); } else ActiveOption = SelectedOption; @@ -124,7 +122,19 @@ private void FinalizeSet() SelectedOption = null; if (wasOption != ActiveOption && ActiveOption != null) + { + if (AfterApply != null) + AfterApply(); + + foreach (var impact in Impacts) + { + if (impact.ImpactedBy is not null) + impact.ImpactedBy(this, wasOption, ActiveOption); + impact.Update(); + } + ValueChanged(this, wasOption, ActiveOption); + } } public override void CreateMenu(System.Windows.Forms.ContextMenuStrip contextMenu) diff --git a/PowerControl/Options/FPSLimit.cs b/PowerControl/Options/FPSLimit.cs index cca55c2..6ec3d99 100644 --- a/PowerControl/Options/FPSLimit.cs +++ b/PowerControl/Options/FPSLimit.cs @@ -67,6 +67,50 @@ public static class FPSLimit CommonHelpers.Log.TraceException("RTSS", e); } return null; + }, + ImpactedBy = (option, was, isNow) => + { + if (Instance is null) + return; + + try + { + if (!Dependencies.EnsureRTSS(null)) + return; + + var refreshRate = DisplayResolutionController.GetRefreshRate(); + if (refreshRate <= 0) + return; + + RTSS.LoadProfile(); + RTSS.GetProfileProperty("FramerateLimit", out int fpsLimit); + if (fpsLimit == 0) + return; + + // FPSLimit, RR => outcome + // 50 + 60 => 60 (div 1) + // 25 + 60 => 30 (div 2) + // 10 + 60 => 15 (div 6) + // 60 + 50 => 50 (div 0) + // 50 + 40 => 40 (div 0) + // 60 + 30 => 30 (div 0) + int div = refreshRate / fpsLimit; + if (div >= 4) + fpsLimit = refreshRate / 4; + else if (div >= 2) + fpsLimit = refreshRate / 2; + else + fpsLimit = refreshRate; + RTSS.SetProfileProperty("FramerateLimit", fpsLimit); + RTSS.SaveProfile(); + RTSS.UpdateProfiles(); + } + catch (Exception e) + { +#if DEBUG + CommonHelpers.Log.TraceException("RTSS", e); +#endif + } } }; } diff --git a/PowerControl/Options/GPUScalingItem.cs b/PowerControl/Options/GPUScalingItem.cs index eb4ed6d..983f28e 100644 --- a/PowerControl/Options/GPUScalingItem.cs +++ b/PowerControl/Options/GPUScalingItem.cs @@ -40,13 +40,6 @@ public static class GPUScalingItem Resolution.Instance, RefreshRate.Instance, FPSLimit.Instance - }, - AfterApply = () => - { - Resolution.Instance.Update(); - RefreshRate.Instance.Update(); - FPSLimit.Instance.Reset(); - FPSLimit.Instance.Update(); } }; } diff --git a/PowerControl/Options/RefreshRate.cs b/PowerControl/Options/RefreshRate.cs index a607342..118116e 100644 --- a/PowerControl/Options/RefreshRate.cs +++ b/PowerControl/Options/RefreshRate.cs @@ -31,12 +31,6 @@ public static class RefreshRate Impacts = { FPSLimit.Instance - }, - AfterApply = () => - { - // force reset and refresh of FPS limit - FPSLimit.Instance.Reset(); - FPSLimit.Instance.Update(); } }; } diff --git a/PowerControl/Options/Resolution.cs b/PowerControl/Options/Resolution.cs index a212542..43d2a81 100644 --- a/PowerControl/Options/Resolution.cs +++ b/PowerControl/Options/Resolution.cs @@ -39,14 +39,6 @@ public static class Resolution { RefreshRate.Instance, FPSLimit.Instance - }, - AfterApply = () => - { - // force refresh Refresh Rate - RefreshRate.Instance.Update(); - // force reset and refresh of FPS limit - FPSLimit.Instance.Reset(); - FPSLimit.Instance.Update(); } }; } diff --git a/RELEASE.md b/RELEASE.md index 37371a8..12ceb7f 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -9,6 +9,7 @@ ## 0.6.x +- PowerControl: Retain FPS Limit (proportion) on refresh rate change - PowerControl: Support RTSS in custom folder - SteamController: Fix Steam Big Picture detection for non-english - PowerControl: Allow user to configure selectable TDP, CPU and GPU from `PowerControl.dll.ini`