aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarrett Brown <themagnificentmrb@gmail.com>2017-10-09 12:23:45 -0700
committerGarrett Brown <themagnificentmrb@gmail.com>2017-10-09 12:23:45 -0700
commit51b2d768b05be9ec1610cccc2bff61040e2f1b9b (patch)
treea6e5682333e35607d870a52aa275a828a61d03bb
parentf51e9d6d65a14ef1b915d1070f787b5efc1896ea (diff)
Joysticks: Fix accelerometers preventing screensaver
This fixes accelerometers on PS4 controllers preventing the screensaver by only monitoring mapped buttons and axes. By changing from IDriverHandler to IInputHandler, we receive input for higher-level controller features instead of lower-level driver events. If the driver input is not mapped to a controller, the IInputHandler will receive no input, meaning it can't interrupt a screensaver.
-rw-r--r--xbmc/input/joysticks/JoystickMonitor.cpp27
-rw-r--r--xbmc/input/joysticks/JoystickMonitor.h19
-rw-r--r--xbmc/peripherals/devices/PeripheralJoystick.cpp12
-rw-r--r--xbmc/peripherals/devices/PeripheralJoystick.h4
4 files changed, 44 insertions, 18 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/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;