From f48dd9e1cf9c29f5a55020ca3c0e8cf6416fb955 Mon Sep 17 00:00:00 2001
From: Tobias scheuer <tobias.scheuer@sap.com>
Date: Wed, 9 Aug 2017 12:44:41 +0200
Subject: [PATCH] fix get_monitor_info on windows

---
 src/win/wsystem.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/win/wsystem.c b/src/win/wsystem.c
index 26fbe9ef0..fc87d1456 100644
--- a/src/win/wsystem.c
+++ b/src/win/wsystem.c
@@ -481,6 +481,23 @@ static int win_get_num_video_adapters(void)
    return c;
 }
 
+static int win_find_nth_adapter_with_desktop(DISPLAY_DEVICE* pdd, int adapter)
+{
+   int count = 0;
+   int c = 0;
+
+   while (EnumDisplayDevices(NULL, count, pdd, 0)) {
+      if (pdd->StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) {
+         if (c == adapter)
+            return true;
+         c++;
+      }
+      count++;
+   }
+
+   return false;
+}
+
 static bool win_get_monitor_info(int adapter, ALLEGRO_MONITOR_INFO *info)
 {
    DISPLAY_DEVICE dd;
@@ -488,7 +505,7 @@ static bool win_get_monitor_info(int adapter, ALLEGRO_MONITOR_INFO *info)
 
    memset(&dd, 0, sizeof(dd));
    dd.cb = sizeof(dd);
-   if (!EnumDisplayDevices(NULL, adapter, &dd, 0)) {
+   if (!win_find_nth_adapter_with_desktop(&dd, adapter)) {
       return false;
    }
 
-- 
2.11.0.windows.1

