steam-deck-tools/PowerControl/MenuStack.cs

463 lines
20 KiB
C#
Raw Normal View History

using CommonHelpers;
2022-11-18 21:00:52 +01:00
using PowerControl.Helpers;
using PowerControl.Helpers.AMD;
using System.Diagnostics;
using static PowerControl.Helpers.AMD.DCE;
namespace PowerControl
{
internal class MenuStack
{
public static Menu.MenuRoot Root = new Menu.MenuRoot()
{
Name = String.Format("\r\n\r\nPower Control v{0}\r\n", Application.ProductVersion.ToString()),
Items =
{
new Menu.MenuItemWithOptions()
{
Name = "Brightness",
Options = { 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100 },
2022-11-19 09:29:44 +01:00
CycleOptions = false,
CurrentValue = delegate()
{
2022-11-18 15:56:44 +01:00
return Helpers.WindowsSettingsBrightnessController.Get(5.0);
},
ApplyValue = delegate(object selected)
{
Helpers.WindowsSettingsBrightnessController.Set((int)selected);
2022-11-18 15:56:44 +01:00
return Helpers.WindowsSettingsBrightnessController.Get(5.0);
}
},
new Menu.MenuItemWithOptions()
{
Name = "Volume",
Options = { 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100 },
2022-11-19 09:29:44 +01:00
CycleOptions = false,
CurrentValue = delegate()
{
2022-11-18 15:56:44 +01:00
return Helpers.AudioManager.GetMasterVolume(5.0);
},
ApplyValue = delegate(object selected)
{
Helpers.AudioManager.SetMasterVolumeMute(false);
Helpers.AudioManager.SetMasterVolume((int)selected);
2022-11-18 15:56:44 +01:00
return Helpers.AudioManager.GetMasterVolume(5.0);
}
},
new Menu.MenuItemSeparator(),
new Menu.MenuItemWithOptions()
2022-11-18 15:20:35 +01:00
{
Name = "Resolution",
ApplyDelay = 1000,
ResetValue = () => {
if (!GPUScaling.SafeResolutionChange && !Settings.Default.EnableExperimentalFeatures)
return null;
return DisplayResolutionController.GetAllResolutions().Last();
},
2022-11-18 15:20:35 +01:00
OptionsValues = delegate()
{
var resolutions = DisplayResolutionController.GetAllResolutions();
2022-11-18 15:20:35 +01:00
if (resolutions.Count() > 1)
return resolutions.Select(item => (object)item).ToArray();
return null;
},
CurrentValue = delegate()
{
if (!GPUScaling.SafeResolutionChange && !Settings.Default.EnableExperimentalFeatures)
return null;
return DisplayResolutionController.GetResolution();
2022-11-18 15:20:35 +01:00
},
ApplyValue = delegate(object selected)
{
DisplayResolutionController.SetResolution((DisplayResolutionController.DisplayResolution)selected);
// force refresh Refresh Rate
Root["Refresh Rate"].Update();
// force reset and refresh of FPS limit
Root["FPS Limit"].Reset();
Root["FPS Limit"].Update();
return DisplayResolutionController.GetResolution();
2022-11-18 15:20:35 +01:00
}
},
new Menu.MenuItemWithOptions()
{
Name = "Refresh Rate",
ApplyDelay = 1000,
ResetValue = () => { return DisplayResolutionController.GetRefreshRates().Max(); },
OptionsValues = delegate()
{
var refreshRates = DisplayResolutionController.GetRefreshRates();
if (refreshRates.Count() > 1)
return refreshRates.Select(item => (object)item).ToArray();
return null;
},
CurrentValue = delegate()
{
return DisplayResolutionController.GetRefreshRate();
},
ApplyValue = delegate(object selected)
{
DisplayResolutionController.SetRefreshRate((int)selected);
// force reset and refresh of FPS limit
Root["FPS Limit"].Reset();
Root["FPS Limit"].Update();
return DisplayResolutionController.GetRefreshRate();
}
},
new Menu.MenuItemWithOptions()
2022-11-16 20:38:45 +01:00
{
Name = "FPS Limit",
ApplyDelay = 500,
2022-11-18 16:14:29 +01:00
ResetValue = () => { return "Off"; },
2022-11-16 20:38:45 +01:00
OptionsValues = delegate()
{
var refreshRate = DisplayResolutionController.GetRefreshRate();
2022-11-16 20:38:45 +01:00
return new object[]
{
2022-11-19 09:29:44 +01:00
refreshRate / 4, refreshRate / 2, refreshRate, "Off"
2022-11-16 20:38:45 +01:00
};
},
CurrentValue = delegate()
{
try
{
RTSS.LoadProfile();
if (RTSS.GetProfileProperty("FramerateLimit", out int framerate))
return (framerate == 0) ? "Off" : framerate;
}
catch
{
}
return null;
},
ApplyValue = delegate(object selected)
{
try
{
int framerate = 0;
if (selected != null && selected.ToString() != "Off")
framerate = (int)selected;
RTSS.LoadProfile();
if (!RTSS.SetProfileProperty("FramerateLimit", framerate))
return null;
if (!RTSS.GetProfileProperty("FramerateLimit", out framerate))
return null;
RTSS.SaveProfile();
RTSS.UpdateProfiles();
return (framerate == 0) ? "Off" : framerate;
}
catch
{
}
return null;
}
},
new Menu.MenuItemWithOptions()
{
Name = "GPU Scaling",
ApplyDelay = 1000,
Options = Enum.GetValues<GPUScaling.ScalingMode>().Cast<object>().Prepend("Off").ToArray(),
CurrentValue = delegate()
{
if (!GPUScaling.IsSupported)
return null;
if (!GPUScaling.Enabled)
return "Off";
return GPUScaling.Mode;
},
ApplyValue = delegate(object selected)
{
if (!GPUScaling.IsSupported)
return null;
if (selected is GPUScaling.ScalingMode)
GPUScaling.Mode = (GPUScaling.ScalingMode)selected;
else
GPUScaling.Enabled = false;
// Since the RadeonSoftware will try to revert values
RadeonSoftware.Kill();
Root["Resolution"].Update();
Root["Refresh Rate"].Update();
Root["FPS Limit"].Reset();
Root["FPS Limit"].Update();
if (!GPUScaling.Enabled)
return "Off";
return GPUScaling.Mode;
}
},
new Menu.MenuItemWithOptions()
2022-11-24 01:03:50 +01:00
{
Name = "Sharpening",
ApplyDelay = 500,
Options = { "Off", "On" },
CurrentValue = delegate()
{
var value = ImageSharpening.Enabled;
if (value is null)
return null;
return value.Value ? "On" : "Off";
},
ApplyValue = delegate(object selected)
{
ImageSharpening.Enabled = (string)selected == "On";
var value = ImageSharpening.Enabled;
if (value is null)
return null;
return value.Value ? "On" : "Off";
}
},
new Menu.MenuItemWithOptions()
{
Name = "Colors",
ApplyDelay = 1000,
Options = Enum.GetValues<DCE.Mode>().Cast<object>().ToList(),
CurrentValue = delegate()
{
return DCE.Current;
},
ApplyValue = delegate(object selected)
{
if (DCE.Current is null)
return null;
DCE.Current = (DCE.Mode)selected;
RadeonSoftware.Kill();
return DCE.Current;
}
},
new Menu.MenuItemSeparator(),
new Menu.MenuItemWithOptions()
{
Name = "TDP",
Options = { "3W", "4W", "5W", "6W", "7W", "8W", "10W", "12W", "15W" },
ApplyDelay = 1000,
ResetValue = () => { return "15W"; },
ActiveOption = "?",
ApplyValue = delegate(object selected)
{
uint mW = uint.Parse(selected.ToString().Replace("W", "")) * 1000;
if (VangoghGPU.IsSupported)
{
return Instance.WithGlobalMutex<object>(200, () =>
{
using (var sd = VangoghGPU.Open())
{
if (sd is null)
return null;
sd.SlowTDP = mW;
sd.FastTDP = mW;
}
return selected;
});
}
else
{
uint stampLimit = mW/10;
Process.Start(new ProcessStartInfo()
{
FileName = "Resources/RyzenAdj/ryzenadj.exe",
ArgumentList = {
"--stapm-limit=" + stampLimit.ToString(),
"--slow-limit=" + mW.ToString(),
"--fast-limit=" + mW.ToString(),
},
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = false,
CreateNoWindow = true
});
return selected;
}
}
},
new Menu.MenuItemWithOptions()
{
2022-11-20 19:00:53 +01:00
Name = "GPU",
Options = { "Default", "400MHz", "800MHz", "1200MHz", "1600MHz" },
ApplyDelay = 1000,
Visible = VangoghGPU.IsSupported,
ActiveOption = "?",
2022-11-20 19:00:53 +01:00
ResetValue = () => { return "Default"; },
ApplyValue = delegate(object selected)
{
return Instance.WithGlobalMutex<object>(200, () =>
2022-11-15 22:30:59 +01:00
{
using (var sd = VangoghGPU.Open())
2022-11-20 19:00:53 +01:00
{
if (sd is null)
return null;
if (selected.ToString() == "Default")
{
sd.HardMinGfxClock = 200;
return selected;
}
sd.HardMinGfxClock = uint.Parse(selected.ToString().Replace("MHz", ""));
2022-11-20 19:00:53 +01:00
return selected;
}
});
}
},
new Menu.MenuItemWithOptions()
{
2022-11-20 19:00:53 +01:00
Name = "CPU",
Options = { "Default", "Power-Save", "Balanced", "Max" },
ApplyDelay = 1000,
ActiveOption = "?",
Visible = VangoghGPU.IsSupported,
2022-11-20 19:00:53 +01:00
ResetValue = () => { return "Default"; },
ApplyValue = delegate(object selected)
{
return Instance.WithGlobalMutex<object>(200, () =>
{
using (var sd = VangoghGPU.Open())
2022-11-20 19:00:53 +01:00
{
if (sd is null)
return null;
2022-11-20 19:00:53 +01:00
switch(selected.ToString())
{
case "Default":
sd.MinCPUClock = 1400;
sd.MaxCPUClock = 3500;
break;
2022-11-20 19:00:53 +01:00
case "Power-Save":
sd.MinCPUClock = 1400;
sd.MaxCPUClock = 1800;
break;
2022-11-20 19:00:53 +01:00
case "Balanced":
sd.MinCPUClock = 2200;
sd.MaxCPUClock = 2800;
break;
2022-11-20 19:00:53 +01:00
case "Max":
sd.MinCPUClock = 3000;
sd.MaxCPUClock = 3500;
break;
default:
return null;
}
return selected;
2022-11-20 19:00:53 +01:00
}
});
}
},
2022-11-18 21:00:52 +01:00
new Menu.MenuItemWithOptions()
{
Name = "SMT",
ApplyDelay = 500,
Options = { "No", "Yes" },
ResetValue = () => { return "Yes"; },
CurrentValue = delegate()
{
if (!RTSS.IsOSDForeground(out var processId))
return null;
if (!ProcessorCores.HasSMTThreads())
return null;
return ProcessorCores.IsUsingSMT(processId.Value) ? "Yes" : "No";
},
ApplyValue = delegate(object selected)
{
if (!RTSS.IsOSDForeground(out var processId))
return null;
if (!ProcessorCores.HasSMTThreads())
return null;
ProcessorCores.SetProcessSMT(processId.Value, selected.ToString() == "Yes");
return ProcessorCores.IsUsingSMT(processId.Value) ? "Yes" : "No";
}
},
new Menu.MenuItemSeparator(),
new Menu.MenuItemWithOptions()
{
Name = "OSD",
ApplyDelay = 500,
OptionsValues = delegate()
{
return Enum.GetValues<OverlayEnabled>().Select(item => (object)item).ToArray();
},
CurrentValue = delegate()
{
if (SharedData<OverlayModeSetting>.GetExistingValue(out var value))
return value.CurrentEnabled;
return null;
},
ApplyValue = delegate(object selected)
{
if (!SharedData<OverlayModeSetting>.GetExistingValue(out var value))
return null;
value.DesiredEnabled = (OverlayEnabled)selected;
if (!SharedData<OverlayModeSetting>.SetExistingValue(value))
return null;
return selected;
}
},
new Menu.MenuItemWithOptions()
{
Name = "OSD Mode",
ApplyDelay = 500,
OptionsValues = delegate()
{
return Enum.GetValues<OverlayMode>().Select(item => (object)item).ToArray();
},
CurrentValue = delegate()
{
if (SharedData<OverlayModeSetting>.GetExistingValue(out var value))
return value.Current;
return null;
},
ApplyValue = delegate(object selected)
{
if (!SharedData<OverlayModeSetting>.GetExistingValue(out var value))
return null;
value.Desired = (OverlayMode)selected;
if (!SharedData<OverlayModeSetting>.SetExistingValue(value))
return null;
return selected;
}
},
new Menu.MenuItemWithOptions()
{
Name = "FAN",
ApplyDelay = 500,
OptionsValues = delegate()
{
return Enum.GetValues<FanMode>().Select(item => (object)item).ToArray();
},
CurrentValue = delegate()
{
if (SharedData<FanModeSetting>.GetExistingValue(out var value))
return value.Current;
return null;
},
ApplyValue = delegate(object selected)
{
if (!SharedData<FanModeSetting>.GetExistingValue(out var value))
return null;
value.Desired = (FanMode)selected;
if (!SharedData<FanModeSetting>.SetExistingValue(value))
return null;
return selected;
}
}
}
};
}
}