Skip to content

Commit 8a8ac10

Browse files
committed
Address code review concerns
1 parent e49d220 commit 8a8ac10

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

library/Core.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2464,8 +2464,9 @@ bool Core::doSdlInputEvent(SDL_Event* ev)
24642464
DEBUG(keybinding).print("mouse button down: button=%d\n", but.button);
24652465
// don't mess with the first three buttons, which are critical elements of DF's control scheme
24662466
if (but.button > 3) {
2467+
// We represent mouse buttons as a negative number, permitting buttons 4-15
24672468
SDL_Keycode sym = -but.button;
2468-
if (sym >= -15 && sym <= -1 && hotkey_mgr->handleKeybind(sym, modstate))
2469+
if (sym >= -15 && sym <= -3 && hotkey_mgr->handleKeybind(sym, modstate))
24692470
return suppress_duplicate_keyboard_events;
24702471
}
24712472
} else if (ev->type == SDL_TEXTINPUT) {

library/LuaApi.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,12 +1897,13 @@ void hotkey_pushBindArray(lua_State *L, const std::vector<Hotkey::KeyBinding>& b
18971897
for (const auto& bind : binds) {
18981898
lua_createtable(L, 0, 2);
18991899

1900-
lua_pushstring(L, "spec");
1901-
lua_pushstring(L, Hotkey::keyspec_to_string(bind.spec, true).c_str());
1900+
lua_pushlstring(L, "spec", 4);
1901+
auto spec_str = Hotkey::keyspec_to_string(bind.spec, true);
1902+
lua_pushlstring(L, spec_str.data(), spec_str.size());
19021903
lua_settable(L, -3);
19031904

1904-
lua_pushstring(L, "command");
1905-
lua_pushstring(L, bind.cmdline.c_str());
1905+
lua_pushlstring(L, "command", 7);
1906+
lua_pushlstring(L, bind.cmdline.data(), bind.cmdline.size());
19061907
lua_settable(L, -3);
19071908
lua_rawseti(L, -2, i++);
19081909
}

library/include/modules/Hotkey.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ namespace DFHack {
3737
bool addKeybind(std::string keyspec, std::string cmd);
3838
bool addKeybind(Hotkey::KeySpec spec, std::string cmd);
3939
// Clear a keybind with the given keyspec, optionally for any focus, or with a specific command
40-
bool clearKeybind(std::string keyspec, bool any_focus=false, std::string cmdline="");
41-
bool clearKeybind(const Hotkey::KeySpec& spec, bool any_focus=false, std::string cmdline="");
40+
bool clearKeybind(std::string keyspec, bool any_focus=false, std::string_view cmdline="");
41+
bool clearKeybind(const Hotkey::KeySpec& spec, bool any_focus=false, std::string_view cmdline="");
4242

4343
std::vector<std::string> listKeybinds(std::string keyspec);
4444
std::vector<std::string> listKeybinds(const Hotkey::KeySpec& spec);

library/modules/Hotkey.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ 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 cmdline) {
184+
bool HotkeyManager::clearKeybind(const KeySpec& spec, bool any_focus, std::string_view cmdline) {
185185
std::lock_guard<std::mutex> l(lock);
186186
if (!bindings.contains(spec.sym))
187187
return false;
@@ -199,7 +199,7 @@ bool HotkeyManager::clearKeybind(const KeySpec& spec, bool any_focus, std::strin
199199
return true;
200200
}
201201

202-
bool HotkeyManager::clearKeybind(std::string keyspec, bool any_focus, std::string cmdline) {
202+
bool HotkeyManager::clearKeybind(std::string keyspec, bool any_focus, std::string_view cmdline) {
203203
std::optional<KeySpec> spec_opt = Hotkey::parseKeySpec(keyspec);
204204
if (!spec_opt.has_value())
205205
return false;

0 commit comments

Comments
 (0)