diff --git a/interface/resources/controllers/keyboardMouse.json b/interface/resources/controllers/keyboardMouse.json index 9449d37f7d..a91151f4e5 100644 --- a/interface/resources/controllers/keyboardMouse.json +++ b/interface/resources/controllers/keyboardMouse.json @@ -3,9 +3,9 @@ "channels": [ { "from": "Keyboard.A", "when": ["Keyboard.RightMouseButton", "!Keyboard.Control"], "to": "Actions.LATERAL_LEFT" }, { "from": "Keyboard.D", "when": ["Keyboard.RightMouseButton", "!Keyboard.Control"], "to": "Actions.LATERAL_RIGHT" }, - { "from": "Keyboard.E", "when": ["!Application.CameraSelfie", "!Keyboard.Control"], "to": "Actions.LATERAL_RIGHT" }, - { "from": "Keyboard.Q", "when": ["!Application.CameraSelfie", "!Keyboard.Control"], "to": "Actions.LATERAL_LEFT" }, + { "from": "Keyboard.Q", "when": ["!Application.CameraSelfie", "!Keyboard.Control", "!Application.CaptureMouse"], "to": "Actions.LATERAL_LEFT" }, { "from": "Keyboard.Q", "when": ["Application.CameraSelfie", "!Keyboard.Control"], "to": "Actions.LATERAL_RIGHT" }, + { "from": "Keyboard.E", "when": ["!Application.CameraSelfie", "!Keyboard.Control", "!Application.CaptureMouse"], "to": "Actions.LATERAL_RIGHT" }, { "from": "Keyboard.E", "when": ["Application.CameraSelfie", "!Keyboard.Control"], "to": "Actions.LATERAL_LEFT" }, { "from": "Keyboard.T", "when": "!Keyboard.Control", "to": "Actions.TogglePushToTalk" }, @@ -72,46 +72,20 @@ { "from": { "makeAxis" : [ ["Keyboard.Left"], ["Keyboard.Right"] - ] + ] }, - "when": ["Application.CameraFirstPerson", "!Keyboard.Shift"], + "when": ["!Application.CameraFSM", "!Application.CameraIndependent", "!Application.CameraEntity", "!Application.CaptureMouse", "!Keyboard.Shift"], "to": "Actions.Yaw" }, - { "from": { "makeAxis" : [ - ["Keyboard.Left"], - ["Keyboard.Right"] - ] - }, - "when": ["Application.CameraFirstPersonLookat", "!Keyboard.Shift"], - "to": "Actions.Yaw" + { "from": "Keyboard.Left", + "when": ["!Application.CameraFSM", "!Application.CameraIndependent", "!Application.CameraEntity", "Application.CaptureMouse", "!Keyboard.Shift"], + "to": "Actions.LATERAL_LEFT" }, - { "from": { "makeAxis" : [ - ["Keyboard.Left"], - ["Keyboard.Right"] - ] - }, - "when": ["Application.CameraThirdPerson", "!Keyboard.Shift"], - "to": "Actions.Yaw" - }, - - { "from": { "makeAxis" : [ - ["Keyboard.Left"], - ["Keyboard.Right"] - ] - }, - "when": ["Application.CameraLookAt", "!Keyboard.Shift"], - "to": "Actions.Yaw" - }, - - { "from": { "makeAxis" : [ - ["Keyboard.Left"], - ["Keyboard.Right"] - ] - }, - "when": ["Application.CameraSelfie", "!Keyboard.Shift"], - "to": "Actions.Yaw" + { "from": "Keyboard.Right", + "when": ["!Application.CameraFSM", "!Application.CameraIndependent", "!Application.CameraEntity", "Application.CaptureMouse", "!Keyboard.Shift"], + "to": "Actions.LATERAL_RIGHT" }, { "from": { "makeAxis" : [ @@ -119,53 +93,18 @@ ["Keyboard.D"] ] }, - "when": ["Application.CameraFirstPerson", "!Keyboard.Control"], + "when": ["!Application.CameraFSM", "!Application.CameraIndependent", "!Application.CameraEntity", "!Application.CaptureMouse", "!Keyboard.Control"], "to": "Actions.Yaw" }, - { "from": { "makeAxis" : [ - ["Keyboard.A"], - ["Keyboard.D"] - ] - }, - "when": ["Application.CameraFirstPersonLookat", "!Keyboard.Control"], - "to": "Actions.Yaw" + { "from": "Keyboard.A", + "when": ["!Application.CameraFSM", "!Application.CameraIndependent", "!Application.CameraEntity", "Application.CaptureMouse", "!Keyboard.Control"], + "to": "Actions.LATERAL_LEFT" }, - { "from": { "makeAxis" : [ - ["Keyboard.A"], - ["Keyboard.D"] - ] - }, - "when": ["Application.CameraThirdPerson", "!Keyboard.Control"], - "to": "Actions.Yaw" - }, - - { "from": { "makeAxis" : [ - ["Keyboard.A"], - ["Keyboard.D"] - ] - }, - "when": ["Application.CameraLookAt", "!Keyboard.Control"], - "to": "Actions.Yaw" - }, - - { "from": { "makeAxis" : [ - ["Keyboard.A"], - ["Keyboard.D"] - ] - }, - "when": ["Application.CameraSelfie", "!Keyboard.Control"], - "to": "Actions.Yaw" - }, - - { "from": { "makeAxis" : [ - ["Keyboard.TouchpadLeft"], - ["Keyboard.TouchpadRight"] - ] - }, - "when": "Application.CameraFirstPerson", - "to": "Actions.Yaw" + { "from": "Keyboard.D", + "when": ["!Application.CameraFSM", "!Application.CameraIndependent", "!Application.CameraEntity", "Application.CaptureMouse", "!Keyboard.Control"], + "to": "Actions.LATERAL_RIGHT" }, { "from": { "makeAxis" : [ @@ -173,39 +112,12 @@ ["Keyboard.TouchpadRight"] ] }, - "when": "Application.CameraFirstPersonLookat", - "to": "Actions.Yaw" - }, - - { "from": { "makeAxis" : [ - ["Keyboard.TouchpadLeft"], - ["Keyboard.TouchpadRight"] - ] - }, - "when": "Application.CameraThirdPerson", - "to": "Actions.Yaw" - }, - - { "from": { "makeAxis" : [ - ["Keyboard.TouchpadLeft"], - ["Keyboard.TouchpadRight"] - ] - }, - "when": "Application.CameraLookAt", - "to": "Actions.Yaw" - }, - - { "from": { "makeAxis" : [ - ["Keyboard.TouchpadLeft"], - ["Keyboard.TouchpadRight"] - ] - }, - "when": "Application.CameraSelfie", + "when": ["!Application.CameraFSM", "!Application.CameraIndependent", "!Application.CameraEntity"], "to": "Actions.Yaw" }, { "from": { "makeAxis" : ["Keyboard.MouseMoveLeft", "Keyboard.MouseMoveRight"] }, - "when": "Keyboard.RightMouseButton", + "when": ["Keyboard.RightMouseButton", "!Application.CaptureMouse"], "to": "Actions.DeltaYaw", "filters": [ @@ -223,7 +135,7 @@ }, { "from": { "makeAxis" : ["Keyboard.MouseMoveUp", "Keyboard.MouseMoveDown"] }, - "when": ["!Application.CameraSelfie", "!Application.CameraLookAt", "Keyboard.RightMouseButton"], + "when": ["!Application.CameraSelfie", "!Application.CameraLookAt", "!Application.CaptureMouse", "Keyboard.RightMouseButton"], "to": "Actions.DeltaPitch", "filters": [ diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 024df2343b..e46182ed83 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4699,6 +4699,11 @@ void Application::maybeToggleMenuVisible(QMouseEvent* event) const { void Application::mouseMoveEvent(QMouseEvent* event) { PROFILE_RANGE(app_input_mouse, __FUNCTION__); + if (_ignoreMouseMove) { + _ignoreMouseMove = false; + return; + } + maybeToggleMenuVisible(event); auto& compositor = getApplicationCompositor(); @@ -4744,7 +4749,7 @@ void Application::mouseMoveEvent(QMouseEvent* event) { } if (_keyboardMouseDevice->isActive()) { - _keyboardMouseDevice->mouseMoveEvent(event); + _keyboardMouseDevice->mouseMoveEvent(event, _captureMouse, _mouseCaptureTarget); } } @@ -5916,15 +5921,13 @@ void Application::cameraModeChanged() { cameraMenuChanged(); } -void Application::captureMouseChanged() { - if (_myCamera.getCaptureMouse()) { - // we want to grab the mouse here so that no other widgets get events, and also hide the mouse, but these don't work: - //_glWidget->grabMouse(); - //QCursor::setShape(Qt::CursorShape::BlankCursor); +void Application::captureMouseChanged(bool captureMouse) { + _captureMouse = captureMouse; + if (_captureMouse) { + _glWidget->setCursor(QCursor(Qt::BlankCursor)); } else { - // we want to release the mouse here so that other widgets get events, and also show the mouse, but these don't work: - //_glWidget->releaseMouse(); - //QCursor::setShape(Qt::CursorShape::ArrowCursor); + _mouseCaptureTarget = QPointF(NAN, NAN); + _glWidget->unsetCursor(); } } @@ -6278,6 +6281,15 @@ void Application::update(float deltaTime) { PROFILE_ASYNC_END(app, "Scene Loading", ""); } + if (_captureMouse) { + QPoint point = _glWidget->mapToGlobal(_glWidget->geometry().center()); + if (QCursor::pos() != point) { + _mouseCaptureTarget = point; + _ignoreMouseMove = true; + QCursor::setPos(point); + } + } + auto myAvatar = getMyAvatar(); { PerformanceTimer perfTimer("devices"); diff --git a/interface/src/Application.h b/interface/src/Application.h index 50ae9860fa..d66d9c32b3 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -430,7 +430,7 @@ public slots: void cycleCamera(); void cameraModeChanged(); void cameraMenuChanged(); - void captureMouseChanged(); + void captureMouseChanged(bool captureMouse); void toggleOverlays(); void setOverlaysVisible(bool visible); Q_INVOKABLE void centerUI(); @@ -756,7 +756,9 @@ private: bool _settingsLoaded { false }; - bool _fakedMouseEvent { false }; + bool _captureMouse { false }; + bool _ignoreMouseMove { false }; + QPointF _mouseCaptureTarget { NAN, NAN }; bool _isMissingSequenceNumbers { false }; diff --git a/libraries/display-plugins/src/display-plugins/CompositorHelper.cpp b/libraries/display-plugins/src/display-plugins/CompositorHelper.cpp index a1138b3018..0cc3e5216e 100644 --- a/libraries/display-plugins/src/display-plugins/CompositorHelper.cpp +++ b/libraries/display-plugins/src/display-plugins/CompositorHelper.cpp @@ -213,7 +213,6 @@ void CompositorHelper::setAllowMouseCapture(bool capture) { _allowMouseCapture = capture; emit allowMouseCaptureChanged(); } - _allowMouseCapture = capture; } void CompositorHelper::handleLeaveEvent() { diff --git a/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.cpp b/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.cpp index c436a5b510..a49c822014 100755 --- a/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.cpp +++ b/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.cpp @@ -36,13 +36,12 @@ void KeyboardMouseDevice::pluginUpdate(float deltaTime, const controller::InputC _inputDevice->_axisStateMap[MOUSE_AXIS_X].value = _lastCursor.x(); _inputDevice->_axisStateMap[MOUSE_AXIS_Y].value = _lastCursor.y(); - QPoint currentMove = _lastCursor - _previousCursor; - updateDeltaAxisValue(MOUSE_AXIS_X_POS, currentMove.x() > 0 ? currentMove.x() : 0.0f); - updateDeltaAxisValue(MOUSE_AXIS_X_NEG, currentMove.x() < 0 ? -currentMove.x() : 0.0f); + updateDeltaAxisValue(MOUSE_AXIS_X_POS, _accumulatedMove.x() > 0 ? _accumulatedMove.x() : 0.0f); + updateDeltaAxisValue(MOUSE_AXIS_X_NEG, _accumulatedMove.x() < 0 ? -_accumulatedMove.x() : 0.0f); // Y mouse is inverted positive is pointing up the screen - updateDeltaAxisValue(MOUSE_AXIS_Y_POS, currentMove.y() < 0 ? -currentMove.y() : 0.0f); - updateDeltaAxisValue(MOUSE_AXIS_Y_NEG, currentMove.y() > 0 ? currentMove.y() : 0.0f); - _previousCursor = _lastCursor; + updateDeltaAxisValue(MOUSE_AXIS_Y_POS, _accumulatedMove.y() < 0 ? -_accumulatedMove.y() : 0.0f); + updateDeltaAxisValue(MOUSE_AXIS_Y_NEG, _accumulatedMove.y() > 0 ? _accumulatedMove.y() : 0.0f); + _accumulatedMove = QPoint(0.0f, 0.0f); }); // For touch event, we need to check that the last event is not too long ago @@ -113,9 +112,16 @@ void KeyboardMouseDevice::eraseMouseClicked() { _inputDevice->_buttonPressedMap.erase(_inputDevice->makeInput(Qt::RightButton, true).getChannel()); } -void KeyboardMouseDevice::mouseMoveEvent(QMouseEvent* event) { +void KeyboardMouseDevice::mouseMoveEvent(QMouseEvent* event, bool capture, QPointF captureTarget) { QPoint currentPos = event->pos(); + if (!capture) { + _accumulatedMove += currentPos - _lastCursor; + } else if (!isNaN(captureTarget.x())) { + QPointF change = event->globalPos() - captureTarget; + _accumulatedMove += QPoint(change.x(), change.y()); + } + // FIXME - this has the characteristic that it will show large jumps when you move the cursor // outside of the application window, because we don't get MouseEvents when the cursor is outside // of the application window. diff --git a/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.h b/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.h index 4286ced477..158e2f594f 100644 --- a/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.h +++ b/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.h @@ -79,7 +79,7 @@ public: void keyPressEvent(QKeyEvent* event); void keyReleaseEvent(QKeyEvent* event); - void mouseMoveEvent(QMouseEvent* event); + void mouseMoveEvent(QMouseEvent* event, bool capture, QPointF captureTarget); void mousePressEvent(QMouseEvent* event); void mouseReleaseEvent(QMouseEvent* event); void eraseMouseClicked(); @@ -123,7 +123,7 @@ public: protected: QPoint _lastCursor; - QPoint _previousCursor; + QPoint _accumulatedMove; QPoint _mousePressPos; quint64 _mousePressTime; qreal _lastTotalScaleFactor; diff --git a/libraries/shared/src/shared/Camera.h b/libraries/shared/src/shared/Camera.h index 2564a3f7c8..d8ed98c0a2 100644 --- a/libraries/shared/src/shared/Camera.h +++ b/libraries/shared/src/shared/Camera.h @@ -123,7 +123,7 @@ public slots: * @function Camera.setCaptureMouse * @param {boolean} captureMouse - Whether or not to capture the mouse. */ - void setCaptureMouse(bool captureMouse) { _captureMouse = captureMouse; } + void setCaptureMouse(bool captureMouse) { _captureMouse = captureMouse; emit captureMouseUpdated(captureMouse); } /**jsdoc * Computes a {@link PickRay} based on the current camera configuration and the specified x, y position on the