Skip to content

Commit df3f896

Browse files
committed
Allow toggling button remapping from systray menu
1 parent 89c3fa8 commit df3f896

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

Xb2XInput/Xb2XInput.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ bool StartupDeleteEntry()
127127
// lower 12 bits are controller index into XboxController::controllers_
128128
#define ID_CONTROLLER_GUIDEBTN 0x2000
129129
#define ID_CONTROLLER_VIBRATION 0x4000
130+
#define ID_CONTROLLER_REMAP 0x8000
130131

131132
WCHAR tray_text[128];
132133

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

182+
InsertMenu(hControllerMenu, 0xFFFFFFFF, MF_BYPOSITION | MF_STRING |
183+
(controller.RemapEnabled() ? MF_CHECKED : MF_UNCHECKED), ID_CONTROLLER_REMAP + i, L"Enable button remappings");
184+
185+
auto remapCount = "- " + std::to_string(controller.Settings().button_remap.size()) + " buttons remapped";
186+
InsertMenuA(hControllerMenu, 0xFFFFFFFF, MF_BYPOSITION | MF_STRING | MF_GRAYED, ID_TRAY_SEP, remapCount.c_str());
187+
181188
InsertMenu(hControllerMenu, 0xFFFFFFFF, MF_SEPARATOR, ID_TRAY_SEP, L"SEP");
182189

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

236-
if (wmId & ID_CONTROLLER_GUIDEBTN || wmId & ID_CONTROLLER_VIBRATION)
243+
if (wmId & ID_CONTROLLER_GUIDEBTN || wmId & ID_CONTROLLER_VIBRATION || wmId & ID_CONTROLLER_REMAP)
237244
{
238245
auto controllerId = wmId & 0xFFF;
239246
auto& pads = XboxController::GetControllers();
@@ -244,6 +251,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
244251
controller.GuideEnabled(!controller.GuideEnabled());
245252
if (wmId & ID_CONTROLLER_VIBRATION)
246253
controller.VibrationEnabled(!controller.VibrationEnabled());
254+
if (wmId & ID_CONTROLLER_REMAP)
255+
controller.RemapEnabled(!controller.RemapEnabled());
247256
}
248257
}
249258
else

Xb2XInput/Xb2XInput.rc

0 Bytes
Binary file not shown.

Xb2XInput/XboxController.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ bool XboxController::update()
546546
deadZoneCalc(&triggerbuf, NULL, input_prev_.Gamepad.bAnalogButtons[OGXINPUT_GAMEPAD_RIGHT_TRIGGER], 0, settings_.deadzone.bRightTrigger, 0xFF);
547547
gamepad_.bRightTrigger = triggerbuf;
548548

549-
if (settings_.button_remap.size())
549+
if (settings_.remap_enabled && settings_.button_remap.size())
550550
{
551551
auto buttons = gamepad_.wButtons;
552552
gamepad_.wButtons = 0;

Xb2XInput/XboxController.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ class XboxController
139139
bool VibrationEnabled() { return settings_.vibration_enabled; }
140140
void VibrationEnabled(bool value);
141141

142+
bool RemapEnabled() { return settings_.remap_enabled; }
143+
void RemapEnabled(bool value) { settings_.remap_enabled = value; }
144+
145+
const UserSettings& Settings() { return settings_; }
146+
142147
XboxController(libusb_device_handle* handle, uint8_t* usb_ports, int num_ports);
143148
~XboxController();
144149
int GetProductId() const { return usb_product_; }

0 commit comments

Comments
 (0)