From d599513d4a72d66ac62ffdedc41d6653fa81b39e Mon Sep 17 00:00:00 2001 From: ItsOhen Date: Sat, 11 Oct 2025 02:40:18 +0200 Subject: 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. --- src/managers/KeybindManager.cpp | 14 ++++++++------ src/managers/KeybindManager.hpp | 16 ++++++++++++---- 2 files changed, 20 insertions(+), 10 deletions(-) (limited to 'src/managers') 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 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 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> m_dispatchers; @@ -117,7 +125,7 @@ class CKeybindManager { private: std::vector m_pressedKeys; - inline static std::string m_currentSelectedSubmap = ""; + inline static SSubmap m_currentSelectedSubmap = {}; std::vector> m_activeKeybinds; WP m_lastLongPressKeybind; -- cgit v1.2.3