diff --git a/src/overlaycontroller.cpp b/src/overlaycontroller.cpp index fbbf18f..e2cd4ee 100644 --- a/src/overlaycontroller.cpp +++ b/src/overlaycontroller.cpp @@ -464,14 +464,7 @@ QPoint OverlayController::getMousePositionForEvent( vr::VREvent_Mouse_t mouse ) return QPoint( mouse.x, y ); } -/*! -Checks if an action has been activated and dispatches the related action if it -has been. - -This function should probably be split into several functions that are specific -to a binding type as the amount of actions grows. -*/ -void OverlayController::processInputBindings() +void OverlayController::processMediaKeyBindings() { if ( m_actions.nextSong() ) { @@ -489,6 +482,10 @@ void OverlayController::processInputBindings() { m_utilitiesTabController.sendMediaStopSong(); } +} + +void OverlayController::processRoomBindings() +{ // Execution order for moveCenterTabController actions is important. Don't // reorder these. Override actions must always come after normal because // active priority is set based on which action is "newest" @@ -511,6 +508,39 @@ void OverlayController::processInputBindings() m_actions.optionalOverrideRightHandRoomTurn() ); } +void OverlayController::processPushToTalkBindings() +{ + const auto pushToTalkCannotChange = !m_audioTabController.pttChangeValid(); + if ( pushToTalkCannotChange ) + { + return; + } + + const auto pushToTalkButtonActivated = m_actions.pushToTalk(); + const auto pushToTalkCurrentlyActive = m_audioTabController.pttActive(); + if ( pushToTalkButtonActivated && !pushToTalkCurrentlyActive ) + { + m_audioTabController.startPtt(); + } + else if ( !pushToTalkButtonActivated && pushToTalkCurrentlyActive ) + { + m_audioTabController.stopPtt(); + } +} + +/*! +Checks if an action has been activated and dispatches the related action if it +has been. +*/ +void OverlayController::processInputBindings() +{ + processMediaKeyBindings(); + + processRoomBindings(); + + processPushToTalkBindings(); +} + // vsync implementation: // (this function triggers every 1ms) void OverlayController::OnTimeoutPumpEvents() diff --git a/src/overlaycontroller.h b/src/overlaycontroller.h index d06a097..252f258 100644 --- a/src/overlaycontroller.h +++ b/src/overlaycontroller.h @@ -123,6 +123,9 @@ public: // I know it's an ugly hack to make them public to enable external private: QPoint getMousePositionForEvent( vr::VREvent_Mouse_t mouse ); void processInputBindings(); + void processMediaKeyBindings(); + void processRoomBindings(); + void processPushToTalkBindings(); public: OverlayController( bool desktopMode, bool noSound, QQmlEngine& qmlEngine ); diff --git a/src/tabcontrollers/AudioTabController.h b/src/tabcontrollers/AudioTabController.h index c66f492..9c0f269 100644 --- a/src/tabcontrollers/AudioTabController.h +++ b/src/tabcontrollers/AudioTabController.h @@ -87,7 +87,7 @@ private: void onPttStop() override; void onPttEnabled() override; void onPttDisabled() override; - bool pttChangeValid() override; + virtual vr::VROverlayHandle_t getNotificationOverlayHandle() override { return m_ulNotificationOverlayHandle; @@ -114,6 +114,8 @@ public: void eventLoopTick(); + bool pttChangeValid() override; + int playbackDeviceIndex() const; int mirrorDeviceIndex() const; diff --git a/src/tabcontrollers/PttController.cpp b/src/tabcontrollers/PttController.cpp index cf2bdda..fc618c3 100644 --- a/src/tabcontrollers/PttController.cpp +++ b/src/tabcontrollers/PttController.cpp @@ -222,118 +222,8 @@ void PttController::savePttConfig() void PttController::checkPttStatus() { - static auto handleControllerState - = []( const vr::VRControllerState_t& state, - PttControllerConfig* config ) -> bool { - if ( state.ulButtonPressed & config->digitalButtonMask ) - { - return true; - } - if ( config->triggerMode ) - { - if ( state.ulButtonPressed - & vr::ButtonMaskFromId( vr::k_EButton_SteamVR_Trigger ) ) - { - return true; - } - } - if ( config->touchpadMode ) - { - if ( ( ( config->touchpadMode & 1 ) - && ( state.ulButtonTouched - & vr::ButtonMaskFromId( - vr::k_EButton_SteamVR_Touchpad ) ) ) - || ( ( config->touchpadMode & 2 ) - && ( state.ulButtonPressed - & vr::ButtonMaskFromId( - vr::k_EButton_SteamVR_Touchpad ) ) ) ) - { - if ( config->touchpadAreas - == ( PAD_AREA_LEFT + PAD_AREA_TOP + PAD_AREA_RIGHT - + PAD_AREA_BOTTOM ) ) - { - return true; - } - else - { - float x = state.rAxis[0].x; - float y = state.rAxis[0].y; - if ( std::abs( x ) >= 0.2 || std::abs( y ) >= 0.2 ) - { // deadzone in the middle - if ( x < 0 && std::abs( y ) < -x - && ( config->touchpadAreas & PAD_AREA_LEFT ) ) - { - return true; - } - else if ( y > 0 && std::abs( x ) < y - && ( config->touchpadAreas & PAD_AREA_TOP ) ) - { - return true; - } - else if ( x > 0 && std::abs( y ) < x - && ( config->touchpadAreas - & PAD_AREA_RIGHT ) ) - { - return true; - } - else if ( y < 0 && std::abs( x ) < -y - && ( config->touchpadAreas - & PAD_AREA_BOTTOM ) ) - { - return true; - } - } - } - } - } - return false; - }; - if ( m_pttEnabled ) - { - bool newState = false; - if ( m_pttLeftControllerEnabled ) - { - auto leftId - = vr::VRSystem()->GetTrackedDeviceIndexForControllerRole( - vr::TrackedControllerRole_LeftHand ); - if ( leftId != vr::k_unTrackedDeviceIndexInvalid ) - { - vr::VRControllerState_t state; - if ( vr::VRSystem()->GetControllerState( - leftId, &state, sizeof( vr::VRControllerState_t ) ) ) - { - // logControllerState(state, "Left "); - newState |= handleControllerState( state, - m_pttControllerConfigs ); - } - } - } - if ( m_pttRightControllerEnabled ) - { - auto rightId - = vr::VRSystem()->GetTrackedDeviceIndexForControllerRole( - vr::TrackedControllerRole_RightHand ); - if ( rightId != vr::k_unTrackedDeviceIndexInvalid ) - { - vr::VRControllerState_t state; - if ( vr::VRSystem()->GetControllerState( - rightId, &state, sizeof( vr::VRControllerState_t ) ) ) - { - // logControllerState(state, "Right "); - newState |= handleControllerState( - state, m_pttControllerConfigs + 1 ); - } - } - } - if ( newState && !m_pttActive && pttChangeValid() ) - { - startPtt(); - } - else if ( !newState && m_pttActive && pttChangeValid() ) - { - stopPtt(); - } - } + // PTT Controls are now handled in the overlaycontroller using public + // functions. } void PttController::startPtt() diff --git a/src/tabcontrollers/PttController.h b/src/tabcontrollers/PttController.h index 3ffc980..fe78662 100644 --- a/src/tabcontrollers/PttController.h +++ b/src/tabcontrollers/PttController.h @@ -75,10 +75,7 @@ protected: virtual void onPttStop(){}; virtual void onPttEnabled(){}; virtual void onPttDisabled(){}; - virtual bool pttChangeValid() - { - return true; - } + virtual vr::VROverlayHandle_t getNotificationOverlayHandle() { return vr::k_ulOverlayHandleInvalid; @@ -100,6 +97,11 @@ public: void savePttProfiles(); void savePttConfig(); + virtual bool pttChangeValid() + { + return true; + } + Q_INVOKABLE QVariantList pttDigitalButtons( unsigned controller ); Q_INVOKABLE unsigned long pttDigitalButtonMask( unsigned controller ); Q_INVOKABLE unsigned pttTouchpadMode( unsigned controller );