From 5f97b1cf6223589b87ccb64d8ec3a5d6a960520b Mon Sep 17 00:00:00 2001 From: Craig Watson Date: Fri, 6 May 2016 12:25:34 +0200 Subject: [PATCH] Fixed indexing of control and display screens Caused problems e.g with podcast mode, where if the control and display views were swapped in the preferences, the wrong screen would be recorded when switching to desktop mode during recording of the podcast. This happened even if only one screen was plugged in, so a black screen was recorded in that case (at least on OS X 10.10) --- src/core/UBApplication.cpp | 15 +++++++++++++++ src/core/UBApplication.h | 3 +++ src/core/UBDisplayManager.cpp | 4 ++-- src/desktop/UBDesktopAnnotationController.cpp | 2 +- src/gui/UBScreenMirror.cpp | 2 +- src/podcast/UBPodcastController.cpp | 4 ++-- src/web/browser/WBBrowserWindow.cpp | 2 +- 7 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/core/UBApplication.cpp b/src/core/UBApplication.cpp index 494feff8..9e08461b 100644 --- a/src/core/UBApplication.cpp +++ b/src/core/UBApplication.cpp @@ -670,3 +670,18 @@ bool UBApplication::isFromWeb(QString url) return res; } + +QScreen* UBApplication::controlScreen() +{ + QList screenList = screens(); + if (screenList.size() == 1) + return screenList.first(); + + return screenList[controlScreenIndex()]; +} + + +int UBApplication::controlScreenIndex() +{ + return applicationController->displayManager()->controleScreenIndex(); +} diff --git a/src/core/UBApplication.h b/src/core/UBApplication.h index ccb8f605..848b96d3 100644 --- a/src/core/UBApplication.h +++ b/src/core/UBApplication.h @@ -100,6 +100,9 @@ class UBApplication : public QtSingleApplication static QString urlFromHtml(QString html); static bool isFromWeb(QString url); + static QScreen* controlScreen(); + static int controlScreenIndex(); + signals: public slots: diff --git a/src/core/UBDisplayManager.cpp b/src/core/UBDisplayManager.cpp index 21cb706d..89a80b96 100644 --- a/src/core/UBDisplayManager.cpp +++ b/src/core/UBDisplayManager.cpp @@ -71,7 +71,7 @@ void UBDisplayManager::initScreenIndexes() if (screenCount > 0) { mControlScreenIndex = mDesktop->primaryScreen(); - if (UBSettings::settings()->swapControlAndDisplayScreens->get().toBool()) + if (mDesktop->screenCount() > 1 && UBSettings::settings()->swapControlAndDisplayScreens->get().toBool()) { mControlScreenIndex = mControlScreenIndex^1; } @@ -118,7 +118,7 @@ int UBDisplayManager::numScreens() { if (mUseMultiScreen) { - return mDesktop->numScreens(); + return mDesktop->screenCount(); } else { diff --git a/src/desktop/UBDesktopAnnotationController.cpp b/src/desktop/UBDesktopAnnotationController.cpp index 4f7a0a76..f34fb7b5 100644 --- a/src/desktop/UBDesktopAnnotationController.cpp +++ b/src/desktop/UBDesktopAnnotationController.cpp @@ -500,7 +500,7 @@ void UBDesktopAnnotationController::screenCapture() QPixmap UBDesktopAnnotationController::getScreenPixmap() { QDesktopWidget *desktop = QApplication::desktop(); - QScreen * screen = QApplication::primaryScreen(); + QScreen * screen = UBApplication::controlScreen(); QRect rect = desktop->screenGeometry(QCursor::pos()); diff --git a/src/gui/UBScreenMirror.cpp b/src/gui/UBScreenMirror.cpp index a8bc0f37..e9fd0020 100644 --- a/src/gui/UBScreenMirror.cpp +++ b/src/gui/UBScreenMirror.cpp @@ -99,7 +99,7 @@ void UBScreenMirror::grabPixmap() // this is the case we are showing the desktop but the is no widget and we use the last widget rectagle to know // what we have to grab. Not very good way of doing QDesktopWidget * desktop = QApplication::desktop(); - QScreen * screen = QApplication::primaryScreen(); + QScreen * screen = UBApplication::controlScreen(); mLastPixmap = screen->grabWindow(desktop->effectiveWinId(), mRect.x(), mRect.y(), mRect.width(), mRect.height()); } diff --git a/src/podcast/UBPodcastController.cpp b/src/podcast/UBPodcastController.cpp index b588ca96..9ac2fc1d 100644 --- a/src/podcast/UBPodcastController.cpp +++ b/src/podcast/UBPodcastController.cpp @@ -762,8 +762,8 @@ void UBPodcastController::timerEvent(QTimerEvent *event) && mSourceWidget == qApp->desktop()) { QDesktopWidget * dtop = QApplication::desktop(); - QRect dtopRect = dtop->screenGeometry(); - QScreen * screen = QApplication::primaryScreen(); + QRect dtopRect = dtop->screenGeometry(UBApplication::controlScreenIndex()); + QScreen * screen = UBApplication::controlScreen(); QPixmap desktop = screen->grabWindow(dtop->effectiveWinId(), dtopRect.x(), dtopRect.y(), dtopRect.width(), dtopRect.height()); diff --git a/src/web/browser/WBBrowserWindow.cpp b/src/web/browser/WBBrowserWindow.cpp index 8cba1382..520b861e 100644 --- a/src/web/browser/WBBrowserWindow.cpp +++ b/src/web/browser/WBBrowserWindow.cpp @@ -182,7 +182,7 @@ WBHistoryManager *WBBrowserWindow::historyManager() QSize WBBrowserWindow::sizeHint() const { - QRect desktopRect = QApplication::desktop()->screenGeometry(); + QRect desktopRect = QApplication::desktop()->screenGeometry(UBApplication::controlScreenIndex()); QSize size = desktopRect.size() * qreal(0.9); return size; }