From e91127bc5cfde808d19272280c91789482ef5a59 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 11 Oct 2013 14:56:37 -0700 Subject: [PATCH] implement hide cursor on no mouse movement --- interface/src/Application.cpp | 17 +++++++++++++++++ interface/src/Application.h | 2 ++ 2 files changed, 19 insertions(+) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index bdd1f8379f..a90244cd21 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -105,6 +105,8 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : _profile(QString()), _mouseX(0), _mouseY(0), + _lastMouseMove(usecTimestampNow()), + _mouseHidden(false), _touchAvgX(0.0f), _touchAvgY(0.0f), _isTouchPressed(false), @@ -978,6 +980,12 @@ void Application::keyReleaseEvent(QKeyEvent* event) { } void Application::mouseMoveEvent(QMouseEvent* event) { + _lastMouseMove = usecTimestampNow(); + if (_mouseHidden) { + getGLWidget()->setCursor(Qt::ArrowCursor); + _mouseHidden = false; + } + if (activeWindow() == _window) { _mouseX = event->x(); _mouseY = event->y(); @@ -2119,6 +2127,15 @@ void Application::update(float deltaTime) { _audio.setLastVelocity(_myAvatar.getVelocity()); _audio.eventuallyAnalyzePing(); #endif + + // watch mouse position, if it hasn't moved, hide the cursor + uint64_t now = usecTimestampNow(); + int elapsed = now - _lastMouseMove; + const int HIDE_CURSOR_TIMEOUT = 1 * 1000 * 1000; // 1 second + if (elapsed > HIDE_CURSOR_TIMEOUT) { + getGLWidget()->setCursor(Qt::BlankCursor); + _mouseHidden = true; + } } void Application::updateAvatar(float deltaTime) { diff --git a/interface/src/Application.h b/interface/src/Application.h index c030b61a74..cb3a3ca73d 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -305,6 +305,8 @@ private: int _mouseY; int _mouseDragStartedX; int _mouseDragStartedY; + uint64_t _lastMouseMove; + bool _mouseHidden; float _touchAvgX; float _touchAvgY;