Skip to content

Commit 3e215aa

Browse files
authored
Merge pull request #470 from cscd98/mouse-bindings
libretro: add option to disable default mouse bindings
2 parents b4c88b4 + 1250c08 commit 3e215aa

3 files changed

Lines changed: 37 additions & 10 deletions

File tree

Source/Core/DolphinLibretro/Common/Options.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,6 +1778,20 @@ static struct retro_core_option_v2_definition option_defs[] = {
17781778
"disabled"
17791779
#endif
17801780
},
1781+
{
1782+
Libretro::Options::retroarch_core::ENABLE_DEFAULT_MOUSE_BINDINGS,
1783+
"RetroArch core > Enable Default Mouse Bindings",
1784+
"Enable Default Mouse Bindings",
1785+
"Enable default Mouse Bindings, disable for more control on bindings.",
1786+
nullptr,
1787+
CATEGORY_RETROARCH_CORE,
1788+
{
1789+
{ "disabled", nullptr },
1790+
{ "enabled", nullptr },
1791+
{ nullptr, nullptr }
1792+
},
1793+
"enabled"
1794+
},
17811795

17821796
{ nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, {{0}}, nullptr }
17831797
};

Source/Core/DolphinLibretro/Common/Options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ namespace retroarch_core {
319319
#endif
320320

321321
constexpr const char ENABLE_LIBRETRO_VFS[] = "dolphin_libretro_vfs_enabled";
322+
constexpr const char ENABLE_DEFAULT_MOUSE_BINDINGS[] = "dolphin_default_mouse_bindings_enabled";
322323

323324
} // namespace wiimote
324325

Source/Core/DolphinLibretro/Input.cpp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,18 @@ static WiimoteEmu::Wiimote* load_saved_controller_config(unsigned port, unsigned
12131213
return nullptr; // nothing found, applies hard-coded defaults
12141214
}
12151215

1216+
// returns retropad_expr on its own, with additional mouse bindings
1217+
static std::string bindMouse(const std::string& retropad_expr, const std::string& mouse_target)
1218+
{
1219+
static const bool enable_default_mouse_bindings =
1220+
Libretro::Options::GetCached<bool>(Libretro::Options::retroarch_core::ENABLE_DEFAULT_MOUSE_BINDINGS, /*def=*/true);
1221+
1222+
if (!enable_default_mouse_bindings)
1223+
return retropad_expr;
1224+
1225+
return retropad_expr + " | `" + mouse_target + "`";
1226+
}
1227+
12161228
void retro_set_controller_port_device_gc(unsigned port, unsigned device)
12171229
{
12181230
std::string devJoypad = Libretro::Input::GetQualifiedName(port, RETRO_DEVICE_JOYPAD);
@@ -1413,12 +1425,12 @@ void retro_set_controller_port_device_wii(unsigned port, unsigned device)
14131425
ncStick->SetControlExpression(1, "`" + devAnalog + ":Y0+`"); // Down
14141426
ncStick->SetControlExpression(2, "`" + devAnalog + ":X0-`"); // Left
14151427
ncStick->SetControlExpression(3, "`" + devAnalog + ":X0+`"); // Right
1416-
ncShake->SetControlExpression(0, "L2 | `" + devMouse + ":Middle`"); // Nunchuk shake X
1417-
ncShake->SetControlExpression(1, "L2 | `" + devMouse + ":Middle`"); // Nunchuk shake Y
1418-
ncShake->SetControlExpression(2, "L2 | `" + devMouse + ":Middle`"); // Nunchuk shake Z
1428+
ncShake->SetControlExpression(0, bindMouse("L2", devMouse + ":Middle")); // Nunchuk shake X
1429+
ncShake->SetControlExpression(1, bindMouse("L2", devMouse + ":Middle")); // Nunchuk shake Y
1430+
ncShake->SetControlExpression(2, bindMouse("L2", devMouse + ":Middle")); // Nunchuk shake Z
14191431

1420-
wmButtons->SetControlExpression(0, "A | `" + devMouse + ":Left`"); // A
1421-
wmButtons->SetControlExpression(1, "B | `" + devMouse + ":Right`"); // B
1432+
wmButtons->SetControlExpression(0, bindMouse("A", devMouse + ":Left")); // A
1433+
wmButtons->SetControlExpression(1, bindMouse("B", devMouse + ":Right")); // B
14221434
wmButtons->SetControlExpression(2, "Start"); // 1
14231435
wmButtons->SetControlExpression(3, "Select"); // 2
14241436
wmButtons->SetControlExpression(4, "L"); // -
@@ -1430,8 +1442,8 @@ void retro_set_controller_port_device_wii(unsigned port, unsigned device)
14301442
{
14311443
if (device == RETRO_DEVICE_WIIMOTE)
14321444
{
1433-
wmButtons->SetControlExpression(0, "A | `" + devMouse + ":Left`"); // A
1434-
wmButtons->SetControlExpression(1, "B | `" + devMouse + ":Right`"); // B
1445+
wmButtons->SetControlExpression(0, bindMouse("A", devMouse + ":Left")); // A
1446+
wmButtons->SetControlExpression(1, bindMouse("B", devMouse + ":Right")); // B
14351447
wmButtons->SetControlExpression(2, "X"); // 1
14361448
wmButtons->SetControlExpression(3, "Y"); // 2
14371449
}
@@ -1506,9 +1518,9 @@ void retro_set_controller_port_device_wii(unsigned port, unsigned device)
15061518
f.sideways = true;
15071519
Libretro::Input::UpdateWiimoteMappings(f, port, device);
15081520

1509-
wmShake->SetControlExpression(0, "R2 | `" + devMouse + ":Middle`"); // Wiimote shake X
1510-
wmShake->SetControlExpression(1, "R2 | `" + devMouse + ":Middle`"); // Wiimote shake Y
1511-
wmShake->SetControlExpression(2, "R2 | `" + devMouse + ":Middle`"); // Wiimote shake Z
1521+
wmShake->SetControlExpression(0, bindMouse("L2", devMouse + ":Middle")); // Wiimote shake X
1522+
wmShake->SetControlExpression(1, bindMouse("L2", devMouse + ":Middle")); // Wiimote shake Y
1523+
wmShake->SetControlExpression(2, bindMouse("L2", devMouse + ":Middle")); // Wiimote shake Z
15121524
}
15131525

15141526
ControllerEmu::ControlGroup* wmOptions = wm->GetWiimoteGroup(WiimoteGroup::Options);

0 commit comments

Comments
 (0)