Debian Codegraph @

xbmc/peripherals/devices/PeripheralImon.cpp

raw
1 /*
2 * Copyright (C) 2012-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 "PeripheralImon.h"
10
11 #include "input/InputManager.h"
12 #include "settings/Settings.h"
13 #include "utils/log.h"
14
15 using namespace PERIPHERALS;
16
17 std::atomic<long> CPeripheralImon::m_lCountOfImonsConflictWithDInput(0L);
18
19 CPeripheralImon::CPeripheralImon(CPeripherals& manager,
20 const PeripheralScanResult& scanResult,
21 CPeripheralBus* bus)
22 : CPeripheralHID(manager, scanResult, bus)
23 {
24 m_features.push_back(FEATURE_IMON);
25 m_bImonConflictsWithDInput = false;
26 }
27
28 void CPeripheralImon::OnDeviceRemoved()
29 {
30 if (m_bImonConflictsWithDInput)
31 {
32 if (--m_lCountOfImonsConflictWithDInput == 0)
33 ActionOnImonConflict(false);
34 }
35 }
36
37 bool CPeripheralImon::InitialiseFeature(const PeripheralFeature feature)
38 {
39 if (feature == FEATURE_IMON)
40 {
41 #if defined(TARGET_WINDOWS)
42 if (HasSetting("disable_winjoystick") && GetSettingBool("disable_winjoystick"))
43 m_bImonConflictsWithDInput = true;
44 else
45 #endif // TARGET_WINDOWS
46 m_bImonConflictsWithDInput = false;
47
48 if (m_bImonConflictsWithDInput)
49 {
50 ++m_lCountOfImonsConflictWithDInput;
51 ActionOnImonConflict(true);
52 }
53 return CPeripheral::InitialiseFeature(feature);
54 }
55
56 return CPeripheralHID::InitialiseFeature(feature);
57 }
58
59 void CPeripheralImon::AddSetting(const std::string& strKey,
60 const std::shared_ptr<const CSetting>& setting,
61 int order)
62 {
63 #if !defined(TARGET_WINDOWS)
64 if (strKey.compare("disable_winjoystick") != 0)
65 #endif // !TARGET_WINDOWS
66 CPeripheralHID::AddSetting(strKey, setting, order);
67 }
68
69 void CPeripheralImon::OnSettingChanged(const std::string& strChangedSetting)
70 {
71 if (strChangedSetting.compare("disable_winjoystick") == 0)
72 {
73 if (m_bImonConflictsWithDInput && !GetSettingBool("disable_winjoystick"))
74 {
75 m_bImonConflictsWithDInput = false;
76 if (--m_lCountOfImonsConflictWithDInput == 0)
77 ActionOnImonConflict(false);
78 }
79 else if (!m_bImonConflictsWithDInput && GetSettingBool("disable_winjoystick"))
80 {
81 m_bImonConflictsWithDInput = true;
82 ++m_lCountOfImonsConflictWithDInput;
83 ActionOnImonConflict(true);
84 }
85 }
86 }
87
88 void CPeripheralImon::ActionOnImonConflict(bool deviceInserted /*= true*/)
89 {
90 }