Browse Source

Add display status to debug overlay

Will help with testing and troubleshooting.

One detail is that we add an ugly bool parameter to
getApplicationDisplay(). This is to avoid log spam, because the debug
overlay is updated every second.
Vincent Lang 9 years ago
parent
commit
fbbc816c61

+ 61 - 6
src/display/DisplayComponent.cpp

@@ -221,25 +221,80 @@ bool DisplayComponent::restorePreviousVideoMode()
 
 
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
-int DisplayComponent::getApplicationDisplay()
+int DisplayComponent::getApplicationDisplay(bool silent)
 {
 {
   QWindow* activeWindow = m_applicationWindow;
   QWindow* activeWindow = m_applicationWindow;
 
 
   int display = -1;
   int display = -1;
   if (activeWindow && m_displayManager)
   if (activeWindow && m_displayManager)
   {
   {
-    QLOG_DEBUG() << "Looking for a display at:" << activeWindow->geometry()
-                 << "(center:" << activeWindow->geometry().center() << ")";
+    if (!silent)
+    {
+      QLOG_DEBUG() << "Looking for a display at:" << activeWindow->geometry()
+                   << "(center:" << activeWindow->geometry().center() << ")";
+    }
     display = m_displayManager->getDisplayFromPoint(activeWindow->geometry().center());
     display = m_displayManager->getDisplayFromPoint(activeWindow->geometry().center());
   }
   }
 
 
+  if (!silent)
+  {
+    QLOG_DEBUG() << "Display index:" << display;
+  }
+  return display;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+QString DisplayComponent::displayName(int display)
+{
   if (display < 0)
   if (display < 0)
+    return "(not found)";
+  QString id = QString("#%0 ").arg(display);
+  if (m_displayManager->isValidDisplay(display))
+    return id + m_displayManager->displays[display]->name;
+  else
+    return id + "(not valid)";
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+QString DisplayComponent::modePretty(int display, int mode)
+{
+  if (mode < 0)
+    return "(not found)";
+  QString id = QString("#%0 ").arg(mode);
+  if (m_displayManager->isValidDisplayMode(display, mode))
+    return id + m_displayManager->displays[display]->videoModes[mode]->getPrettyName();
+  else
+    return id + "(not valid)";
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+QString DisplayComponent::debugInformation()
+{
+  QString debugInfo;
+  QTextStream stream(&debugInfo);
+  stream << "Display" << endl;
+
+  if (!m_displayManager)
   {
   {
-    QLOG_WARN() << "Unable to locate current display.";
+    stream << "  (no DisplayManager initialized)" << endl;
   }
   }
   else
   else
   {
   {
-    QLOG_DEBUG() << "Display found:" << display;
+    int display = getApplicationDisplay(true);
+    int mode = display < 0 ? -1 : m_displayManager->getCurrentDisplayMode(display);
+
+    stream << "  Current screen: " << displayName(display) << endl;
+    if (display >= 0)
+      stream << "  Current mode: " << modePretty(display, mode) << endl;
+    if (m_displayManager->isValidDisplayMode(m_lastDisplay, m_lastVideoMode))
+    {
+      stream << "  Switch back on screen: " << displayName(m_lastDisplay) << endl;
+      stream << "  Switch back to mode: " << modePretty(m_lastDisplay, m_lastVideoMode) << endl;
+    }
   }
   }
-  return display;
+
+  stream << endl;
+  stream << flush;
+  return debugInfo;
 }
 }
+

+ 5 - 1
src/display/DisplayComponent.h

@@ -19,7 +19,7 @@ public:
   virtual bool componentInitialize();
   virtual bool componentInitialize();
 
 
   inline DisplayManager* getDisplayManager() { return m_displayManager; }
   inline DisplayManager* getDisplayManager() { return m_displayManager; }
-  int getApplicationDisplay();
+  int getApplicationDisplay(bool silent = false);
 
 
   void setApplicationWindow(QWindow* window) { m_applicationWindow = window; }
   void setApplicationWindow(QWindow* window) { m_applicationWindow = window; }
 
 
@@ -33,8 +33,12 @@ public:
 
 
   double currentRefreshRate();
   double currentRefreshRate();
 
 
+  QString debugInformation();
+
 private:
 private:
   DisplayComponent(QObject *parent = 0);
   DisplayComponent(QObject *parent = 0);
+  QString displayName(int display);
+  QString modePretty(int display, int mode);
 
 
   DisplayManager  *m_displayManager;
   DisplayManager  *m_displayManager;
   int m_lastVideoMode;
   int m_lastVideoMode;

+ 4 - 2
src/ui/KonvergoWindow.cpp

@@ -317,8 +317,10 @@ void KonvergoWindow::onScreenCountChanged(int newCount)
 /////////////////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////////////////
 void KonvergoWindow::updateDebugInfo()
 void KonvergoWindow::updateDebugInfo()
 {
 {
-  if (m_debugInfo.size() == 0)
-    m_debugInfo = SystemComponent::Get().debugInformation();
+  if (m_systemDebugInfo.size() == 0)
+    m_systemDebugInfo = SystemComponent::Get().debugInformation();
+  m_debugInfo = m_systemDebugInfo;
+  m_debugInfo += DisplayComponent::Get().debugInformation();
   m_videoInfo = PlayerComponent::Get().videoInformation();
   m_videoInfo = PlayerComponent::Get().videoInformation();
   emit debugInfoChanged();
   emit debugInfoChanged();
 }
 }

+ 1 - 1
src/ui/KonvergoWindow.h

@@ -73,7 +73,7 @@ private:
   bool m_debugLayer;
   bool m_debugLayer;
   MouseEventFilter* m_eventFilter;
   MouseEventFilter* m_eventFilter;
   QTimer* m_infoTimer;
   QTimer* m_infoTimer;
-  QString m_debugInfo, m_videoInfo;
+  QString m_debugInfo, m_systemDebugInfo, m_videoInfo;
 };
 };
 
 
 #endif // KONVERGOWINDOW_H
 #endif // KONVERGOWINDOW_H