Skip to content

Commit

Permalink
Allow toggling button remapping from systray menu
Browse files Browse the repository at this point in the history
  • Loading branch information
emoose committed Feb 1, 2021
1 parent 89c3fa8 commit df3f896
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
11 changes: 10 additions & 1 deletion Xb2XInput/Xb2XInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ bool StartupDeleteEntry()
// lower 12 bits are controller index into XboxController::controllers_
#define ID_CONTROLLER_GUIDEBTN 0x2000
#define ID_CONTROLLER_VIBRATION 0x4000
#define ID_CONTROLLER_REMAP 0x8000

WCHAR tray_text[128];

Expand Down Expand Up @@ -178,6 +179,12 @@ void SysTrayShowContextMenu()
InsertMenuA(hControllerMenu, 0xFFFFFFFF, MF_BYPOSITION | MF_STRING | MF_GRAYED, ID_TRAY_SEP, combo.c_str());
}

InsertMenu(hControllerMenu, 0xFFFFFFFF, MF_BYPOSITION | MF_STRING |
(controller.RemapEnabled() ? MF_CHECKED : MF_UNCHECKED), ID_CONTROLLER_REMAP + i, L"Enable button remappings");

auto remapCount = "- " + std::to_string(controller.Settings().button_remap.size()) + " buttons remapped";
InsertMenuA(hControllerMenu, 0xFFFFFFFF, MF_BYPOSITION | MF_STRING | MF_GRAYED, ID_TRAY_SEP, remapCount.c_str());

InsertMenu(hControllerMenu, 0xFFFFFFFF, MF_SEPARATOR, ID_TRAY_SEP, L"SEP");

// Insert current deadzone adjustments into context menu
Expand Down Expand Up @@ -233,7 +240,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case WM_COMMAND:
wmId = LOWORD(wParam);

if (wmId & ID_CONTROLLER_GUIDEBTN || wmId & ID_CONTROLLER_VIBRATION)
if (wmId & ID_CONTROLLER_GUIDEBTN || wmId & ID_CONTROLLER_VIBRATION || wmId & ID_CONTROLLER_REMAP)
{
auto controllerId = wmId & 0xFFF;
auto& pads = XboxController::GetControllers();
Expand All @@ -244,6 +251,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
controller.GuideEnabled(!controller.GuideEnabled());
if (wmId & ID_CONTROLLER_VIBRATION)
controller.VibrationEnabled(!controller.VibrationEnabled());
if (wmId & ID_CONTROLLER_REMAP)
controller.RemapEnabled(!controller.RemapEnabled());
}
}
else
Expand Down
Binary file modified Xb2XInput/Xb2XInput.rc
Binary file not shown.
2 changes: 1 addition & 1 deletion Xb2XInput/XboxController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ bool XboxController::update()
deadZoneCalc(&triggerbuf, NULL, input_prev_.Gamepad.bAnalogButtons[OGXINPUT_GAMEPAD_RIGHT_TRIGGER], 0, settings_.deadzone.bRightTrigger, 0xFF);
gamepad_.bRightTrigger = triggerbuf;

if (settings_.button_remap.size())
if (settings_.remap_enabled && settings_.button_remap.size())
{
auto buttons = gamepad_.wButtons;
gamepad_.wButtons = 0;
Expand Down
5 changes: 5 additions & 0 deletions Xb2XInput/XboxController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ class XboxController
bool VibrationEnabled() { return settings_.vibration_enabled; }
void VibrationEnabled(bool value);

bool RemapEnabled() { return settings_.remap_enabled; }
void RemapEnabled(bool value) { settings_.remap_enabled = value; }

const UserSettings& Settings() { return settings_; }

XboxController(libusb_device_handle* handle, uint8_t* usb_ports, int num_ports);
~XboxController();
int GetProductId() const { return usb_product_; }
Expand Down

0 comments on commit df3f896

Please sign in to comment.