bool WindowsGamepadService::ScanForXInputDevices() { MOZ_ASSERT(mXInput, "XInput should be present!"); bool found = false; for (int i = 0; i < XUSER_MAX_COUNT; i++) { XINPUT_STATE state = {}; if (mXInput.mXInputGetState(i, &state) != ERROR_SUCCESS) { continue; } found = true; // See if this device is already present in our list. if (HaveXInputGamepad(i)) { continue; } // Not already present, add it. Gamepad gamepad = {}; gamepad.type = kXInputGamepad; gamepad.present = true; gamepad.state = state; gamepad.userIndex = i; gamepad.numButtons = kStandardGamepadButtons; gamepad.numAxes = kStandardGamepadAxes; gamepad.id = AddGamepad("xinput", GamepadMappingType::Standard, kStandardGamepadButtons, kStandardGamepadAxes); mGamepads.AppendElement(gamepad); } return found; }
void GamepadService::Update(const GamepadChangeEvent& aEvent) { if (aEvent.type() == GamepadChangeEvent::TGamepadAdded) { const GamepadAdded& a = aEvent.get_GamepadAdded(); AddGamepad(a.index(), a.id(), static_cast<GamepadMappingType>(a.mapping()), a.num_buttons(), a.num_axes()); } else if (aEvent.type() == GamepadChangeEvent::TGamepadRemoved) { const GamepadRemoved& a = aEvent.get_GamepadRemoved(); RemoveGamepad(a.index()); } else if (aEvent.type() == GamepadChangeEvent::TGamepadButtonInformation) { const GamepadButtonInformation& a = aEvent.get_GamepadButtonInformation(); NewButtonEvent(a.index(), a.button(), a.pressed(), a.value()); } else if (aEvent.type() == GamepadChangeEvent::TGamepadAxisInformation) { const GamepadAxisInformation& a = aEvent.get_GamepadAxisInformation(); NewAxisMoveEvent(a.index(), a.axis(), a.value()); } else { MOZ_CRASH("We shouldn't be here!"); } }