summaryrefslogtreecommitdiff
path: root/src/managers
diff options
context:
space:
mode:
authorArchSav <96357545+ArchSav@users.noreply.github.com>2026-03-14 00:48:01 +1100
committerGitHub <noreply@github.com>2026-03-13 08:48:01 -0500
commit24a95621e5118e39e1a6e05b17ef89f4ec2c8c01 (patch)
treea37133cd549fb7107ebbaa5bf60fafd52a5bdd77 /src/managers
parente8684034525829d58054c32da914d1713398fbb8 (diff)
input: add device specific binds (#13073)
Adds support for device-specific binds
Diffstat (limited to 'src/managers')
-rw-r--r--src/managers/KeybindManager.cpp37
-rw-r--r--src/managers/KeybindManager.hpp57
-rw-r--r--src/managers/PointerManager.cpp4
-rw-r--r--src/managers/input/InputManager.cpp10
-rw-r--r--src/managers/input/InputManager.hpp4
5 files changed, 60 insertions, 52 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;
diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp
index 1f013606..16f0b67d 100644
--- a/src/managers/KeybindManager.hpp
+++ b/src/managers/KeybindManager.hpp
@@ -3,6 +3,7 @@
#include "../defines.hpp"
#include <vector>
#include <set>
+#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <xkbcommon/xkbcommon.h>
@@ -26,30 +27,32 @@ struct SSubmap {
};
struct SKeybind {
- std::string key = "";
- std::set<xkb_keysym_t> sMkKeys = {};
- uint32_t keycode = 0;
- bool catchAll = false;
- uint32_t modmask = 0;
- std::set<xkb_keysym_t> sMkMods = {};
- std::string handler = "";
- std::string arg = "";
- bool locked = false;
- SSubmap submap = {};
- std::string description = "";
- bool release = false;
- bool repeat = false;
- bool longPress = false;
- bool mouse = false;
- bool nonConsuming = false;
- bool transparent = false;
- bool ignoreMods = false;
- bool multiKey = false;
- bool hasDescription = false;
- bool dontInhibit = false;
- bool click = false;
- bool drag = false;
- bool submapUniversal = false;
+ std::string key = "";
+ std::set<xkb_keysym_t> sMkKeys = {};
+ uint32_t keycode = 0;
+ bool catchAll = false;
+ uint32_t modmask = 0;
+ std::set<xkb_keysym_t> sMkMods = {};
+ std::string handler = "";
+ std::string arg = "";
+ bool locked = false;
+ SSubmap submap = {};
+ std::string description = "";
+ bool release = false;
+ bool repeat = false;
+ bool longPress = false;
+ bool mouse = false;
+ bool nonConsuming = false;
+ bool transparent = false;
+ bool ignoreMods = false;
+ bool multiKey = false;
+ bool hasDescription = false;
+ bool dontInhibit = false;
+ bool click = false;
+ bool drag = false;
+ bool submapUniversal = false;
+ bool deviceInclusive = false;
+ std::unordered_set<std::string> devices = {};
// DO NOT INITIALIZE
bool shadowed = false;
@@ -94,8 +97,8 @@ class CKeybindManager {
~CKeybindManager();
bool onKeyEvent(std::any, SP<IKeyboard>);
- bool onAxisEvent(const IPointer::SAxisEvent&);
- bool onMouseEvent(const IPointer::SButtonEvent&);
+ bool onAxisEvent(const IPointer::SAxisEvent&, SP<IPointer>);
+ bool onMouseEvent(const IPointer::SButtonEvent&, SP<IPointer>);
void resizeWithBorder(const IPointer::SButtonEvent&);
void onSwitchEvent(const std::string&);
void onSwitchOnEvent(const std::string&);
@@ -145,7 +148,7 @@ class CKeybindManager {
CTimer m_scrollTimer;
- SDispatchResult handleKeybinds(const uint32_t, const SPressedKeyWithMods&, bool, SP<IKeyboard>);
+ SDispatchResult handleKeybinds(const uint32_t, const SPressedKeyWithMods&, bool, SP<IKeyboard>, SP<IHID>);
std::set<xkb_keysym_t> m_mkKeys = {};
std::set<xkb_keysym_t> m_mkMods = {};
diff --git a/src/managers/PointerManager.cpp b/src/managers/PointerManager.cpp
index d004f5b8..f78984f9 100644
--- a/src/managers/PointerManager.cpp
+++ b/src/managers/PointerManager.cpp
@@ -950,8 +950,8 @@ void CPointerManager::attachPointer(SP<IPointer> pointer) {
CKeybindManager::dpms("on");
});
- listener->button = pointer->m_pointerEvents.button.listen([](const IPointer::SButtonEvent& event) {
- g_pInputManager->onMouseButton(event);
+ listener->button = pointer->m_pointerEvents.button.listen([weak = WP<IPointer>(pointer)](const IPointer::SButtonEvent& event) {
+ g_pInputManager->onMouseButton(event, weak.lock());
PROTO::idle->onActivity();
});
diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp
index 9195536f..d88b29cd 100644
--- a/src/managers/input/InputManager.cpp
+++ b/src/managers/input/InputManager.cpp
@@ -647,7 +647,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus, bool mouse, st
g_pSeatManager->sendPointerMotion(time, surfaceLocal);
}
-void CInputManager::onMouseButton(IPointer::SButtonEvent e) {
+void CInputManager::onMouseButton(IPointer::SButtonEvent e, SP<IPointer> mouse) {
Event::SCallbackInfo info;
Event::bus()->m_events.input.mouse.button.emit(e, info);
if (info.cancelled)
@@ -667,7 +667,7 @@ void CInputManager::onMouseButton(IPointer::SButtonEvent e) {
}
switch (m_clickBehavior) {
- case CLICKMODE_DEFAULT: processMouseDownNormal(e); break;
+ case CLICKMODE_DEFAULT: processMouseDownNormal(e, mouse); break;
case CLICKMODE_KILL: processMouseDownKill(e); break;
default: break;
}
@@ -755,11 +755,11 @@ void CInputManager::setClickMode(eClickBehaviorMode mode) {
}
}
-void CInputManager::processMouseDownNormal(const IPointer::SButtonEvent& e) {
+void CInputManager::processMouseDownNormal(const IPointer::SButtonEvent& e, SP<IPointer> mouse) {
// notify the keybind manager
static auto PPASSMOUSE = CConfigValue<Hyprlang::INT>("binds:pass_mouse_when_bound");
- const auto PASS = g_pKeybindManager->onMouseEvent(e);
+ const auto PASS = g_pKeybindManager->onMouseEvent(e, mouse);
static auto PFOLLOWMOUSE = CConfigValue<Hyprlang::INT>("input:follow_mouse");
static auto PRESIZEONBORDER = CConfigValue<Hyprlang::INT>("general:resize_on_border");
static auto PBORDERSIZE = CConfigValue<Hyprlang::INT>("general:border_size");
@@ -884,7 +884,7 @@ void CInputManager::onMouseWheel(IPointer::SAxisEvent e, SP<IPointer> pointer) {
if (e.mouse)
recheckMouseWarpOnMouseInput();
- bool passEvent = g_pKeybindManager->onAxisEvent(e);
+ bool passEvent = g_pKeybindManager->onAxisEvent(e, pointer);
if (!passEvent)
return;
diff --git a/src/managers/input/InputManager.hpp b/src/managers/input/InputManager.hpp
index ca235a23..0727b7b1 100644
--- a/src/managers/input/InputManager.hpp
+++ b/src/managers/input/InputManager.hpp
@@ -89,7 +89,7 @@ class CInputManager {
void onMouseMoved(IPointer::SMotionEvent);
void onMouseWarp(IPointer::SMotionAbsoluteEvent);
- void onMouseButton(IPointer::SButtonEvent);
+ void onMouseButton(IPointer::SButtonEvent, SP<IPointer>);
void onMouseWheel(IPointer::SAxisEvent, SP<IPointer> pointer = nullptr);
void onPointerFrame();
void onKeyboardKey(const IKeyboard::SKeyEvent&, SP<IKeyboard>);
@@ -233,7 +233,7 @@ class CInputManager {
void setupKeyboard(SP<IKeyboard> keeb);
void setupMouse(SP<IPointer> mauz);
- void processMouseDownNormal(const IPointer::SButtonEvent& e);
+ void processMouseDownNormal(const IPointer::SButtonEvent& e, SP<IPointer>);
void processMouseDownKill(const IPointer::SButtonEvent& e);
bool cursorImageUnlocked();