Debian Codegraph @

xbmc/input/joysticks/JoystickMonitor.cpp

raw
1 /*
2 * Copyright (C) 2015-2024 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9 #include "JoystickMonitor.h"
10
11 #include "ServiceBroker.h"
12 #include "application/ApplicationComponents.h"
13 #include "application/ApplicationPowerHandling.h"
14 #include "games/controllers/ControllerIDs.h"
15 #include "input/InputManager.h"
16
17 #include <cmath>
18
19 using namespace KODI;
20 using namespace JOYSTICK;
21
22 #define AXIS_DEADZONE 0.05f
23
24 std::string CJoystickMonitor::ControllerID() const
25 {
26 return DEFAULT_CONTROLLER_ID;
27 }
28
29 bool CJoystickMonitor::AcceptsInput(const FeatureName& feature) const
30 {
31 // Only accept input when screen saver is active
32 auto& components = CServiceBroker::GetAppComponents();
33 const auto appPower = components.GetComponent<CApplicationPowerHandling>();
34 return appPower->IsInScreenSaver();
35 }
36
37 bool CJoystickMonitor::OnButtonPress(const FeatureName& feature, bool bPressed)
38 {
39 if (bPressed)
40 {
41 CServiceBroker::GetInputManager().SetMouseActive(false);
42 return ResetTimers();
43 }
44
45 return false;
46 }
47
48 bool CJoystickMonitor::OnButtonMotion(const FeatureName& feature,
49 float magnitude,
50 unsigned int motionTimeMs)
51 {
52 if (std::fabs(magnitude) > AXIS_DEADZONE)
53 {
54 CServiceBroker::GetInputManager().SetMouseActive(false);
55 return ResetTimers();
56 }
57
58 return false;
59 }
60
61 bool CJoystickMonitor::OnAnalogStickMotion(const FeatureName& feature,
62 float x,
63 float y,
64 unsigned int motionTimeMs)
65 {
66 // Analog stick deadzone already processed
67 if (x != 0.0f || y != 0.0f)
68 {
69 CServiceBroker::GetInputManager().SetMouseActive(false);
70 return ResetTimers();
71 }
72
73 return false;
74 }
75
76 bool CJoystickMonitor::OnWheelMotion(const FeatureName& feature,
77 float position,
78 unsigned int motionTimeMs)
79 {
80 if (std::fabs(position) > AXIS_DEADZONE)
81 {
82 CServiceBroker::GetInputManager().SetMouseActive(false);
83 return ResetTimers();
84 }
85
86 return false;
87 }
88
89 bool CJoystickMonitor::OnThrottleMotion(const FeatureName& feature,
90 float position,
91 unsigned int motionTimeMs)
92 {
93 if (std::fabs(position) > AXIS_DEADZONE)
94 {
95 CServiceBroker::GetInputManager().SetMouseActive(false);
96 return ResetTimers();
97 }
98
99 return false;
100 }
101
102 bool CJoystickMonitor::ResetTimers(void)
103 {
104 auto& components = CServiceBroker::GetAppComponents();
105 const auto appPower = components.GetComponent<CApplicationPowerHandling>();
106 appPower->ResetSystemIdleTimer();
107 appPower->ResetScreenSaver();
108 return appPower->WakeUpScreenSaverAndDPMS();
109
110 return true;
111 }