From fe9fab68bfd6ea1c94d48a16bb5c29d09af4ff78 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 26 Nov 2014 17:30:59 -0800 Subject: [PATCH 1/3] don't exit app in full screen or hdm mode --- interface/src/Application.cpp | 1 + interface/src/ui/HMDToolsDialog.cpp | 103 ++++++++++++++++++---------- interface/src/ui/HMDToolsDialog.h | 4 ++ 3 files changed, 70 insertions(+), 38 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 397f883b3e..6791ae3d62 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -438,6 +438,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : void Application::aboutToQuit() { _aboutToQuit = true; + setFullscreen(false); // if you exit while in full screen, you'll get bad behavior when you restart. } Application::~Application() { diff --git a/interface/src/ui/HMDToolsDialog.cpp b/interface/src/ui/HMDToolsDialog.cpp index a5e54fa546..f2be62a026 100644 --- a/interface/src/ui/HMDToolsDialog.cpp +++ b/interface/src/ui/HMDToolsDialog.cpp @@ -30,7 +30,8 @@ HMDToolsDialog::HMDToolsDialog(QWidget* parent) : QDialog(parent, Qt::Window | Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint) , _previousScreen(NULL), _hmdScreen(NULL), - _previousDialogScreen(NULL) + _previousDialogScreen(NULL), + _inHDMMode(false) { this->setWindowTitle("HMD Tools"); @@ -65,14 +66,18 @@ HMDToolsDialog::HMDToolsDialog(QWidget* parent) : QWindow* mainWindow = Application::getInstance()->getWindow()->windowHandle(); connect(mainWindow, &QWindow::screenChanged, this, &HMDToolsDialog::applicationWindowScreenChanged); - // watch for our dialog window moving screens. If it does we want to enforce our rules about what screens we're - // allowed on + // watch for our dialog window moving screens. If it does we want to enforce our rules about + // what screens we're allowed on QWindow* dialogWindow = windowHandle(); connect(dialogWindow, &QWindow::screenChanged, this, &HMDToolsDialog::dialogWindowScreenChanged); connect(dialogWindow, &QWindow::xChanged, this, &HMDToolsDialog::dialogWindowGeometryChanged); connect(dialogWindow, &QWindow::yChanged, this, &HMDToolsDialog::dialogWindowGeometryChanged); connect(dialogWindow, &QWindow::widthChanged, this, &HMDToolsDialog::dialogWindowGeometryChanged); connect(dialogWindow, &QWindow::heightChanged, this, &HMDToolsDialog::dialogWindowGeometryChanged); + + // when the application is about to quit, leave HDM mode + connect(Application::getInstance(), SIGNAL(aboutToQuit()), this, SLOT(aboutToQuit())); + } HMDToolsDialog::~HMDToolsDialog() { @@ -159,37 +164,45 @@ QString HMDToolsDialog::getDebugDetails() const { } void HMDToolsDialog::enterModeClicked(bool checked) { - _debugDetails->setText(getDebugDetails()); + enterHDMMode(); +} - int hmdScreen = OculusManager::getHMDScreen(); - qDebug() << "enterModeClicked().... hmdScreen:" << hmdScreen; +void HMDToolsDialog::enterHDMMode() { + if (!_inHDMMode) { + _debugDetails->setText(getDebugDetails()); + + int hmdScreen = OculusManager::getHMDScreen(); + qDebug() << "enterModeClicked().... hmdScreen:" << hmdScreen; - if (hmdScreen >= 0) { - QWindow* mainWindow = Application::getInstance()->getWindow()->windowHandle(); - _hmdScreen = QGuiApplication::screens()[hmdScreen]; + if (hmdScreen >= 0) { + QWindow* mainWindow = Application::getInstance()->getWindow()->windowHandle(); + _hmdScreen = QGuiApplication::screens()[hmdScreen]; - _previousRect = Application::getInstance()->getWindow()->rect(); - _previousRect = QRect(mainWindow->mapToGlobal(_previousRect.topLeft()), - mainWindow->mapToGlobal(_previousRect.bottomRight())); - _previousScreen = mainWindow->screen(); - QRect rect = QApplication::desktop()->screenGeometry(hmdScreen); - mainWindow->setScreen(_hmdScreen); - mainWindow->setGeometry(rect); + _previousRect = Application::getInstance()->getWindow()->rect(); + _previousRect = QRect(mainWindow->mapToGlobal(_previousRect.topLeft()), + mainWindow->mapToGlobal(_previousRect.bottomRight())); + _previousScreen = mainWindow->screen(); + QRect rect = QApplication::desktop()->screenGeometry(hmdScreen); + mainWindow->setScreen(_hmdScreen); + mainWindow->setGeometry(rect); - _wasMoved = true; - } + _wasMoved = true; + } - // if we're on a single screen setup, then hide our tools window when entering HMD mode - if (QApplication::desktop()->screenCount() == 1) { - close(); - } + // if we're on a single screen setup, then hide our tools window when entering HMD mode + if (QApplication::desktop()->screenCount() == 1) { + close(); + } - Application::getInstance()->setFullscreen(true); - Application::getInstance()->setEnableVRMode(true); + Application::getInstance()->setFullscreen(true); + Application::getInstance()->setEnableVRMode(true); - const int SLIGHT_DELAY = 500; - QTimer::singleShot(SLIGHT_DELAY, this, SLOT(activateWindowAfterEnterMode())); + const int SLIGHT_DELAY = 500; + QTimer::singleShot(SLIGHT_DELAY, this, SLOT(activateWindowAfterEnterMode())); + + _inHDMMode = true; + } } void HMDToolsDialog::activateWindowAfterEnterMode() { @@ -199,23 +212,30 @@ void HMDToolsDialog::activateWindowAfterEnterMode() { centerCursorOnWidget(Application::getInstance()->getWindow()); } - void HMDToolsDialog::leaveModeClicked(bool checked) { - _debugDetails->setText(getDebugDetails()); + leaveHDMMode(); +} - Application::getInstance()->setFullscreen(false); - Application::getInstance()->setEnableVRMode(false); - Application::getInstance()->getWindow()->activateWindow(); - if (_wasMoved) { - QWindow* mainWindow = Application::getInstance()->getWindow()->windowHandle(); - mainWindow->setScreen(_previousScreen); - mainWindow->setGeometry(_previousRect); +void HMDToolsDialog::leaveHDMMode() { + if (_inHDMMode) { + _debugDetails->setText(getDebugDetails()); + + Application::getInstance()->setFullscreen(false); + Application::getInstance()->setEnableVRMode(false); + Application::getInstance()->getWindow()->activateWindow(); + + if (_wasMoved) { + QWindow* mainWindow = Application::getInstance()->getWindow()->windowHandle(); + mainWindow->setScreen(_previousScreen); + mainWindow->setGeometry(_previousRect); - const int SLIGHT_DELAY = 1500; - QTimer::singleShot(SLIGHT_DELAY, this, SLOT(moveWindowAfterLeaveMode())); + const int SLIGHT_DELAY = 1500; + QTimer::singleShot(SLIGHT_DELAY, this, SLOT(moveWindowAfterLeaveMode())); + } + _wasMoved = false; + _inHDMMode = false; } - _wasMoved = false; } void HMDToolsDialog::moveWindowAfterLeaveMode() { @@ -256,3 +276,10 @@ void HMDToolsDialog::hideEvent(QHideEvent* event) { } +void HMDToolsDialog::aboutToQuit() { + if (_inHDMMode) { + leaveHDMMode(); + } +} + + diff --git a/interface/src/ui/HMDToolsDialog.h b/interface/src/ui/HMDToolsDialog.h index 4fe0dd626f..d2068d9e82 100644 --- a/interface/src/ui/HMDToolsDialog.h +++ b/interface/src/ui/HMDToolsDialog.h @@ -35,6 +35,7 @@ public slots: void applicationWindowScreenChanged(QScreen* screen); void dialogWindowScreenChanged(QScreen* screen); void dialogWindowGeometryChanged(int arg); + void aboutToQuit(); protected: virtual void closeEvent(QCloseEvent*); // Emits a 'closed' signal when this dialog is closed. @@ -43,6 +44,8 @@ protected: private: void centerCursorOnWidget(QWidget* widget); + void enterHDMMode(); + void leaveHDMMode(); bool _wasMoved; QRect _previousRect; @@ -52,6 +55,7 @@ private: QRect _previousDialogRect; QScreen* _previousDialogScreen; + bool _inHDMMode; }; #endif // hifi_HMDToolsDialog_h From 184acaedefa7e5ff8b7aecb520529ec8f982dc7e Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 26 Nov 2014 19:43:01 -0800 Subject: [PATCH 2/3] switch to single button for mode switching --- interface/src/ui/HMDToolsDialog.cpp | 31 ++++++++++++++--------------- interface/src/ui/HMDToolsDialog.h | 4 ++-- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/interface/src/ui/HMDToolsDialog.cpp b/interface/src/ui/HMDToolsDialog.cpp index f2be62a026..d7cb5b4756 100644 --- a/interface/src/ui/HMDToolsDialog.cpp +++ b/interface/src/ui/HMDToolsDialog.cpp @@ -28,6 +28,8 @@ HMDToolsDialog::HMDToolsDialog(QWidget* parent) : QDialog(parent, Qt::Window | Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint) , + _switchModeButton(NULL), + _debugDetails(NULL), _previousScreen(NULL), _hmdScreen(NULL), _previousDialogScreen(NULL), @@ -37,21 +39,17 @@ HMDToolsDialog::HMDToolsDialog(QWidget* parent) : // Create layouter QFormLayout* form = new QFormLayout(); + const int WIDTH = 350; // Add a button to enter - QPushButton* enterModeButton = new QPushButton("Enter HMD Mode"); - form->addRow("", enterModeButton); - connect(enterModeButton,SIGNAL(clicked(bool)),this,SLOT(enterModeClicked(bool))); - - // Add a button to leave - QPushButton* leaveModeButton = new QPushButton("Leave HMD Mode"); - form->addRow("", leaveModeButton); - connect(leaveModeButton,SIGNAL(clicked(bool)),this,SLOT(leaveModeClicked(bool))); + _switchModeButton = new QPushButton("Enter HMD Mode"); + _switchModeButton->setFixedWidth(WIDTH); + form->addRow("", _switchModeButton); + connect(_switchModeButton,SIGNAL(clicked(bool)),this,SLOT(switchModeClicked(bool))); // Create a label with debug details... _debugDetails = new QLabel(); _debugDetails->setText(getDebugDetails()); - const int WIDTH = 350; const int HEIGHT = 100; _debugDetails->setFixedSize(WIDTH, HEIGHT); form->addRow("", _debugDetails); @@ -163,12 +161,17 @@ QString HMDToolsDialog::getDebugDetails() const { return results; } -void HMDToolsDialog::enterModeClicked(bool checked) { - enterHDMMode(); +void HMDToolsDialog::switchModeClicked(bool checked) { + if (!_inHDMMode) { + enterHDMMode(); + } else { + leaveHDMMode(); + } } void HMDToolsDialog::enterHDMMode() { if (!_inHDMMode) { + _switchModeButton->setText("Leave HMD Mode"); _debugDetails->setText(getDebugDetails()); int hmdScreen = OculusManager::getHMDScreen(); @@ -212,13 +215,9 @@ void HMDToolsDialog::activateWindowAfterEnterMode() { centerCursorOnWidget(Application::getInstance()->getWindow()); } -void HMDToolsDialog::leaveModeClicked(bool checked) { - leaveHDMMode(); -} - - void HMDToolsDialog::leaveHDMMode() { if (_inHDMMode) { + _switchModeButton->setText("Enter HMD Mode"); _debugDetails->setText(getDebugDetails()); Application::getInstance()->setFullscreen(false); diff --git a/interface/src/ui/HMDToolsDialog.h b/interface/src/ui/HMDToolsDialog.h index d2068d9e82..91db300224 100644 --- a/interface/src/ui/HMDToolsDialog.h +++ b/interface/src/ui/HMDToolsDialog.h @@ -28,8 +28,7 @@ signals: public slots: void reject(); - void enterModeClicked(bool checked); - void leaveModeClicked(bool checked); + void switchModeClicked(bool checked); void activateWindowAfterEnterMode(); void moveWindowAfterLeaveMode(); void applicationWindowScreenChanged(QScreen* screen); @@ -51,6 +50,7 @@ private: QRect _previousRect; QScreen* _previousScreen; QScreen* _hmdScreen; + QPushButton* _switchModeButton; QLabel* _debugDetails; QRect _previousDialogRect; From fe010b685a6a9ccf71348986ce85e5605ba145c5 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 26 Nov 2014 20:19:23 -0800 Subject: [PATCH 3/3] more HMD Tools improvements, better support for detecting adding/removing screens --- interface/src/ui/HMDToolsDialog.cpp | 47 ++++++++++++++++++++++------- interface/src/ui/HMDToolsDialog.h | 6 ++-- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/interface/src/ui/HMDToolsDialog.cpp b/interface/src/ui/HMDToolsDialog.cpp index d7cb5b4756..88924f68d1 100644 --- a/interface/src/ui/HMDToolsDialog.cpp +++ b/interface/src/ui/HMDToolsDialog.cpp @@ -28,10 +28,11 @@ HMDToolsDialog::HMDToolsDialog(QWidget* parent) : QDialog(parent, Qt::Window | Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint) , - _switchModeButton(NULL), - _debugDetails(NULL), _previousScreen(NULL), _hmdScreen(NULL), + _hmdScreenNumber(-1), + _switchModeButton(NULL), + _debugDetails(NULL), _previousDialogScreen(NULL), _inHDMMode(false) { @@ -75,6 +76,9 @@ HMDToolsDialog::HMDToolsDialog(QWidget* parent) : // when the application is about to quit, leave HDM mode connect(Application::getInstance(), SIGNAL(aboutToQuit()), this, SLOT(aboutToQuit())); + + // keep track of changes to the number of screens + connect(QApplication::desktop(), &QDesktopWidget::screenCountChanged, this, &HMDToolsDialog::screenCountChanged); } @@ -99,11 +103,11 @@ void HMDToolsDialog::dialogWindowScreenChanged(QScreen* screen) { // if we have more than one screen, and a known hmdScreen then try to // keep our dialog off of the hmdScreen if (QApplication::desktop()->screenCount() > 1) { - int hmdScreenNumber = OculusManager::getHMDScreen(); - - if (hmdScreenNumber >= 0) { - QScreen* hmdScreen = QGuiApplication::screens()[hmdScreenNumber]; + // we want to use a local variable here because we are not necesarily in HMD mode + int hmdScreenNumber = OculusManager::getHMDScreen(); + if (_hmdScreenNumber >= 0) { + QScreen* hmdScreen = QGuiApplication::screens()[hmdScreenNumber]; if (screen == hmdScreen) { qDebug() << "HMD Tools: Whoa! What are you doing? You don't want to move me to the HMD Screen!"; QWindow* dialogWindow = windowHandle(); @@ -157,6 +161,7 @@ QString HMDToolsDialog::getDebugDetails() const { results += "Application Primary Screen: " + QGuiApplication::primaryScreen()->name() + "\n"; QScreen* mainWindowScreen = Application::getInstance()->getWindow()->windowHandle()->screen(); results += "Application Main Window Screen: " + mainWindowScreen->name() + "\n"; + results += "Total Screens: " + QString::number(QApplication::desktop()->screenCount()) + "\n"; return results; } @@ -174,18 +179,17 @@ void HMDToolsDialog::enterHDMMode() { _switchModeButton->setText("Leave HMD Mode"); _debugDetails->setText(getDebugDetails()); - int hmdScreen = OculusManager::getHMDScreen(); - qDebug() << "enterModeClicked().... hmdScreen:" << hmdScreen; + _hmdScreenNumber = OculusManager::getHMDScreen(); - if (hmdScreen >= 0) { + if (_hmdScreenNumber >= 0) { QWindow* mainWindow = Application::getInstance()->getWindow()->windowHandle(); - _hmdScreen = QGuiApplication::screens()[hmdScreen]; + _hmdScreen = QGuiApplication::screens()[_hmdScreenNumber]; _previousRect = Application::getInstance()->getWindow()->rect(); _previousRect = QRect(mainWindow->mapToGlobal(_previousRect.topLeft()), mainWindow->mapToGlobal(_previousRect.bottomRight())); _previousScreen = mainWindow->screen(); - QRect rect = QApplication::desktop()->screenGeometry(hmdScreen); + QRect rect = QApplication::desktop()->screenGeometry(_hmdScreenNumber); mainWindow->setScreen(_hmdScreen); mainWindow->setGeometry(rect); @@ -281,4 +285,25 @@ void HMDToolsDialog::aboutToQuit() { } } +void HMDToolsDialog::screenCountChanged(int newCount) { + if (!OculusManager::isConnected()) { + OculusManager::connect(); + } + int hmdScreenNumber = OculusManager::getHMDScreen(); + + if (_inHDMMode && _hmdScreenNumber != hmdScreenNumber) { + qDebug() << "HMD Display changed WHILE IN HMD MODE"; + leaveHDMMode(); + + // if there is a new best HDM screen then go back into HDM mode after done leaving + if (hmdScreenNumber >= 0) { + qDebug() << "Trying to go back into HDM Mode"; + const int SLIGHT_DELAY = 2000; + QTimer::singleShot(SLIGHT_DELAY, this, SLOT(enterHDMMode())); + } + } + _debugDetails->setText(getDebugDetails()); +} + + diff --git a/interface/src/ui/HMDToolsDialog.h b/interface/src/ui/HMDToolsDialog.h index 91db300224..e3e5573533 100644 --- a/interface/src/ui/HMDToolsDialog.h +++ b/interface/src/ui/HMDToolsDialog.h @@ -34,8 +34,9 @@ public slots: void applicationWindowScreenChanged(QScreen* screen); void dialogWindowScreenChanged(QScreen* screen); void dialogWindowGeometryChanged(int arg); - void aboutToQuit(); - + void aboutToQuit(); + void screenCountChanged(int newCount); + protected: virtual void closeEvent(QCloseEvent*); // Emits a 'closed' signal when this dialog is closed. virtual void showEvent(QShowEvent* event); @@ -50,6 +51,7 @@ private: QRect _previousRect; QScreen* _previousScreen; QScreen* _hmdScreen; + int _hmdScreenNumber; QPushButton* _switchModeButton; QLabel* _debugDetails;