WindowsDisplayAPI icon indicating copy to clipboard operation
WindowsDisplayAPI copied to clipboard

Enabling displays does not work

Open novacto3 opened this issue 4 years ago • 10 comments

Hello,

I tried to use the new version of Your library and it seems that enabling displays stopped working. The sample throws an exception for "DeviceContext: Enable All" in

var validSetting = display.DisplayScreen.GetPreferredSetting();

because display.DisplayScreen is null. I tried to enable displays in my code via API call but it did not work either.

novacto3 avatar Jun 15 '20 09:06 novacto3

Hey,

This is the master branch, right? Since the latest release and the NuGet package don't have the DisplayScreen class yet.

I will take a look at that. Thanks for reporting.

falahati avatar Jun 15 '20 10:06 falahati

Yes, sorry for not specifying that. Let me know if I can be of any help with this.

novacto3 avatar Jun 15 '20 10:06 novacto3

I checked the v1.3.0.13 release and it does not work either. No exception is raised, but the disabled display is not enabled. In v1.2.0.2 it works fine.

novacto3 avatar Jun 15 '20 10:06 novacto3

What you are trying to do? The DriverContext API is a legacy and might not work as expected. Especially if you are trying to enable a device that was connected to a display source or if it was in a clone group. You simply can't do much.

I suggest using classes inside the DisplayConfig namespace. Find your physical device using the PathDisplayTarget and create a logical desktop corresponding to using the PathDisplaySource class then wire them all together and apply the configuration using the PathInfo class.

I gave more descriptive information in the following issues: https://github.com/falahati/NvAPIWrapper/issues/8#issuecomment-465103838 https://github.com/falahati/NvAPIWrapper/issues/26#issuecomment-634543169

falahati avatar Jun 15 '20 10:06 falahati

I have a display that is "disconnected" (in the terminology of Windows display settings) - it is connected, but disabled. Calling display.Enable(new WindowsDisplayAPI.DisplaySetting(display.GetPreferedSetting())); in previous versions of Your library started the display (that is the desired state for me). This functionality is not present in the latest release. Is it a bug or a feature? :-)

novacto3 avatar Jun 15 '20 11:06 novacto3

I don't think I change anything related to this with the last release, give me a moment to check it on my device. So the v1.2 or the v1.1 works but v1.3 fails? What are the values of the unattached display's properties? Does it have a valid display name? ("//DISPLAY1", "//DISPLAY2" ...) And is there an already attached display that has the same name?

falahati avatar Jun 15 '20 11:06 falahati

I found the bug. In previous versions (tested on v1.1 and v1.2) the attached displays had names "//DISPLAY1", "//DISPLAY2", "//DISPLAY3" and the unattached display had name "//DISPLAY4". In the new release (v1.3), the attached display names stay the same, but the unattached display has the name "//DISPLAY2" (so there is a duplicity in the naming).

novacto3 avatar Jun 15 '20 11:06 novacto3

Ok, the only change between the version that might be remotely related is the changes to the GetDisplayDevices() method. I will take another look into that. Meanwhile, if you don't need the DPI functionality you can use v1.2 safely.

Thanks for reporting this issue

falahati avatar Jun 15 '20 11:06 falahati

[DllImport("user32")]
public static extern Win32Status DisplayConfigGetDeviceInfo(
    ref DisplayConfigSupportVirtualResolution targetSupportVirtualResolution
);

Does it work well?

This is the Windows api:

WINUSERAPI LONG WINAPI DisplayConfigGetDeviceInfo( Inout_ DISPLAYCONFIG_DEVICE_INFO_HEADER* requestPacket);

And How convert DisplayConfigSupportVirtualResolution to DISPLAYCONFIG_DEVICE_INFO_HEADER?

nxnxfly avatar Dec 16 '20 07:12 nxnxfly

Yes, that part is correct. It is not the source of the problem. You see, DisplayConfigGetDeviceInfo fills data based on the header of the passed struct. So in this case, DisplayConfigSupportVirtualResolution is a struct that is used to get virtual resolution information. What you are seeing in the native signature as DISPLAYCONFIG_DEVICE_INFO_HEADER is actually defined as DisplayConfigDeviceInfoHeader in this library and is included as the header of the DisplayConfigSupportVirtualResolution to notify the native method of the type of the data requested.

Check here: https://github.com/falahati/WindowsDisplayAPI/blob/62e27b37dd1a3aa4e49a36286ae39b5aee7f3671/WindowsDisplayAPI/Native/DisplayConfig/Structures/DisplayConfigSupportVirtualResolution.cs#L11 And here: https://github.com/falahati/WindowsDisplayAPI/blob/62e27b37dd1a3aa4e49a36286ae39b5aee7f3671/WindowsDisplayAPI/Native/DisplayConfig/Structures/DisplayConfigDeviceInfoHeader.cs

falahati avatar Dec 17 '20 22:12 falahati