summaryrefslogtreecommitdiff
path: root/src/managers/KeybindManager.cpp
diff options
context:
space:
mode:
authornyx <nnyyxxxx@protonmail.com>2025-03-24 23:59:13 +0000
committerGitHub <noreply@github.com>2025-03-25 00:59:13 +0100
commitf7ba86d1f335112ae0d13548947ddbd76b1477b6 (patch)
treeee038c82296281ce2b4b6b7039868b1fce104eff /src/managers/KeybindManager.cpp
parentf3db1b172c6c61df7d5b8c960feccf3c19eb8e23 (diff)
keybinds: add sendkeystate dispatcher (#9599)
Diffstat (limited to 'src/managers/KeybindManager.cpp')
-rw-r--r--src/managers/KeybindManager.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp
index 42e2bc14..cc912938 100644
--- a/src/managers/KeybindManager.cpp
+++ b/src/managers/KeybindManager.cpp
@@ -117,6 +117,7 @@ CKeybindManager::CKeybindManager() {
m_mDispatchers["submap"] = setSubmap;
m_mDispatchers["pass"] = pass;
m_mDispatchers["sendshortcut"] = sendshortcut;
+ m_mDispatchers["sendkeystate"] = sendkeystate;
m_mDispatchers["layoutmsg"] = layoutmsg;
m_mDispatchers["dpms"] = dpms;
m_mDispatchers["movewindowpixel"] = moveWindow;
@@ -3215,3 +3216,45 @@ SDispatchResult CKeybindManager::setProp(std::string args) {
return {};
}
+
+SDispatchResult CKeybindManager::sendkeystate(std::string args) {
+ // args=<NEW_MODKEYS><NEW_KEY><STATE>[,WINDOW_RULES]
+ const auto ARGS = CVarList(args, 4);
+ if (ARGS.size() != 4) {
+ Debug::log(ERR, "sendkeystate: invalid args");
+ return {.success = false, .error = "sendkeystate: invalid args"};
+ }
+
+ const auto STATE = ARGS[2];
+
+ if (STATE != "down" && STATE != "repeat" && STATE != "up") {
+ Debug::log(ERR, "sendkeystate: invalid state, must be 'down', 'repeat', or 'up'");
+ return {.success = false, .error = "sendkeystate: invalid state, must be 'down', 'repeat', or 'up'"};
+ }
+
+ std::string modifiedArgs = ARGS[0] + "," + ARGS[1] + "," + ARGS[3];
+
+ const int oldPassPressed = g_pKeybindManager->m_iPassPressed;
+
+ if (STATE == "down")
+ g_pKeybindManager->m_iPassPressed = 1;
+ else if (STATE == "up")
+ g_pKeybindManager->m_iPassPressed = 0;
+ else if (STATE == "repeat")
+ g_pKeybindManager->m_iPassPressed = 1;
+
+ auto result = sendshortcut(modifiedArgs);
+
+ if (STATE == "repeat" && result.success)
+ result = sendshortcut(modifiedArgs);
+
+ g_pKeybindManager->m_iPassPressed = oldPassPressed;
+
+ if (!result.success && !result.error.empty()) {
+ size_t pos = result.error.find("sendshortcut:");
+ if (pos != std::string::npos)
+ result.error = "sendkeystate:" + result.error.substr(pos + 13);
+ }
+
+ return result;
+}