Nonary / MonitorSwapAutomation

Automates swapping to a dummy plug when streaming, then automates swapping back to primary monitor once finished.
290 stars 8 forks source link

README

This script automates the process of switching your primary monitor with a dummy monitor using MultiMonitorTool. This is useful for users of Sunshine (a screen sharing software) who experience issues with sharing their primary monitor.

Caveats:

REQUIREMENTS

For GFE users

For Sunshine users

INSTRUCTIONS

  1. Open up MultiMonitorTool and click on File -> Save Monitors Configuration and save it in the current folder this script is located in with the name of primary.cfg.

  2. Repeat the same steps of step 1, except save it with the name of dummy.cfg.

  3. Open up the dummy.cfg file and set every parameter related to your primary monitor's position, refresh rate, etc. to 0. For example:

    Name=\\.\DISPLAY1
    MonitorID=MONITOR\GSMC0C8\{4d36e96e-e325-11ce-bfc1-08002be10318}\0009
    SerialNumber=LGTV
    BitsPerPixel=0
    Width=0
    Height=0
    DisplayFlags=0
    DisplayFrequency=0
    DisplayOrientation=0
    PositionX=0
    
    Name=\\.\DISPLAY11
    MonitorID=MONITOR\XMD29831\{4d36e96e-e325-11ce-bfc1-08002be10318}\0007
    SerialNumber=DUMMY
    BitsPerPixel=32
    Width=3840
    Height=2160
    DisplayFlags=0
    DisplayFrequency=120
    DisplayOrientation=0
    PositionX=0

    In the example above, every numerical value has been set to 0, which lets the script know that the display should be turned off. Also take note in the example, that my dummy display should have values configured to let it know that it should be turned on.

  4. Verify that the dummy.cfg file has only one display that contains values for the BitsPerPixel, Width, Height, and so on. 4a. For the primary.cfg file, it does not matter if there are other displays enabled, but you would want to make sure your dummy is "zeroed out" so you don't end up with an invisible monitor.

  5. Basically, primary will "zero out" the dummy plug, and dummy will "zero out" the main display. This will automatically transfer games and windows back to the primary monitor if setup this way.

  6. In the dummy.cfg file, locate your dummy MonitorId and copy and paste it to the dummyMonitorId key in the settings.json file. Make sure to escape the backslashes.

  7. Validate you have escaped the backslashes, below is an example of a valid settings.json file.

    {
    "startDelay": 2,
    "gracePeriod": 60,
    "configSaveLocation": "%TEMP%",
    "dummyMonitorId": "MONITOR\\XMD009A\\{4d36e96e-e325-11ce-bfc1-08002be10318}\\0010"
    }
  8. Install the script by double clicking the Install.bat file, you may get a smart-screen warning... this is normal.

  9. You will be prompted for administrator rights, as modifying Sunshine configuration will require admin rights in the coming future.

  10. If there are no error messages presented on the screen, the script successfully installed and you can close the terminal.

The paths referenced above will vary on your machine.

TROUBLESHOOTING

If you encounter issues with the script, you can try the following:

Monitor is not swapping before stream or afterwards

ResolutionAutomation script isn't changing my resolution after connecting and or is intermittently working

Only One Screen is Being Restored, Everything Else Works

Primary Monitor Wasn't Restored

Check the logs to see if they claim the primary monitor was successfully restored. If it was, enable enableStrictRestoration in the settings.json file by setting it to true. If the logs do not show it restored, it probably was closed out before the script could finish (in the case of reboots). In such cases, you can't do much to resolve it other than ensuring you do not reboot before returning to your machine.

Resolution Change When Resuming or Starting a New Stream

Change Log

v1.1.9

v1.1.8

v1.1.7

v1.1.6