| 174 | |
| 175 | |
| 176 | bool HotkeyManager::addKeybind(KeySpec spec, std::string_view cmd) { |
| 177 | // No point in a hotkey with no action |
| 178 | if (cmd.empty()) |
| 179 | return false; |
| 180 | |
| 181 | KeyBinding binding; |
| 182 | binding.spec = std::move(spec); |
| 183 | binding.cmdline = cmd; |
| 184 | size_t space_idx = cmd.find(' '); |
| 185 | binding.command = space_idx == std::string::npos ? cmd : cmd.substr(0, space_idx); |
| 186 | |
| 187 | std::lock_guard<std::mutex> l(lock); |
| 188 | auto& bindings = this->bindings[binding.spec.sym]; |
| 189 | for (auto& bind : bindings) { |
| 190 | // Don't set a keybind twice, but return true as there isn't an issue |
| 191 | if (bind == binding) |
| 192 | return true; |
| 193 | } |
| 194 | |
| 195 | bindings.emplace_back(binding); |
| 196 | return true; |
| 197 | } |
| 198 | |
| 199 | bool HotkeyManager::addKeybind(std::string keyspec, std::string_view cmd) { |
| 200 | std::optional<KeySpec> spec_opt = KeySpec::parse(std::move(keyspec)); |
no test coverage detected