Set default FPS limit as main display refresh rate

https: //cdn.discordapp.com/attachments/377894067712950275/1136002569660014653/image.png
Co-Authored-By: $wag Messiah <135360571+sahelantrophus@users.noreply.github.com>
This commit is contained in:
pizzaboxer 2023-08-01 19:29:10 +01:00
parent 48afdd7036
commit 04dda07620
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8
2 changed files with 22 additions and 9 deletions

View File

@ -1,5 +1,7 @@
using System.Windows.Input;
using System.Windows.Media.Animation;
using System.Windows.Forms;
using Windows.Win32;
using Windows.Win32.Graphics.Gdi;
namespace Bloxstrap
{
@ -152,12 +154,6 @@ namespace Bloxstrap
SetValue(pair.Value, value);
}
public void SetPresetOnce(string key, object? value)
{
if (GetPreset(key) is null)
SetPreset(key, value);
}
public void SetPresetEnum(string prefix, string target, object? value)
{
foreach (var pair in PresetFlags.Where(x => x.Key.StartsWith(prefix)))
@ -207,8 +203,24 @@ namespace Bloxstrap
{
base.Load();
SetPresetOnce("Rendering.Framerate", 9999);
CheckManualFullscreenPreset();
if (GetPreset("Rendering.Framerate") is not null)
return;
// set it to be the framerate of the primary display by default
var screen = Screen.AllScreens.Where(x => x.Primary).Single();
var devmode = new DEVMODEW();
PInvoke.EnumDisplaySettings(screen.DeviceName, ENUM_DISPLAY_SETTINGS_MODE.ENUM_CURRENT_SETTINGS, ref devmode);
uint framerate = devmode.dmDisplayFrequency;
if (framerate <= 100)
framerate *= 2;
SetPreset("Rendering.Framerate", framerate);
}
}
}

View File

@ -2,3 +2,4 @@
FlashWindow
GetWindowLong
SetWindowLong
EnumDisplaySettings