diff options
| author | ArchSav <96357545+ArchSav@users.noreply.github.com> | 2026-03-14 00:48:01 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-13 08:48:01 -0500 |
| commit | 24a95621e5118e39e1a6e05b17ef89f4ec2c8c01 (patch) | |
| tree | a37133cd549fb7107ebbaa5bf60fafd52a5bdd77 /src/managers/KeybindManager.cpp | |
| parent | e8684034525829d58054c32da914d1713398fbb8 (diff) | |
input: add device specific binds (#13073)
Adds support for device-specific binds
Diffstat (limited to 'src/managers/KeybindManager.cpp')
| -rw-r--r-- | src/managers/KeybindManager.cpp | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index fd7c4e72..e6064472 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -480,7 +480,7 @@ bool CKeybindManager::onKeyEvent(std::any event, SP<IKeyboard> pKeyboard) { m_pressedKeys.push_back(KEY); - suppressEvent = !handleKeybinds(MODS, KEY, true, pKeyboard).passEvent; + suppressEvent = !handleKeybinds(MODS, KEY, true, pKeyboard, pKeyboard).passEvent; if (suppressEvent) shadowKeybinds(keysym, KEYCODE); @@ -491,7 +491,7 @@ bool CKeybindManager::onKeyEvent(std::any event, SP<IKeyboard> pKeyboard) { bool foundInPressedKeys = false; for (auto it = m_pressedKeys.begin(); it != m_pressedKeys.end();) { if (it->keycode == KEYCODE) { - handleKeybinds(MODS, *it, false, pKeyboard); + handleKeybinds(MODS, *it, false, pKeyboard, pKeyboard); foundInPressedKeys = true; suppressEvent = !it->sent; it = m_pressedKeys.erase(it); @@ -502,7 +502,7 @@ bool CKeybindManager::onKeyEvent(std::any event, SP<IKeyboard> pKeyboard) { if (!foundInPressedKeys) { Log::logger->log(Log::ERR, "BUG THIS: key not found in m_dPressedKeys"); // fallback with wrong `KEY.modmaskAtPressTime`, this can be buggy - suppressEvent = !handleKeybinds(MODS, KEY, false, pKeyboard).passEvent; + suppressEvent = !handleKeybinds(MODS, KEY, false, pKeyboard, pKeyboard).passEvent; } shadowKeybinds(); @@ -511,7 +511,7 @@ bool CKeybindManager::onKeyEvent(std::any event, SP<IKeyboard> pKeyboard) { return !suppressEvent && !mouseBindWasActive; } -bool CKeybindManager::onAxisEvent(const IPointer::SAxisEvent& e) { +bool CKeybindManager::onAxisEvent(const IPointer::SAxisEvent& e, SP<IPointer> pointer) { const auto MODS = g_pInputManager->getModsFromAllKBs(); static auto PDELAY = CConfigValue<Hyprlang::INT>("binds:scroll_event_delay"); @@ -526,14 +526,14 @@ bool CKeybindManager::onAxisEvent(const IPointer::SAxisEvent& e) { bool found = false; if (e.source == WL_POINTER_AXIS_SOURCE_WHEEL && e.axis == WL_POINTER_AXIS_VERTICAL_SCROLL) { if (e.delta < 0) - found = !handleKeybinds(MODS, SPressedKeyWithMods{.keyName = "mouse_down"}, true, nullptr).passEvent; + found = !handleKeybinds(MODS, SPressedKeyWithMods{.keyName = "mouse_down"}, true, nullptr, pointer).passEvent; else - found = !handleKeybinds(MODS, SPressedKeyWithMods{.keyName = "mouse_up"}, true, nullptr).passEvent; + found = !handleKeybinds(MODS, SPressedKeyWithMods{.keyName = "mouse_up"}, true, nullptr, pointer).passEvent; } else if (e.source == WL_POINTER_AXIS_SOURCE_WHEEL && e.axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL) { if (e.delta < 0) - found = !handleKeybinds(MODS, SPressedKeyWithMods{.keyName = "mouse_left"}, true, nullptr).passEvent; + found = !handleKeybinds(MODS, SPressedKeyWithMods{.keyName = "mouse_left"}, true, nullptr, pointer).passEvent; else - found = !handleKeybinds(MODS, SPressedKeyWithMods{.keyName = "mouse_right"}, true, nullptr).passEvent; + found = !handleKeybinds(MODS, SPressedKeyWithMods{.keyName = "mouse_right"}, true, nullptr, pointer).passEvent; } if (found) @@ -542,7 +542,7 @@ bool CKeybindManager::onAxisEvent(const IPointer::SAxisEvent& e) { return !found; } -bool CKeybindManager::onMouseEvent(const IPointer::SButtonEvent& e) { +bool CKeybindManager::onMouseEvent(const IPointer::SButtonEvent& e, SP<IPointer> mouse) { const auto MODS = g_pInputManager->getModsFromAllKBs(); bool suppressEvent = false; @@ -566,7 +566,7 @@ bool CKeybindManager::onMouseEvent(const IPointer::SButtonEvent& e) { if (e.state == WL_POINTER_BUTTON_STATE_PRESSED) { m_pressedKeys.push_back(KEY); - suppressEvent = !handleKeybinds(MODS, KEY, true, nullptr).passEvent; + suppressEvent = !handleKeybinds(MODS, KEY, true, nullptr, mouse).passEvent; if (suppressEvent) shadowKeybinds(); @@ -576,7 +576,7 @@ bool CKeybindManager::onMouseEvent(const IPointer::SButtonEvent& e) { bool foundInPressedKeys = false; for (auto it = m_pressedKeys.begin(); it != m_pressedKeys.end();) { if (it->keyName == KEY_NAME) { - suppressEvent = !handleKeybinds(MODS, *it, false, nullptr).passEvent; + suppressEvent = !handleKeybinds(MODS, *it, false, nullptr, mouse).passEvent; foundInPressedKeys = true; suppressEvent = !it->sent; it = m_pressedKeys.erase(it); @@ -587,7 +587,7 @@ bool CKeybindManager::onMouseEvent(const IPointer::SButtonEvent& e) { if (!foundInPressedKeys) { Log::logger->log(Log::ERR, "BUG THIS: key not found in m_dPressedKeys (2)"); // fallback with wrong `KEY.modmaskAtPressTime`, this can be buggy - suppressEvent = !handleKeybinds(MODS, KEY, false, nullptr).passEvent; + suppressEvent = !handleKeybinds(MODS, KEY, false, nullptr, mouse).passEvent; } shadowKeybinds(); @@ -601,15 +601,15 @@ void CKeybindManager::resizeWithBorder(const IPointer::SButtonEvent& e) { } void CKeybindManager::onSwitchEvent(const std::string& switchName) { - handleKeybinds(0, SPressedKeyWithMods{.keyName = "switch:" + switchName}, true, nullptr); + handleKeybinds(0, SPressedKeyWithMods{.keyName = "switch:" + switchName}, true, nullptr, nullptr); } void CKeybindManager::onSwitchOnEvent(const std::string& switchName) { - handleKeybinds(0, SPressedKeyWithMods{.keyName = "switch:on:" + switchName}, true, nullptr); + handleKeybinds(0, SPressedKeyWithMods{.keyName = "switch:on:" + switchName}, true, nullptr, nullptr); } void CKeybindManager::onSwitchOffEvent(const std::string& switchName) { - handleKeybinds(0, SPressedKeyWithMods{.keyName = "switch:off:" + switchName}, true, nullptr); + handleKeybinds(0, SPressedKeyWithMods{.keyName = "switch:off:" + switchName}, true, nullptr, nullptr); } eMultiKeyCase CKeybindManager::mkKeysymSetMatches(const std::set<xkb_keysym_t> keybindKeysyms, const std::set<xkb_keysym_t> pressedKeysyms) { @@ -642,7 +642,7 @@ SSubmap CKeybindManager::getCurrentSubmap() { return m_currentSelectedSubmap; } -SDispatchResult CKeybindManager::handleKeybinds(const uint32_t modmask, const SPressedKeyWithMods& key, bool pressed, SP<IKeyboard> keyboard) { +SDispatchResult CKeybindManager::handleKeybinds(const uint32_t modmask, const SPressedKeyWithMods& key, bool pressed, SP<IKeyboard> keyboard, SP<IHID> device) { static auto PDISABLEINHIBIT = CConfigValue<Hyprlang::INT>("binds:disable_keybind_grabbing"); static auto PDRAGTHRESHOLD = CConfigValue<Hyprlang::INT>("binds:drag_threshold"); @@ -682,6 +682,11 @@ SDispatchResult CKeybindManager::handleKeybinds(const uint32_t modmask, const SP if (!IGNORECONDITIONS && ((modmask != k->modmask && !k->ignoreMods) || (k->submap != m_currentSelectedSubmap && !k->submapUniversal) || k->shadowed)) continue; + if (device) { + if (k->deviceInclusive ^ k->devices.contains(device->m_hlName)) + continue; + } + if (k->multiKey) { switch (mkBindMatches(k)) { case MK_NO_MATCH: continue; |
