diff options
author | Garrett Brown <themagnificentmrb@gmail.com> | 2017-10-11 16:58:12 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-11 16:58:12 -0700 |
commit | b0626a540332926613f5e554f1e10711db0f437b (patch) | |
tree | 7ba75286e0a21925c8aa3a6c0f163048a1e8710b | |
parent | f51e9d6d65a14ef1b915d1070f787b5efc1896ea (diff) | |
parent | ff3c555571e9d2f9ad3f7a3728afcf7ed7ac8676 (diff) |
Merge pull request #12900 from garbear/fix-acc-krypton
[Backport] Joysticks: Fix accelerometers preventing screensaver
-rw-r--r-- | xbmc/input/joysticks/JoystickMonitor.cpp | 27 | ||||
-rw-r--r-- | xbmc/input/joysticks/JoystickMonitor.h | 19 | ||||
-rw-r--r-- | xbmc/input/joysticks/generic/FeatureHandling.cpp | 4 | ||||
-rw-r--r-- | xbmc/peripherals/devices/PeripheralJoystick.cpp | 12 | ||||
-rw-r--r-- | xbmc/peripherals/devices/PeripheralJoystick.h | 4 |
5 files changed, 44 insertions, 22 deletions
diff --git a/xbmc/input/joysticks/JoystickMonitor.cpp b/xbmc/input/joysticks/JoystickMonitor.cpp index ee081bea4d..b792a721e4 100644 --- a/xbmc/input/joysticks/JoystickMonitor.cpp +++ b/xbmc/input/joysticks/JoystickMonitor.cpp @@ -19,12 +19,28 @@ */ #include "JoystickMonitor.h" +#include "DefaultJoystick.h" #include "Application.h" #include "input/InputManager.h" +#include <cmath> + using namespace JOYSTICK; -bool CJoystickMonitor::OnButtonMotion(unsigned int buttonIndex, bool bPressed) +#define AXIS_DEADZONE 0.05f + +std::string CJoystickMonitor::ControllerID() const +{ + return DEFAULT_CONTROLLER_ID; +} + +bool CJoystickMonitor::AcceptsInput() +{ + // Only accept input when screen saver is active + return g_application.IsInScreenSaver(); +} + +bool CJoystickMonitor::OnButtonPress(const FeatureName& feature, bool bPressed) { if (bPressed) { @@ -35,9 +51,9 @@ bool CJoystickMonitor::OnButtonMotion(unsigned int buttonIndex, bool bPressed) return false; } -bool CJoystickMonitor::OnHatMotion(unsigned int hatIndex, HAT_STATE state) +bool CJoystickMonitor::OnButtonMotion(const FeatureName& feature, float magnitude) { - if (state != HAT_STATE::UNPRESSED) + if (std::fabs(magnitude) > AXIS_DEADZONE) { CInputManager::GetInstance().SetMouseActive(false); return ResetTimers(); @@ -46,9 +62,10 @@ bool CJoystickMonitor::OnHatMotion(unsigned int hatIndex, HAT_STATE state) return false; } -bool CJoystickMonitor::OnAxisMotion(unsigned int axisIndex, float position, int center, unsigned int range) +bool CJoystickMonitor::OnAnalogStickMotion(const FeatureName& feature, float x, float y, unsigned int motionTimeMs) { - if (position) + // Analog stick deadzone already processed + if (x != 0.0f || y != 0.0f) { CInputManager::GetInstance().SetMouseActive(false); return ResetTimers(); diff --git a/xbmc/input/joysticks/JoystickMonitor.h b/xbmc/input/joysticks/JoystickMonitor.h index 6409ea0544..0a3c122463 100644 --- a/xbmc/input/joysticks/JoystickMonitor.h +++ b/xbmc/input/joysticks/JoystickMonitor.h @@ -19,7 +19,7 @@ */ #pragma once -#include "IDriverHandler.h" +#include "IInputHandler.h" namespace JOYSTICK { @@ -28,14 +28,19 @@ namespace JOYSTICK * \brief Monitors joystick input and resets screensaver/shutdown timers * whenever motion occurs. */ - class CJoystickMonitor : public IDriverHandler + class CJoystickMonitor : public IInputHandler { public: - // implementation of IDriverHandler - virtual bool OnButtonMotion(unsigned int buttonIndex, bool bPressed) override; - virtual bool OnHatMotion(unsigned int hatIndex, HAT_STATE state) override; - virtual bool OnAxisMotion(unsigned int axisIndex, float position, int center, unsigned int range) override; - virtual void ProcessAxisMotions(void) override { } + // implementation of IInputHandler + virtual std::string ControllerID() const override; + virtual bool HasFeature(const FeatureName& feature) const override { return true; } + virtual bool AcceptsInput(void) override; + virtual INPUT_TYPE GetInputType(const FeatureName& feature) const override { return INPUT_TYPE::ANALOG; } + virtual bool OnButtonPress(const FeatureName& feature, bool bPressed) override; + virtual void OnButtonHold(const FeatureName& feature, unsigned int holdTimeMs) override { } + virtual bool OnButtonMotion(const FeatureName& feature, float magnitude) override; + virtual bool OnAnalogStickMotion(const FeatureName& feature, float x, float y, unsigned int motionTimeMs) override; + virtual bool OnAccelerometerMotion(const FeatureName& feature, float x, float y, float z) override { return false; } private: /*! diff --git a/xbmc/input/joysticks/generic/FeatureHandling.cpp b/xbmc/input/joysticks/generic/FeatureHandling.cpp index d4258d5df6..5f785d6f4f 100644 --- a/xbmc/input/joysticks/generic/FeatureHandling.cpp +++ b/xbmc/input/joysticks/generic/FeatureHandling.cpp @@ -51,10 +51,6 @@ bool CJoystickFeature::AcceptsInput(bool bActivation) { if (m_handler->AcceptsInput()) bAcceptsInput = true; - - // Avoid sticking - if (!bActivation) - bAcceptsInput = true; } return bAcceptsInput; diff --git a/xbmc/peripherals/devices/PeripheralJoystick.cpp b/xbmc/peripherals/devices/PeripheralJoystick.cpp index 062fbfd72f..a6fc7e3683 100644 --- a/xbmc/peripherals/devices/PeripheralJoystick.cpp +++ b/xbmc/peripherals/devices/PeripheralJoystick.cpp @@ -20,6 +20,8 @@ #include "PeripheralJoystick.h" #include "input/joysticks/DeadzoneFilter.h" +#include "input/joysticks/IDriverHandler.h" +#include "input/joysticks/JoystickMonitor.h" #include "input/joysticks/JoystickTranslator.h" #include "peripherals/Peripherals.h" #include "peripherals/addons/AddonButtonMap.h" @@ -48,11 +50,12 @@ CPeripheralJoystick::CPeripheralJoystick(const PeripheralScanResult& scanResult, CPeripheralJoystick::~CPeripheralJoystick(void) { - m_deadzoneFilter.reset(); - m_buttonMap.reset(); m_defaultInputHandler.AbortRumble(); + UnregisterJoystickInputHandler(m_joystickMonitor.get()); + m_joystickMonitor.reset(); UnregisterJoystickInputHandler(&m_defaultInputHandler); - UnregisterJoystickDriverHandler(&m_joystickMonitor); + m_deadzoneFilter.reset(); + m_buttonMap.reset(); } bool CPeripheralJoystick::InitialiseFeature(const PeripheralFeature feature) @@ -74,7 +77,8 @@ bool CPeripheralJoystick::InitialiseFeature(const PeripheralFeature feature) // Give joystick monitor priority over default controller RegisterJoystickInputHandler(&m_defaultInputHandler); - RegisterJoystickDriverHandler(&m_joystickMonitor, false); + m_joystickMonitor.reset(new CJoystickMonitor); + RegisterJoystickInputHandler(m_joystickMonitor.get()); } } else if (feature == FEATURE_RUMBLE) diff --git a/xbmc/peripherals/devices/PeripheralJoystick.h b/xbmc/peripherals/devices/PeripheralJoystick.h index db6540edd9..9664fa789f 100644 --- a/xbmc/peripherals/devices/PeripheralJoystick.h +++ b/xbmc/peripherals/devices/PeripheralJoystick.h @@ -22,7 +22,6 @@ #include "Peripheral.h" #include "input/joysticks/DefaultJoystick.h" #include "input/joysticks/IDriverReceiver.h" -#include "input/joysticks/JoystickMonitor.h" #include "input/joysticks/JoystickTypes.h" #include "threads/CriticalSection.h" @@ -37,6 +36,7 @@ namespace JOYSTICK class CDeadzoneFilter; class IButtonMap; class IDriverHandler; + class IInputHandler; } namespace PERIPHERALS @@ -119,7 +119,7 @@ namespace PERIPHERALS unsigned int m_motorCount; bool m_supportsPowerOff; JOYSTICK::CDefaultJoystick m_defaultInputHandler; - JOYSTICK::CJoystickMonitor m_joystickMonitor; + std::unique_ptr<JOYSTICK::IInputHandler> m_joystickMonitor; std::unique_ptr<JOYSTICK::IButtonMap> m_buttonMap; std::unique_ptr<JOYSTICK::CDeadzoneFilter> m_deadzoneFilter; std::vector<DriverHandler> m_driverHandlers; |