瀏覽代碼

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 年之前
父節點
當前提交
78f379795e
共有 1 個文件被更改,包括 18 次插入12 次删除
  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;
     }
   }