Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't enable disabled monitor #2

Open
Cynary opened this issue Jul 7, 2024 · 1 comment
Open

Can't enable disabled monitor #2

Cynary opened this issue Jul 7, 2024 · 1 comment

Comments

@Cynary
Copy link

Cynary commented Jul 7, 2024

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:

# display 0 is enabled
$displays = WindowsDisplayManager\GetAllPotentialDisplays
$displays[0].disable() # Returns True, display 0 is disabled now.
$displays[0].enable() # Returns True, display 0 is enabled now.
$displays[0].disable() # Returns True, display 0 is disabled now.
$displays = WindowsDisplayManager\GetAllPotentialDisplays # display 0 now has no target.
$displays[0].enable() # Returns True, but nothing happens.

Output with display 0 enabled:

Display ID   Description            Active  Enabled  Primary  Resolution           HDR Info               Position   Recommended Resolution   Source                       Target
----------   -----------            ------  -------  -------  ----------           --------               --------   ----------------------   ------                       ------
0-4353       AW3423DWF via NVIDIA   True    True     False    Width       : 3440   HdrSupported : True    X : 3840   Width  : 3440            Id          : 0              Id             : 4353
             GeForce RTX 4090                                 Height      : 1440   HdrEnabled   : True    Y : 0      Height : 1440            Name        : \\.\DISPLAY1   FriendlyName   : AW3423DWF
                                                              RefreshRate : 60     BitDepth     : 10                                          Description : NVIDIA         ConnectionType :
                                                                                                                                              GeForce RTX 4090             DisplayportExternal
1            Unconnected NVIDIA     True    False    True     Width       : 3840   N/A                    X : 0      N/A                      Id          : 1              None
             GeForce RTX 4090                                 Height      : 2160                          Y : 0                               Name        : \\.\DISPLAY2
             source                                           RefreshRate : 120                                                               Description : NVIDIA
                                                                                                                                              GeForce RTX 4090
2            Unconnected NVIDIA     False   False    False    N/A                  N/A                    N/A        N/A                      Id          : 2              None
             GeForce RTX 4090                                                                                                                 Name        : \\.\DISPLAY3
             source                                                                                                                           Description : NVIDIA
                                                                                                                                              GeForce RTX 4090
3            Unconnected NVIDIA     False   False    False    N/A                  N/A                    N/A        N/A                      Id          : 3              None
             GeForce RTX 4090                                                                                                                 Name        : \\.\DISPLAY4
             source                                                                                                                           Description : NVIDIA
                                                                                                                                              GeForce RTX 4090

Output with display 0 disabled:

Display ID   Description            Active  Enabled  Primary  Resolution           HDR Info               Position   Recommended Resolution   Source                       Target
----------   -----------            ------  -------  -------  ----------           --------               --------   ----------------------   ------                       ------
0            Unconnected NVIDIA     False   False    False    N/A                  N/A                    N/A        N/A                      Id          : 0              None
             GeForce RTX 4090                                                                                                                 Name        : \\.\DISPLAY1
             source                                                                                                                           Description : NVIDIA
                                                                                                                                              GeForce RTX 4090
1-4352       DENON-AVR via NVIDIA   True    True     True     Width       : 3840   HdrSupported : True    X : 0      Width  : 3840            Id          : 1              Id             : 4352
             GeForce RTX 4090                                 Height      : 2160   HdrEnabled   : True    Y : 0      Height : 2160            Name        : \\.\DISPLAY2   FriendlyName   : DENON-AVR
                                                              RefreshRate : 120    BitDepth     : 10                                          Description : NVIDIA         ConnectionType : Hdmi
                                                                                                                                              GeForce RTX 4090
2            Unconnected NVIDIA     False   False    False    N/A                  N/A                    N/A        N/A                      Id          : 2              None
             GeForce RTX 4090                                                                                                                 Name        : \\.\DISPLAY3
             source                                                                                                                           Description : NVIDIA
                                                                                                                                              GeForce RTX 4090
3            Unconnected NVIDIA     False   False    False    N/A                  N/A                    N/A        N/A                      Id          : 3              None
             GeForce RTX 4090                                                                                                                 Name        : \\.\DISPLAY4
             source                                                                                                                           Description : NVIDIA
                                                                                                                                              GeForce RTX 4090
@patrick-theprogrammer
Copy link
Owner

patrick-theprogrammer commented Nov 8, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants