@@ -20,20 +20,20 @@ using namespace DFHack;
2020using Hotkey::KeySpec;
2121using Hotkey::KeyBinding;
2222
23- enum HotkeySignal {
23+ enum HotkeySignal : uint8_t {
2424 None = 0 ,
2525 CmdReady,
2626 Shutdown,
2727};
2828
29- bool operator ==(const KeySpec& a, const KeySpec& b) {
29+ static bool operator ==(const KeySpec& a, const KeySpec& b) {
3030 return a.modifiers == b.modifiers && a.sym == b.sym &&
3131 a.focus .size () == b.focus .size () &&
3232 std::equal (a.focus .begin (), a.focus .end (), b.focus .begin ());
3333}
3434
3535// Equality operator for key bindings
36- bool operator ==(const KeyBinding& a, const KeyBinding& b) {
36+ static bool operator ==(const KeyBinding& a, const KeyBinding& b) {
3737 return a.spec == b.spec &&
3838 a.command == b.command &&
3939 a.cmdline == b.cmdline ;
@@ -134,7 +134,7 @@ bool KeySpec::isDisruptive() const {
134134 // Letters A-Z, 0-9, and other special keys such as return/escape, and other general typing keys
135135 bool is_essential_key = (this ->sym >= SDLK_a && this ->sym <= SDLK_z) // A-Z
136136 || (this ->sym >= SDLK_0 && this ->sym <= SDLK_9) // 0-9
137- || essential_key_set.find (this ->sym ) != std::string::npos
137+ || ( this -> sym < CHAR_MAX && essential_key_set.find (( char ) this ->sym ) != std::string::npos)
138138 || (this ->sym >= SDLK_LEFT && this ->sym <= SDLK_UP); // Arrow keys
139139
140140 // Essential keys are safe, so long as they have a modifier that isn't Shift
@@ -173,13 +173,13 @@ void HotkeyManager::hotkey_thread_fn() {
173173}
174174
175175
176- bool HotkeyManager::addKeybind (KeySpec spec, std::string cmd) {
176+ bool HotkeyManager::addKeybind (KeySpec spec, std::string_view cmd) {
177177 // No point in a hotkey with no action
178178 if (cmd.empty ())
179179 return false ;
180180
181181 KeyBinding binding;
182- binding.spec = spec;
182+ binding.spec = std::move ( spec) ;
183183 binding.cmdline = cmd;
184184 size_t space_idx = cmd.find (' ' );
185185 binding.command = space_idx == std::string::npos ? cmd : cmd.substr (0 , space_idx);
@@ -196,8 +196,8 @@ bool HotkeyManager::addKeybind(KeySpec spec, std::string cmd) {
196196 return true ;
197197}
198198
199- bool HotkeyManager::addKeybind (std::string keyspec, std::string cmd) {
200- std::optional<KeySpec> spec_opt = KeySpec::parse (keyspec);
199+ bool HotkeyManager::addKeybind (std::string keyspec, std::string_view cmd) {
200+ std::optional<KeySpec> spec_opt = KeySpec::parse (std::move ( keyspec) );
201201 if (!spec_opt.has_value ())
202202 return false ;
203203 return this ->addKeybind (spec_opt.value (), cmd);
@@ -223,7 +223,7 @@ bool HotkeyManager::removeKeybind(const KeySpec& spec, bool match_focus, std::st
223223}
224224
225225bool HotkeyManager::removeKeybind (std::string keyspec, bool match_focus, std::string_view cmdline) {
226- std::optional<KeySpec> spec_opt = KeySpec::parse (keyspec);
226+ std::optional<KeySpec> spec_opt = KeySpec::parse (std::move ( keyspec) );
227227 if (!spec_opt.has_value ())
228228 return false ;
229229 return this ->removeKeybind (spec_opt.value (), match_focus, cmdline);
@@ -261,7 +261,7 @@ std::vector<std::string> HotkeyManager::listKeybinds(const KeySpec& spec) {
261261
262262std::vector<std::string> HotkeyManager::listKeybinds (std::string keyspec) {
263263 std::lock_guard<std::mutex> l (lock);
264- std::optional<KeySpec> spec_opt = KeySpec::parse (keyspec);
264+ std::optional<KeySpec> spec_opt = KeySpec::parse (std::move ( keyspec) );
265265 if (!spec_opt.has_value ())
266266 return {};
267267 return this ->listKeybinds (spec_opt.value ());
@@ -371,7 +371,7 @@ bool HotkeyManager::handleKeybind(int sym, int modifiers) {
371371
372372void HotkeyManager::setHotkeyCommand (std::string cmd) {
373373 std::unique_lock<std::mutex> l (lock);
374- queued_command = cmd;
374+ queued_command = std::move ( cmd) ;
375375 hotkey_sig = HotkeySignal::CmdReady;
376376 l.unlock ();
377377 cond.notify_all ();
@@ -391,7 +391,7 @@ std::string HotkeyManager::getKeybindingInput() {
391391void HotkeyManager::handleKeybindingCommand (color_ostream &con, const std::vector<std::string>& parts) {
392392 std::string parse_error;
393393 if (parts.size () >= 3 && (parts[0 ] == " set" || parts[0 ] == " add" )) {
394- std::string keystr = parts[1 ];
394+ const std::string& keystr = parts[1 ];
395395 if (parts[0 ] == " set" )
396396 removeKeybind (keystr);
397397 for (const auto & part : parts | std::views::drop (2 ) | std::views::reverse) {
@@ -426,22 +426,22 @@ void HotkeyManager::handleKeybindingCommand(color_ostream &con, const std::vecto
426426 }
427427 std::vector<std::string> list = listKeybinds (spec.value ());
428428 if (list.empty ())
429- con << " No bindings." << std::endl ;
429+ con << " No bindings.\n " ;
430430 for (const auto & kb : list)
431- con << " " << kb << std::endl ;
431+ con << " " << kb << " \n " ;
432432 }
433433 else {
434- con << " Usage:" << std::endl
435- << " keybinding list <key>" << std::endl
436- << " keybinding clear <key>[@context]..." << std::endl
437- << " keybinding set <key>[@context] \" cmdline\" \" cmdline\" ..." << std::endl
438- << " keybinding add <key>[@context] \" cmdline\" \" cmdline\" ..." << std::endl
439- << " Later adds, and earlier items within one command have priority." << std::endl
440- << " Key format: [Ctrl-][Alt-][Super-][Shift-](A-Z, 0-9, F1-F12, `, etc.)." << std::endl
441- << " Context may be used to limit the scope of the binding, by" << std::endl
442- << " requiring the current context to have a certain prefix." << std::endl
443- << " Current UI context is: " << std::endl
444- << join_strings (" \n " , Gui::getCurFocus (true )) << std::endl ;
434+ con << " Usage:\n "
435+ << " keybinding list <key>\n "
436+ << " keybinding clear <key>[@context]...\n "
437+ << " keybinding set <key>[@context] \" cmdline\" \" cmdline\" ...\n "
438+ << " keybinding add <key>[@context] \" cmdline\" \" cmdline\" ...\n "
439+ << " Later adds, and earlier items within one command have priority.\n "
440+ << " Key format: [Ctrl-][Alt-][Super-][Shift-](A-Z, 0-9, F1-F12, `, etc.).\n "
441+ << " Context may be used to limit the scope of the binding, by\n "
442+ << " requiring the current context to have a certain prefix.\n "
443+ << " Current UI context is: \n "
444+ << join_strings (" \n " , Gui::getCurFocus (true )) << " \n " ;
445445 }
446446}
447447
0 commit comments