@@ -181,16 +181,17 @@ bool HotkeyManager::addKeybind(std::string keyspec, std::string cmd) {
181181 return this ->addKeybind (spec_opt.value (), cmd);
182182}
183183
184- bool HotkeyManager::clearKeybind (const KeySpec& spec, bool any_focus , std::string_view cmdline) {
184+ bool HotkeyManager::removeKeybind (const KeySpec& spec, bool match_focus , std::string_view cmdline) {
185185 std::lock_guard<std::mutex> l (lock);
186186 if (!bindings.contains (spec.sym ))
187187 return false ;
188188 auto & binds = bindings[spec.sym ];
189189
190- auto new_end = std::remove_if (binds.begin (), binds.end (), [any_focus, spec, &cmdline](const auto & v) {
191- return (any_focus
192- ? v.spec .sym == spec.sym && v.spec .modifiers == spec.modifiers
193- : v.spec == spec) && (cmdline.empty () || v.cmdline == cmdline);
190+ auto new_end = std::remove_if (binds.begin (), binds.end (), [match_focus, spec, &cmdline](const auto & v) {
191+ return v.spec .sym == spec.sym
192+ && v.spec .modifiers == spec.modifiers
193+ && (!match_focus || v.spec .focus == spec.focus )
194+ && (cmdline.empty () || v.cmdline == cmdline);
194195 });
195196 if (new_end == binds.end ())
196197 return false ; // No bindings removed
@@ -199,11 +200,11 @@ bool HotkeyManager::clearKeybind(const KeySpec& spec, bool any_focus, std::strin
199200 return true ;
200201}
201202
202- bool HotkeyManager::clearKeybind (std::string keyspec, bool any_focus , std::string_view cmdline) {
203+ bool HotkeyManager::removeKeybind (std::string keyspec, bool match_focus , std::string_view cmdline) {
203204 std::optional<KeySpec> spec_opt = Hotkey::parseKeySpec (keyspec);
204205 if (!spec_opt.has_value ())
205206 return false ;
206- return this ->clearKeybind (spec_opt.value (), any_focus , cmdline);
207+ return this ->removeKeybind (spec_opt.value (), match_focus , cmdline);
207208}
208209
209210std::vector<std::string> HotkeyManager::listKeybinds (const KeySpec& spec) {
@@ -237,13 +238,15 @@ std::vector<std::string> HotkeyManager::listKeybinds(const KeySpec& spec) {
237238}
238239
239240std::vector<std::string> HotkeyManager::listKeybinds (std::string keyspec) {
241+ std::lock_guard<std::mutex> l (lock);
240242 std::optional<KeySpec> spec_opt = Hotkey::parseKeySpec (keyspec);
241243 if (!spec_opt.has_value ())
242244 return {};
243245 return this ->listKeybinds (spec_opt.value ());
244246}
245247
246248std::vector<KeyBinding> HotkeyManager::listActiveKeybinds () {
249+ std::lock_guard<std::mutex> l (lock);
247250 std::vector<KeyBinding> out;
248251
249252 for (const auto & [_, bind_set] : bindings) {
@@ -267,6 +270,7 @@ std::vector<KeyBinding> HotkeyManager::listActiveKeybinds() {
267270}
268271
269272std::vector<KeyBinding> HotkeyManager::listAllKeybinds () {
273+ std::lock_guard<std::mutex> l (lock);
270274 std::vector<KeyBinding> out;
271275
272276 for (const auto & [_, bind_set] : bindings) {
@@ -351,13 +355,13 @@ void HotkeyManager::setHotkeyCommand(std::string cmd) {
351355 cond.notify_all ();
352356}
353357
354- void HotkeyManager::requestKeybindInput ( ) {
358+ void HotkeyManager::requestKeybindingInput ( bool cancel ) {
355359 std::lock_guard<std::mutex> l (lock);
356- keybind_save_requested = true ;
357- requested_keybind = " " ;
360+ keybind_save_requested = !cancel ;
361+ requested_keybind. clear () ;
358362}
359363
360- std::string HotkeyManager::readKeybindInput () {
364+ std::string HotkeyManager::getKeybindingInput () {
361365 std::lock_guard<std::mutex> l (lock);
362366 return requested_keybind;
363367}
@@ -367,7 +371,7 @@ void HotkeyManager::handleKeybindingCommand(color_ostream &con, const std::vecto
367371 if (parts.size () >= 3 && (parts[0 ] == " set" || parts[0 ] == " add" )) {
368372 std::string keystr = parts[1 ];
369373 if (parts[0 ] == " set" )
370- clearKeybind (keystr);
374+ removeKeybind (keystr);
371375 for (const auto & part : parts | std::views::drop (2 ) | std::views::reverse) {
372376 auto spec = Hotkey::parseKeySpec (keystr, &parse_error);
373377 if (!spec.has_value ()) {
@@ -386,7 +390,7 @@ void HotkeyManager::handleKeybindingCommand(color_ostream &con, const std::vecto
386390 if (!spec.has_value ()) {
387391 con.printerr (" %s\n " , parse_error.c_str ());
388392 }
389- if (!clearKeybind (spec.value ())) {
393+ if (!removeKeybind (spec.value ())) {
390394 con.printerr (" No matching keybinds to remove\n " );
391395 break ;
392396 }
0 commit comments