1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
8 // https://cs.chromium.org/chromium/src/device/gamepad/gamepad_standard_mappings.h
10 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
11 // Use of this source code is governed by a BSD-style license that can be
12 // found in the LICENSE file.
14 #include "mozilla/dom/GamepadRemapping.h"
15 #include "mozilla/dom/GamepadPlatformService.h"
18 #include <unordered_map>
20 namespace mozilla::dom
{
22 const float BUTTON_THRESHOLD_VALUE
= 0.1f
;
24 float NormalizeTouch(long aValue
, long aMin
, long aMax
) {
25 return (2.f
* (aValue
- aMin
) / static_cast<float>(aMax
- aMin
)) - 1.f
;
28 double AxisToButtonValue(double aValue
) {
29 // Mapping axis value range from (-1, +1) to (0, +1).
30 return (aValue
+ 1.0f
) * 0.5f
;
33 void FetchDpadFromAxis(GamepadHandle aHandle
, double dir
) {
39 // Dpad is mapped as a direction on one axis, where -1 is up and it
40 // increases clockwise to 1, which is up + left. It's set to a large (> 1.f)
41 // number when nothing is depressed, except on start up, sometimes it's 0.0
42 // for no data, rather than the large number.
44 up
= (dir
>= -1.f
&& dir
< -0.7f
) || (dir
>= .95f
&& dir
<= 1.f
);
45 right
= dir
>= -.75f
&& dir
< -.1f
;
46 down
= dir
>= -.2f
&& dir
< .45f
;
47 left
= dir
>= .4f
&& dir
<= 1.f
;
50 RefPtr
<GamepadPlatformService
> service
=
51 GamepadPlatformService::GetParentService();
56 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_DPAD_UP
, up
);
57 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_DPAD_RIGHT
, right
);
58 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_DPAD_DOWN
, down
);
59 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_DPAD_LEFT
, left
);
62 class DefaultRemapper final
: public GamepadRemapper
{
64 virtual uint32_t GetAxisCount() const override
{ return numAxes
; }
66 virtual uint32_t GetButtonCount() const override
{ return numButtons
; }
68 virtual void SetAxisCount(uint32_t aAxisCount
) override
{
72 virtual void SetButtonCount(uint32_t aButtonCount
) override
{
73 numButtons
= aButtonCount
;
76 virtual GamepadMappingType
GetMappingType() const override
{
77 return GamepadMappingType::_empty
;
80 virtual void RemapAxisMoveEvent(GamepadHandle aHandle
, uint32_t aAxis
,
81 double aValue
) const override
{
82 if (GetAxisCount() <= aAxis
) {
84 nsPrintfCString("Axis idx '%d' doesn't support in DefaultRemapper().",
89 RefPtr
<GamepadPlatformService
> service
=
90 GamepadPlatformService::GetParentService();
94 service
->NewAxisMoveEvent(aHandle
, aAxis
, aValue
);
97 virtual void RemapButtonEvent(GamepadHandle aHandle
, uint32_t aButton
,
98 bool aPressed
) const override
{
99 if (GetButtonCount() <= aButton
) {
102 "Button idx '%d' doesn't support in DefaultRemapper().", aButton
)
106 RefPtr
<GamepadPlatformService
> service
=
107 GamepadPlatformService::GetParentService();
111 service
->NewButtonEvent(aHandle
, aButton
, aPressed
);
119 class ADT1Remapper final
: public GamepadRemapper
{
121 virtual uint32_t GetAxisCount() const override
{ return AXIS_INDEX_COUNT
; }
123 virtual uint32_t GetButtonCount() const override
{
124 return BUTTON_INDEX_COUNT
;
127 virtual void RemapAxisMoveEvent(GamepadHandle aHandle
, uint32_t aAxis
,
128 double aValue
) const override
{
129 RefPtr
<GamepadPlatformService
> service
=
130 GamepadPlatformService::GetParentService();
137 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_X
, aValue
);
140 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_Y
, aValue
);
143 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_X
, aValue
);
146 const double value
= AxisToButtonValue(aValue
);
147 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_RIGHT_TRIGGER
,
148 value
> BUTTON_THRESHOLD_VALUE
, value
);
152 const double value
= AxisToButtonValue(aValue
);
153 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_LEFT_TRIGGER
,
154 value
> BUTTON_THRESHOLD_VALUE
, value
);
158 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_Y
, aValue
);
161 FetchDpadFromAxis(aHandle
, aValue
);
165 nsPrintfCString("Axis idx '%d' doesn't support in ADT1Remapper().",
172 virtual void RemapButtonEvent(GamepadHandle aHandle
, uint32_t aButton
,
173 bool aPressed
) const override
{
174 RefPtr
<GamepadPlatformService
> service
=
175 GamepadPlatformService::GetParentService();
180 if (GetButtonCount() <= aButton
) {
182 nsPrintfCString("Button idx '%d' doesn't support in ADT1Remapper().",
188 const std::unordered_map
<uint32_t, uint32_t> buttonMapping
= {
189 {3, BUTTON_INDEX_TERTIARY
},
190 {4, BUTTON_INDEX_QUATERNARY
},
191 {6, BUTTON_INDEX_LEFT_SHOULDER
},
192 {7, BUTTON_INDEX_RIGHT_SHOULDER
},
193 {12, BUTTON_INDEX_META
},
194 {13, BUTTON_INDEX_LEFT_THUMBSTICK
},
195 {14, BUTTON_INDEX_RIGHT_THUMBSTICK
}};
197 auto find
= buttonMapping
.find(aButton
);
198 if (find
!= buttonMapping
.end()) {
199 service
->NewButtonEvent(aHandle
, find
->second
, aPressed
);
201 service
->NewButtonEvent(aHandle
, aButton
, aPressed
);
206 class TwoAxesEightKeysRemapper final
: public GamepadRemapper
{
208 virtual uint32_t GetAxisCount() const override
{ return 0; }
210 virtual uint32_t GetButtonCount() const override
{
211 return BUTTON_INDEX_COUNT
- 1;
214 virtual void RemapAxisMoveEvent(GamepadHandle aHandle
, uint32_t aAxis
,
215 double aValue
) const override
{
216 RefPtr
<GamepadPlatformService
> service
=
217 GamepadPlatformService::GetParentService();
224 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_DPAD_LEFT
,
225 AxisNegativeAsButton(aValue
));
226 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_DPAD_RIGHT
,
227 AxisPositiveAsButton(aValue
));
230 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_DPAD_UP
,
231 AxisNegativeAsButton(aValue
));
232 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_DPAD_DOWN
,
233 AxisPositiveAsButton(aValue
));
238 "Axis idx '%d' doesn't support in TwoAxesEightKeysRemapper().",
245 virtual void RemapButtonEvent(GamepadHandle aHandle
, uint32_t aButton
,
246 bool aPressed
) const override
{
247 RefPtr
<GamepadPlatformService
> service
=
248 GamepadPlatformService::GetParentService();
253 if (GetButtonCount() <= aButton
) {
256 "Button idx '%d' doesn't support in TwoAxesEightKeysRemapper().",
262 const std::unordered_map
<uint32_t, uint32_t> buttonMapping
= {
263 {0, BUTTON_INDEX_QUATERNARY
},
264 {2, BUTTON_INDEX_PRIMARY
},
265 {3, BUTTON_INDEX_TERTIARY
}};
267 auto find
= buttonMapping
.find(aButton
);
268 if (find
!= buttonMapping
.end()) {
269 service
->NewButtonEvent(aHandle
, find
->second
, aPressed
);
271 service
->NewButtonEvent(aHandle
, aButton
, aPressed
);
276 class StadiaControllerRemapper final
: public GamepadRemapper
{
278 virtual uint32_t GetAxisCount() const override
{ return AXIS_INDEX_COUNT
; }
280 virtual uint32_t GetButtonCount() const override
{
281 return STADIA_BUTTON_COUNT
;
284 virtual void RemapAxisMoveEvent(GamepadHandle aHandle
, uint32_t aAxis
,
285 double aValue
) const override
{
286 RefPtr
<GamepadPlatformService
> service
=
287 GamepadPlatformService::GetParentService();
294 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_X
, aValue
);
297 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_Y
, aValue
);
300 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_X
, aValue
);
303 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_Y
, aValue
);
306 const double value
= AxisToButtonValue(aValue
);
307 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_LEFT_TRIGGER
,
308 value
> BUTTON_THRESHOLD_VALUE
, value
);
312 const double value
= AxisToButtonValue(aValue
);
313 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_RIGHT_TRIGGER
,
314 value
> BUTTON_THRESHOLD_VALUE
, value
);
320 "Axis idx '%d' doesn't support in StadiaControllerRemapper().",
327 virtual void RemapButtonEvent(GamepadHandle aHandle
, uint32_t aButton
,
328 bool aPressed
) const override
{
329 RefPtr
<GamepadPlatformService
> service
=
330 GamepadPlatformService::GetParentService();
335 if (STADIA_BUTTON_COUNT
<= aButton
) {
338 "Button idx '%d' doesn't support in StadiaControllerRemapper().",
344 service
->NewButtonEvent(aHandle
, aButton
, aPressed
);
349 STADIA_BUTTON_EXTRA1
= BUTTON_INDEX_COUNT
,
350 STADIA_BUTTON_EXTRA2
,
355 class Playstation3Remapper final
: public GamepadRemapper
{
357 Playstation3Remapper() = default;
359 uint32_t GetAxisCount() const override
{ return AXIS_INDEX_COUNT
; }
361 uint32_t GetButtonCount() const override
{ return BUTTON_INDEX_COUNT
; }
363 void RemapAxisMoveEvent(GamepadHandle aHandle
, uint32_t aAxis
,
364 double aValue
) const override
{
365 RefPtr
<GamepadPlatformService
> service
=
366 GamepadPlatformService::GetParentService();
373 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_X
, aValue
);
376 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_Y
, aValue
);
379 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_X
, aValue
);
382 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_Y
, aValue
);
387 "Axis idx '%d' doesn't support in Playstation3Remapper().",
394 void RemapButtonEvent(GamepadHandle aHandle
, uint32_t aButton
,
395 bool aPressed
) const override
{
396 RefPtr
<GamepadPlatformService
> service
=
397 GamepadPlatformService::GetParentService();
402 constexpr std::array buttonMapping
= {BUTTON_INDEX_BACK_SELECT
,
403 BUTTON_INDEX_LEFT_THUMBSTICK
,
404 BUTTON_INDEX_RIGHT_THUMBSTICK
,
406 BUTTON_INDEX_DPAD_UP
,
407 BUTTON_INDEX_DPAD_RIGHT
,
408 BUTTON_INDEX_DPAD_DOWN
,
409 BUTTON_INDEX_DPAD_LEFT
,
410 BUTTON_INDEX_LEFT_TRIGGER
,
411 BUTTON_INDEX_RIGHT_TRIGGER
,
412 BUTTON_INDEX_LEFT_SHOULDER
,
413 BUTTON_INDEX_RIGHT_SHOULDER
,
414 BUTTON_INDEX_QUATERNARY
,
415 BUTTON_INDEX_SECONDARY
,
416 BUTTON_INDEX_PRIMARY
,
417 BUTTON_INDEX_TERTIARY
,
420 if (buttonMapping
.size() <= aButton
) {
423 "Button idx '%d' doesn't support in Playstation3Remapper().",
428 service
->NewButtonEvent(aHandle
, buttonMapping
[aButton
], aPressed
);
432 class Dualshock4Remapper final
: public GamepadRemapper
{
434 Dualshock4Remapper() {
435 mLastTouches
.SetLength(TOUCH_EVENT_COUNT
);
436 mLastTouchId
.SetLength(TOUCH_EVENT_COUNT
);
439 virtual uint32_t GetAxisCount() const override
{ return AXIS_INDEX_COUNT
; }
441 virtual uint32_t GetButtonCount() const override
{
442 return DUALSHOCK_BUTTON_COUNT
;
445 virtual uint32_t GetLightIndicatorCount() const override
{
446 return LIGHT_INDICATOR_COUNT
;
449 virtual void GetLightIndicators(
450 nsTArray
<GamepadLightIndicatorType
>& aTypes
) const override
{
451 const uint32_t len
= GetLightIndicatorCount();
452 aTypes
.SetLength(len
);
453 for (uint32_t i
= 0; i
< len
; ++i
) {
454 aTypes
[i
] = GamepadLightIndicatorType::Rgb
;
458 virtual uint32_t GetTouchEventCount() const override
{
459 return TOUCH_EVENT_COUNT
;
462 virtual void GetLightColorReport(
463 uint8_t aRed
, uint8_t aGreen
, uint8_t aBlue
,
464 std::vector
<uint8_t>& aReport
) const override
{
465 const size_t report_length
= 32;
466 aReport
.resize(report_length
);
467 aReport
.assign(report_length
, 0);
469 aReport
[0] = 0x05; // report ID USB only
470 aReport
[1] = 0x02; // LED only
476 virtual uint32_t GetMaxInputReportLength() const override
{
477 return MAX_INPUT_LEN
;
480 virtual void ProcessTouchData(GamepadHandle aHandle
, void* aInput
) override
{
481 nsTArray
<GamepadTouchState
> touches(TOUCH_EVENT_COUNT
);
482 touches
.SetLength(TOUCH_EVENT_COUNT
);
483 uint8_t* rawData
= (uint8_t*)aInput
;
485 const uint32_t kTouchDimensionX
= 1920;
486 const uint32_t kTouchDimensionY
= 942;
487 bool touch0Pressed
= (((rawData
[35] & 0xff) >> 7) == 0);
488 bool touch1Pressed
= (((rawData
[39] & 0xff) >> 7) == 0);
490 if ((touch0Pressed
&& (rawData
[35] & 0xff) < mLastTouchId
[0]) ||
491 (touch1Pressed
&& (rawData
[39] & 0xff) < mLastTouchId
[1])) {
496 touches
[0].touchId
= mTouchIdBase
+ (rawData
[35] & 0x7f);
497 touches
[0].surfaceId
= 0;
498 touches
[0].position
[0] = NormalizeTouch(
499 ((rawData
[37] & 0xf) << 8) | rawData
[36], 0, (kTouchDimensionX
- 1));
500 touches
[0].position
[1] =
501 NormalizeTouch(rawData
[38] << 4 | ((rawData
[37] & 0xf0) >> 4), 0,
502 (kTouchDimensionY
- 1));
503 touches
[0].surfaceDimensions
[0] = kTouchDimensionX
;
504 touches
[0].surfaceDimensions
[1] = kTouchDimensionY
;
505 touches
[0].isSurfaceDimensionsValid
= true;
506 mLastTouchId
[0] = rawData
[35] & 0x7f;
509 touches
[1].touchId
= mTouchIdBase
+ (rawData
[39] & 0x7f);
510 touches
[1].surfaceId
= 0;
511 touches
[1].position
[0] =
512 NormalizeTouch((((rawData
[41] & 0xf) << 8) | rawData
[40]) + 1, 0,
513 (kTouchDimensionX
- 1));
514 touches
[1].position
[1] =
515 NormalizeTouch(rawData
[42] << 4 | ((rawData
[41] & 0xf0) >> 4), 0,
516 (kTouchDimensionY
- 1));
517 touches
[1].surfaceDimensions
[0] = kTouchDimensionX
;
518 touches
[1].surfaceDimensions
[1] = kTouchDimensionY
;
519 touches
[1].isSurfaceDimensionsValid
= true;
520 mLastTouchId
[1] = rawData
[39] & 0x7f;
523 RefPtr
<GamepadPlatformService
> service
=
524 GamepadPlatformService::GetParentService();
529 // Avoid to send duplicate untouched events to the gamepad service.
530 if ((mLastTouches
[0] != touch0Pressed
) || touch0Pressed
) {
531 service
->NewMultiTouchEvent(aHandle
, 0, touches
[0]);
533 if ((mLastTouches
[1] != touch1Pressed
) || touch1Pressed
) {
534 service
->NewMultiTouchEvent(aHandle
, 1, touches
[1]);
536 mLastTouches
[0] = touch0Pressed
;
537 mLastTouches
[1] = touch1Pressed
;
540 virtual void RemapAxisMoveEvent(GamepadHandle aHandle
, uint32_t aAxis
,
541 double aValue
) const override
{
542 RefPtr
<GamepadPlatformService
> service
=
543 GamepadPlatformService::GetParentService();
550 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_X
, aValue
);
553 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_Y
, aValue
);
556 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_X
, aValue
);
559 const double value
= AxisToButtonValue(aValue
);
560 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_LEFT_TRIGGER
,
561 value
> BUTTON_THRESHOLD_VALUE
, value
);
565 const double value
= AxisToButtonValue(aValue
);
566 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_RIGHT_TRIGGER
,
567 value
> BUTTON_THRESHOLD_VALUE
, value
);
571 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_Y
, aValue
);
574 FetchDpadFromAxis(aHandle
, aValue
);
579 "Axis idx '%d' doesn't support in Dualshock4Remapper().", aAxis
)
585 virtual void RemapButtonEvent(GamepadHandle aHandle
, uint32_t aButton
,
586 bool aPressed
) const override
{
587 RefPtr
<GamepadPlatformService
> service
=
588 GamepadPlatformService::GetParentService();
593 constexpr std::array
<uint32_t, 14> buttonMapping
= {
594 BUTTON_INDEX_TERTIARY
,
595 BUTTON_INDEX_PRIMARY
,
596 BUTTON_INDEX_SECONDARY
,
597 BUTTON_INDEX_QUATERNARY
,
598 BUTTON_INDEX_LEFT_SHOULDER
,
599 BUTTON_INDEX_RIGHT_SHOULDER
,
600 BUTTON_INDEX_LEFT_TRIGGER
,
601 BUTTON_INDEX_RIGHT_TRIGGER
,
602 BUTTON_INDEX_BACK_SELECT
,
604 BUTTON_INDEX_LEFT_THUMBSTICK
,
605 BUTTON_INDEX_RIGHT_THUMBSTICK
,
607 DUALSHOCK_BUTTON_TOUCHPAD
};
609 if (buttonMapping
.size() <= aButton
) {
610 NS_WARNING(nsPrintfCString(
611 "Button idx '%d' doesn't support in Dualshock4Remapper().",
617 service
->NewButtonEvent(aHandle
, buttonMapping
[aButton
], aPressed
);
621 enum Dualshock4Buttons
{
622 DUALSHOCK_BUTTON_TOUCHPAD
= BUTTON_INDEX_COUNT
,
623 DUALSHOCK_BUTTON_COUNT
626 static const uint32_t LIGHT_INDICATOR_COUNT
= 1;
627 static const uint32_t TOUCH_EVENT_COUNT
= 2;
628 static const uint32_t MAX_INPUT_LEN
= 68;
630 nsTArray
<unsigned long> mLastTouchId
;
631 nsTArray
<bool> mLastTouches
;
632 unsigned long mTouchIdBase
= 0;
635 class Xbox360Remapper final
: public GamepadRemapper
{
637 virtual uint32_t GetAxisCount() const override
{ return AXIS_INDEX_COUNT
; }
639 virtual uint32_t GetButtonCount() const override
{
640 return BUTTON_INDEX_COUNT
;
643 virtual void RemapAxisMoveEvent(GamepadHandle aHandle
, uint32_t aAxis
,
644 double aValue
) const override
{
645 RefPtr
<GamepadPlatformService
> service
=
646 GamepadPlatformService::GetParentService();
653 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_X
, aValue
);
656 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_Y
, aValue
);
659 const double value
= AxisToButtonValue(aValue
);
660 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_LEFT_TRIGGER
,
661 value
> BUTTON_THRESHOLD_VALUE
, value
);
665 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_X
, aValue
);
668 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_Y
, aValue
);
671 const double value
= AxisToButtonValue(aValue
);
672 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_RIGHT_TRIGGER
,
673 value
> BUTTON_THRESHOLD_VALUE
, value
);
679 "Axis idx '%d' doesn't support in Xbox360Remapper().", aAxis
)
685 virtual void RemapButtonEvent(GamepadHandle aHandle
, uint32_t aButton
,
686 bool aPressed
) const override
{
687 RefPtr
<GamepadPlatformService
> service
=
688 GamepadPlatformService::GetParentService();
693 if (GetButtonCount() <= aButton
) {
696 "Button idx '%d' doesn't support in Xbox360Remapper().", aButton
)
701 const std::unordered_map
<uint32_t, uint32_t> buttonMapping
= {
702 {6, BUTTON_INDEX_LEFT_THUMBSTICK
}, {7, BUTTON_INDEX_RIGHT_THUMBSTICK
},
703 {8, BUTTON_INDEX_START
}, {9, BUTTON_INDEX_BACK_SELECT
},
704 {10, BUTTON_INDEX_META
}, {11, BUTTON_INDEX_DPAD_UP
},
705 {12, BUTTON_INDEX_DPAD_DOWN
}, {13, BUTTON_INDEX_DPAD_LEFT
},
706 {14, BUTTON_INDEX_DPAD_RIGHT
}};
708 auto find
= buttonMapping
.find(aButton
);
709 if (find
!= buttonMapping
.end()) {
710 service
->NewButtonEvent(aHandle
, find
->second
, aPressed
);
712 service
->NewButtonEvent(aHandle
, aButton
, aPressed
);
717 class XboxOneSRemapper final
: public GamepadRemapper
{
719 virtual uint32_t GetAxisCount() const override
{ return AXIS_INDEX_COUNT
; }
721 virtual uint32_t GetButtonCount() const override
{
722 return BUTTON_INDEX_COUNT
;
725 virtual void RemapAxisMoveEvent(GamepadHandle aHandle
, uint32_t aAxis
,
726 double aValue
) const override
{
727 RefPtr
<GamepadPlatformService
> service
=
728 GamepadPlatformService::GetParentService();
735 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_X
, aValue
);
738 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_Y
, aValue
);
741 const double value
= AxisToButtonValue(aValue
);
742 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_LEFT_TRIGGER
,
743 value
> BUTTON_THRESHOLD_VALUE
, value
);
747 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_X
, aValue
);
750 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_Y
, aValue
);
753 const double value
= AxisToButtonValue(aValue
);
754 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_RIGHT_TRIGGER
,
755 value
> BUTTON_THRESHOLD_VALUE
, value
);
759 FetchDpadFromAxis(aHandle
, aValue
);
764 "Axis idx '%d' doesn't support in XboxOneSRemapper().", aAxis
)
770 virtual void RemapButtonEvent(GamepadHandle aHandle
, uint32_t aButton
,
771 bool aPressed
) const override
{
772 RefPtr
<GamepadPlatformService
> service
=
773 GamepadPlatformService::GetParentService();
778 if (GetButtonCount() <= aButton
) {
781 "Button idx '%d' doesn't support in XboxOneSRemapper().", aButton
)
786 const std::unordered_map
<uint32_t, uint32_t> buttonMapping
= {
787 {6, BUTTON_INDEX_BACK_SELECT
},
788 {7, BUTTON_INDEX_START
},
789 {8, BUTTON_INDEX_LEFT_THUMBSTICK
},
790 {9, BUTTON_INDEX_RIGHT_THUMBSTICK
},
791 {10, BUTTON_INDEX_META
}};
793 auto find
= buttonMapping
.find(aButton
);
794 if (find
!= buttonMapping
.end()) {
795 service
->NewButtonEvent(aHandle
, find
->second
, aPressed
);
797 service
->NewButtonEvent(aHandle
, aButton
, aPressed
);
802 class XboxOneS2016FirmwareRemapper final
: public GamepadRemapper
{
804 virtual uint32_t GetAxisCount() const override
{ return AXIS_INDEX_COUNT
; }
806 virtual uint32_t GetButtonCount() const override
{
807 return BUTTON_INDEX_COUNT
;
810 virtual void RemapAxisMoveEvent(GamepadHandle aHandle
, uint32_t aAxis
,
811 double aValue
) const override
{
812 RefPtr
<GamepadPlatformService
> service
=
813 GamepadPlatformService::GetParentService();
820 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_X
, aValue
);
823 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_Y
, aValue
);
826 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_X
, aValue
);
829 const double value
= AxisToButtonValue(aValue
);
830 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_LEFT_TRIGGER
,
831 value
> BUTTON_THRESHOLD_VALUE
, value
);
835 const double value
= AxisToButtonValue(aValue
);
836 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_RIGHT_TRIGGER
,
837 value
> BUTTON_THRESHOLD_VALUE
, value
);
841 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_Y
, aValue
);
844 FetchDpadFromAxis(aHandle
, aValue
);
847 NS_WARNING(nsPrintfCString("Axis idx '%d' doesn't support in "
848 "XboxOneS2016FirmwareRemapper().",
855 virtual void RemapButtonEvent(GamepadHandle aHandle
, uint32_t aButton
,
856 bool aPressed
) const override
{
857 RefPtr
<GamepadPlatformService
> service
=
858 GamepadPlatformService::GetParentService();
863 if (GetButtonCount() <= aButton
) {
864 NS_WARNING(nsPrintfCString("Button idx '%d' doesn't support in "
865 "XboxOneS2016FirmwareRemapper().",
871 // kMicrosoftProductXboxOneSWireless2016 controller received a firmware
872 // update in 2019 that changed which field is populated with the meta button
873 // state. In order to cover the old and new cases, we have to check both
874 // fields of {12, 15} buttons.
875 const std::unordered_map
<uint32_t, uint32_t> buttonMapping
= {
876 {0, BUTTON_INDEX_PRIMARY
},
877 {1, BUTTON_INDEX_SECONDARY
},
878 {3, BUTTON_INDEX_TERTIARY
},
879 {4, BUTTON_INDEX_QUATERNARY
},
880 {6, BUTTON_INDEX_LEFT_SHOULDER
},
881 {7, BUTTON_INDEX_RIGHT_SHOULDER
},
882 {11, BUTTON_INDEX_START
},
883 {12, BUTTON_INDEX_META
},
884 {13, BUTTON_INDEX_LEFT_THUMBSTICK
},
885 {14, BUTTON_INDEX_RIGHT_THUMBSTICK
},
886 {15, BUTTON_INDEX_META
},
887 {16, BUTTON_INDEX_BACK_SELECT
}};
889 auto find
= buttonMapping
.find(aButton
);
890 if (find
!= buttonMapping
.end()) {
891 service
->NewButtonEvent(aHandle
, find
->second
, aPressed
);
893 service
->NewButtonEvent(aHandle
, aButton
, aPressed
);
898 class XboxOneRemapper final
: public GamepadRemapper
{
900 virtual uint32_t GetAxisCount() const override
{ return AXIS_INDEX_COUNT
; }
902 virtual uint32_t GetButtonCount() const override
{
903 return BUTTON_INDEX_COUNT
;
906 virtual void RemapAxisMoveEvent(GamepadHandle aHandle
, uint32_t aAxis
,
907 double aValue
) const override
{
908 RefPtr
<GamepadPlatformService
> service
=
909 GamepadPlatformService::GetParentService();
916 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_X
, aValue
);
919 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_Y
, aValue
);
922 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_X
, aValue
);
925 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_Y
, aValue
);
928 FetchDpadFromAxis(aHandle
, aValue
);
931 const double value
= AxisToButtonValue(aValue
);
932 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_LEFT_TRIGGER
,
933 value
> BUTTON_THRESHOLD_VALUE
, value
);
937 const double value
= AxisToButtonValue(aValue
);
938 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_RIGHT_TRIGGER
,
939 value
> BUTTON_THRESHOLD_VALUE
, value
);
945 "Axis idx '%d' doesn't support in XboxOneRemapper().", aAxis
)
951 virtual void RemapButtonEvent(GamepadHandle aHandle
, uint32_t aButton
,
952 bool aPressed
) const override
{
953 RefPtr
<GamepadPlatformService
> service
=
954 GamepadPlatformService::GetParentService();
959 if (GetButtonCount() <= aButton
) {
962 "Button idx '%d' doesn't support in XboxOneRemapper().", aButton
)
967 // Accessing {30, 31} buttons looks strange to me
968 // and without an avilable device to help verify it.
969 // It is according to `MapperXboxOneBluetooth()` in
970 // https://cs.chromium.org/chromium/src/device/gamepad/gamepad_standard_mappings_mac.mm
971 const std::unordered_map
<uint32_t, uint32_t> buttonMapping
= {
972 {0, BUTTON_INDEX_PRIMARY
},
973 {1, BUTTON_INDEX_SECONDARY
},
974 {3, BUTTON_INDEX_TERTIARY
},
975 {4, BUTTON_INDEX_QUATERNARY
},
976 {6, BUTTON_INDEX_LEFT_SHOULDER
},
977 {7, BUTTON_INDEX_RIGHT_SHOULDER
},
978 {11, BUTTON_INDEX_START
},
979 {13, BUTTON_INDEX_LEFT_THUMBSTICK
},
980 {14, BUTTON_INDEX_RIGHT_THUMBSTICK
},
981 {30, BUTTON_INDEX_META
},
982 {31, BUTTON_INDEX_BACK_SELECT
}};
984 auto find
= buttonMapping
.find(aButton
);
985 if (find
!= buttonMapping
.end()) {
986 service
->NewButtonEvent(aHandle
, find
->second
, aPressed
);
988 service
->NewButtonEvent(aHandle
, aButton
, aPressed
);
993 class XboxSeriesXRemapper final
: public GamepadRemapper
{
995 virtual uint32_t GetAxisCount() const override
{ return AXIS_INDEX_COUNT
; }
997 virtual uint32_t GetButtonCount() const override
{
998 return BUTTON_INDEX_COUNT
;
1001 virtual void RemapAxisMoveEvent(GamepadHandle aHandle
, uint32_t aAxis
,
1002 double aValue
) const override
{
1003 RefPtr
<GamepadPlatformService
> service
=
1004 GamepadPlatformService::GetParentService();
1011 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_X
, aValue
);
1014 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_Y
, aValue
);
1017 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_X
, aValue
);
1020 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_Y
, aValue
);
1023 FetchDpadFromAxis(aHandle
, aValue
);
1026 const double value
= AxisToButtonValue(aValue
);
1027 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_RIGHT_TRIGGER
,
1028 value
> BUTTON_THRESHOLD_VALUE
, value
);
1032 const double value
= AxisToButtonValue(aValue
);
1033 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_LEFT_TRIGGER
,
1034 value
> BUTTON_THRESHOLD_VALUE
, value
);
1040 "Axis idx '%d' doesn't support in XboxSeriesXRemapper().",
1047 virtual void RemapButtonEvent(GamepadHandle aHandle
, uint32_t aButton
,
1048 bool aPressed
) const override
{
1049 RefPtr
<GamepadPlatformService
> service
=
1050 GamepadPlatformService::GetParentService();
1055 if (GetButtonCount() <= aButton
) {
1058 "Button idx '%d' doesn't support in XboxSeriesXRemapper().",
1064 const std::unordered_map
<uint32_t, uint32_t> buttonMapping
= {
1065 {0, BUTTON_INDEX_PRIMARY
},
1066 {1, BUTTON_INDEX_SECONDARY
},
1067 {3, BUTTON_INDEX_TERTIARY
},
1068 {4, BUTTON_INDEX_QUATERNARY
},
1069 {6, BUTTON_INDEX_LEFT_SHOULDER
},
1070 {7, BUTTON_INDEX_RIGHT_SHOULDER
},
1071 {10, BUTTON_INDEX_BACK_SELECT
},
1072 {11, BUTTON_INDEX_START
},
1073 {12, BUTTON_INDEX_META
},
1074 {13, BUTTON_INDEX_LEFT_THUMBSTICK
},
1075 {14, BUTTON_INDEX_RIGHT_THUMBSTICK
}};
1077 auto find
= buttonMapping
.find(aButton
);
1078 if (find
!= buttonMapping
.end()) {
1079 service
->NewButtonEvent(aHandle
, find
->second
, aPressed
);
1081 service
->NewButtonEvent(aHandle
, aButton
, aPressed
);
1086 class LogitechDInputRemapper final
: public GamepadRemapper
{
1088 virtual uint32_t GetAxisCount() const override
{ return AXIS_INDEX_COUNT
; }
1090 virtual uint32_t GetButtonCount() const override
{
1091 // The Logitech button (BUTTON_INDEX_META) is not accessible through the
1093 return BUTTON_INDEX_COUNT
- 1;
1096 virtual void RemapAxisMoveEvent(GamepadHandle aHandle
, uint32_t aAxis
,
1097 double aValue
) const override
{
1098 RefPtr
<GamepadPlatformService
> service
=
1099 GamepadPlatformService::GetParentService();
1106 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_X
, aValue
);
1109 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_Y
, aValue
);
1112 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_X
, aValue
);
1115 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_Y
, aValue
);
1118 FetchDpadFromAxis(aHandle
, aValue
);
1123 "Axis idx '%d' doesn't support in LogitechDInputRemapper().",
1130 virtual void RemapButtonEvent(GamepadHandle aHandle
, uint32_t aButton
,
1131 bool aPressed
) const override
{
1132 RefPtr
<GamepadPlatformService
> service
=
1133 GamepadPlatformService::GetParentService();
1138 if (GetButtonCount() <= aButton
) {
1141 "Button idx '%d' doesn't support in LogitechDInputRemapper().",
1147 const std::unordered_map
<uint32_t, uint32_t> buttonMapping
= {
1148 {0, BUTTON_INDEX_TERTIARY
},
1149 {1, BUTTON_INDEX_PRIMARY
},
1150 {2, BUTTON_INDEX_SECONDARY
}};
1152 auto find
= buttonMapping
.find(aButton
);
1153 if (find
!= buttonMapping
.end()) {
1154 service
->NewButtonEvent(aHandle
, find
->second
, aPressed
);
1156 service
->NewButtonEvent(aHandle
, aButton
, aPressed
);
1161 class SwitchJoyConRemapper final
: public GamepadRemapper
{
1163 virtual uint32_t GetAxisCount() const override
{ return 2; }
1165 virtual uint32_t GetButtonCount() const override
{
1166 return BUTTON_INDEX_COUNT
;
1169 virtual void RemapAxisMoveEvent(GamepadHandle aHandle
, uint32_t aAxis
,
1170 double aValue
) const override
{
1171 if (GetAxisCount() <= aAxis
) {
1174 "Axis idx '%d' doesn't support in SwitchJoyConRemapper().", aAxis
)
1178 RefPtr
<GamepadPlatformService
> service
=
1179 GamepadPlatformService::GetParentService();
1184 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_X
, aValue
);
1187 virtual void RemapButtonEvent(GamepadHandle aHandle
, uint32_t aButton
,
1188 bool aPressed
) const override
{
1189 RefPtr
<GamepadPlatformService
> service
=
1190 GamepadPlatformService::GetParentService();
1195 service
->NewButtonEvent(aHandle
, aButton
, aPressed
);
1199 class SwitchProRemapper final
: public GamepadRemapper
{
1201 virtual uint32_t GetAxisCount() const override
{ return AXIS_INDEX_COUNT
; }
1203 virtual uint32_t GetButtonCount() const override
{
1204 // The Switch Pro controller has a Capture button that has no equivalent in
1205 // the Standard Gamepad.
1206 return SWITCHPRO_BUTTON_COUNT
;
1209 virtual void RemapAxisMoveEvent(GamepadHandle aHandle
, uint32_t aAxis
,
1210 double aValue
) const override
{
1211 if (GetAxisCount() <= aAxis
) {
1214 "Axis idx '%d' doesn't support in SwitchProRemapper().", aAxis
)
1218 RefPtr
<GamepadPlatformService
> service
=
1219 GamepadPlatformService::GetParentService();
1224 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_X
, aValue
);
1227 virtual void RemapButtonEvent(GamepadHandle aHandle
, uint32_t aButton
,
1228 bool aPressed
) const override
{
1229 RefPtr
<GamepadPlatformService
> service
=
1230 GamepadPlatformService::GetParentService();
1235 service
->NewButtonEvent(aHandle
, aButton
, aPressed
);
1239 enum SwitchProButtons
{
1240 SWITCHPRO_BUTTON_EXTRA
= BUTTON_INDEX_COUNT
,
1241 SWITCHPRO_BUTTON_COUNT
1245 class NvShieldRemapper final
: public GamepadRemapper
{
1247 virtual uint32_t GetAxisCount() const override
{ return AXIS_INDEX_COUNT
; }
1249 virtual uint32_t GetButtonCount() const override
{
1250 return SHIELD_BUTTON_COUNT
;
1253 virtual void RemapAxisMoveEvent(GamepadHandle aHandle
, uint32_t aAxis
,
1254 double aValue
) const override
{
1255 RefPtr
<GamepadPlatformService
> service
=
1256 GamepadPlatformService::GetParentService();
1263 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_X
, aValue
);
1266 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_Y
, aValue
);
1269 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_X
, aValue
);
1272 const double value
= AxisToButtonValue(aValue
);
1273 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_RIGHT_TRIGGER
,
1274 value
> BUTTON_THRESHOLD_VALUE
, value
);
1278 const double value
= AxisToButtonValue(aValue
);
1279 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_LEFT_TRIGGER
,
1280 value
> BUTTON_THRESHOLD_VALUE
, value
);
1284 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_Y
, aValue
);
1287 FetchDpadFromAxis(aHandle
, aValue
);
1292 "Axis idx '%d' doesn't support in NvShieldRemapper().", aAxis
)
1298 virtual void RemapButtonEvent(GamepadHandle aHandle
, uint32_t aButton
,
1299 bool aPressed
) const override
{
1300 RefPtr
<GamepadPlatformService
> service
=
1301 GamepadPlatformService::GetParentService();
1306 if (GetButtonCount() <= aButton
) {
1309 "Button idx '%d' doesn't support in NvShieldRemapper().", aButton
)
1314 const std::unordered_map
<uint32_t, uint32_t> buttonMapping
= {
1315 {2, BUTTON_INDEX_META
},
1316 {3, BUTTON_INDEX_TERTIARY
},
1317 {4, BUTTON_INDEX_QUATERNARY
},
1318 {5, SHIELD_BUTTON_CIRCLE
},
1319 {6, BUTTON_INDEX_LEFT_SHOULDER
},
1320 {7, BUTTON_INDEX_RIGHT_SHOULDER
},
1321 {9, BUTTON_INDEX_BACK_SELECT
},
1322 {11, BUTTON_INDEX_START
},
1323 {13, BUTTON_INDEX_LEFT_THUMBSTICK
},
1324 {14, BUTTON_INDEX_RIGHT_THUMBSTICK
}};
1326 auto find
= buttonMapping
.find(aButton
);
1327 if (find
!= buttonMapping
.end()) {
1328 service
->NewButtonEvent(aHandle
, find
->second
, aPressed
);
1330 service
->NewButtonEvent(aHandle
, aButton
, aPressed
);
1335 enum ShieldButtons
{
1336 SHIELD_BUTTON_CIRCLE
= BUTTON_INDEX_COUNT
,
1341 class NvShield2017Remapper final
: public GamepadRemapper
{
1343 virtual uint32_t GetAxisCount() const override
{ return AXIS_INDEX_COUNT
; }
1345 virtual uint32_t GetButtonCount() const override
{
1346 return SHIELD2017_BUTTON_COUNT
;
1349 virtual void RemapAxisMoveEvent(GamepadHandle aHandle
, uint32_t aAxis
,
1350 double aValue
) const override
{
1351 RefPtr
<GamepadPlatformService
> service
=
1352 GamepadPlatformService::GetParentService();
1359 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_X
, aValue
);
1362 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_Y
, aValue
);
1365 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_X
, aValue
);
1368 const double value
= AxisToButtonValue(aValue
);
1369 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_RIGHT_TRIGGER
,
1370 value
> BUTTON_THRESHOLD_VALUE
, value
);
1374 const double value
= AxisToButtonValue(aValue
);
1375 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_LEFT_TRIGGER
,
1376 value
> BUTTON_THRESHOLD_VALUE
, value
);
1380 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_Y
, aValue
);
1383 FetchDpadFromAxis(aHandle
, aValue
);
1388 "Axis idx '%d' doesn't support in NvShield2017Remapper().",
1395 virtual void RemapButtonEvent(GamepadHandle aHandle
, uint32_t aButton
,
1396 bool aPressed
) const override
{
1397 RefPtr
<GamepadPlatformService
> service
=
1398 GamepadPlatformService::GetParentService();
1403 if (GetButtonCount() <= aButton
) {
1406 "Button idx '%d' doesn't support in NvShield2017Remapper().",
1412 const std::unordered_map
<uint32_t, uint32_t> buttonMapping
= {
1413 {2, BUTTON_INDEX_META
},
1414 {3, BUTTON_INDEX_TERTIARY
},
1415 {4, BUTTON_INDEX_QUATERNARY
},
1416 {5, BUTTON_INDEX_START
},
1417 {6, BUTTON_INDEX_LEFT_SHOULDER
},
1418 {7, BUTTON_INDEX_RIGHT_SHOULDER
},
1419 {8, BUTTON_INDEX_BACK_SELECT
},
1420 {11, SHIELD2017_BUTTON_PLAYPAUSE
},
1421 {13, BUTTON_INDEX_LEFT_THUMBSTICK
},
1422 {14, BUTTON_INDEX_RIGHT_THUMBSTICK
}};
1424 auto find
= buttonMapping
.find(aButton
);
1425 if (find
!= buttonMapping
.end()) {
1426 service
->NewButtonEvent(aHandle
, find
->second
, aPressed
);
1428 service
->NewButtonEvent(aHandle
, aButton
, aPressed
);
1433 enum Shield2017Buttons
{
1434 SHIELD2017_BUTTON_PLAYPAUSE
= BUTTON_INDEX_COUNT
,
1435 SHIELD2017_BUTTON_COUNT
1439 class IBuffaloRemapper final
: public GamepadRemapper
{
1441 virtual uint32_t GetAxisCount() const override
{ return 2; }
1443 virtual uint32_t GetButtonCount() const override
{
1444 return BUTTON_INDEX_COUNT
- 1; /* no meta */
1447 virtual void RemapAxisMoveEvent(GamepadHandle aHandle
, uint32_t aAxis
,
1448 double aValue
) const override
{
1449 RefPtr
<GamepadPlatformService
> service
=
1450 GamepadPlatformService::GetParentService();
1457 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_X
, aValue
);
1458 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_DPAD_LEFT
,
1459 AxisNegativeAsButton(aValue
));
1460 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_DPAD_RIGHT
,
1461 AxisPositiveAsButton(aValue
));
1464 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_Y
, aValue
);
1465 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_DPAD_UP
,
1466 AxisNegativeAsButton(aValue
));
1467 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_DPAD_DOWN
,
1468 AxisPositiveAsButton(aValue
));
1473 "Axis idx '%d' doesn't support in IBuffaloRemapper().", aAxis
)
1479 virtual void RemapButtonEvent(GamepadHandle aHandle
, uint32_t aButton
,
1480 bool aPressed
) const override
{
1481 RefPtr
<GamepadPlatformService
> service
=
1482 GamepadPlatformService::GetParentService();
1487 if (GetButtonCount() <= aButton
) {
1490 "Button idx '%d' doesn't support in IBuffaloRemapper().", aButton
)
1495 const std::unordered_map
<uint32_t, uint32_t> buttonMapping
= {
1496 {0, BUTTON_INDEX_SECONDARY
}, {1, BUTTON_INDEX_PRIMARY
},
1497 {2, BUTTON_INDEX_QUATERNARY
}, {3, BUTTON_INDEX_TERTIARY
},
1498 {5, BUTTON_INDEX_RIGHT_TRIGGER
}, {6, BUTTON_INDEX_BACK_SELECT
},
1499 {7, BUTTON_INDEX_START
}};
1501 auto find
= buttonMapping
.find(aButton
);
1502 if (find
!= buttonMapping
.end()) {
1503 service
->NewButtonEvent(aHandle
, find
->second
, aPressed
);
1505 service
->NewButtonEvent(aHandle
, aButton
, aPressed
);
1510 class XSkillsRemapper final
: public GamepadRemapper
{
1512 virtual uint32_t GetAxisCount() const override
{ return AXIS_INDEX_COUNT
; }
1514 virtual uint32_t GetButtonCount() const override
{
1515 return GAMECUBE_BUTTON_COUNT
;
1518 virtual void RemapAxisMoveEvent(GamepadHandle aHandle
, uint32_t aAxis
,
1519 double aValue
) const override
{
1520 RefPtr
<GamepadPlatformService
> service
=
1521 GamepadPlatformService::GetParentService();
1528 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_X
, aValue
);
1531 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_Y
, aValue
);
1534 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_Y
, aValue
);
1537 const double value
= AxisToButtonValue(aValue
);
1538 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_RIGHT_TRIGGER
,
1539 value
> BUTTON_THRESHOLD_VALUE
, value
);
1543 const double value
= AxisToButtonValue(aValue
);
1544 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_LEFT_TRIGGER
,
1545 value
> BUTTON_THRESHOLD_VALUE
, value
);
1549 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_X
, aValue
);
1554 "Axis idx '%d' doesn't support in XSkillsRemapper().", aAxis
)
1560 virtual void RemapButtonEvent(GamepadHandle aHandle
, uint32_t aButton
,
1561 bool aPressed
) const override
{
1562 RefPtr
<GamepadPlatformService
> service
=
1563 GamepadPlatformService::GetParentService();
1568 if (GetButtonCount() <= aButton
) {
1571 "Button idx '%d' doesn't support in XSkillsRemapper().", aButton
)
1576 const std::unordered_map
<uint32_t, uint32_t> buttonMapping
= {
1577 {0, BUTTON_INDEX_PRIMARY
}, // A
1578 {1, BUTTON_INDEX_TERTIARY
}, // B
1579 {2, BUTTON_INDEX_SECONDARY
}, // X
1580 {3, BUTTON_INDEX_QUATERNARY
}, // Y
1581 {4, GAMECUBE_BUTTON_LEFT_TRIGGER_CLICK
},
1582 {5, GAMECUBE_BUTTON_RIGHT_TRIGGER_CLICK
},
1583 {6, BUTTON_INDEX_RIGHT_SHOULDER
},
1584 {7, BUTTON_INDEX_START
},
1585 {8, BUTTON_INDEX_DPAD_LEFT
},
1586 {9, BUTTON_INDEX_DPAD_RIGHT
},
1587 {10, BUTTON_INDEX_DPAD_DOWN
},
1588 {11, BUTTON_INDEX_DPAD_UP
}};
1590 auto find
= buttonMapping
.find(aButton
);
1591 if (find
!= buttonMapping
.end()) {
1592 service
->NewButtonEvent(aHandle
, find
->second
, aPressed
);
1594 service
->NewButtonEvent(aHandle
, aButton
, aPressed
);
1599 enum GamecubeButtons
{
1600 GAMECUBE_BUTTON_LEFT_TRIGGER_CLICK
= BUTTON_INDEX_COUNT
,
1601 GAMECUBE_BUTTON_RIGHT_TRIGGER_CLICK
,
1602 GAMECUBE_BUTTON_COUNT
1606 class BoomN64PsxRemapper final
: public GamepadRemapper
{
1608 virtual uint32_t GetAxisCount() const override
{ return AXIS_INDEX_COUNT
; }
1610 virtual uint32_t GetButtonCount() const override
{
1611 return BUTTON_INDEX_COUNT
- 1; // no meta
1614 virtual void RemapAxisMoveEvent(GamepadHandle aHandle
, uint32_t aAxis
,
1615 double aValue
) const override
{
1616 RefPtr
<GamepadPlatformService
> service
=
1617 GamepadPlatformService::GetParentService();
1624 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_X
, aValue
);
1627 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_Y
, aValue
);
1630 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_X
, aValue
);
1633 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_Y
, aValue
);
1638 "Axis idx '%d' doesn't support in BoomN64PsxRemapper().", aAxis
)
1644 virtual void RemapButtonEvent(GamepadHandle aHandle
, uint32_t aButton
,
1645 bool aPressed
) const override
{
1646 RefPtr
<GamepadPlatformService
> service
=
1647 GamepadPlatformService::GetParentService();
1652 static constexpr std::array buttonMapping
= {
1653 BUTTON_INDEX_QUATERNARY
, BUTTON_INDEX_SECONDARY
,
1654 BUTTON_INDEX_PRIMARY
, BUTTON_INDEX_TERTIARY
,
1655 BUTTON_INDEX_LEFT_TRIGGER
, BUTTON_INDEX_RIGHT_TRIGGER
,
1656 BUTTON_INDEX_LEFT_SHOULDER
, BUTTON_INDEX_RIGHT_SHOULDER
,
1657 BUTTON_INDEX_BACK_SELECT
, BUTTON_INDEX_LEFT_THUMBSTICK
,
1658 BUTTON_INDEX_RIGHT_THUMBSTICK
, BUTTON_INDEX_START
,
1659 BUTTON_INDEX_DPAD_UP
, BUTTON_INDEX_DPAD_RIGHT
,
1660 BUTTON_INDEX_DPAD_DOWN
, BUTTON_INDEX_DPAD_LEFT
};
1662 if (buttonMapping
.size() <= aButton
) {
1663 NS_WARNING(nsPrintfCString(
1664 "Button idx '%d' doesn't support in BoomN64PsxRemapper().",
1670 service
->NewButtonEvent(aHandle
, buttonMapping
[aButton
], aPressed
);
1674 enum GamecubeButtons
{
1675 GAMECUBE_BUTTON_LEFT_TRIGGER_CLICK
= BUTTON_INDEX_COUNT
,
1676 GAMECUBE_BUTTON_RIGHT_TRIGGER_CLICK
,
1677 GAMECUBE_BUTTON_COUNT
1681 class StadiaControllerOldFirmwareRemapper final
: public GamepadRemapper
{
1683 virtual uint32_t GetAxisCount() const override
{ return AXIS_INDEX_COUNT
; }
1685 virtual uint32_t GetButtonCount() const override
{
1686 return ANALOG_GAMEPAD_BUTTON_COUNT
;
1689 virtual void RemapAxisMoveEvent(GamepadHandle aHandle
, uint32_t aAxis
,
1690 double aValue
) const override
{
1691 RefPtr
<GamepadPlatformService
> service
=
1692 GamepadPlatformService::GetParentService();
1699 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_X
, aValue
);
1702 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_Y
, aValue
);
1705 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_X
, aValue
);
1708 const double value
= AxisToButtonValue(aValue
);
1709 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_RIGHT_TRIGGER
,
1710 value
> BUTTON_THRESHOLD_VALUE
, value
);
1714 const double value
= AxisToButtonValue(aValue
);
1715 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_LEFT_TRIGGER
,
1716 value
> BUTTON_THRESHOLD_VALUE
, value
);
1720 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_Y
, aValue
);
1723 FetchDpadFromAxis(aHandle
, aValue
);
1728 "Axis idx '%d' doesn't support in AnalogGamepadRemapper().",
1735 virtual void RemapButtonEvent(GamepadHandle aHandle
, uint32_t aButton
,
1736 bool aPressed
) const override
{
1737 RefPtr
<GamepadPlatformService
> service
=
1738 GamepadPlatformService::GetParentService();
1743 if (GetButtonCount() <= aButton
) {
1746 "Button idx '%d' doesn't support in AnalogGamepadRemapper().",
1752 const std::unordered_map
<uint32_t, uint32_t> buttonMapping
= {
1753 {3, BUTTON_INDEX_TERTIARY
},
1754 {4, BUTTON_INDEX_QUATERNARY
},
1755 {6, BUTTON_INDEX_LEFT_SHOULDER
},
1756 {7, BUTTON_INDEX_RIGHT_SHOULDER
},
1757 {10, BUTTON_INDEX_BACK_SELECT
},
1758 {11, BUTTON_INDEX_META
},
1759 {12, BUTTON_INDEX_START
},
1760 {13, BUTTON_INDEX_LEFT_THUMBSTICK
},
1761 {14, BUTTON_INDEX_RIGHT_THUMBSTICK
},
1762 {16, ANALOG_GAMEPAD_BUTTON_EXTRA
},
1763 {17, ANALOG_GAMEPAD_BUTTON_EXTRA2
}};
1765 auto find
= buttonMapping
.find(aButton
);
1766 if (find
!= buttonMapping
.end()) {
1767 service
->NewButtonEvent(aHandle
, find
->second
, aPressed
);
1769 service
->NewButtonEvent(aHandle
, aButton
, aPressed
);
1774 enum AnalogGamepadButtons
{
1775 ANALOG_GAMEPAD_BUTTON_EXTRA
= BUTTON_INDEX_COUNT
,
1776 ANALOG_GAMEPAD_BUTTON_EXTRA2
,
1777 ANALOG_GAMEPAD_BUTTON_COUNT
1781 class RazerServalRemapper final
: public GamepadRemapper
{
1783 virtual uint32_t GetAxisCount() const override
{ return AXIS_INDEX_COUNT
; }
1785 virtual uint32_t GetButtonCount() const override
{
1786 return BUTTON_INDEX_COUNT
- 1; /* no meta */
1789 virtual void RemapAxisMoveEvent(GamepadHandle aHandle
, uint32_t aAxis
,
1790 double aValue
) const override
{
1791 RefPtr
<GamepadPlatformService
> service
=
1792 GamepadPlatformService::GetParentService();
1799 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_X
, aValue
);
1802 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_Y
, aValue
);
1805 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_X
, aValue
);
1808 const double value
= AxisToButtonValue(aValue
);
1809 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_RIGHT_TRIGGER
,
1810 value
> BUTTON_THRESHOLD_VALUE
, value
);
1814 const double value
= AxisToButtonValue(aValue
);
1815 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_LEFT_TRIGGER
,
1816 value
> BUTTON_THRESHOLD_VALUE
, value
);
1820 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_Y
, aValue
);
1823 FetchDpadFromAxis(aHandle
, aValue
);
1828 "Axis idx '%d' doesn't support in RazerServalRemapper().",
1835 virtual void RemapButtonEvent(GamepadHandle aHandle
, uint32_t aButton
,
1836 bool aPressed
) const override
{
1837 RefPtr
<GamepadPlatformService
> service
=
1838 GamepadPlatformService::GetParentService();
1843 if (GetButtonCount() <= aButton
) {
1846 "Button idx '%d' doesn't support in RazerServalRemapper().",
1852 const std::unordered_map
<uint32_t, uint32_t> buttonMapping
= {
1853 {3, BUTTON_INDEX_TERTIARY
}, {4, BUTTON_INDEX_QUATERNARY
},
1854 {6, BUTTON_INDEX_LEFT_SHOULDER
}, {7, BUTTON_INDEX_RIGHT_SHOULDER
},
1855 {10, BUTTON_INDEX_BACK_SELECT
}, {11, BUTTON_INDEX_START
},
1856 {12, BUTTON_INDEX_START
}, {13, BUTTON_INDEX_LEFT_THUMBSTICK
},
1857 {14, BUTTON_INDEX_RIGHT_THUMBSTICK
}};
1859 auto find
= buttonMapping
.find(aButton
);
1860 if (find
!= buttonMapping
.end()) {
1861 service
->NewButtonEvent(aHandle
, find
->second
, aPressed
);
1863 service
->NewButtonEvent(aHandle
, aButton
, aPressed
);
1868 class MogaProRemapper final
: public GamepadRemapper
{
1870 virtual uint32_t GetAxisCount() const override
{ return AXIS_INDEX_COUNT
; }
1872 virtual uint32_t GetButtonCount() const override
{
1873 return BUTTON_INDEX_COUNT
- 1; /* no meta */
1876 virtual void RemapAxisMoveEvent(GamepadHandle aHandle
, uint32_t aAxis
,
1877 double aValue
) const override
{
1878 RefPtr
<GamepadPlatformService
> service
=
1879 GamepadPlatformService::GetParentService();
1886 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_X
, aValue
);
1889 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_Y
, aValue
);
1892 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_X
, aValue
);
1895 const double value
= AxisToButtonValue(aValue
);
1896 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_RIGHT_TRIGGER
,
1897 value
> BUTTON_THRESHOLD_VALUE
, value
);
1901 const double value
= AxisToButtonValue(aValue
);
1902 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_LEFT_TRIGGER
,
1903 value
> BUTTON_THRESHOLD_VALUE
, value
);
1907 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_Y
, aValue
);
1910 FetchDpadFromAxis(aHandle
, aValue
);
1915 "Axis idx '%d' doesn't support in MogaProRemapper().", aAxis
)
1921 virtual void RemapButtonEvent(GamepadHandle aHandle
, uint32_t aButton
,
1922 bool aPressed
) const override
{
1923 RefPtr
<GamepadPlatformService
> service
=
1924 GamepadPlatformService::GetParentService();
1929 if (GetButtonCount() <= aButton
) {
1932 "Button idx '%d' doesn't support in MogaProRemapper().", aButton
)
1937 const std::unordered_map
<uint32_t, uint32_t> buttonMapping
= {
1938 {3, BUTTON_INDEX_TERTIARY
}, {4, BUTTON_INDEX_QUATERNARY
},
1939 {6, BUTTON_INDEX_LEFT_SHOULDER
}, {7, BUTTON_INDEX_RIGHT_SHOULDER
},
1940 {11, BUTTON_INDEX_START
}, {13, BUTTON_INDEX_LEFT_THUMBSTICK
},
1941 {14, BUTTON_INDEX_RIGHT_THUMBSTICK
}};
1943 auto find
= buttonMapping
.find(aButton
);
1944 if (find
!= buttonMapping
.end()) {
1945 service
->NewButtonEvent(aHandle
, find
->second
, aPressed
);
1947 service
->NewButtonEvent(aHandle
, aButton
, aPressed
);
1952 class OnLiveWirelessRemapper final
: public GamepadRemapper
{
1954 virtual uint32_t GetAxisCount() const override
{ return AXIS_INDEX_COUNT
; }
1956 virtual uint32_t GetButtonCount() const override
{
1957 return BUTTON_INDEX_COUNT
;
1960 virtual void RemapAxisMoveEvent(GamepadHandle aHandle
, uint32_t aAxis
,
1961 double aValue
) const override
{
1962 RefPtr
<GamepadPlatformService
> service
=
1963 GamepadPlatformService::GetParentService();
1970 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_X
, aValue
);
1973 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_Y
, aValue
);
1976 const double value
= AxisToButtonValue(aValue
);
1977 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_LEFT_TRIGGER
,
1978 value
> BUTTON_THRESHOLD_VALUE
, value
);
1982 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_X
, aValue
);
1985 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_Y
, aValue
);
1988 const double value
= AxisToButtonValue(aValue
);
1989 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_RIGHT_TRIGGER
,
1990 value
> BUTTON_THRESHOLD_VALUE
, value
);
1994 FetchDpadFromAxis(aHandle
, aValue
);
1999 "Axis idx '%d' doesn't support in OnLiveWirelessRemapper().",
2006 virtual void RemapButtonEvent(GamepadHandle aHandle
, uint32_t aButton
,
2007 bool aPressed
) const override
{
2008 RefPtr
<GamepadPlatformService
> service
=
2009 GamepadPlatformService::GetParentService();
2014 if (GetButtonCount() <= aButton
) {
2017 "Button idx '%d' doesn't support in OnLiveWirelessRemapper().",
2023 const std::unordered_map
<uint32_t, uint32_t> buttonMapping
= {
2024 {3, BUTTON_INDEX_TERTIARY
},
2025 {4, BUTTON_INDEX_QUATERNARY
},
2026 {6, BUTTON_INDEX_LEFT_SHOULDER
},
2027 {7, BUTTON_INDEX_RIGHT_SHOULDER
},
2028 {12, BUTTON_INDEX_META
},
2029 {13, BUTTON_INDEX_LEFT_THUMBSTICK
},
2030 {14, BUTTON_INDEX_RIGHT_THUMBSTICK
}};
2032 auto find
= buttonMapping
.find(aButton
);
2033 if (find
!= buttonMapping
.end()) {
2034 service
->NewButtonEvent(aHandle
, find
->second
, aPressed
);
2036 service
->NewButtonEvent(aHandle
, aButton
, aPressed
);
2041 class OUYARemapper final
: public GamepadRemapper
{
2043 virtual uint32_t GetAxisCount() const override
{ return AXIS_INDEX_COUNT
; }
2045 virtual uint32_t GetButtonCount() const override
{
2046 return BUTTON_INDEX_COUNT
;
2049 virtual void RemapAxisMoveEvent(GamepadHandle aHandle
, uint32_t aAxis
,
2050 double aValue
) const override
{
2051 RefPtr
<GamepadPlatformService
> service
=
2052 GamepadPlatformService::GetParentService();
2059 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_X
, aValue
);
2062 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_LEFT_STICK_Y
, aValue
);
2065 const double value
= AxisToButtonValue(aValue
);
2066 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_LEFT_TRIGGER
,
2067 value
> BUTTON_THRESHOLD_VALUE
, value
);
2071 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_X
, aValue
);
2074 service
->NewAxisMoveEvent(aHandle
, AXIS_INDEX_RIGHT_STICK_Y
, aValue
);
2077 const double value
= AxisToButtonValue(aValue
);
2078 service
->NewButtonEvent(aHandle
, BUTTON_INDEX_RIGHT_TRIGGER
,
2079 value
> BUTTON_THRESHOLD_VALUE
, value
);
2084 nsPrintfCString("Axis idx '%d' doesn't support in OUYARemapper().",
2091 virtual void RemapButtonEvent(GamepadHandle aHandle
, uint32_t aButton
,
2092 bool aPressed
) const override
{
2093 RefPtr
<GamepadPlatformService
> service
=
2094 GamepadPlatformService::GetParentService();
2099 if (GetButtonCount() <= aButton
) {
2101 nsPrintfCString("Button idx '%d' doesn't support in OUYARemapper().",
2107 const std::unordered_map
<uint32_t, uint32_t> buttonMapping
= {
2108 {1, BUTTON_INDEX_TERTIARY
}, {2, BUTTON_INDEX_QUATERNARY
},
2109 {3, BUTTON_INDEX_SECONDARY
}, {6, BUTTON_INDEX_LEFT_THUMBSTICK
},
2110 {7, BUTTON_INDEX_RIGHT_THUMBSTICK
}, {8, BUTTON_INDEX_DPAD_UP
},
2111 {9, BUTTON_INDEX_DPAD_DOWN
}, {10, BUTTON_INDEX_DPAD_LEFT
},
2112 {11, BUTTON_INDEX_DPAD_RIGHT
}, {15, BUTTON_INDEX_META
}};
2114 auto find
= buttonMapping
.find(aButton
);
2115 if (find
!= buttonMapping
.end()) {
2116 service
->NewButtonEvent(aHandle
, find
->second
, aPressed
);
2118 service
->NewButtonEvent(aHandle
, aButton
, aPressed
);
2123 already_AddRefed
<GamepadRemapper
> GetGamepadRemapper(const uint16_t aVendorId
,
2124 const uint16_t aProductId
,
2125 bool& aUsingDefault
) {
2126 const std::vector
<GamepadRemappingData
> remappingRules
= {
2127 {GamepadId::kAsusTekProduct4500
, new ADT1Remapper()},
2128 {GamepadId::kDragonRiseProduct0011
, new TwoAxesEightKeysRemapper()},
2129 {GamepadId::kGoogleProduct2c40
, new ADT1Remapper()},
2130 {GamepadId::kGoogleProduct9400
, new StadiaControllerRemapper()},
2131 {GamepadId::kLogitechProductc216
, new LogitechDInputRemapper()},
2132 {GamepadId::kLogitechProductc218
, new LogitechDInputRemapper()},
2133 {GamepadId::kLogitechProductc219
, new LogitechDInputRemapper()},
2134 {GamepadId::kMicrosoftProductXbox360Wireless
, new Xbox360Remapper()},
2135 {GamepadId::kMicrosoftProductXbox360Wireless2
, new Xbox360Remapper()},
2136 {GamepadId::kMicrosoftProductXboxOneElite2Wireless
,
2137 new XboxOneRemapper()},
2138 {GamepadId::kMicrosoftProductXboxOneSWireless
, new XboxOneSRemapper()},
2139 {GamepadId::kMicrosoftProductXboxOneSWireless2016
,
2140 new XboxOneS2016FirmwareRemapper()},
2141 {GamepadId::kMicrosoftProductXboxAdaptiveWireless
, new XboxOneRemapper()},
2142 {GamepadId::kMicrosoftProductXboxSeriesXWireless
,
2143 new XboxSeriesXRemapper()},
2144 {GamepadId::kNintendoProduct2006
, new SwitchJoyConRemapper()},
2145 {GamepadId::kNintendoProduct2007
, new SwitchJoyConRemapper()},
2146 {GamepadId::kNintendoProduct2009
, new SwitchProRemapper()},
2147 {GamepadId::kNintendoProduct200e
, new SwitchProRemapper()},
2148 {GamepadId::kNvidiaProduct7210
, new NvShieldRemapper()},
2149 {GamepadId::kNvidiaProduct7214
, new NvShield2017Remapper()},
2150 {GamepadId::kPadixProduct2060
, new IBuffaloRemapper()},
2151 {GamepadId::kPlayComProduct0005
, new XSkillsRemapper()},
2152 {GamepadId::kPrototypeVendorProduct0667
, new BoomN64PsxRemapper()},
2153 {GamepadId::kPrototypeVendorProduct9401
,
2154 new StadiaControllerOldFirmwareRemapper()},
2155 {GamepadId::kRazer1532Product0900
, new RazerServalRemapper()},
2156 {GamepadId::kSonyProduct0268
, new Playstation3Remapper()},
2157 {GamepadId::kSonyProduct05c4
, new Dualshock4Remapper()},
2158 {GamepadId::kSonyProduct09cc
, new Dualshock4Remapper()},
2159 {GamepadId::kSonyProduct0ba0
, new Dualshock4Remapper()},
2160 {GamepadId::kVendor20d6Product6271
, new MogaProRemapper()},
2161 {GamepadId::kVendor2378Product1008
, new OnLiveWirelessRemapper()},
2162 {GamepadId::kVendor2378Product100a
, new OnLiveWirelessRemapper()},
2163 {GamepadId::kVendor2836Product0001
, new OUYARemapper()}};
2164 const GamepadId id
= static_cast<GamepadId
>((aVendorId
<< 16) | aProductId
);
2166 for (uint32_t i
= 0; i
< remappingRules
.size(); ++i
) {
2167 if (id
== remappingRules
[i
].id
) {
2168 aUsingDefault
= false;
2169 return do_AddRef(remappingRules
[i
].remapping
.get());
2173 RefPtr
<GamepadRemapper
> defaultRemapper
= new DefaultRemapper();
2174 aUsingDefault
= true;
2175 return do_AddRef(defaultRemapper
.get());
2178 } // namespace mozilla::dom