Fixed formatting from clang-format

This commit is contained in:
nickci2002 2025-06-17 10:36:09 -04:00
parent 429c64a51b
commit 990e349424
4 changed files with 66 additions and 77 deletions

View file

@ -223,25 +223,19 @@ void ParseInputConfig(const std::string game_id = "") {
while (std::getline(file, line)) { while (std::getline(file, line)) {
lineCount++; lineCount++;
auto line_kpmask = (line.substr(0, 2) == "kp ") ? line.begin() + 2 : line.begin();
// Strip the ; and whitespace // Strip the ; and whitespace
line.erase(std::remove_if(line_kpmask, line.end(), line.erase(std::remove_if(line.begin(), line.end(),
[](unsigned char c) { return std::isspace(c); }), [](unsigned char c) { return std::isspace(c); }),
line.end()); line.end());
if (line.empty()) { if (line.empty()) {
continue; continue;
} }
// Truncate lines starting at # // Truncate lines starting at #
std::size_t comment_pos = line.find('#'); std::size_t comment_pos = line.find('#');
if (comment_pos != std::string::npos) { if (comment_pos != std::string::npos) {
line = line.substr(0, comment_pos); line = line.substr(0, comment_pos);
} }
// Remove trailing semicolon
if (!line.empty() && std::distance(line_kpmask, line.end()) != 1 && line[line.length() - 1] == ';') {
line = line.substr(0, line.length() - 1);
}
if (line.empty()) { if (line.empty()) {
continue; continue;
} }
@ -256,14 +250,18 @@ void ParseInputConfig(const std::string game_id = "") {
std::string output_string = line.substr(0, equal_pos); std::string output_string = line.substr(0, equal_pos);
std::string input_string = line.substr(equal_pos + 1); std::string input_string = line.substr(equal_pos + 1);
std::size_t comma_pos = input_string.find(','); // Remove trailing semicolon from input_string
if (!input_string.empty() && input_string[input_string.length() - 1] == ';') {
if (!(input_string == ";" || input_string == "kp;")) {
line = line.substr(0, line.length() - 1);
}
}
std::size_t comma_pos = input_string.find(',');
auto parseInt = [](const std::string& s) -> std::optional<int> { auto parseInt = [](const std::string& s) -> std::optional<int> {
int value = 0; try {
auto [ptr, ec] = std::from_chars(s.data(), s.data() + s.size(), value); return std::stoi(s);
if (ec == std::errc()) { } catch (...) {
return value;
} else {
return std::nullopt; return std::nullopt;
} }
}; };
@ -377,7 +375,6 @@ void ParseInputConfig(const std::string game_id = "") {
BindingConnection connection(InputID(), nullptr); BindingConnection connection(InputID(), nullptr);
auto button_it = string_to_cbutton_map.find(output_string); auto button_it = string_to_cbutton_map.find(output_string);
auto axis_it = string_to_axis_map.find(output_string); auto axis_it = string_to_axis_map.find(output_string);
if (binding.IsEmpty()) { if (binding.IsEmpty()) {
LOG_WARNING(Input, "Invalid format at line: {}, data: \"{}\", skipping line.", LOG_WARNING(Input, "Invalid format at line: {}, data: \"{}\", skipping line.",
lineCount, line); lineCount, line);
@ -444,11 +441,11 @@ InputEvent InputBinding::GetInputEventFromSDLEvent(const SDL_Event& e) {
e.type == SDL_EVENT_MOUSE_WHEEL, 0); e.type == SDL_EVENT_MOUSE_WHEEL, 0);
case SDL_EVENT_GAMEPAD_BUTTON_DOWN: case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
case SDL_EVENT_GAMEPAD_BUTTON_UP: case SDL_EVENT_GAMEPAD_BUTTON_UP:
return InputEvent(InputType::Controller, static_cast<u32>(e.gbutton.button), return InputEvent(InputType::Controller, static_cast<u32>(e.gbutton.button), e.gbutton.down,
e.gbutton.down, 0); 0); // clang made me do it
case SDL_EVENT_GAMEPAD_AXIS_MOTION: case SDL_EVENT_GAMEPAD_AXIS_MOTION:
return InputEvent(InputType::Axis, static_cast<u32>(e.gaxis.axis), return InputEvent(InputType::Axis, static_cast<u32>(e.gaxis.axis), true,
true, e.gaxis.value / 256); e.gaxis.value / 256); // this too
default: default:
return InputEvent(); return InputEvent();
} }

View file

@ -32,7 +32,6 @@
#define KEY_TOGGLE 0x00200000 #define KEY_TOGGLE 0x00200000
#define SDL_INVALID_ID UINT32_MAX #define SDL_INVALID_ID UINT32_MAX
namespace Input { namespace Input {
@ -241,14 +240,14 @@ const std::map<std::string, u32> string_to_keyboard_key_map = {
{"kp7", SDLK_KP_7}, {"kp7", SDLK_KP_7},
{"kp8", SDLK_KP_8}, {"kp8", SDLK_KP_8},
{"kp9", SDLK_KP_9}, {"kp9", SDLK_KP_9},
{"kp .", SDLK_KP_PERIOD}, {"kp.", SDLK_KP_PERIOD},
{"kp ,", SDLK_KP_COMMA}, {"kp,", SDLK_KP_COMMA},
{"kp /", SDLK_KP_DIVIDE}, {"kp/", SDLK_KP_DIVIDE},
{"kp *", SDLK_KP_MULTIPLY}, {"kp*", SDLK_KP_MULTIPLY},
{"kp -", SDLK_KP_MINUS}, {"kp-", SDLK_KP_MINUS},
{"kp +", SDLK_KP_PLUS}, {"kp+", SDLK_KP_PLUS},
{"kp =", SDLK_KP_EQUALS}, {"kp=", SDLK_KP_EQUALS},
{"kp enter", SDLK_KP_ENTER}, {"kpenter", SDLK_KP_ENTER},
// mouse // mouse
{"leftbutton", SDL_BUTTON_LEFT}, {"leftbutton", SDL_BUTTON_LEFT},

View file

@ -225,12 +225,6 @@ void KBMSettings::SaveKBMConfig(bool close_on_save) {
while (std::getline(file, line)) { while (std::getline(file, line)) {
lineCount++; lineCount++;
// remove whitespace from the beginning of the line
auto line_kpmask = (line.substr(0, 2) == "kp ") ? line.begin() + 2 : line.begin();
line.erase(std::remove_if(line_kpmask, line.end(),
[](unsigned char c) { return std::isspace(c); }),
line.end());
if (line.empty()) { if (line.empty()) {
lines.push_back(line); lines.push_back(line);
continue; continue;
@ -293,10 +287,10 @@ void KBMSettings::SaveKBMConfig(bool close_on_save) {
} }
void KBMSettings::SetDefault() { void KBMSettings::SetDefault() {
ui->CrossButton->setText("kp 2"); ui->CrossButton->setText("kp2");
ui->CircleButton->setText("kp 6"); ui->CircleButton->setText("kp6");
ui->TriangleButton->setText("kp 8"); ui->TriangleButton->setText("kp8");
ui->SquareButton->setText("kp 4"); ui->SquareButton->setText("kp4");
ui->L1Button->setText("q"); ui->L1Button->setText("q");
ui->L2Button->setText("e"); ui->L2Button->setText("e");
@ -354,7 +348,6 @@ void KBMSettings::SetUIValuestoMappings(std::string config_id) {
if (std::find(ControllerInputs.begin(), ControllerInputs.end(), input_string) == if (std::find(ControllerInputs.begin(), ControllerInputs.end(), input_string) ==
ControllerInputs.end()) { ControllerInputs.end()) {
if (output_string == "cross") { if (output_string == "cross") {
ui->CrossButton->setText(QString::fromStdString(input_string)); ui->CrossButton->setText(QString::fromStdString(input_string));
} else if (output_string == "circle") { } else if (output_string == "circle") {
@ -532,8 +525,8 @@ void KBMSettings::SetMapping(QString input) {
} }
// Helper lambda to get the modified button text based on the current keyboard modifiers // Helper lambda to get the modified button text based on the current keyboard modifiers
auto GetModifiedButton = [](Qt::KeyboardModifiers modifier, auto GetModifiedButton = [](Qt::KeyboardModifiers modifier, const std::string& m_button,
const std::string& m_button, const std::string& n_button) -> QString { const std::string& n_button) -> QString {
if (QApplication::keyboardModifiers() & modifier) { if (QApplication::keyboardModifiers() & modifier) {
return QString::fromStdString(m_button); return QString::fromStdString(m_button);
} else { } else {
@ -641,34 +634,34 @@ bool KBMSettings::eventFilter(QObject* obj, QEvent* event) {
pressedKeys.insert("z"); pressedKeys.insert("z");
break; break;
case Qt::Key_0: case Qt::Key_0:
pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp 0", "0")); pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp0", "0"));
break; break;
case Qt::Key_1: case Qt::Key_1:
pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp 1", "1")); pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp1", "1"));
break; break;
case Qt::Key_2: case Qt::Key_2:
pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp 2", "2")); pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp2", "2"));
break; break;
case Qt::Key_3: case Qt::Key_3:
pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp 3", "3")); pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp3", "3"));
break; break;
case Qt::Key_4: case Qt::Key_4:
pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp 4", "4")); pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp4", "4"));
break; break;
case Qt::Key_5: case Qt::Key_5:
pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp 5", "5")); pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp5", "5"));
break; break;
case Qt::Key_6: case Qt::Key_6:
pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp 6", "6")); pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp6", "6"));
break; break;
case Qt::Key_7: case Qt::Key_7:
pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp 7", "7")); pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp7", "7"));
break; break;
case Qt::Key_8: case Qt::Key_8:
pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp 8", "8")); pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp8", "8"));
break; break;
case Qt::Key_9: case Qt::Key_9:
pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp 9", "9")); pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp9", "9"));
break; break;
// symbols // symbols
@ -694,7 +687,7 @@ bool KBMSettings::eventFilter(QObject* obj, QEvent* event) {
pressedKeys.insert("&"); pressedKeys.insert("&");
break; break;
case Qt::Key_Asterisk: case Qt::Key_Asterisk:
pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp *", "*")); pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp*", "*"));
break; break;
case Qt::Key_ParenLeft: case Qt::Key_ParenLeft:
pressedKeys.insert("("); pressedKeys.insert("(");
@ -703,16 +696,16 @@ bool KBMSettings::eventFilter(QObject* obj, QEvent* event) {
pressedKeys.insert(")"); pressedKeys.insert(")");
break; break;
case Qt::Key_Minus: case Qt::Key_Minus:
pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp -", "-")); pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp-", "-"));
break; break;
case Qt::Key_Underscore: case Qt::Key_Underscore:
pressedKeys.insert("_"); pressedKeys.insert("_");
break; break;
case Qt::Key_Equal: case Qt::Key_Equal:
pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp =", "=")); pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp=", "="));
break; break;
case Qt::Key_Plus: case Qt::Key_Plus:
pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp +", "+")); pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp+", "+"));
break; break;
case Qt::Key_BracketLeft: case Qt::Key_BracketLeft:
pressedKeys.insert("["); pressedKeys.insert("[");
@ -745,19 +738,19 @@ bool KBMSettings::eventFilter(QObject* obj, QEvent* event) {
pressedKeys.insert("\""); pressedKeys.insert("\"");
break; break;
case Qt::Key_Comma: case Qt::Key_Comma:
pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp ,", ",")); pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp,", ","));
break; break;
case Qt::Key_Less: case Qt::Key_Less:
pressedKeys.insert("<"); pressedKeys.insert("<");
break; break;
case Qt::Key_Period: case Qt::Key_Period:
pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp .", ".")); pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp.", "."));
break; break;
case Qt::Key_Greater: case Qt::Key_Greater:
pressedKeys.insert(">"); pressedKeys.insert(">");
break; break;
case Qt::Key_Slash: case Qt::Key_Slash:
pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp /", "/")); pressedKeys.insert(GetModifiedButton(Qt::KeypadModifier, "kp/", "/"));
break; break;
case Qt::Key_Question: case Qt::Key_Question:
pressedKeys.insert("question"); pressedKeys.insert("question");
@ -804,7 +797,7 @@ bool KBMSettings::eventFilter(QObject* obj, QEvent* event) {
pressedKeys.insert("enter"); pressedKeys.insert("enter");
break; break;
case Qt::Key_Enter: case Qt::Key_Enter:
pressedKeys.insert(GetModifiedButton(Qt::ShiftModifier, "kp enter", "enter")); pressedKeys.insert(GetModifiedButton(Qt::ShiftModifier, "kpenter", "enter"));
break; break;
case Qt::Key_Shift: case Qt::Key_Shift:
if (keyEvent->nativeScanCode() == LSHIFT_KEY) { if (keyEvent->nativeScanCode() == LSHIFT_KEY) {
@ -920,16 +913,16 @@ bool KBMSettings::eventFilter(QObject* obj, QEvent* event) {
if (wheelEvent->angleDelta().x() > 5) { if (wheelEvent->angleDelta().x() > 5) {
if (std::find(AxisList.begin(), AxisList.end(), MappingButton) == AxisList.end()) { if (std::find(AxisList.begin(), AxisList.end(), MappingButton) == AxisList.end()) {
// QT changes scrolling to horizontal for all widgets with the alt modifier // QT changes scrolling to horizontal for all widgets with the alt modifier
pressedKeys.insert(GetModifiedButton(Qt::AltModifier, pressedKeys.insert(
"mousewheelup", "mousewheelright")); GetModifiedButton(Qt::AltModifier, "mousewheelup", "mousewheelright"));
} else { } else {
QMessageBox::information(this, tr("Cannot set mapping"), QMessageBox::information(this, tr("Cannot set mapping"),
tr("Mousewheel cannot be mapped to stick outputs")); tr("Mousewheel cannot be mapped to stick outputs"));
} }
} else if (wheelEvent->angleDelta().x() < -5) { } else if (wheelEvent->angleDelta().x() < -5) {
if (std::find(AxisList.begin(), AxisList.end(), MappingButton) == AxisList.end()) { if (std::find(AxisList.begin(), AxisList.end(), MappingButton) == AxisList.end()) {
pressedKeys.insert(GetModifiedButton(Qt::AltModifier, pressedKeys.insert(
"mousewheeldown", "mousewheelleft")); GetModifiedButton(Qt::AltModifier, "mousewheeldown", "mousewheelleft"));
} else { } else {
QMessageBox::information(this, tr("Cannot set mapping"), QMessageBox::information(this, tr("Cannot set mapping"),
tr("Mousewheel cannot be mapped to stick outputs")); tr("Mousewheel cannot be mapped to stick outputs"));