Open Nonary opened 1 year ago
Seems to work like a charm. Thanks for the writeup!
Confirming that I had to do this,
My log was spitting out the following
Screen will not be reverted because we are already streaming
Failed to restore display(s), some displays require multiple attempts and may not restore until returning back to the computer. Trying again after 5 seconds...
Failed to restore display(s), some displays require multiple attempts and may not restore until returning back to the computer. Trying again after 5 seconds...
Etc.
My monitors are "slow' to turn on though,
Mon0: Dummy Plug Mon1: 1920x1080 LG24GM77 Mon2: 2560x1440 LG27GP850 Mon3: 1920x1080 Asus 247H
Mon1 and Mon2 would hang and not reconnect. Adding in MonitorSwitcher worked.
- Open the MonitorSwapper-Functions.ps1 file.
- In the "SetPrimaryScreen" function, look for this line:
& .\MultiMonitorTool.exe /LoadConfig "primary.cfg"
- Replace the line mentioned above with this line instead.
& .\MonitorSwitcher.exe -load:Primary.xml
- Save the file, and you should be good to go.
Heads up for anyone doing this fix at step 7 and can't find MonitorSwapper-Functions.ps1, the file to look in is now Events.ps1
Did the steps but when I close my stream via Moonlight, the first time it won't switch back, second time I close stream it switches back but then my Main display turns on and off every 5-10 seconds. Going into Display settings and enabling my virtual monitor cause it to becomes disabled when my main display turns off, like the script is still running and repeating itself
Did the steps but when I close my stream via Moonlight, the first time it won't switch back, second time I close stream it switches back but then my Main display turns on and off every 5-10 seconds. Going into Display settings and enabling my virtual monitor cause it to becomes disabled when my main display turns off, like the script is still running and repeating itself
Can you zip the entire script folder, and also upload the current_monitor_cfg file located in %temp% so I can look at that?
Did the steps but when I close my stream via Moonlight, the first time it won't switch back, second time I close stream it switches back but then my Main display turns on and off every 5-10 seconds. Going into Display settings and enabling my virtual monitor cause it to becomes disabled when my main display turns off, like the script is still running and repeating itself
Can you zip the entire script folder, and also upload the current_monitor_cfg file located in %temp% so I can look at that?
Did the steps but when I close my stream via Moonlight, the first time it won't switch back, second time I close stream it switches back but then my Main display turns on and off every 5-10 seconds. Going into Display settings and enabling my virtual monitor cause it to becomes disabled when my main display turns off, like the script is still running and repeating itself
Can you zip the entire script folder, and also upload the current_monitor_cfg file located in %temp% so I can look at that?
Not seeing any errors in the log that would cause that, can you replace your Event.ps1 with this one
And in settings, enable the debug option by setting it to true
@Metrinui I think I fixed it, can you try this one and let me know?
@Metrinui I think I fixed it, can you try this one and let me know?
You're amazing, thank you so much! Problem solved!!! What an absolute legend!
Thanks for this tip, I ended up having issues with it switching between dual monitors and a dummy because of the monitor startup time, (also OP's monitorswitcher didn't work) I found that using the commands from https://www.nirsoft.net/utils/multi_monitor_tool.html and editing events.ps1 I was able to get it working by using /enable and /disable to one by one enable and disable monitors then use /LoadConfig to set my left and right monitors to the appropriate locations
function SetPrimaryScreen() {
Write-Debug "Starting SetPrimaryScreen function"
Write-Debug "Checking if currently streaming"
if (IsCurrentlyStreaming) {
Write-Debug "Currently streaming, exiting function"
return
}
Write-Debug "Loading Monitor 1"
& .\MultiMonitorTool.exe /enable "\\.\DISPLAY1"
Write-Debug "Sleeping for 3 seconds to allow configuration to take effect"
Start-Sleep -Seconds 3
Write-Debug "Loading Monitor 2"
& .\MultiMonitorTool.exe /enable "\\.\DISPLAY2"
Write-Debug "Sleeping for 3 seconds to allow configuration to take effect"
Start-Sleep -Seconds 3
Write-Debug "Disable Monitor 3"
& .\MultiMonitorTool.exe /disable "\\.\DISPLAY5"
Write-Debug "Sleeping for 3 seconds to allow configuration to take effect"
Start-Sleep -Seconds 3
Write-Debug "Set Left Right"
& .\MultiMonitorTool.exe /LoadConfig primary.cfg
Write-Debug "Sleeping for 3 seconds to allow configuration to take effect"
Start-Sleep -Seconds 3
Write-Debug "SetPrimaryScreen function completed"}
Based on @RikuKunMS2 comment, this is what I had to do for my "long startup" monitor.
The delta is mostly auto-detecting which monitors to /disable
and /enable
.
One might have to play with the delay variables.
enableStrictRestoration = false
(true
did not seem to help)function SetPrimaryScreen() {
Write-Debug "Starting SetPrimaryScreen function"
Write-Debug "Checking if currently streaming"
if (IsCurrentlyStreaming) {
Write-Debug "Currently streaming, exiting function"
return
}
# ---------------------------------------------
# extra cruft for 'long turn on' monitors
# https://github.com/Nonary/MonitorSwapAutomation/issues/9#issuecomment-2181039417
# ---------------------------------------------
$sleepDelayPerMon = 4
$trailingSleep = 3
$monIds = @( Get-Content .\primary.cfg | Where-Object { $_ -match '^MonitorID=' } | ForEach-Object { (($_ -split '=')[1]) } )
# there's a bug in the windows spotify client with multi monitors
#get-process -Name '*spotify*' | Stop-Process -Force -ea 0
Write-Debug "Disabling $($dummyMonitorId) + $($sleepDelayPerMon)s sleep"
& .\MultiMonitorTool.exe /disable $dummyMonitorId
Start-Sleep -Seconds $sleepDelayPerMon
foreach($monId in $monIds) {
if($monId -eq $dummyMonitorId) {
continue
}
Write-Debug "Enabling $($monId) + $($sleepDelayPerMon)s sleep"
& .\MultiMonitorTool.exe /enable $monId
Start-Sleep -Seconds $sleepDelayPerMon
}
Write-Debug "Trailing disable/enable sleep for $($trailingSleep)s"
Start-Sleep -Seconds $trailingSleep
# ------------------------------------------
# ...
A bug has been identified in the Nirsoft MultiMonitor tool that prevents certain user setups from being able to properly restore both monitors, usually what will happen is only one of the two will be restored. I am aware of this issue and currently I do not have an easy solution to it as I do not maintain the MultiMonitor tool.
All other monitor profile loading tools are very user unfriendly compared to editing a simple config file, as such I do not have any plans to swap the backend of the script because it would become even more confusing to the general user public.
Workaround
For now, I suggest using this workaround to the issue until the issue has been resolved on Nirsoft's MultiMonitorTool.
Download Monitor Switcher from Sourceforge https://sourceforge.net/projects/monitorswitcher/
Copy the MonitorSwitcher.exe and paste it into the same folder MonitorSwapper is saved in.
Make sure you current Monitor Settings are exactly how you want them to be once you've finished streaming, as we will be saving that configuration as the restore point once you've finished streaming.
Open command prompt or PowerShell at the folder MonitorSwapper (not Switcher) is saved in, for Windows 11 users that can easily be done by right clicking a blank area in the folder and selecting Open in Terminal.
Type in MonitorSwitcher, then press tab so the terminal automatically completes the rest of the command, then type in -save:Primary.xml
It should look like this:
PowerShell will prepend the command with .\ this is normal.
Open the Events.ps1 file, or if you're using an older version of this script... open the MonitorSwapper-Functions.ps1 file instead.
In the "SetPrimaryScreen" function, look for this line:
Replace the line mentioned above with this line instead.
Save the file, and you should be good to go.