FrogTheFrog / moondeck-buddy

A server-side part of the MoonDeck plugin for the SteamDeck.
GNU Lesser General Public License v3.0
151 stars 9 forks source link

Feature Request: Config to toggle certain system settings #58

Closed ejams1 closed 1 year ago

ejams1 commented 1 year ago

I love this tool and have been working to tweak my setup through Sunshine. However, I have been trying to figure out reliable ways to toggle the following:

I know moondeck automatically passes resolution information to sunshine which is great. These other features would help out a lot too and was wondering if it made sense to request them as part of the moondeck buddy server or possibly as separate tools like gsync-toggle.

With HDR, I found that windows has a shortcut combo to toggle it so this could be as simple as writing a powershell script to send the combination. The FPS cap would likely require a similar solution to gsync-toggle since it would require interfacing with the NvAPI as it is a control panel setting.

FrogTheFrog commented 1 year ago

So, I'm not planning to extend Buddy with any new functionality. In fact, I plan to remove the resolution change support once Sunshine implements it (if they implement it).


With that said, I don't have HDR, but after searching online, it says that it's a bad idea to change it with NvApi and windows settings should be used instead. The keyboard shortcut is Win+Alt+B, so this script should work?

$source = @"
using System;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace Sunshine
{
    public class Utils
    {
        [DllImport("user32.dll")]
        public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

        private const int KEYEVENTF_EXTENDEDKEY = 0x0001;
        private const int KEYEVENTF_KEYUP = 0x0002;

        // From https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
        private const byte VK_LWIN = 0x5B;
        private const byte VK_ALT = 0x12;
        private const byte VK_B = 0x42;

        public static void ToggleHdr()
        {
            // Press down the keyboard shortcut
            keybd_event(VK_ALT, 0, KEYEVENTF_EXTENDEDKEY, 0);
            keybd_event(VK_LWIN, 0, KEYEVENTF_EXTENDEDKEY, 0);
            keybd_event(VK_B, 0, KEYEVENTF_EXTENDEDKEY, 0);

            // Release the keyboard shortcut
            keybd_event(VK_B, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
            keybd_event(VK_LWIN, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
            keybd_event(VK_ALT, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
        }
    }
}
"@
Add-Type -TypeDefinition $source -ReferencedAssemblies "System.Windows.Forms"

Write-Output "Toggle HDR"
[Sunshine.Utils]::ToggleHdr()
Write-Output "HDR toggled"
Start-Sleep -Seconds 2

It can be then executed like this: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File "C:\Users\frog\Desktop\test.ps1" where test.ps1 is the script file.


As for the FPS limiter, I can create another tool if you want, but I also recommend using the RTSS instead (it has nearly perfect frametimes). It can also be toggled via keyboard shortcuts. Still let me know if you want the NVidia tool.

ejams1 commented 1 year ago

Nice, I will try the script. Thanks for writing it up! I was also thinking of a simpler alternative like creating an autohotkey script to hit the keys, then compile it to an exe. That way autohotkey isn't even necessary after the compilation. Something similar could probably be done for FPS capping through RTSS once a hotkey is configured as well.

My thinking with that along with editing the nvidia control panel settings is that it means fewer third party tools are required and it simplifies setup for future use (or other people) to just take a script and run it through sunshine. I would appreciate a script solution to edit the control panel so if you think it wouldn't take much effort, then by all means :smile:

FrogTheFrog commented 1 year ago

@ejams1 Here's the FRL toggle thingy: https://github.com/FrogTheFrog/frl-toggle/releases

ejams1 commented 1 year ago

Thank you!!