Open Cynary opened 4 months ago
You can manually supply a target id of the device you want to enable to the enable function like $displays[0].enable(4353)
in this case.
The windows display apis only really give us a list of sources eg GPU ports and, if a one of those is connected, information about the target it's connected to eg your monitor. Also if you unplug and plug things back in, the target IDs may change.
Basically you have to remember the target id of the device back when it was enabled to be able to reenable it.
Display objects will hold onto the IDs they have when created which is why you can reenable so long as you don't refetch the display. The only way I can think of making this better would involve implementing some persistent storage for the tool to remember previous target IDs even for newly fetched disabled displays. That would add some complexity though to do properly, and I'm not sure when or if I'll have time to get to it.
Curious do you have a particular reason in your use case why you can't hold on to the display object and have to re-fetch it after disable?
If a monitor is disabled when I run GetAllPotentialDisplays, I have no way to enable it. But if I use an earlier returned value, it works. Here's an easy repro:
Output with display 0 enabled:
Output with display 0 disabled: