designer-living / sunshine_utils

Apache License 2.0
76 stars 6 forks source link

Error and unhandled exception when trying to switch displays using --detach-other-monitors #6

Open janlothar opened 1 year ago

janlothar commented 1 year ago

Trying to switch to a display that is disabled results in throwing a unhandled exception. Here I try to switch to DISPLAY2

PS C:\Program Files\sunshine_utils> .\resolution_change.exe -d \\.\DISPLAY2 --width 3840 --height 2160 --refreshrate 120 --detach-other-monitors
Traceback (most recent call last):
  File "resolution_change.py", line 196, in <module>
  File "resolution_change.py", line 95, in change_display
KeyError: '\\\\.\\DISPLAY2'
[11188] Failed to execute script 'resolution_change' due to unhandled exception!

after enabling the monitor through display settings and running the the same command, it works:

PS C:\Program Files\sunshine_utils> .\resolution_change.exe -d \\.\DISPLAY2 --width 3840 --height 2160 --refreshrate 120 --detach-other-monitors
Switching resolution to 3840x2160 at 120Hz

and using -r afterwards also works fine

PS C:\Program Files\sunshine_utils> .\resolution_change.exe -r
Resetting resolution
Reset to:
Display name: \\.\DISPLAY1 -  Enabled: True, Primary: True - 3440x1440
Display name: \\.\DISPLAY2 -  Enabled: True, Primary: False - 3840x2160

Were I to switch to DISPLAY2 using --detach-other-monitors and then try to switch back to DISPLAY1 then I would get the same error:

PS C:\Program Files\sunshine_utils> .\resolution_change.exe -d \\.\DISPLAY2 --width 3840 --height 2160 --refreshrate 120 --detach-other-monitors
Switching resolution to 3840x2160 at 120Hz
PS C:\Program Files\sunshine_utils> .\resolution_change.exe -d \\.\DISPLAY1 --width 3440 --height 1440 --refreshrate 144 --detach-other-monitors
Traceback (most recent call last):
  File "resolution_change.py", line 196, in <module>
  File "resolution_change.py", line 95, in change_display
KeyError: '\\\\.\\DISPLAY1'
[8572] Failed to execute script 'resolution_change' due to unhandled exception!
PS C:\Program Files\sunshine_utils> .\resolution_change.exe -r
Resetting resolution
Reset to:
Display name: \\.\DISPLAY1 -  Enabled: True, Primary: True - 3440x1440
Display name: \\.\DISPLAY2 -  Enabled: True, Primary: False - 3840x2160