MartinGC94 / DisplayConfig

PowerShell module for configuring Windows display settings
MIT License
44 stars 2 forks source link

Cannot see inactive displays #12

Open waldner opened 6 days ago

waldner commented 6 days ago

See this for example:

displays

With Windows, I can select display 2 and enable it, extend desktop to it, etc.

But DisplayConfig shows this:

PS C:\Users\admin> Get-DisplayInfo

 DisplayId DisplayName      Active  Primary Position    Mode                  ConnectionType
 --------- -----------      ------  ------- --------    ----                  --------------
         1 QEMU Monitor       True    False -1024 0     1024x768@1 Hz                  Other
         2 D1150-PL2.0        True     True 0 0         1024x768@60.00384...            HDMI
         3 D1150-PL2.0        True    False 1024 0      1024x768@60.00384...            HDMI

So not only is the display Windows identifies as "2" missing from this output (it's a VGA-connected monitor), but those that are seen have a different numbering. Is this intended, and is there a workaround?

MartinGC94 commented 6 days ago

When I researched the API I saw something about forced output for analog connection types like VGA but I figured it wasn't necessary to think about in 2024 but I guess I was wrong about that.

I think I know what changes I need to make but I will need your help to test it because I don't have a VGA compatible system/display.

Can you send me a copy of your displayconfig before and after you enable the display in the settings app? You can export them with: Get-DisplayConfig | Export-Clixml $HOME\Before.xml just zip them up and attach them here.

As for the numbering, that is by design. Microsoft haven't documented how they assign the display Ids so I've had to invent my own logic which obviously won't match theirs. For more info, read this: https://github.com/MartinGC94/DisplayConfig/issues/7

waldner commented 6 days ago

Thanks, very interesting. On my system, for some reason that I haven't been able to understand (but there seem to be many people in the same situation), it seems that one display will always be disabled, and enabling it will disable another one, and so on. Nonetheless, all four are shown and can be acted upon in the windows settings, so it would be great if the same coud be done with DisplayConfig. As for the numbering, I think it's not vital since other criteria can be used to identify a display (eg the connection type).

So here's the XML for the setup I showed earlier (where display "2" is disabled - btw it looks like it's a displayport, not VGA, I couldn't check since it's a remote machine): Before.xml.gz

When I enable display 2, display 4 gets disabled. Here's what happens: after

and here's the XML for this: After.xml.gz

Let me know if you need me to do more tests or provide more information.

MartinGC94 commented 5 days ago

It seems to have been a regression I added in 3.1.0.
I added a check to ensure I wouldn't add a display with an existing ID to the list of available displays to avoid conflicting Ids when enabling a display but because your GPU only supports 2 display outputs this means that duplicate Ids are expected and I just need to handle that in the Enable-Display command code.

I'm attaching a test version here, can you give it a try and see if it actually works? 3.1.1.zip Get-DisplayInfo should of course show all 4 displays and you should be able to switch between displays 2 and 4 with Enable-Display -DisplayId 2 -DisplayIdToDisable 4 or whatever the Ids my module will assign to those displays. You can also try it without the DisplayIdToDisable parameter. I'd expect it to throw an error but it would be nice to get a confirmation.

waldner commented 5 days ago

Getting this while trying to import (surely I'm doing something wrong, I'm not that versed in PS):

> Import-Module .\DisplayConfig.psd1
Import-Module : Could not load file or assembly 'file:///C:\Users\admin\Desktop\3.1.1\DisplayConfig.dll' or one of its
dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
At line:1 char:1
+ Import-Module .\DisplayConfig.psd1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Import-Module], FileLoadException
    + FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommand

OS is Window 10.

EDIT:

After copying the module into C:\Program Files\WindowsPowerShell\Modules\DisplayConfig\3.1.1, the commands are available on the command line, but if I try to run them I get:

PS C:\Users\admin> Get-DisplayInfo
Get-DisplayInfo : The 'Get-DisplayInfo' command was found in the module 'DisplayConfig', but the module could not be
loaded. For more information, run 'Import-Module DisplayConfig'.
At line:1 char:1
+ Get-DisplayInfo
+ ~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-DisplayInfo:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

PS C:\Users\admin> import-module displayconfig
import-module : Could not load file or assembly 'file:///C:\Program
Files\WindowsPowerShell\Modules\displayconfig\3.1.1\DisplayConfig.dll' or one of its dependencies. Operation is not
supported. (Exception from HRESULT: 0x80131515)
At line:1 char:1
+ import-module displayconfig
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Import-Module], FileLoadException
    + FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommand
MartinGC94 commented 5 days ago

Files downloaded in most browsers get a "Mark of the web" so you need to unblock the files as described here: https://stackoverflow.com/questions/34400546/could-not-load-file-or-assembly-operation-is-not-supported-exception-from-hres

Protip: Unblock the zip file and then extract the files so you don't have to unblock a bunch of files. Alternatively, use 7-zip to unzip because it doesn't apply the mark to the unzipped files.

waldner commented 5 days ago

Well...learn something new every day. So here's what I get:

PS C:\Users\admin> Get-DisplayInfo

 DisplayId DisplayName      Active  Primary Position    Mode                  ConnectionType
 --------- -----------      ------  ------- --------    ----                  --------------
         1 QEMU Monitor       True     True 0 0         1024x768@1 Hz                  Other
         2                    True    False 1024 0      1024x768@60.00384...     DisplayPort
         3 D1150-PL2.0        True    False 2048 0      1024x768@60.00384...            HDMI
         4 D1150-PL2.0       False    False 0 0                                         HDMI

Which corresponds to this, as seen by Windows:

4disabled

So in this case the numbering by DisplayConfig matches what Windows reports. My goal is to have the two HDMI displays active.

Trying to just enable display 4 produces an error:

PS C:\Users\admin> Enable-Display -DisplayId 4
Enable-Display : A device attached to the system is not functioning
At line:1 char:1
+ Enable-Display -DisplayId 4
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : DeviceError: (:) [Enable-Display], Win32Exception
    + FullyQualifiedErrorId : FailedToApplyAlternativeConfig,MartinGC94.DisplayConfig.Commands.EnableDisplayCommand

Enabling 4 while at the same time disabling 2 also produces an error:

PS C:\Users\admin> Enable-Display -DisplayId 4 -DisplayIdToDisable 2
Enable-Display : The parameter is incorrect
At line:1 char:1
+ Enable-Display -DisplayId 4 -DisplayIdToDisable 2
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Enable-Display], Win32Exception
    + FullyQualifiedErrorId : FailedToApplyAlternativeConfig,MartinGC94.DisplayConfig.Commands.EnableDisplayCommand

EDIT:

so it looks like there's more to this, because the following sequence of commands does work to enable 4 and disable 2:

PS C:\Users\admin> Enable-Display -DisplayId 4 -DisplayIdToDisable 3
PS C:\Users\admin> Enable-Display -DisplayId 3 -DisplayIdToDisable 2

and this leaves me like this:

PS C:\Users\admin> Get-DisplayInfo

 DisplayId DisplayName      Active  Primary Position    Mode                  ConnectionType
 --------- -----------      ------  ------- --------    ----                  --------------
         1 QEMU Monitor       True     True 0 0         1024x768@1 Hz                  Other
         2                   False    False 0 0                                  DisplayPort
         3 D1150-PL2.0        True    False 2048 0      1024x768@60.00384...            HDMI
         4 D1150-PL2.0        True    False 1024 0      1024x768@60.00384...            HDMI

and in Windows

2disabled

Any idea why the direct/obvious route isn't working?

MartinGC94 commented 4 days ago

No idea. I've ordered a dummy display plug so I can test out this limit myself. Expect an update next week where I've hopefully received it and learned something from it.

waldner commented 4 days ago

I might be able to arrange remote VNC access to the machine for you, if you are interested. My contact: look for the URL in my profile here: https://github.com/waldner, go to that page, scroll to the very bottom and click "contact", run the code you find (sorry but spam etc.) and you'll get one of my email addresses. You need to run that on a unix terminal, or anything that can run "sh". If not, I'll wait for you to carry out your tests. Thanks.