Implement pass binds (#2503)

* Implement pass binds

Pass binds run the associated dispatcher but do not prevent windows
from receiving the bind.

* Fix pass binds not working properly with release binds

* Rename `pass` to `nonConsuming`
This commit is contained in:
outfoxxed 2023-06-14 04:08:56 -07:00 committed by GitHub
parent 9a88c19f1a
commit f0e4f6622e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 21 deletions

View file

@ -770,11 +770,12 @@ void CConfigManager::handleBind(const std::string& command, const std::string& v
// bind[fl]=SUPER,G,exec,dmenu_run <args> // bind[fl]=SUPER,G,exec,dmenu_run <args>
// flags // flags
bool locked = false; bool locked = false;
bool release = false; bool release = false;
bool repeat = false; bool repeat = false;
bool mouse = false; bool mouse = false;
const auto BINDARGS = command.substr(4); bool nonConsuming = false;
const auto BINDARGS = command.substr(4);
for (auto& arg : BINDARGS) { for (auto& arg : BINDARGS) {
if (arg == 'l') { if (arg == 'l') {
@ -785,6 +786,8 @@ void CConfigManager::handleBind(const std::string& command, const std::string& v
repeat = true; repeat = true;
} else if (arg == 'm') { } else if (arg == 'm') {
mouse = true; mouse = true;
} else if (arg == 'n') {
nonConsuming = true;
} else { } else {
parseError = "bind: invalid flag"; parseError = "bind: invalid flag";
return; return;
@ -842,11 +845,11 @@ void CConfigManager::handleBind(const std::string& command, const std::string& v
if (KEY != "") { if (KEY != "") {
if (isNumber(KEY) && std::stoi(KEY) > 9) if (isNumber(KEY) && std::stoi(KEY) > 9)
g_pKeybindManager->addKeybind(SKeybind{"", std::stoi(KEY), MOD, HANDLER, COMMAND, locked, m_szCurrentSubmap, release, repeat, mouse}); g_pKeybindManager->addKeybind(SKeybind{"", std::stoi(KEY), MOD, HANDLER, COMMAND, locked, m_szCurrentSubmap, release, repeat, mouse, nonConsuming});
else if (KEY.find("code:") == 0 && isNumber(KEY.substr(5))) else if (KEY.find("code:") == 0 && isNumber(KEY.substr(5)))
g_pKeybindManager->addKeybind(SKeybind{"", std::stoi(KEY.substr(5)), MOD, HANDLER, COMMAND, locked, m_szCurrentSubmap, release, repeat, mouse}); g_pKeybindManager->addKeybind(SKeybind{"", std::stoi(KEY.substr(5)), MOD, HANDLER, COMMAND, locked, m_szCurrentSubmap, release, repeat, mouse, nonConsuming});
else else
g_pKeybindManager->addKeybind(SKeybind{KEY, -1, MOD, HANDLER, COMMAND, locked, m_szCurrentSubmap, release, repeat, mouse}); g_pKeybindManager->addKeybind(SKeybind{KEY, -1, MOD, HANDLER, COMMAND, locked, m_szCurrentSubmap, release, repeat, mouse, nonConsuming});
} }
} }

View file

@ -592,6 +592,8 @@ std::string bindsRequest(HyprCtl::eHyprCtlOutputFormat format) {
ret += "r"; ret += "r";
if (kb.repeat) if (kb.repeat)
ret += "e"; ret += "e";
if (kb.nonConsuming)
ret += "n";
ret += getFormat("\n\tmodmask: %u\n\tsubmap: %s\n\tkey: %s\n\tkeycode: %d\n\tdispatcher: %s\n\targ: %s\n\n", kb.modmask, kb.submap.c_str(), kb.key.c_str(), kb.keycode, ret += getFormat("\n\tmodmask: %u\n\tsubmap: %s\n\tkey: %s\n\tkeycode: %d\n\tdispatcher: %s\n\targ: %s\n\n", kb.modmask, kb.submap.c_str(), kb.key.c_str(), kb.keycode,
kb.handler.c_str(), kb.arg.c_str()); kb.handler.c_str(), kb.arg.c_str());
@ -607,6 +609,7 @@ std::string bindsRequest(HyprCtl::eHyprCtlOutputFormat format) {
"mouse": %s, "mouse": %s,
"release": %s, "release": %s,
"repeat": %s, "repeat": %s,
"non_consuming": %s,
"modmask": %u, "modmask": %u,
"submap": "%s", "submap": "%s",
"key": "%s", "key": "%s",
@ -614,8 +617,9 @@ std::string bindsRequest(HyprCtl::eHyprCtlOutputFormat format) {
"dispatcher": "%s", "dispatcher": "%s",
"arg": "%s" "arg": "%s"
},)#", },)#",
kb.locked ? "true" : "false", kb.mouse ? "true" : "false", kb.release ? "true" : "false", kb.repeat ? "true" : "false", kb.modmask, kb.locked ? "true" : "false", kb.mouse ? "true" : "false", kb.release ? "true" : "false", kb.repeat ? "true" : "false", kb.nonConsuming ? "true" : "false",
escapeJSONStrings(kb.submap).c_str(), escapeJSONStrings(kb.key).c_str(), kb.keycode, escapeJSONStrings(kb.handler).c_str(), escapeJSONStrings(kb.arg).c_str()); kb.modmask, escapeJSONStrings(kb.submap).c_str(), escapeJSONStrings(kb.key).c_str(), kb.keycode, escapeJSONStrings(kb.handler).c_str(),
escapeJSONStrings(kb.arg).c_str());
} }
trimTrailingComma(ret); trimTrailingComma(ret);
ret += "]"; ret += "]";

View file

@ -414,6 +414,9 @@ bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const std::string&
} }
if (pressed && k.release) { if (pressed && k.release) {
if (k.nonConsuming)
return false;
// suppress down event // suppress down event
m_kHeldBack = keysym; m_kHeldBack = keysym;
return true; return true;
@ -452,7 +455,8 @@ bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const std::string&
wl_event_source_timer_update(m_pActiveKeybindEventSource, PACTIVEKEEB->repeatDelay); wl_event_source_timer_update(m_pActiveKeybindEventSource, PACTIVEKEEB->repeatDelay);
} }
found = true; if (!k.nonConsuming)
found = true;
} }
return found; return found;

View file

@ -11,16 +11,17 @@ class CConfigManager;
class CPluginSystem; class CPluginSystem;
struct SKeybind { struct SKeybind {
std::string key = ""; std::string key = "";
int keycode = -1; int keycode = -1;
uint32_t modmask = 0; uint32_t modmask = 0;
std::string handler = ""; std::string handler = "";
std::string arg = ""; std::string arg = "";
bool locked = false; bool locked = false;
std::string submap = ""; std::string submap = "";
bool release = false; bool release = false;
bool repeat = false; bool repeat = false;
bool mouse = false; bool mouse = false;
bool nonConsuming = false;
// DO NOT INITIALIZE // DO NOT INITIALIZE
bool shadowed = false; bool shadowed = false;