16 using namespace swift::input;
18 using namespace swift::misc::input;
22 CInputManager::CInputManager(QObject *parent) : QObject(parent) { reloadHotkeySettings(); }
26 if (!m_availableActions.contains(action))
28 m_availableActions.insert(action, icon);
35 for (
const auto &action : actions)
37 if (!m_availableActions.contains(action))
39 m_availableActions.insert(action, {});
47 auto info = std::find_if(m_boundActions.begin(), m_boundActions.end(),
48 [index](
const BindInfo &info) { return info.m_index == index; });
49 if (info != m_boundActions.end()) { m_boundActions.erase(info); }
52 void CInputManager::reloadHotkeySettings()
54 m_configuredActions.clear();
55 for (
const CActionHotkey &actionHotkey : m_actionHotkeys.getThreadLocal())
57 if (!actionHotkey.getApplicableMachine().isFromLocalMachine()) {
continue; }
59 if (combination.
isEmpty())
continue;
61 m_configuredActions.insert(combination, actionHotkey.getAction());
65 void CInputManager::processKeyCombinationChanged(
const CHotkeyCombination &combination)
71 processCombination(copy);
74 void CInputManager::processButtonCombinationChanged(
const CHotkeyCombination &combination)
80 processCombination(copy);
85 m_captureActive =
true;
86 m_capturedCombination = {};
87 m_combinationBeforeCapture = m_lastCombination;
92 if (action.isEmpty()) {
return; }
95 for (
const auto &boundAction : std::as_const(m_boundActions))
97 if (boundAction.m_action == action) { boundAction.m_function(isKeyDown); }
104 QString previousAction = m_configuredActions.value(m_lastCombination);
105 QString action = m_configuredActions.value(combination);
108 m_lastCombination = combination;
113 m_keyboard = IKeyboard::create(
this);
114 m_joystick = IJoystick::create(
this);
115 connect(m_keyboard.get(), &IKeyboard::keyCombinationChanged,
this, &CInputManager::processKeyCombinationChanged,
116 Qt::QueuedConnection);
117 connect(m_joystick.get(), &IJoystick::buttonCombinationChanged,
this,
118 &CInputManager::processButtonCombinationChanged, Qt::QueuedConnection);
129 return m_joystick->getAllAvailableJoystickButtons();
132 int CInputManager::bindImpl(
const QString &action, QObject *receiver, std::function<
void(
bool)>
function)
134 static int index = 0;
135 Q_ASSERT(index < INT_MAX);
137 info.m_index = index;
139 info.m_function =
function;
140 info.m_action = action;
141 info.m_receiver = receiver;
142 m_boundActions.push_back(info);
153 if (m_capturedCombination.
isEmpty() && deltaCombination.
isEmpty()) {
return; }
155 if (deltaCombination.
size() < m_capturedCombination.
size())
158 m_captureActive =
false;
163 m_capturedCombination = deltaCombination;
168 QSet<QString> newActiveActions;
169 for (
const auto [combination, action] :
makePairsRange(std::as_const(m_configuredActions)))
171 if (combination.
isSubsetOf(currentCombination)) { newActiveActions.insert(action); }
174 const QSet<QString> pressedActions = newActiveActions - m_activeActions;
175 const QSet<QString> releasedActions = m_activeActions - newActiveActions;
176 m_activeActions = newActiveActions;
177 for (
const QString &action : pressedActions) {
callFunctionsBy(action,
true); }
178 for (
const QString &action : releasedActions) {
callFunctionsBy(action,
false); }
181 m_lastCombination = currentCombination;
IconIndex
Index for each icon, allows to send them via DBus, efficiently store them, etc.
Backend services of the swift project, like dealing with the network or the simulators.
Free functions in swift::misc.
auto makePairsRange(const T &container)
Returns a const CRange for iterating over the keys and values of a Qt associative container.