diff --git a/gvr-interface/src/GVRInterface.cpp b/gvr-interface/src/GVRInterface.cpp index 51e2182775..aa30a563e8 100644 --- a/gvr-interface/src/GVRInterface.cpp +++ b/gvr-interface/src/GVRInterface.cpp @@ -17,19 +17,18 @@ #include #include -#endif - -#include -#include - #ifdef HAVE_LIBOVR -#include #include #include #include #endif +#endif + +#include +#include +#include #include "GVRMainWindow.h" #include "RenderingClient.h" diff --git a/gvr-interface/src/GVRInterface.h b/gvr-interface/src/GVRInterface.h index b126dd1a45..c3f7d0167a 100644 --- a/gvr-interface/src/GVRInterface.h +++ b/gvr-interface/src/GVRInterface.h @@ -14,12 +14,13 @@ #include -class RenderingClient; - -#ifdef HAVE_LIBOVR +#if defined(ANDROID) && defined(HAVE_LIBOVR) class ovrMobile; class ovrHmdInfo; -#endif +#endif + +class RenderingClient; +class QKeyEvent; #if defined(qApp) #undef qApp @@ -29,10 +30,12 @@ class ovrHmdInfo; class GVRInterface : public QApplication { Q_OBJECT public: - GVRInterface(int argc, char* argv[]); - + GVRInterface(int argc, char* argv[]); RenderingClient* getClient() { return _client; } +protected: + void keyPressEvent(QKeyEvent* event); + private slots: void handleApplicationStateChange(Qt::ApplicationState state); void idle(); @@ -41,13 +44,13 @@ private: void enterVRMode(); void leaveVRMode(); - RenderingClient* _client; - bool _inVRMode; - -#ifdef HAVE_LIBOVR +#if defined(ANDROID) && defined(HAVE_LIBOVR) ovrMobile* _ovr; ovrHmdInfo* _hmdInfo; #endif + + RenderingClient* _client; + bool _inVRMode; }; #endif // hifi_GVRInterface_h diff --git a/gvr-interface/src/GVRMainWindow.cpp b/gvr-interface/src/GVRMainWindow.cpp index 1589afd009..fbdee20435 100644 --- a/gvr-interface/src/GVRMainWindow.cpp +++ b/gvr-interface/src/GVRMainWindow.cpp @@ -9,13 +9,18 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include #include -#include #include #include +#include #ifndef ANDROID #include +#else +#ifdef HAVE_LIBOVR +#include +#endif #endif #include @@ -25,8 +30,16 @@ #include "GVRMainWindow.h" +const float LIBOVR_DOUBLE_TAP_DURATION = 0.25f; +const float LIBOVR_LONG_PRESS_DURATION = 0.75f; + GVRMainWindow::GVRMainWindow(QWidget* parent) : QMainWindow(parent), +#if defined(ANDROID) && defined(HAVE_LIBOVR) + _backKeyState(LIBOVR_DOUBLE_TAP_DURATION, LIBOVR_LONG_PRESS_DURATION), + _wasBackKeyDown(false), +#endif + _mainLayout(NULL), _menuBar(NULL) { @@ -57,6 +70,31 @@ GVRMainWindow::~GVRMainWindow() { delete _menuBar; } +void GVRMainWindow::keyPressEvent(QKeyEvent* event) { +#ifdef ANDROID + if (event->key() == Qt::Key_Back) { + // got the Android back key, hand off to OVR KeyState + _backKeyState.HandleEvent(ovr_GetTimeInSeconds(), true, (_wasBackKeyDown ? 1 : 0)); + _wasBackKeyDown = true; + return; + } +#endif + QWidget::keyPressEvent(event); +} + +void GVRMainWindow::keyReleaseEvent(QKeyEvent* event) { +#ifdef ANDROID + if (event->key() == Qt::Key_Back) { + // release on the Android back key, hand off to OVR KeyState + _backKeyState.HandleEvent(ovr_GetTimeInSeconds(), false, 0); + _wasBackKeyDown = false; + + auto backEvent = _backKeyState.Update(ovr_GetTimeInSeconds()); + } +#endif + QWidget::keyReleaseEvent(event); +} + void GVRMainWindow::setupMenuBar() { QMenu* fileMenu = new QMenu("File"); QMenu* helpMenu = new QMenu("Help"); diff --git a/gvr-interface/src/GVRMainWindow.h b/gvr-interface/src/GVRMainWindow.h index 44d3bd7196..9f389d9904 100644 --- a/gvr-interface/src/GVRMainWindow.h +++ b/gvr-interface/src/GVRMainWindow.h @@ -14,6 +14,11 @@ #include +#if defined(ANDROID) && defined(HAVE_LIBOVR) +#include +#endif + +class QKeyEvent; class QMenuBar; class QVBoxLayout; @@ -24,9 +29,17 @@ public: ~GVRMainWindow(); public slots: void showAddressBar(); +protected: + void keyPressEvent(QKeyEvent* event); + void keyReleaseEvent(QKeyEvent* event); private: void setupMenuBar(); +#if defined(ANDROID) && defined(HAVE_LIBOVR) + OVR::KeyState _backKeyState; + bool _wasBackKeyDown; +#endif + QVBoxLayout* _mainLayout; QMenuBar* _menuBar; };