Skip to content

About

Sunshine/Moonlight streaming: switch to the client's resolution on connect and restore your original resolution afterwards. PowerShell.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

sunshine-scripts

Automatic resolution switching for Sunshine game streaming on Windows.

When a Moonlight client connects, your PC switches to the client's resolution: 1080p for a laptop, 2560×1600 for a tablet. When the stream ends, the original resolution comes back, whether that's ultrawide, 4K or anything else. No more black bars or tiny text on your phone, and no more manually resetting your monitor afterwards.

Pure PowerShell, nothing to install, no admin rights needed for the switching itself.

How it works

Set-Resolution.ps1 is used as a Sunshine prep command:

Call What it does
-FromClient Reads SUNSHINE_CLIENT_WIDTH, SUNSHINE_CLIENT_HEIGHT and SUNSHINE_CLIENT_FPS (set by Sunshine) and switches to that mode
-Width 1920 -Height 1080 [-RefreshRate 60] Switches to a fixed mode
-Restore Goes back to the mode that was active before the first switch
-WhatIf Only checks whether a mode is supported (CDS_TEST), changes nothing

Details:

  • Before switching, the current mode is saved to %LOCALAPPDATA%\sunshine-scripts\previous.json. It is only saved once, so reconnecting doesn't overwrite your real desktop resolution with the streaming one.
  • Every mode is tested with CDS_TEST first, so an unsupported mode never leaves you with a black screen.
  • If the client's refresh rate isn't available (e.g. a 120 Hz client on a 60 Hz monitor), the script retries without it.
  • Everything is logged to %LOCALAPPDATA%\sunshine-scripts\log.txt.

Setup

  1. Clone or download this repo to a permanent place, e.g. C:\Tools\sunshine-scripts.

  2. Install the app list into Sunshine (admin PowerShell, because Sunshine lives in Program Files):

    cd C:\Tools\sunshine-scripts
    .\Install.ps1            # copies apps.json (backup of the old one is kept)
    .\Install.ps1 -WithConf  # also copies sunshine.conf

    {{SCRIPTS}} in apps.json is replaced by the repo path automatically.

  3. Restart Sunshine.

Included apps

App Behavior
Desktop Client resolution, restore afterwards
Desktop (1080p) Always 1920×1080, restore afterwards
Steam Big Picture Client resolution + Big Picture, both undone afterwards

sunshine.conf advertises 1920x1080 and 1280x720 to clients. Adjust it to the resolutions your devices use.

Use it in your own apps

In the Sunshine web UI → Applications → Command Preparations:

Do:   powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -File "C:\Tools\sunshine-scripts\Set-Resolution.ps1" -FromClient
Undo: powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -File "C:\Tools\sunshine-scripts\Set-Resolution.ps1" -Restore

set_1080p.ps1 and set_ultrawide.ps1 are small examples of fixed presets.

Limitations

  • Changes the primary display only.
  • If your monitor doesn't support the client's resolution, nothing is changed. Create a custom resolution in your GPU driver (NVIDIA/AMD control panel) or use a virtual display driver.

License

MIT © 2026 Paul Hohmann


🇩🇪 Kurz auf Deutsch

Wenn sich ein Moonlight-Gerät verbindet, schaltet der PC auf dessen Auflösung um. Nach dem Stream stellt er die vorherige Auflösung wieder her. Einrichten: Repo an einen festen Ort legen, Install.ps1 als Admin ausführen und Sunshine neu starten. Mit -WhatIf kannst du gefahrlos prüfen, ob ein Modus unterstützt wird.

About

Sunshine/Moonlight streaming: switch to the client's resolution on connect and restore your original resolution afterwards. PowerShell.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages