ClassicOldSong / Widecar

Sidecar for Windows - with Sunshine and Moonlight
MIT License
86 stars 1 forks source link

Main display switches to display 2 #1

Closed sergeivich closed 1 month ago

sergeivich commented 1 month ago

Hi, is there any way to force sunshine/parsec/widecar to maintain display 1 as main display persistent? Display 2 always becomes main display when connecting.

ClassicOldSong commented 1 month ago

Setting the virtual display to primary before the stream starts is a must for sunshine to use the virtual screen for streaming.

You can set the primary display back after the stream starts manually or using MultiMonitorTool to automate the process.

https://www.nirsoft.net/utils/multi_monitor_tool.html

Add to the game command like this with the proper display name to your "Desktop" app:

image

You can obtain the display name by running the MultiMonitorTool directly from Explorer.

sergeivich commented 1 month ago

Thank you for the tip. I ran the command in sunshine directly, but it just mirrored the displays. I had to set a delay. I tried some other tools with sunshine directly but it only mirrors displays if there is no delay. For anyone else reading this, I made an autohotkey script so the primary display reverts to internal after launch.

Sure! Here's a script to execute the command D:\Tools\MultiMonitorTool.exe /SetPrimary \\.\DISPLAY1 when a second display is detected:

#Persistent

; Function to check if a second display is connected
CheckSecondDisplay() {
    SysGet, MonitorCount, MonitorCount
    return (MonitorCount > 1) ; Return true if more than one monitor is detected
}

; Variable to track the state of the second display
secondDisplayConnected := false

; Loop indefinitely
Loop {
    ; Check for second display
    if CheckSecondDisplay() {
        if (!secondDisplayConnected) {
            ; Second display is now connected
            secondDisplayConnected := true

            ; Wait for an additional 10 seconds
            Sleep, 10000

            ; Execute the command to set primary display
            Run, D:\Tools\MultiMonitorTool.exe /SetPrimary \\.\DISPLAY1
        }
    } else {
        ; Reset the state if the second display is not detected
        secondDisplayConnected := false
    }

    ; Wait for 500 milliseconds before checking again
    Sleep, 500
}

Explanation:

  1. CheckSecondDisplay(): Function to check if a second display is connected.
  2. secondDisplayConnected: Variable to track the state of the second display.
  3. Loop: Continuously checks if a second display is connected.
  4. if CheckSecondDisplay(): Checks if more than one monitor is detected.
  5. if (!secondDisplayConnected): Executes the command only when the second display is newly detected.
  6. Sleep, 10000: Waits for an additional 10 seconds.
  7. Run, D:\Tools\MultiMonitorTool.exe /SetPrimary \.\DISPLAY1: Executes the command to set the primary display.
  8. secondDisplayConnected := false: Resets the state if the second display is not detected.
  9. Sleep, 500: Waits for 500 milliseconds before checking again.

Save this script with a .ahk extension and run it using AutoHotkey. The script will wait until a second display is detected, wait for 10 seconds, execute the command to set the primary display to \\.\DISPLAY1, and then continue monitoring for changes.

ClassicOldSong commented 1 month ago

You need to put the command at GAME COMMAND, it's not the same place you put widecar commands, nor Detatched commands.

When Sunshine executes the game command, it's already streaming with the correct display.

Edit: After some testing it does capture the internal display sometimes. Looking for a better solution...

ClassicOldSong commented 1 month ago

Add the line to Detatched commands, remove the game command

image

You can change the timeout accordingly.

sergeivich commented 1 month ago

This works great, tested back to back 10 times just using extended desktop. 8/10 times it worked, 2/10 mirrored internal monitor. thank you