Kaynağa Gözat

DisplayManagerWin: simplify getDisplayFromPoint()

Instead of calling getCurrentDisplayMode() and 	getModeInfo()
just to retrieve the DEVMODE (which is quite roudnabout), query the
current DEVMODE directly. This is conceptually simpler, and avoids
hitting bugs in these functions. This change also adds more logging.
Vincent Lang 9 yıl önce
ebeveyn
işleme
78f379795e
1 değiştirilmiş dosya ile 18 ekleme ve 12 silme
  1. 18 12
      src/display/win/DisplayManagerWin.cpp

+ 18 - 12
src/display/win/DisplayManagerWin.cpp

@@ -176,20 +176,26 @@ int DisplayManagerWin::getDisplayFromPoint(int x, int y)
 {
   foreach (int displayId, displays.keys())
   {
-    int currentMode = getCurrentDisplayMode(displayId);
-    if (currentMode >= 0)
+    QString dispName = m_displayAdapters[displayId];
+
+    DEVMODEW modeInfo = {};
+    modeInfo.dmSize = sizeof(modeInfo);
+
+    QLOG_DEBUG() << "Looking at display" << displayId << dispName;
+
+    if (!EnumDisplaySettingsW((LPCWSTR)dispName.utf16(), ENUM_CURRENT_SETTINGS,
+                              &modeInfo))
     {
-      DEVMODEW modeInfo;
-      if (getModeInfo(displayId, currentMode, modeInfo))
-      {
-        QRect displayRect(modeInfo.dmPosition.x, modeInfo.dmPosition.y, modeInfo.dmPelsWidth,
-                          modeInfo.dmPelsHeight);
-        QLOG_DEBUG() << "Looking at display" << displayId << "mode" << currentMode
-                     << "at" << displayRect;
+      QLOG_ERROR() << "Failed to retrieve current mode.";
+    }
+    else
+    {
+      QRect displayRect(modeInfo.dmPosition.x, modeInfo.dmPosition.y, modeInfo.dmPelsWidth,
+                        modeInfo.dmPelsHeight);
+      QLOG_DEBUG() << "Position on virtual desktop:" << displayRect;
 
-        if (displayRect.contains(x, y))
-          return displayId;
-      }
+      if (displayRect.contains(x, y))
+        return displayId;
     }
   }