From 6f9fdfba2fc001a175cf271adee235a50fc78da4 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 14 Oct 2013 11:39:48 -0700 Subject: [PATCH] make mouse cursor hiding more aware of focused window and bounds --- interface/src/Application.cpp | 24 ++++++++++++++++++------ interface/src/Application.h | 1 + 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 9afb269f1b..81e40cc109 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -107,6 +107,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : _mouseY(0), _lastMouseMove(usecTimestampNow()), _mouseHidden(false), + _seenMouseMove(false), _touchAvgX(0.0f), _touchAvgY(0.0f), _isTouchPressed(false), @@ -988,6 +989,7 @@ void Application::mouseMoveEvent(QMouseEvent* event) { if (_mouseHidden) { getGLWidget()->setCursor(Qt::ArrowCursor); _mouseHidden = false; + _seenMouseMove = true; } if (activeWindow() == _window) { @@ -2133,12 +2135,22 @@ void Application::update(float deltaTime) { #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; + bool underMouse = _glWidget->underMouse(); + if (!_mouseHidden) { + uint64_t now = usecTimestampNow(); + int elapsed = now - _lastMouseMove; + const int HIDE_CURSOR_TIMEOUT = 1 * 1000 * 1000; // 1 second + if (elapsed > HIDE_CURSOR_TIMEOUT && (underMouse || !_seenMouseMove)) { + getGLWidget()->setCursor(Qt::BlankCursor); + _mouseHidden = true; + } + } else { + // if the mouse is hidden, but we're not inside our window, then consider ourselves to be moving + if (!underMouse && _seenMouseMove) { + _lastMouseMove = usecTimestampNow(); + getGLWidget()->setCursor(Qt::ArrowCursor); + _mouseHidden = false; + } } } diff --git a/interface/src/Application.h b/interface/src/Application.h index cb3a3ca73d..595f337bf5 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -307,6 +307,7 @@ private: int _mouseDragStartedY; uint64_t _lastMouseMove; bool _mouseHidden; + bool _seenMouseMove; float _touchAvgX; float _touchAvgY;