Skip to content

Commit 1bd5017

Browse files
authored
Fix unfriendly keybind modifiers (#1809)
* Update LoaderImpl.cpp * turn set into member of LoaderImpl also fix issue with overlapping keybinds
1 parent fb2aff3 commit 1bd5017

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

loader/src/loader/LoaderImpl.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,9 +390,23 @@ void Loader::Impl::populateModList(std::vector<ModMetadata>& modQueue) {
390390
Keybind keybind(data.key, data.modifiers);
391391
bool down = data.action != KeyboardInputData::Action::Release;
392392
bool repeat = data.action == KeyboardInputData::Action::Repeat;
393-
for (auto& setting : m_keybindSettings[keybind]) {
394-
if (KeybindSettingPressedEventV3(setting->getModID(), setting->getKey()).send(keybind, down, repeat, data.timestamp)) {
395-
return ListenerResult::Stop;
393+
if (down) {
394+
auto it = m_keybindSettings.find(keybind);
395+
if (it != m_keybindSettings.end()) {
396+
for (auto& setting : it->second) {
397+
if (!repeat) m_activeKeybinds[setting.get()] = keybind;
398+
if (KeybindSettingPressedEventV3(setting->getModID(), setting->getKey()).send(keybind, down, repeat, data.timestamp)) {
399+
return ListenerResult::Stop;
400+
}
401+
}
402+
}
403+
} else {
404+
for (auto& [setting, heldKeybind] : m_activeKeybinds) {
405+
if (heldKeybind.key == data.key) {
406+
KeybindSettingPressedEventV3(setting->getModID(), setting->getKey()).send(heldKeybind, down, repeat, data.timestamp);
407+
m_activeKeybinds.erase(setting);
408+
break;
409+
}
396410
}
397411
}
398412
return ListenerResult::Propagate;

loader/src/loader/LoaderImpl.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ namespace geode {
161161
std::optional<std::string> getBinaryPath() const;
162162

163163
std::unordered_map<Keybind, std::vector<std::shared_ptr<KeybindSettingV3>>> m_keybindSettings;
164+
std::unordered_map<KeybindSettingV3*, Keybind> m_activeKeybinds;
164165
void onKeybindSettingChanged(std::shared_ptr<KeybindSettingV3> setting, std::vector<Keybind> const& keybinds);
165166
};
166167

0 commit comments

Comments
 (0)