Skip to content

Commit e49d220

Browse files
committed
Make keyspecs case-insensitive (excluding focus strings)
1 parent 1fcee14 commit e49d220

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

library/modules/Hotkey.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ std::optional<KeySpec> Hotkey::parseKeySpec(std::string spec, std::string* err)
7979
spec.erase(focus_idx);
8080
}
8181

82+
// Treat remaining keyspec as lowercase for case-insensitivity.
83+
std::transform(spec.begin(), spec.end(), spec.begin(), tolower);
84+
8285
// Determine modifier flags
8386
auto match_modifier = [&out, &spec](std::string_view prefix, int mod) {
8487
bool found = spec.starts_with(prefix);
@@ -88,25 +91,28 @@ std::optional<KeySpec> Hotkey::parseKeySpec(std::string spec, std::string* err)
8891
}
8992
return found;
9093
};
91-
while (match_modifier("Shift-", DFH_MOD_SHIFT) || match_modifier("Ctrl-", DFH_MOD_CTRL) || match_modifier("Alt-", DFH_MOD_ALT)) {}
94+
while (match_modifier("shift-", DFH_MOD_SHIFT) || match_modifier("ctrl-", DFH_MOD_CTRL) || match_modifier("alt-", DFH_MOD_ALT)) {}
9295

9396
out.sym = DFSDL::DFSDL_GetKeyFromName(spec.c_str());
9497
if (out.sym != SDLK_UNKNOWN)
9598
return out;
9699

97100
// Attempt to parse as a mouse binding
98-
if (spec.starts_with("MOUSE")) {
101+
if (spec.starts_with("mouse")) {
99102
spec.erase(0, 5);
100103
// Read button number, ensuring between 1 and 15 inclusive
101104
try {
102105
int mbutton = std::stoi(spec);
103-
if (mbutton >= 1 && mbutton <= 15) {
106+
if (mbutton >= 4 && mbutton <= 15) {
104107
out.sym = -mbutton;
105108
return out;
106109
}
107110
} catch (...) {
108111
// If integer parsing fails, it isn't valid
109112
}
113+
if (err)
114+
*err = "Invalid mouse button '" + spec + "', only 4-15 are valid";
115+
return std::nullopt;
110116
}
111117

112118
if (err)

0 commit comments

Comments
 (0)