summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorItsOhen <TNordfeldt@gmail.com>2025-10-11 02:40:18 +0200
committerGitHub <noreply@github.com>2025-10-11 02:40:18 +0200
commitd599513d4a72d66ac62ffdedc41d6653fa81b39e (patch)
tree9ce093a84421330da38f015d40c94941b43e6a04 /src
parent6a01c399a971a57854fb4a99ce246534139beda4 (diff)
config: add automatic closing to submaps (#11760)
* Allow submaps to auto reset to parent. * Really should be a stack instead. If hyprlang would allow for { } i would be so happy. * Fixed: Somewhat better way to do it.. Lets you define what submap you want to go to instead. * squash! Fixed: Somewhat better way to do it.. * God i hate cf.. * Force clang-format on the whole thing.. * Removed {}. * Added tests Tests and reset fix.
Diffstat (limited to 'src')
-rw-r--r--src/config/ConfigManager.cpp12
-rw-r--r--src/config/ConfigManager.hpp3
-rw-r--r--src/debug/HyprCtl.cpp8
-rw-r--r--src/managers/KeybindManager.cpp14
-rw-r--r--src/managers/KeybindManager.hpp16
5 files changed, 31 insertions, 22 deletions
diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp
index 936ec383..47ac4730 100644
--- a/src/config/ConfigManager.cpp
+++ b/src/config/ConfigManager.cpp
@@ -2630,7 +2630,7 @@ std::optional<std::string> CConfigManager::handleBind(const std::string& command
if ((!KEY.empty()) || multiKey) {
SParsedKey parsedKey = parseKey(KEY);
- if (parsedKey.catchAll && m_currentSubmap.empty()) {
+ if (parsedKey.catchAll && m_currentSubmap.name.empty()) {
Debug::log(ERR, "Catchall not allowed outside of submap!");
return "Invalid catchall, catchall keybinds are only allowed in submaps.";
}
@@ -3011,12 +3011,10 @@ std::optional<std::string> CConfigManager::handleWorkspaceRules(const std::strin
return {};
}
-std::optional<std::string> CConfigManager::handleSubmap(const std::string& command, const std::string& submap) {
- if (submap == "reset")
- m_currentSubmap = "";
- else
- m_currentSubmap = submap;
-
+std::optional<std::string> CConfigManager::handleSubmap(const std::string&, const std::string& submap) {
+ const auto SUBMAP = CConstVarList(submap);
+ m_currentSubmap.name = (SUBMAP[0] == "reset") ? "" : SUBMAP[0];
+ m_currentSubmap.reset = SUBMAP[1];
return {};
}
diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp
index cff146f3..7f32be41 100644
--- a/src/config/ConfigManager.hpp
+++ b/src/config/ConfigManager.hpp
@@ -22,6 +22,7 @@
#include "../helpers/memory/Memory.hpp"
#include "../desktop/WindowRule.hpp"
#include "../managers/XWaylandManager.hpp"
+#include "../managers/KeybindManager.hpp"
#include <hyprlang.hpp>
@@ -307,7 +308,7 @@ class CConfigManager {
Hyprutils::Animation::CAnimationConfigTree m_animationTree;
- std::string m_currentSubmap = ""; // For storing the current keybind submap
+ SSubmap m_currentSubmap;
std::vector<SExecRequestedRule> m_execRequestedRules; // rules requested with exec, e.g. [workspace 2] kitty
diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp
index 116ddac9..ebf7acd6 100644
--- a/src/debug/HyprCtl.cpp
+++ b/src/debug/HyprCtl.cpp
@@ -1000,7 +1000,7 @@ static std::string bindsRequest(eHyprCtlOutputFormat format, std::string request
ret += "d";
ret += std::format("\n\tmodmask: {}\n\tsubmap: {}\n\tkey: {}\n\tkeycode: {}\n\tcatchall: {}\n\tdescription: {}\n\tdispatcher: {}\n\targ: {}\n\n", kb->modmask,
- kb->submap, kb->key, kb->keycode, kb->catchAll, kb->description, kb->handler, kb->arg);
+ kb->submap.name, kb->key, kb->keycode, kb->catchAll, kb->description, kb->handler, kb->arg);
}
} else {
// json
@@ -1026,8 +1026,8 @@ static std::string bindsRequest(eHyprCtlOutputFormat format, std::string request
"arg": "{}"
}},)#",
kb->locked ? "true" : "false", kb->mouse ? "true" : "false", kb->release ? "true" : "false", kb->repeat ? "true" : "false", kb->longPress ? "true" : "false",
- kb->nonConsuming ? "true" : "false", kb->hasDescription ? "true" : "false", kb->modmask, escapeJSONStrings(kb->submap), escapeJSONStrings(kb->key), kb->keycode,
- kb->catchAll ? "true" : "false", escapeJSONStrings(kb->description), escapeJSONStrings(kb->handler), escapeJSONStrings(kb->arg));
+ kb->nonConsuming ? "true" : "false", kb->hasDescription ? "true" : "false", kb->modmask, escapeJSONStrings(kb->submap.name), escapeJSONStrings(kb->key),
+ kb->keycode, kb->catchAll ? "true" : "false", escapeJSONStrings(kb->description), escapeJSONStrings(kb->handler), escapeJSONStrings(kb->arg));
}
trimTrailingComma(ret);
ret += "]";
@@ -1962,7 +1962,7 @@ static std::string getDescriptions(eHyprCtlOutputFormat format, std::string requ
}
static std::string submapRequest(eHyprCtlOutputFormat format, std::string request) {
- std::string submap = g_pKeybindManager->getCurrentSubmap();
+ std::string submap = g_pKeybindManager->getCurrentSubmap().name;
if (submap.empty())
submap = "default";
diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp
index 81c88d63..c9008c2f 100644
--- a/src/managers/KeybindManager.cpp
+++ b/src/managers/KeybindManager.cpp
@@ -643,7 +643,7 @@ eMultiKeyCase CKeybindManager::mkBindMatches(const SP<SKeybind> keybind) {
return mkKeysymSetMatches(keybind->sMkKeys, m_mkKeys);
}
-std::string CKeybindManager::getCurrentSubmap() {
+SSubmap CKeybindManager::getCurrentSubmap() {
return m_currentSelectedSubmap;
}
@@ -795,6 +795,8 @@ SDispatchResult CKeybindManager::handleKeybinds(const uint32_t modmask, const SP
found = true; // don't process keybinds on submap change.
break;
}
+ if (k->handler != "submap" && !k->submap.reset.empty())
+ setSubmap(k->submap.reset);
}
if (pressed && k->repeat) {
@@ -2390,19 +2392,19 @@ SDispatchResult CKeybindManager::toggleSwallow(std::string args) {
SDispatchResult CKeybindManager::setSubmap(std::string submap) {
if (submap == "reset" || submap.empty()) {
- m_currentSelectedSubmap = "";
+ m_currentSelectedSubmap.name = "";
Debug::log(LOG, "Reset active submap to the default one.");
g_pEventManager->postEvent(SHyprIPCEvent{"submap", ""});
- EMIT_HOOK_EVENT("submap", m_currentSelectedSubmap);
+ EMIT_HOOK_EVENT("submap", m_currentSelectedSubmap.name);
return {};
}
for (const auto& k : g_pKeybindManager->m_keybinds) {
- if (k->submap == submap) {
- m_currentSelectedSubmap = submap;
+ if (k->submap.name == submap) {
+ m_currentSelectedSubmap.name = submap;
Debug::log(LOG, "Changed keybind submap to {}", submap);
g_pEventManager->postEvent(SHyprIPCEvent{"submap", submap});
- EMIT_HOOK_EVENT("submap", m_currentSelectedSubmap);
+ EMIT_HOOK_EVENT("submap", m_currentSelectedSubmap.name);
return {};
}
}
diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp
index 2272aa8f..45742e78 100644
--- a/src/managers/KeybindManager.hpp
+++ b/src/managers/KeybindManager.hpp
@@ -17,6 +17,14 @@ class IKeyboard;
enum eMouseBindMode : int8_t;
+struct SSubmap {
+ std::string name = "";
+ std::string reset = "";
+ bool operator==(const SSubmap& other) const {
+ return name == other.name;
+ }
+};
+
struct SKeybind {
std::string key = "";
std::set<xkb_keysym_t> sMkKeys = {};
@@ -27,7 +35,7 @@ struct SKeybind {
std::string handler = "";
std::string arg = "";
bool locked = false;
- std::string submap = "";
+ SSubmap submap = {};
std::string description = "";
bool release = false;
bool repeat = false;
@@ -63,7 +71,7 @@ struct SPressedKeyWithMods {
uint32_t keycode = 0;
uint32_t modmaskAtPressTime = 0;
bool sent = false;
- std::string submapAtPress = "";
+ SSubmap submapAtPress = {};
Vector2D mousePosAtPress = {};
};
@@ -98,7 +106,7 @@ class CKeybindManager {
uint32_t keycodeToModifier(xkb_keycode_t);
void clearKeybinds();
void shadowKeybinds(const xkb_keysym_t& doesntHave = 0, const uint32_t doesntHaveCode = 0);
- std::string getCurrentSubmap();
+ SSubmap getCurrentSubmap();
std::unordered_map<std::string, std::function<SDispatchResult(std::string)>> m_dispatchers;
@@ -117,7 +125,7 @@ class CKeybindManager {
private:
std::vector<SPressedKeyWithMods> m_pressedKeys;
- inline static std::string m_currentSelectedSubmap = "";
+ inline static SSubmap m_currentSelectedSubmap = {};
std::vector<WP<SKeybind>> m_activeKeybinds;
WP<SKeybind> m_lastLongPressKeybind;