bind: new long press option

impl #8245
This commit is contained in:
littleblack111 2024-10-31 00:27:38 +08:00 committed by Vaxry
parent a8ff3a452c
commit f260e9cbbd
2 changed files with 28 additions and 1 deletions

View file

@ -2169,6 +2169,7 @@ std::optional<std::string> CConfigManager::handleBind(const std::string& command
bool transparent = false; bool transparent = false;
bool ignoreMods = false; bool ignoreMods = false;
bool multiKey = false; bool multiKey = false;
bool longPress = false;
bool hasDescription = false; bool hasDescription = false;
bool dontInhibit = false; bool dontInhibit = false;
const auto BINDARGS = command.substr(4); const auto BINDARGS = command.substr(4);
@ -2190,6 +2191,8 @@ std::optional<std::string> CConfigManager::handleBind(const std::string& command
ignoreMods = true; ignoreMods = true;
} else if (arg == 's') { } else if (arg == 's') {
multiKey = true; multiKey = true;
} else if (arg == 'o') {
longPress = true;
} else if (arg == 'd') { } else if (arg == 'd') {
hasDescription = true; hasDescription = true;
} else if (arg == 'p') { } else if (arg == 'p') {
@ -2264,7 +2267,7 @@ std::optional<std::string> CConfigManager::handleBind(const std::string& command
g_pKeybindManager->addKeybind(SKeybind{ g_pKeybindManager->addKeybind(SKeybind{
parsedKey.key, KEYSYMS, parsedKey.keycode, parsedKey.catchAll, MOD, MODS, HANDLER, COMMAND, locked, m_szCurrentSubmap, DESCRIPTION, release, parsedKey.key, KEYSYMS, parsedKey.keycode, parsedKey.catchAll, MOD, MODS, HANDLER, COMMAND, locked, m_szCurrentSubmap, DESCRIPTION, release,
repeat, mouse, nonConsuming, transparent, ignoreMods, multiKey, hasDescription, dontInhibit}); repeat, mouse, nonConsuming, transparent, ignoreMods, multiKey, longPress, hasDescription, dontInhibit});
} }
return {}; return {};

View file

@ -567,6 +567,20 @@ int repeatKeyHandler(void* data) {
return 0; return 0;
} }
int longPressHandler(void* data) {
SKeybind** ppActiveKeybind = (SKeybind**)data;
if (!*ppActiveKeybind || g_pSeatManager->keyboard.expired())
return 0;
const auto DISPATCHER = g_pKeybindManager->m_mDispatchers.find((*ppActiveKeybind)->handler);
Debug::log(LOG, "Keybind long press triggered, calling dispatcher.");
DISPATCHER->second((*ppActiveKeybind)->arg);
return 0;
}
eMultiKeyCase CKeybindManager::mkKeysymSetMatches(const std::set<xkb_keysym_t> keybindKeysyms, const std::set<xkb_keysym_t> pressedKeysyms) { eMultiKeyCase CKeybindManager::mkKeysymSetMatches(const std::set<xkb_keysym_t> keybindKeysyms, const std::set<xkb_keysym_t> pressedKeysyms) {
// Returns whether two sets of keysyms are equal, partially equal, or not // Returns whether two sets of keysyms are equal, partially equal, or not
// matching. (Partially matching means that pressed is a subset of bound) // matching. (Partially matching means that pressed is a subset of bound)
@ -701,6 +715,16 @@ SDispatchResult CKeybindManager::handleKeybinds(const uint32_t modmask, const SP
} }
} }
if (k.longPress) {
m_pActiveKeybind = &k;
m_pActiveKeybindEventSource = wl_event_loop_add_timer(g_pCompositor->m_sWLEventLoop, longPressHandler, &m_pActiveKeybind);
const auto PACTIVEKEEB = g_pSeatManager->keyboard.lock();
wl_event_source_timer_update(m_pActiveKeybindEventSource, PACTIVEKEEB->repeatDelay);
continue;
}
const auto DISPATCHER = m_mDispatchers.find(k.mouse ? "mouse" : k.handler); const auto DISPATCHER = m_mDispatchers.find(k.mouse ? "mouse" : k.handler);
if (SPECIALTRIGGERED && !pressed) if (SPECIALTRIGGERED && !pressed)