bug about multiple displays and first one is not connected to desktop
tobing

Hi, today I debugged into an issue and here's what I found.

Windows 10, Intel graphics.

The laptop has three displays which are enumerated in wsystem.c, and unfortunately only one has the flag DISPLAY_DEVICE_ATTACHED_TO_DESKTOP set. So the reported number of display drivers is 1, but the adapter 0 is not connected to the desktop, which results in win_get_monitor_info reporting a size of 0,0.

So there is an implicit assumption: all enumerated displays which are connected to the desktop are listed first.

I'm not sure about the linux part, but on windows well it's not always true.

As a side note, this happens when I set the laptop to sleep and take put it back into the docking station which is connected to a 4k monitor...

The solution is to use the same logic within win_get_monitor_info as is used in win_get_num_video_adapters to find the nth display that is connected to a desktop.

Here's the updated code (on recent (liballeg/master) wsystem.c line 484ff:

#SelectExpand
1/* new function */ 2static int win_find_nth_adapter_with_desktop(DISPLAY_DEVICE* pdd, int adapter) 3{ 4 int count = 0; 5 int c = 0; 6 7 while(EnumDisplayDevices(NULL, count, pdd, 0)) { 8 if(pdd->StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) { 9 if(c == adapter) 10 return true; 11 c++; 12 } 13 count++; 14 } 15 16 return false; 17} 18 19static bool win_get_monitor_info(int adapter, ALLEGRO_MONITOR_INFO *info) 20{ 21 DISPLAY_DEVICE dd; 22 DEVMODE dm; 23 24 memset(&dd, 0, sizeof(dd)); 25 dd.cb = sizeof(dd); 26 if(!win_find_nth_adapter_with_desktop(&dd, adapter)) /* use new function */ 27 return false; 28 29 memset(&dm, 0, sizeof(dm)); 30 dm.dmSize = sizeof(dm); 31 if (!EnumDisplaySettings(dd.DeviceName, ENUM_CURRENT_SETTINGS, &dm)) { 32 return false; 33 } 34...

I'll try to format a patch as well.

Edit: patch file attached.

SiegeLord

Thanks a lot! I tried to reproduce this issue, but I couldn't so thanks a lot for your work and fix. The logic seems to make sense and it doesn't seem to break things for me.

tobing

Thanks for submitting!

Thread #617001. Printed from Allegro.cc