2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2011-08-03 22:12:08 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cstddef>
|
|
|
|
|
|
|
|
#ifndef UNICODE
|
|
|
|
# define UNICODE
|
|
|
|
#endif
|
|
|
|
#include <windows.h>
|
2014-04-14 21:18:51 +04:00
|
|
|
#include <hidsdi.h>
|
|
|
|
#include <stdio.h>
|
2014-05-12 13:02:40 +04:00
|
|
|
#include <xinput.h>
|
2011-08-03 22:12:08 +04:00
|
|
|
|
|
|
|
#include "nsITimer.h"
|
|
|
|
#include "nsTArray.h"
|
2016-06-28 01:25:00 +03:00
|
|
|
#include "nsThreadUtils.h"
|
2016-06-28 01:25:00 +03:00
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2011-08-03 22:12:08 +04:00
|
|
|
|
2016-06-28 01:25:00 +03:00
|
|
|
#include "mozilla/ipc/BackgroundParent.h"
|
|
|
|
#include "mozilla/dom/GamepadPlatformService.h"
|
|
|
|
|
2011-08-03 22:12:08 +04:00
|
|
|
namespace {
|
|
|
|
|
2016-06-28 01:25:00 +03:00
|
|
|
using namespace mozilla;
|
2014-04-17 03:43:39 +04:00
|
|
|
using namespace mozilla::dom;
|
2014-04-14 21:18:51 +04:00
|
|
|
using mozilla::ArrayLength;
|
|
|
|
|
|
|
|
// USB HID usage tables, page 1, 0x30 = X
|
2019-04-08 23:21:28 +03:00
|
|
|
const uint32_t kAxisMinimumUsageNumber = 0x30;
|
|
|
|
// USB HID usage tables, page 1 (Hat switch)
|
|
|
|
const uint32_t kDpadMinimumUsageNumber = 0x39;
|
|
|
|
const uint32_t kAxesLengthCap = 16;
|
2014-04-14 21:18:51 +04:00
|
|
|
|
|
|
|
// USB HID usage tables
|
2019-04-08 23:21:28 +03:00
|
|
|
const uint32_t kDesktopUsagePage = 0x1;
|
|
|
|
const uint32_t kGameControlsUsagePage = 0x5;
|
|
|
|
const uint32_t kButtonUsagePage = 0x9;
|
2014-04-14 21:18:51 +04:00
|
|
|
|
2011-08-03 22:12:08 +04:00
|
|
|
// Multiple devices-changed notifications can be sent when a device
|
|
|
|
// is connected, because USB devices consist of multiple logical devices.
|
|
|
|
// Therefore, we wait a bit after receiving one before looking for
|
|
|
|
// device changes.
|
2013-04-03 04:59:27 +04:00
|
|
|
const uint32_t kDevicesChangedStableDelay = 200;
|
2016-11-28 20:52:00 +03:00
|
|
|
// Both DirectInput and XInput are polling-driven here,
|
|
|
|
// so we need to poll it periodically.
|
|
|
|
// 50ms is arbitrarily chosen.
|
|
|
|
const uint32_t kWindowsGamepadPollInterval = 50;
|
2014-04-17 03:43:39 +04:00
|
|
|
|
2014-09-02 13:07:25 +04:00
|
|
|
const UINT kRawInputError = (UINT)-1;
|
|
|
|
|
2014-04-17 03:43:39 +04:00
|
|
|
#ifndef XUSER_MAX_COUNT
|
|
|
|
# define XUSER_MAX_COUNT 4
|
|
|
|
#endif
|
2011-08-03 22:12:08 +04:00
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
const struct {
|
|
|
|
int usagePage;
|
|
|
|
int usage;
|
|
|
|
} kUsagePages[] = {
|
|
|
|
// USB HID usage tables, page 1
|
|
|
|
{kDesktopUsagePage, 4}, // Joystick
|
|
|
|
{kDesktopUsagePage, 5} // Gamepad
|
|
|
|
};
|
|
|
|
|
2014-04-17 03:43:39 +04:00
|
|
|
const struct {
|
|
|
|
WORD button;
|
|
|
|
int mapped;
|
|
|
|
} kXIButtonMap[] = {{XINPUT_GAMEPAD_DPAD_UP, 12},
|
|
|
|
{XINPUT_GAMEPAD_DPAD_DOWN, 13},
|
|
|
|
{XINPUT_GAMEPAD_DPAD_LEFT, 14},
|
|
|
|
{XINPUT_GAMEPAD_DPAD_RIGHT, 15},
|
|
|
|
{XINPUT_GAMEPAD_START, 9},
|
|
|
|
{XINPUT_GAMEPAD_BACK, 8},
|
|
|
|
{XINPUT_GAMEPAD_LEFT_THUMB, 10},
|
|
|
|
{XINPUT_GAMEPAD_RIGHT_THUMB, 11},
|
|
|
|
{XINPUT_GAMEPAD_LEFT_SHOULDER, 4},
|
|
|
|
{XINPUT_GAMEPAD_RIGHT_SHOULDER, 5},
|
|
|
|
{XINPUT_GAMEPAD_A, 0},
|
|
|
|
{XINPUT_GAMEPAD_B, 1},
|
|
|
|
{XINPUT_GAMEPAD_X, 2},
|
|
|
|
{XINPUT_GAMEPAD_Y, 3}};
|
|
|
|
const size_t kNumMappings = ArrayLength(kXIButtonMap);
|
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
enum GamepadType { kNoGamepad = 0, kRawInputGamepad, kXInputGamepad };
|
|
|
|
|
2014-04-07 22:28:08 +04:00
|
|
|
class WindowsGamepadService;
|
2016-06-28 01:25:00 +03:00
|
|
|
// This pointer holds a windows gamepad backend service,
|
|
|
|
// it will be created and destroyed by background thread and
|
|
|
|
// used by gMonitorThread
|
|
|
|
WindowsGamepadService* MOZ_NON_OWNING_REF gService = nullptr;
|
|
|
|
nsCOMPtr<nsIThread> gMonitorThread = nullptr;
|
|
|
|
static bool sIsShutdown = false;
|
2014-04-07 22:28:08 +04:00
|
|
|
|
2016-08-05 23:42:50 +03:00
|
|
|
class Gamepad {
|
|
|
|
public:
|
2014-04-14 21:18:51 +04:00
|
|
|
GamepadType type;
|
|
|
|
|
|
|
|
// Handle to raw input device
|
|
|
|
HANDLE handle;
|
|
|
|
|
2014-04-17 03:43:39 +04:00
|
|
|
// XInput Index of the user's controller. Passed to XInputGetState.
|
|
|
|
DWORD userIndex;
|
|
|
|
|
|
|
|
// Last-known state of the controller.
|
|
|
|
XINPUT_STATE state;
|
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
// ID from the GamepadService, also used as the index into
|
|
|
|
// WindowsGamepadService::mGamepads.
|
|
|
|
int id;
|
|
|
|
|
2011-08-03 22:12:08 +04:00
|
|
|
// Information about the physical device.
|
2014-04-14 21:18:51 +04:00
|
|
|
unsigned numAxes;
|
|
|
|
unsigned numButtons;
|
|
|
|
|
2016-08-05 23:42:50 +03:00
|
|
|
nsTArray<bool> buttons;
|
|
|
|
struct axisValue {
|
2014-04-14 21:18:51 +04:00
|
|
|
HIDP_VALUE_CAPS caps;
|
|
|
|
double value;
|
2019-04-08 23:21:28 +03:00
|
|
|
bool active;
|
|
|
|
|
2019-04-22 21:37:11 +03:00
|
|
|
axisValue() : value(0.0f), active(false) {}
|
2019-04-08 23:21:28 +03:00
|
|
|
explicit axisValue(const HIDP_VALUE_CAPS& aCaps)
|
|
|
|
: caps(aCaps), value(0.0f), active(true) {}
|
2016-08-05 23:42:50 +03:00
|
|
|
};
|
|
|
|
nsTArray<axisValue> axes;
|
2014-04-14 21:18:51 +04:00
|
|
|
|
2019-04-08 23:21:28 +03:00
|
|
|
RefPtr<GamepadRemapper> remapper;
|
|
|
|
|
2011-08-03 22:12:08 +04:00
|
|
|
// Used during rescan to find devices that were disconnected.
|
|
|
|
bool present;
|
2016-08-05 23:42:50 +03:00
|
|
|
|
2019-04-08 21:51:25 +03:00
|
|
|
Gamepad(uint32_t aNumAxes, uint32_t aNumButtons, GamepadType aType)
|
2016-08-05 23:42:50 +03:00
|
|
|
: type(aType), numAxes(aNumAxes), numButtons(aNumButtons), present(true) {
|
|
|
|
buttons.SetLength(numButtons);
|
|
|
|
axes.SetLength(numAxes);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-08-05 23:42:50 +03:00
|
|
|
private:
|
|
|
|
Gamepad() {}
|
2011-08-03 22:12:08 +04:00
|
|
|
};
|
|
|
|
|
2014-04-17 03:43:39 +04:00
|
|
|
// Drop this in favor of decltype when we require a new enough SDK.
|
|
|
|
typedef void(WINAPI* XInputEnable_func)(BOOL);
|
|
|
|
|
|
|
|
// RAII class to wrap loading the XInput DLL
|
|
|
|
class XInputLoader {
|
|
|
|
public:
|
|
|
|
XInputLoader()
|
2017-10-09 09:36:36 +03:00
|
|
|
: module(nullptr), mXInputGetState(nullptr), mXInputEnable(nullptr) {
|
2014-04-17 03:43:39 +04:00
|
|
|
// xinput1_4.dll exists on Windows 8
|
|
|
|
// xinput9_1_0.dll exists on Windows 7 and Vista
|
|
|
|
// xinput1_3.dll shipped with the DirectX SDK
|
|
|
|
const wchar_t* dlls[] = {L"xinput1_4.dll", L"xinput9_1_0.dll",
|
|
|
|
L"xinput1_3.dll"};
|
|
|
|
const size_t kNumDLLs = ArrayLength(dlls);
|
|
|
|
for (size_t i = 0; i < kNumDLLs; ++i) {
|
|
|
|
module = LoadLibraryW(dlls[i]);
|
|
|
|
if (module) {
|
|
|
|
mXInputEnable = reinterpret_cast<XInputEnable_func>(
|
|
|
|
GetProcAddress(module, "XInputEnable"));
|
|
|
|
mXInputGetState = reinterpret_cast<decltype(XInputGetState)*>(
|
|
|
|
GetProcAddress(module, "XInputGetState"));
|
|
|
|
if (mXInputEnable) {
|
|
|
|
mXInputEnable(TRUE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~XInputLoader() {
|
|
|
|
// mXInputEnable = nullptr;
|
|
|
|
mXInputGetState = nullptr;
|
|
|
|
|
|
|
|
if (module) {
|
|
|
|
FreeLibrary(module);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
explicit operator bool() { return module && mXInputGetState; }
|
|
|
|
|
|
|
|
HMODULE module;
|
|
|
|
decltype(XInputGetState)* mXInputGetState;
|
|
|
|
XInputEnable_func mXInputEnable;
|
|
|
|
};
|
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
bool GetPreparsedData(HANDLE handle, nsTArray<uint8_t>& data) {
|
|
|
|
UINT size;
|
2014-09-02 13:07:25 +04:00
|
|
|
if (GetRawInputDeviceInfo(handle, RIDI_PREPARSEDDATA, nullptr, &size) ==
|
|
|
|
kRawInputError) {
|
2014-04-14 21:18:51 +04:00
|
|
|
return false;
|
2011-08-03 22:12:08 +04:00
|
|
|
}
|
2014-04-14 21:18:51 +04:00
|
|
|
data.SetLength(size);
|
|
|
|
return GetRawInputDeviceInfo(handle, RIDI_PREPARSEDDATA, data.Elements(),
|
|
|
|
&size) > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given an axis value and a minimum and maximum range,
|
|
|
|
* scale it to be in the range -1.0 .. 1.0.
|
|
|
|
*/
|
|
|
|
double ScaleAxis(ULONG value, LONG min, LONG max) {
|
|
|
|
return 2.0 * (value - min) / (max - min) - 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return true if this USB HID usage page and usage are of a type we
|
|
|
|
* know how to handle.
|
|
|
|
*/
|
|
|
|
bool SupportedUsage(USHORT page, USHORT usage) {
|
|
|
|
for (unsigned i = 0; i < ArrayLength(kUsagePages); i++) {
|
|
|
|
if (page == kUsagePages[i].usagePage && usage == kUsagePages[i].usage) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2011-08-03 22:12:08 +04:00
|
|
|
}
|
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
class HIDLoader {
|
|
|
|
public:
|
2017-10-09 09:36:36 +03:00
|
|
|
HIDLoader()
|
|
|
|
: mHidD_GetProductString(nullptr),
|
2014-04-14 21:18:51 +04:00
|
|
|
mHidP_GetCaps(nullptr),
|
|
|
|
mHidP_GetButtonCaps(nullptr),
|
|
|
|
mHidP_GetValueCaps(nullptr),
|
|
|
|
mHidP_GetUsages(nullptr),
|
|
|
|
mHidP_GetUsageValue(nullptr),
|
2017-10-09 09:36:36 +03:00
|
|
|
mHidP_GetScaledUsageValue(nullptr),
|
|
|
|
mModule(LoadLibraryW(L"hid.dll")) {
|
2014-04-14 21:18:51 +04:00
|
|
|
if (mModule) {
|
|
|
|
mHidD_GetProductString =
|
|
|
|
reinterpret_cast<decltype(HidD_GetProductString)*>(
|
|
|
|
GetProcAddress(mModule, "HidD_GetProductString"));
|
|
|
|
mHidP_GetCaps = reinterpret_cast<decltype(HidP_GetCaps)*>(
|
|
|
|
GetProcAddress(mModule, "HidP_GetCaps"));
|
|
|
|
mHidP_GetButtonCaps = reinterpret_cast<decltype(HidP_GetButtonCaps)*>(
|
|
|
|
GetProcAddress(mModule, "HidP_GetButtonCaps"));
|
|
|
|
mHidP_GetValueCaps = reinterpret_cast<decltype(HidP_GetValueCaps)*>(
|
|
|
|
GetProcAddress(mModule, "HidP_GetValueCaps"));
|
|
|
|
mHidP_GetUsages = reinterpret_cast<decltype(HidP_GetUsages)*>(
|
|
|
|
GetProcAddress(mModule, "HidP_GetUsages"));
|
|
|
|
mHidP_GetUsageValue = reinterpret_cast<decltype(HidP_GetUsageValue)*>(
|
|
|
|
GetProcAddress(mModule, "HidP_GetUsageValue"));
|
|
|
|
mHidP_GetScaledUsageValue =
|
|
|
|
reinterpret_cast<decltype(HidP_GetScaledUsageValue)*>(
|
|
|
|
GetProcAddress(mModule, "HidP_GetScaledUsageValue"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~HIDLoader() {
|
|
|
|
if (mModule) {
|
|
|
|
FreeLibrary(mModule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-16 10:49:53 +03:00
|
|
|
explicit operator bool() {
|
2014-04-14 21:18:51 +04:00
|
|
|
return mModule && mHidD_GetProductString && mHidP_GetCaps &&
|
|
|
|
mHidP_GetButtonCaps && mHidP_GetValueCaps && mHidP_GetUsages &&
|
|
|
|
mHidP_GetUsageValue && mHidP_GetScaledUsageValue;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
decltype(HidD_GetProductString)* mHidD_GetProductString;
|
|
|
|
decltype(HidP_GetCaps)* mHidP_GetCaps;
|
|
|
|
decltype(HidP_GetButtonCaps)* mHidP_GetButtonCaps;
|
|
|
|
decltype(HidP_GetValueCaps)* mHidP_GetValueCaps;
|
|
|
|
decltype(HidP_GetUsages)* mHidP_GetUsages;
|
|
|
|
decltype(HidP_GetUsageValue)* mHidP_GetUsageValue;
|
|
|
|
decltype(HidP_GetScaledUsageValue)* mHidP_GetScaledUsageValue;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
private:
|
|
|
|
HMODULE mModule;
|
|
|
|
};
|
|
|
|
|
2016-12-29 23:00:00 +03:00
|
|
|
HWND sHWnd = nullptr;
|
|
|
|
|
|
|
|
static void DirectInputMessageLoopOnceCallback(nsITimer* aTimer,
|
|
|
|
void* aClosure) {
|
|
|
|
MOZ_ASSERT(NS_GetCurrentThread() == gMonitorThread);
|
|
|
|
MSG msg;
|
2017-06-05 15:52:16 +03:00
|
|
|
while (PeekMessageW(&msg, sHWnd, 0, 0, PM_REMOVE) > 0) {
|
2016-12-29 23:00:00 +03:00
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
|
|
|
aTimer->Cancel();
|
|
|
|
if (!sIsShutdown) {
|
2017-06-29 22:13:25 +03:00
|
|
|
aTimer->InitWithNamedFuncCallback(DirectInputMessageLoopOnceCallback,
|
|
|
|
nullptr, kWindowsGamepadPollInterval,
|
|
|
|
nsITimer::TYPE_ONE_SHOT,
|
|
|
|
"DirectInputMessageLoopOnceCallback");
|
2016-12-29 23:00:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-28 01:25:00 +03:00
|
|
|
class WindowsGamepadService {
|
|
|
|
public:
|
|
|
|
WindowsGamepadService() {
|
2017-10-16 09:15:40 +03:00
|
|
|
mDirectInputTimer = NS_NewTimer();
|
|
|
|
mXInputTimer = NS_NewTimer();
|
|
|
|
mDeviceChangeTimer = NS_NewTimer();
|
2016-06-28 01:25:00 +03:00
|
|
|
}
|
2014-04-14 21:18:51 +04:00
|
|
|
virtual ~WindowsGamepadService() { Cleanup(); }
|
2011-08-03 22:12:08 +04:00
|
|
|
|
2016-06-28 01:25:00 +03:00
|
|
|
void DevicesChanged(bool aIsStablizing);
|
2016-12-29 23:00:00 +03:00
|
|
|
|
|
|
|
void StartMessageLoop() {
|
|
|
|
MOZ_ASSERT(mDirectInputTimer);
|
2017-06-29 22:13:25 +03:00
|
|
|
mDirectInputTimer->InitWithNamedFuncCallback(
|
|
|
|
DirectInputMessageLoopOnceCallback, nullptr,
|
|
|
|
kWindowsGamepadPollInterval, nsITimer::TYPE_ONE_SHOT,
|
|
|
|
"DirectInputMessageLoopOnceCallback");
|
2016-12-29 23:00:00 +03:00
|
|
|
}
|
|
|
|
|
2011-08-03 22:12:08 +04:00
|
|
|
void Startup();
|
|
|
|
void Shutdown();
|
2014-04-14 21:18:51 +04:00
|
|
|
// Parse gamepad input from a WM_INPUT message.
|
|
|
|
bool HandleRawInput(HRAWINPUT handle);
|
2019-05-30 03:21:59 +03:00
|
|
|
void SetLightIndicatorColor(uint32_t aControllerIdx, uint32_t aLightIndex,
|
|
|
|
uint8_t aRed, uint8_t aGreen, uint8_t aBlue);
|
|
|
|
size_t WriteOutputReport(const std::vector<uint8_t>& aReport);
|
2016-06-28 01:25:00 +03:00
|
|
|
static void XInputMessageLoopOnceCallback(nsITimer* aTimer, void* aClosure);
|
|
|
|
static void DevicesChangeCallback(nsITimer* aTimer, void* aService);
|
|
|
|
|
|
|
|
private:
|
2011-08-03 22:12:08 +04:00
|
|
|
void ScanForDevices();
|
2014-04-14 21:18:51 +04:00
|
|
|
// Look for connected raw input devices.
|
|
|
|
void ScanForRawInputDevices();
|
2014-04-17 03:43:39 +04:00
|
|
|
// Look for connected XInput devices.
|
|
|
|
bool ScanForXInputDevices();
|
2017-09-29 01:00:05 +03:00
|
|
|
bool HaveXInputGamepad(unsigned int userIndex);
|
2014-04-17 03:43:39 +04:00
|
|
|
|
2016-06-28 01:25:00 +03:00
|
|
|
bool mIsXInputMonitoring;
|
2014-04-17 03:43:39 +04:00
|
|
|
void PollXInput();
|
|
|
|
void CheckXInputChanges(Gamepad& gamepad, XINPUT_STATE& state);
|
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
// Get information about a raw input gamepad.
|
|
|
|
bool GetRawGamepad(HANDLE handle);
|
2011-08-03 22:12:08 +04:00
|
|
|
void Cleanup();
|
|
|
|
|
|
|
|
// List of connected devices.
|
|
|
|
nsTArray<Gamepad> mGamepads;
|
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
HIDLoader mHID;
|
2019-05-30 03:21:59 +03:00
|
|
|
nsAutoHandle mHidHandle;
|
2014-04-17 03:43:39 +04:00
|
|
|
XInputLoader mXInput;
|
2016-06-28 01:25:00 +03:00
|
|
|
|
2016-12-29 23:00:00 +03:00
|
|
|
nsCOMPtr<nsITimer> mDirectInputTimer;
|
2016-06-28 01:25:00 +03:00
|
|
|
nsCOMPtr<nsITimer> mXInputTimer;
|
|
|
|
nsCOMPtr<nsITimer> mDeviceChangeTimer;
|
2011-08-03 22:12:08 +04:00
|
|
|
};
|
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
void WindowsGamepadService::ScanForRawInputDevices() {
|
|
|
|
if (!mHID) {
|
|
|
|
return;
|
2014-04-07 22:28:08 +04:00
|
|
|
}
|
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
UINT numDevices;
|
|
|
|
if (GetRawInputDeviceList(nullptr, &numDevices, sizeof(RAWINPUTDEVICELIST)) ==
|
2014-09-02 13:07:25 +04:00
|
|
|
kRawInputError) {
|
2014-04-14 21:18:51 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsTArray<RAWINPUTDEVICELIST> devices(numDevices);
|
|
|
|
devices.SetLength(numDevices);
|
|
|
|
if (GetRawInputDeviceList(devices.Elements(), &numDevices,
|
2014-09-02 13:07:25 +04:00
|
|
|
sizeof(RAWINPUTDEVICELIST)) == kRawInputError) {
|
2014-04-14 21:18:51 +04:00
|
|
|
return;
|
|
|
|
}
|
2014-04-07 22:28:08 +04:00
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
for (unsigned i = 0; i < devices.Length(); i++) {
|
|
|
|
if (devices[i].dwType == RIM_TYPEHID) {
|
|
|
|
GetRawGamepad(devices[i].hDevice);
|
2014-04-07 22:28:08 +04:00
|
|
|
}
|
|
|
|
}
|
2014-04-14 21:18:51 +04:00
|
|
|
}
|
2014-04-07 22:28:08 +04:00
|
|
|
|
2016-06-28 01:25:00 +03:00
|
|
|
// static
|
|
|
|
void WindowsGamepadService::XInputMessageLoopOnceCallback(nsITimer* aTimer,
|
|
|
|
void* aService) {
|
|
|
|
MOZ_ASSERT(aService);
|
|
|
|
WindowsGamepadService* self = static_cast<WindowsGamepadService*>(aService);
|
|
|
|
self->PollXInput();
|
|
|
|
if (self->mIsXInputMonitoring) {
|
|
|
|
aTimer->Cancel();
|
2017-06-29 22:13:25 +03:00
|
|
|
aTimer->InitWithNamedFuncCallback(
|
|
|
|
XInputMessageLoopOnceCallback, self, kWindowsGamepadPollInterval,
|
|
|
|
nsITimer::TYPE_ONE_SHOT, "XInputMessageLoopOnceCallback");
|
2016-06-28 01:25:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void WindowsGamepadService::DevicesChangeCallback(nsITimer* aTimer,
|
|
|
|
void* aService) {
|
|
|
|
MOZ_ASSERT(aService);
|
|
|
|
WindowsGamepadService* self = static_cast<WindowsGamepadService*>(aService);
|
|
|
|
self->DevicesChanged(false);
|
|
|
|
}
|
|
|
|
|
2017-09-29 01:00:05 +03:00
|
|
|
bool WindowsGamepadService::HaveXInputGamepad(unsigned int userIndex) {
|
2014-04-17 03:43:39 +04:00
|
|
|
for (unsigned int i = 0; i < mGamepads.Length(); i++) {
|
|
|
|
if (mGamepads[i].type == kXInputGamepad &&
|
|
|
|
mGamepads[i].userIndex == userIndex) {
|
|
|
|
mGamepads[i].present = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WindowsGamepadService::ScanForXInputDevices() {
|
|
|
|
MOZ_ASSERT(mXInput, "XInput should be present!");
|
|
|
|
|
|
|
|
bool found = false;
|
2016-06-28 01:27:00 +03:00
|
|
|
RefPtr<GamepadPlatformService> service =
|
|
|
|
GamepadPlatformService::GetParentService();
|
|
|
|
if (!service) {
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2017-09-29 01:00:05 +03:00
|
|
|
for (unsigned int i = 0; i < XUSER_MAX_COUNT; i++) {
|
2014-04-17 03:43:39 +04:00
|
|
|
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.
|
2019-04-08 21:51:25 +03:00
|
|
|
Gamepad gamepad(kStandardGamepadAxes, kStandardGamepadButtons,
|
|
|
|
kXInputGamepad);
|
2014-04-17 03:43:39 +04:00
|
|
|
gamepad.userIndex = i;
|
2016-08-05 23:42:50 +03:00
|
|
|
gamepad.state = state;
|
2016-06-28 01:25:00 +03:00
|
|
|
gamepad.id = service->AddGamepad(
|
|
|
|
"xinput", GamepadMappingType::Standard, GamepadHand::_empty,
|
2019-05-30 03:21:59 +03:00
|
|
|
kStandardGamepadButtons, kStandardGamepadAxes, 0, 0,
|
2017-02-02 10:00:51 +03:00
|
|
|
0); // TODO: Bug 680289, implement gamepad haptics for Windows.
|
2020-05-11 11:20:52 +03:00
|
|
|
mGamepads.AppendElement(std::move(gamepad));
|
2014-04-17 03:43:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
void WindowsGamepadService::ScanForDevices() {
|
2016-06-28 01:27:00 +03:00
|
|
|
RefPtr<GamepadPlatformService> service =
|
|
|
|
GamepadPlatformService::GetParentService();
|
|
|
|
if (!service) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
for (int i = mGamepads.Length() - 1; i >= 0; i--) {
|
|
|
|
mGamepads[i].present = false;
|
|
|
|
}
|
2014-04-07 22:28:08 +04:00
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
if (mHID) {
|
|
|
|
ScanForRawInputDevices();
|
2011-08-03 22:12:08 +04:00
|
|
|
}
|
2014-04-17 03:43:39 +04:00
|
|
|
if (mXInput) {
|
2016-06-28 01:25:00 +03:00
|
|
|
mXInputTimer->Cancel();
|
2014-04-17 03:43:39 +04:00
|
|
|
if (ScanForXInputDevices()) {
|
2016-06-28 01:25:00 +03:00
|
|
|
mIsXInputMonitoring = true;
|
2017-06-29 22:13:25 +03:00
|
|
|
mXInputTimer->InitWithNamedFuncCallback(
|
|
|
|
XInputMessageLoopOnceCallback, this, kWindowsGamepadPollInterval,
|
|
|
|
nsITimer::TYPE_ONE_SHOT, "XInputMessageLoopOnceCallback");
|
2016-06-28 01:25:00 +03:00
|
|
|
} else {
|
|
|
|
mIsXInputMonitoring = false;
|
2014-04-17 03:43:39 +04:00
|
|
|
}
|
|
|
|
}
|
2011-08-03 22:12:08 +04:00
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
// Look for devices that are no longer present and remove them.
|
|
|
|
for (int i = mGamepads.Length() - 1; i >= 0; i--) {
|
|
|
|
if (!mGamepads[i].present) {
|
2016-06-28 01:25:00 +03:00
|
|
|
service->RemoveGamepad(mGamepads[i].id);
|
2014-04-14 21:18:51 +04:00
|
|
|
mGamepads.RemoveElementAt(i);
|
|
|
|
}
|
|
|
|
}
|
2011-08-03 22:12:08 +04:00
|
|
|
}
|
|
|
|
|
2014-04-17 03:43:39 +04:00
|
|
|
void WindowsGamepadService::PollXInput() {
|
|
|
|
for (unsigned int i = 0; i < mGamepads.Length(); i++) {
|
|
|
|
if (mGamepads[i].type != kXInputGamepad) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
XINPUT_STATE state = {};
|
|
|
|
DWORD res = mXInput.mXInputGetState(mGamepads[i].userIndex, &state);
|
|
|
|
if (res == ERROR_SUCCESS &&
|
|
|
|
state.dwPacketNumber != mGamepads[i].state.dwPacketNumber) {
|
|
|
|
CheckXInputChanges(mGamepads[i], state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WindowsGamepadService::CheckXInputChanges(Gamepad& gamepad,
|
|
|
|
XINPUT_STATE& state) {
|
2016-06-28 01:27:00 +03:00
|
|
|
RefPtr<GamepadPlatformService> service =
|
2016-06-28 01:25:00 +03:00
|
|
|
GamepadPlatformService::GetParentService();
|
2016-06-28 01:27:00 +03:00
|
|
|
if (!service) {
|
|
|
|
return;
|
|
|
|
}
|
2014-04-17 03:43:39 +04:00
|
|
|
// Handle digital buttons first
|
|
|
|
for (size_t b = 0; b < kNumMappings; b++) {
|
|
|
|
if (state.Gamepad.wButtons & kXIButtonMap[b].button &&
|
|
|
|
!(gamepad.state.Gamepad.wButtons & kXIButtonMap[b].button)) {
|
|
|
|
// Button pressed
|
2016-06-28 01:25:00 +03:00
|
|
|
service->NewButtonEvent(gamepad.id, kXIButtonMap[b].mapped, true);
|
2014-04-17 03:43:39 +04:00
|
|
|
} else if (!(state.Gamepad.wButtons & kXIButtonMap[b].button) &&
|
|
|
|
gamepad.state.Gamepad.wButtons & kXIButtonMap[b].button) {
|
|
|
|
// Button released
|
2016-06-28 01:25:00 +03:00
|
|
|
service->NewButtonEvent(gamepad.id, kXIButtonMap[b].mapped, false);
|
2014-04-17 03:43:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Then triggers
|
|
|
|
if (state.Gamepad.bLeftTrigger != gamepad.state.Gamepad.bLeftTrigger) {
|
2020-02-12 05:16:13 +03:00
|
|
|
const bool pressed =
|
2014-04-17 03:43:39 +04:00
|
|
|
state.Gamepad.bLeftTrigger >= XINPUT_GAMEPAD_TRIGGER_THRESHOLD;
|
2016-06-28 01:25:00 +03:00
|
|
|
service->NewButtonEvent(gamepad.id, kButtonLeftTrigger, pressed,
|
|
|
|
state.Gamepad.bLeftTrigger / 255.0);
|
2014-04-17 03:43:39 +04:00
|
|
|
}
|
|
|
|
if (state.Gamepad.bRightTrigger != gamepad.state.Gamepad.bRightTrigger) {
|
2020-02-12 05:16:13 +03:00
|
|
|
const bool pressed =
|
2014-04-17 03:43:39 +04:00
|
|
|
state.Gamepad.bRightTrigger >= XINPUT_GAMEPAD_TRIGGER_THRESHOLD;
|
2016-06-28 01:25:00 +03:00
|
|
|
service->NewButtonEvent(gamepad.id, kButtonRightTrigger, pressed,
|
|
|
|
state.Gamepad.bRightTrigger / 255.0);
|
2014-04-17 03:43:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Finally deal with analog sticks
|
|
|
|
// TODO: bug 1001955 - Support deadzones.
|
|
|
|
if (state.Gamepad.sThumbLX != gamepad.state.Gamepad.sThumbLX) {
|
2020-02-12 05:16:13 +03:00
|
|
|
const float div = state.Gamepad.sThumbLX > 0 ? 32767.0 : 32768.0;
|
2016-06-28 01:25:00 +03:00
|
|
|
service->NewAxisMoveEvent(gamepad.id, kLeftStickXAxis,
|
2020-02-12 05:16:13 +03:00
|
|
|
state.Gamepad.sThumbLX / div);
|
2014-04-17 03:43:39 +04:00
|
|
|
}
|
|
|
|
if (state.Gamepad.sThumbLY != gamepad.state.Gamepad.sThumbLY) {
|
2020-02-12 05:16:13 +03:00
|
|
|
const float div = state.Gamepad.sThumbLY > 0 ? 32767.0 : 32768.0;
|
2016-06-28 01:25:00 +03:00
|
|
|
service->NewAxisMoveEvent(gamepad.id, kLeftStickYAxis,
|
2020-02-12 05:16:13 +03:00
|
|
|
-1.0 * state.Gamepad.sThumbLY / div);
|
2014-04-17 03:43:39 +04:00
|
|
|
}
|
|
|
|
if (state.Gamepad.sThumbRX != gamepad.state.Gamepad.sThumbRX) {
|
2020-02-12 05:16:13 +03:00
|
|
|
const float div = state.Gamepad.sThumbRX > 0 ? 32767.0 : 32768.0;
|
2016-06-28 01:25:00 +03:00
|
|
|
service->NewAxisMoveEvent(gamepad.id, kRightStickXAxis,
|
2020-02-12 05:16:13 +03:00
|
|
|
state.Gamepad.sThumbRX / div);
|
2014-04-17 03:43:39 +04:00
|
|
|
}
|
|
|
|
if (state.Gamepad.sThumbRY != gamepad.state.Gamepad.sThumbRY) {
|
2020-02-12 05:16:13 +03:00
|
|
|
const float div = state.Gamepad.sThumbRY > 0 ? 32767.0 : 32768.0;
|
2016-06-28 01:25:00 +03:00
|
|
|
service->NewAxisMoveEvent(gamepad.id, kRightStickYAxis,
|
2020-02-12 05:16:13 +03:00
|
|
|
-1.0 * state.Gamepad.sThumbRY / div);
|
2014-04-17 03:43:39 +04:00
|
|
|
}
|
|
|
|
gamepad.state = state;
|
|
|
|
}
|
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
// Used to sort a list of axes by HID usage.
|
|
|
|
class HidValueComparator {
|
|
|
|
public:
|
2019-04-08 23:21:28 +03:00
|
|
|
bool Equals(const Gamepad::axisValue& c1,
|
|
|
|
const Gamepad::axisValue& c2) const {
|
|
|
|
return c1.caps.UsagePage == c2.caps.UsagePage &&
|
|
|
|
c1.caps.Range.UsageMin == c2.caps.Range.UsageMin;
|
|
|
|
}
|
|
|
|
bool LessThan(const Gamepad::axisValue& c1,
|
|
|
|
const Gamepad::axisValue& c2) const {
|
|
|
|
if (c1.caps.UsagePage == c2.caps.UsagePage) {
|
|
|
|
return c1.caps.Range.UsageMin < c2.caps.Range.UsageMin;
|
2011-08-03 22:12:08 +04:00
|
|
|
}
|
2019-04-08 23:21:28 +03:00
|
|
|
return c1.caps.UsagePage < c2.caps.UsagePage;
|
2011-08-03 22:12:08 +04:00
|
|
|
}
|
2014-04-14 21:18:51 +04:00
|
|
|
};
|
2011-08-03 22:12:08 +04:00
|
|
|
|
2019-04-08 23:21:28 +03:00
|
|
|
// GetRawGamepad() processes its raw data from HID and
|
|
|
|
// then trying to remapping buttons and axes based on
|
|
|
|
// the mapping rules that are defined for different gamepad products.
|
2014-04-14 21:18:51 +04:00
|
|
|
bool WindowsGamepadService::GetRawGamepad(HANDLE handle) {
|
2016-06-28 01:27:00 +03:00
|
|
|
RefPtr<GamepadPlatformService> service =
|
|
|
|
GamepadPlatformService::GetParentService();
|
|
|
|
if (!service) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
if (!mHID) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < mGamepads.Length(); i++) {
|
|
|
|
if (mGamepads[i].type == kRawInputGamepad &&
|
|
|
|
mGamepads[i].handle == handle) {
|
|
|
|
mGamepads[i].present = true;
|
|
|
|
return true;
|
2011-08-03 22:12:08 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
RID_DEVICE_INFO rdi = {};
|
|
|
|
UINT size = rdi.cbSize = sizeof(RID_DEVICE_INFO);
|
2014-09-02 13:07:25 +04:00
|
|
|
if (GetRawInputDeviceInfo(handle, RIDI_DEVICEINFO, &rdi, &size) ==
|
|
|
|
kRawInputError) {
|
2014-04-14 21:18:51 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Ensure that this is a device we care about
|
|
|
|
if (!SupportedUsage(rdi.hid.usUsagePage, rdi.hid.usUsage)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Device name is a mostly-opaque string.
|
2014-09-02 13:07:25 +04:00
|
|
|
if (GetRawInputDeviceInfo(handle, RIDI_DEVICENAME, nullptr, &size) ==
|
|
|
|
kRawInputError) {
|
2014-04-14 21:18:51 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<wchar_t> devname(size);
|
|
|
|
devname.SetLength(size);
|
2014-09-02 13:07:25 +04:00
|
|
|
if (GetRawInputDeviceInfo(handle, RIDI_DEVICENAME, devname.Elements(),
|
|
|
|
&size) == kRawInputError) {
|
2014-04-14 21:18:51 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Per http://msdn.microsoft.com/en-us/library/windows/desktop/ee417014.aspx
|
|
|
|
// device names containing "IG_" are XInput controllers. Ignore those
|
|
|
|
// devices since we'll handle them with XInput.
|
|
|
|
if (wcsstr(devname.Elements(), L"IG_")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Product string is a human-readable name.
|
|
|
|
// Per
|
|
|
|
// http://msdn.microsoft.com/en-us/library/windows/hardware/ff539681%28v=vs.85%29.aspx
|
|
|
|
// "For USB devices, the maximum string length is 126 wide characters (not
|
|
|
|
// including the terminating NULL character)."
|
|
|
|
wchar_t name[128] = {0};
|
|
|
|
size = sizeof(name);
|
|
|
|
nsTArray<char> gamepad_name;
|
2019-05-30 03:21:59 +03:00
|
|
|
// Creating this file with FILE_FLAG_OVERLAPPED to perform
|
|
|
|
// an asynchronous request in WriteOutputReport.
|
|
|
|
mHidHandle.own(CreateFile(devname.Elements(), GENERIC_READ | GENERIC_WRITE,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr,
|
|
|
|
OPEN_EXISTING, FILE_FLAG_OVERLAPPED, nullptr));
|
|
|
|
if (mHidHandle != INVALID_HANDLE_VALUE) {
|
|
|
|
if (mHID.mHidD_GetProductString(mHidHandle, &name, size)) {
|
2014-04-14 21:18:51 +04:00
|
|
|
int bytes = WideCharToMultiByte(CP_UTF8, 0, name, -1, nullptr, 0, nullptr,
|
|
|
|
nullptr);
|
|
|
|
gamepad_name.SetLength(bytes);
|
|
|
|
WideCharToMultiByte(CP_UTF8, 0, name, -1, gamepad_name.Elements(), bytes,
|
|
|
|
nullptr, nullptr);
|
2014-04-07 22:28:08 +04:00
|
|
|
}
|
2014-04-14 21:18:51 +04:00
|
|
|
}
|
|
|
|
if (gamepad_name.Length() == 0 || !gamepad_name[0]) {
|
|
|
|
const char kUnknown[] = "Unknown Gamepad";
|
|
|
|
gamepad_name.SetLength(ArrayLength(kUnknown));
|
|
|
|
strcpy_s(gamepad_name.Elements(), gamepad_name.Length(), kUnknown);
|
2011-08-03 22:12:08 +04:00
|
|
|
}
|
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
char gamepad_id[256] = {0};
|
|
|
|
_snprintf_s(gamepad_id, _TRUNCATE, "%04x-%04x-%s", rdi.hid.dwVendorId,
|
|
|
|
rdi.hid.dwProductId, gamepad_name.Elements());
|
2011-08-03 22:12:08 +04:00
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
nsTArray<uint8_t> preparsedbytes;
|
|
|
|
if (!GetPreparsedData(handle, preparsedbytes)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
PHIDP_PREPARSED_DATA parsed =
|
|
|
|
reinterpret_cast<PHIDP_PREPARSED_DATA>(preparsedbytes.Elements());
|
|
|
|
HIDP_CAPS caps;
|
|
|
|
if (mHID.mHidP_GetCaps(parsed, &caps) != HIDP_STATUS_SUCCESS) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enumerate buttons.
|
|
|
|
USHORT count = caps.NumberInputButtonCaps;
|
|
|
|
nsTArray<HIDP_BUTTON_CAPS> buttonCaps(count);
|
|
|
|
buttonCaps.SetLength(count);
|
|
|
|
if (mHID.mHidP_GetButtonCaps(HidP_Input, buttonCaps.Elements(), &count,
|
|
|
|
parsed) != HIDP_STATUS_SUCCESS) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-08-05 23:42:50 +03:00
|
|
|
uint32_t numButtons = 0;
|
2014-04-14 21:18:51 +04:00
|
|
|
for (unsigned i = 0; i < count; i++) {
|
|
|
|
// Each buttonCaps is typically a range of buttons.
|
2016-08-05 23:42:50 +03:00
|
|
|
numButtons +=
|
2014-04-14 21:18:51 +04:00
|
|
|
buttonCaps[i].Range.UsageMax - buttonCaps[i].Range.UsageMin + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enumerate value caps, which represent axes and d-pads.
|
|
|
|
count = caps.NumberInputValueCaps;
|
2019-04-08 23:21:28 +03:00
|
|
|
nsTArray<HIDP_VALUE_CAPS> axisCaps(count);
|
|
|
|
axisCaps.SetLength(count);
|
|
|
|
if (mHID.mHidP_GetValueCaps(HidP_Input, axisCaps.Elements(), &count,
|
2014-04-14 21:18:51 +04:00
|
|
|
parsed) != HIDP_STATUS_SUCCESS) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-08-05 23:42:50 +03:00
|
|
|
|
2019-04-08 23:21:28 +03:00
|
|
|
size_t numAxes = 0;
|
|
|
|
nsTArray<Gamepad::axisValue> axes(kAxesLengthCap);
|
|
|
|
// We store these value caps and handle the dpad info in GamepadRemapper
|
|
|
|
// later.
|
|
|
|
axes.SetLength(kAxesLengthCap);
|
|
|
|
|
|
|
|
// Looking for the exisiting ramapping rule.
|
2019-12-06 22:19:50 +03:00
|
|
|
bool defaultRemapper = false;
|
|
|
|
RefPtr<GamepadRemapper> remapper = GetGamepadRemapper(
|
|
|
|
rdi.hid.dwVendorId, rdi.hid.dwProductId, defaultRemapper);
|
2019-04-08 23:21:28 +03:00
|
|
|
MOZ_ASSERT(remapper);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < count; i++) {
|
|
|
|
const size_t axisIndex =
|
|
|
|
axisCaps[i].Range.UsageMin - kAxisMinimumUsageNumber;
|
|
|
|
if (axisIndex < kAxesLengthCap && !axes[axisIndex].active) {
|
|
|
|
axes[axisIndex].caps = axisCaps[i];
|
|
|
|
axes[axisIndex].active = true;
|
|
|
|
numAxes = std::max(numAxes, axisIndex + 1);
|
2011-08-03 22:12:08 +04:00
|
|
|
}
|
2014-04-14 21:18:51 +04:00
|
|
|
}
|
2011-08-03 22:12:08 +04:00
|
|
|
|
2016-08-05 23:42:50 +03:00
|
|
|
// Not already present, add it.
|
|
|
|
|
2019-04-08 23:21:28 +03:00
|
|
|
remapper->SetAxisCount(numAxes);
|
|
|
|
remapper->SetButtonCount(numButtons);
|
|
|
|
Gamepad gamepad(numAxes, numButtons, kRawInputGamepad);
|
2016-08-05 23:42:50 +03:00
|
|
|
gamepad.handle = handle;
|
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
for (unsigned i = 0; i < gamepad.numAxes; i++) {
|
2019-04-08 23:21:28 +03:00
|
|
|
gamepad.axes[i] = axes[i];
|
2011-08-03 22:12:08 +04:00
|
|
|
}
|
2016-08-05 23:42:50 +03:00
|
|
|
|
2019-04-08 23:21:28 +03:00
|
|
|
gamepad.remapper = remapper.forget();
|
2019-05-30 03:21:59 +03:00
|
|
|
// TODO: Bug 680289, implement gamepad haptics for Windows.
|
2019-04-08 23:21:28 +03:00
|
|
|
gamepad.id = service->AddGamepad(
|
|
|
|
gamepad_id, gamepad.remapper->GetMappingType(), GamepadHand::_empty,
|
2019-05-30 03:21:59 +03:00
|
|
|
gamepad.remapper->GetButtonCount(), gamepad.remapper->GetAxisCount(), 0,
|
|
|
|
gamepad.remapper->GetLightIndicatorCount(),
|
|
|
|
gamepad.remapper->GetTouchEventCount());
|
|
|
|
|
|
|
|
nsTArray<GamepadLightIndicatorType> lightTypes;
|
|
|
|
gamepad.remapper->GetLightIndicators(lightTypes);
|
|
|
|
for (uint32_t i = 0; i < lightTypes.Length(); ++i) {
|
|
|
|
if (lightTypes[i] != GamepadLightIndicator::DefaultType()) {
|
|
|
|
service->NewLightIndicatorTypeEvent(gamepad.id, i, lightTypes[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-11 11:20:52 +03:00
|
|
|
mGamepads.AppendElement(std::move(gamepad));
|
2014-04-14 21:18:51 +04:00
|
|
|
return true;
|
2011-08-03 22:12:08 +04:00
|
|
|
}
|
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
bool WindowsGamepadService::HandleRawInput(HRAWINPUT handle) {
|
|
|
|
if (!mHID) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-06-28 01:27:00 +03:00
|
|
|
RefPtr<GamepadPlatformService> service =
|
|
|
|
GamepadPlatformService::GetParentService();
|
2016-08-08 21:33:26 +03:00
|
|
|
if (!service) {
|
|
|
|
return false;
|
2016-06-28 01:27:00 +03:00
|
|
|
}
|
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
// First, get data from the handle
|
|
|
|
UINT size;
|
|
|
|
GetRawInputData(handle, RID_INPUT, nullptr, &size, sizeof(RAWINPUTHEADER));
|
|
|
|
nsTArray<uint8_t> data(size);
|
|
|
|
data.SetLength(size);
|
|
|
|
if (GetRawInputData(handle, RID_INPUT, data.Elements(), &size,
|
2014-09-02 13:07:25 +04:00
|
|
|
sizeof(RAWINPUTHEADER)) == kRawInputError) {
|
2014-04-14 21:18:51 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
PRAWINPUT raw = reinterpret_cast<PRAWINPUT>(data.Elements());
|
|
|
|
|
|
|
|
Gamepad* gamepad = nullptr;
|
|
|
|
for (unsigned i = 0; i < mGamepads.Length(); i++) {
|
|
|
|
if (mGamepads[i].type == kRawInputGamepad &&
|
|
|
|
mGamepads[i].handle == raw->header.hDevice) {
|
|
|
|
gamepad = &mGamepads[i];
|
2011-08-03 22:12:08 +04:00
|
|
|
break;
|
|
|
|
}
|
2014-04-14 21:18:51 +04:00
|
|
|
}
|
|
|
|
if (gamepad == nullptr) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-08-03 22:12:08 +04:00
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
// Second, get the preparsed data
|
|
|
|
nsTArray<uint8_t> parsedbytes;
|
|
|
|
if (!GetPreparsedData(raw->header.hDevice, parsedbytes)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
PHIDP_PREPARSED_DATA parsed =
|
|
|
|
reinterpret_cast<PHIDP_PREPARSED_DATA>(parsedbytes.Elements());
|
|
|
|
|
|
|
|
// Get all the pressed buttons.
|
|
|
|
nsTArray<USAGE> usages(gamepad->numButtons);
|
|
|
|
usages.SetLength(gamepad->numButtons);
|
|
|
|
ULONG usageLength = gamepad->numButtons;
|
|
|
|
if (mHID.mHidP_GetUsages(HidP_Input, kButtonUsagePage, 0, usages.Elements(),
|
|
|
|
&usageLength, parsed, (PCHAR)raw->data.hid.bRawData,
|
|
|
|
raw->data.hid.dwSizeHid) != HIDP_STATUS_SUCCESS) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-05 23:42:50 +03:00
|
|
|
nsTArray<bool> buttons(gamepad->numButtons);
|
|
|
|
buttons.SetLength(gamepad->numButtons);
|
|
|
|
// If we don't zero out the buttons array first, sometimes it can reuse
|
|
|
|
// values.
|
|
|
|
memset(buttons.Elements(), 0, gamepad->numButtons * sizeof(bool));
|
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
for (unsigned i = 0; i < usageLength; i++) {
|
2018-03-17 04:20:31 +03:00
|
|
|
// The button index in usages may be larger than what we detected when
|
|
|
|
// enumerating gamepads. If so, warn and continue.
|
|
|
|
//
|
|
|
|
// Usage ID of 0 is reserved, so it should always be 1 or higher.
|
|
|
|
if (NS_WARN_IF((usages[i] - 1u) >= buttons.Length())) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
buttons[usages[i] - 1u] = true;
|
2014-04-14 21:18:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < gamepad->numButtons; i++) {
|
|
|
|
if (gamepad->buttons[i] != buttons[i]) {
|
2019-04-08 23:21:28 +03:00
|
|
|
gamepad->remapper->RemapButtonEvent(gamepad->id, i, buttons[i]);
|
2014-04-14 21:18:51 +04:00
|
|
|
gamepad->buttons[i] = buttons[i];
|
2011-08-03 22:12:08 +04:00
|
|
|
}
|
2014-04-14 21:18:51 +04:00
|
|
|
}
|
2011-08-03 22:12:08 +04:00
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
// Get all axis values.
|
|
|
|
for (unsigned i = 0; i < gamepad->numAxes; i++) {
|
|
|
|
double new_value;
|
|
|
|
if (gamepad->axes[i].caps.LogicalMin < 0) {
|
|
|
|
LONG value;
|
|
|
|
if (mHID.mHidP_GetScaledUsageValue(
|
|
|
|
HidP_Input, gamepad->axes[i].caps.UsagePage, 0,
|
|
|
|
gamepad->axes[i].caps.Range.UsageMin, &value, parsed,
|
|
|
|
(PCHAR)raw->data.hid.bRawData,
|
|
|
|
raw->data.hid.dwSizeHid) != HIDP_STATUS_SUCCESS) {
|
2014-04-07 22:28:08 +04:00
|
|
|
continue;
|
|
|
|
}
|
2014-04-14 21:18:51 +04:00
|
|
|
new_value = ScaleAxis(value, gamepad->axes[i].caps.LogicalMin,
|
|
|
|
gamepad->axes[i].caps.LogicalMax);
|
2016-06-28 01:25:00 +03:00
|
|
|
} else {
|
2014-04-14 21:18:51 +04:00
|
|
|
ULONG value;
|
|
|
|
if (mHID.mHidP_GetUsageValue(
|
|
|
|
HidP_Input, gamepad->axes[i].caps.UsagePage, 0,
|
|
|
|
gamepad->axes[i].caps.Range.UsageMin, &value, parsed,
|
|
|
|
(PCHAR)raw->data.hid.bRawData,
|
|
|
|
raw->data.hid.dwSizeHid) != HIDP_STATUS_SUCCESS) {
|
|
|
|
continue;
|
2011-08-03 22:12:08 +04:00
|
|
|
}
|
2014-04-14 21:18:51 +04:00
|
|
|
|
|
|
|
new_value = ScaleAxis(value, gamepad->axes[i].caps.LogicalMin,
|
|
|
|
gamepad->axes[i].caps.LogicalMax);
|
|
|
|
}
|
|
|
|
if (gamepad->axes[i].value != new_value) {
|
2019-04-08 23:21:28 +03:00
|
|
|
gamepad->remapper->RemapAxisMoveEvent(gamepad->id, i, new_value);
|
2014-04-14 21:18:51 +04:00
|
|
|
gamepad->axes[i].value = new_value;
|
2011-08-03 22:12:08 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-30 03:21:59 +03:00
|
|
|
BYTE* rawData = raw->data.hid.bRawData;
|
2019-07-15 10:37:19 +03:00
|
|
|
gamepad->remapper->ProcessTouchData(gamepad->id, rawData);
|
2019-05-30 03:21:59 +03:00
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
return true;
|
2011-08-03 22:12:08 +04:00
|
|
|
}
|
|
|
|
|
2019-05-30 03:21:59 +03:00
|
|
|
void WindowsGamepadService::SetLightIndicatorColor(uint32_t aControllerIdx,
|
|
|
|
uint32_t aLightColorIndex,
|
|
|
|
uint8_t aRed, uint8_t aGreen,
|
|
|
|
uint8_t aBlue) {
|
|
|
|
// We get aControllerIdx from GamepadPlatformService::AddGamepad(),
|
|
|
|
// It begins from 1 and is stored at Gamepad.id.
|
|
|
|
const Gamepad* gamepad = nullptr;
|
|
|
|
for (const auto& pad : mGamepads) {
|
|
|
|
if (pad.id == aControllerIdx) {
|
|
|
|
gamepad = &pad;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!gamepad) {
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<GamepadRemapper> remapper = gamepad->remapper;
|
|
|
|
if (!remapper || remapper->GetLightIndicatorCount() <= aLightColorIndex) {
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<uint8_t> report;
|
|
|
|
remapper->GetLightColorReport(aRed, aGreen, aBlue, report);
|
|
|
|
WriteOutputReport(report);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t WindowsGamepadService::WriteOutputReport(
|
|
|
|
const std::vector<uint8_t>& aReport) {
|
|
|
|
DCHECK(static_cast<const void*>(aReport.data()));
|
|
|
|
DCHECK_GE(aReport.size(), 1U);
|
|
|
|
if (!mHidHandle) return 0;
|
|
|
|
|
|
|
|
nsAutoHandle eventHandle(::CreateEvent(nullptr, FALSE, FALSE, nullptr));
|
|
|
|
OVERLAPPED overlapped = {0};
|
|
|
|
overlapped.hEvent = eventHandle;
|
|
|
|
|
|
|
|
// Doing an asynchronous write to allows us to time out
|
|
|
|
// if the write takes too long.
|
|
|
|
DWORD bytesWritten = 0;
|
|
|
|
BOOL writeSuccess =
|
|
|
|
::WriteFile(mHidHandle, static_cast<const void*>(aReport.data()),
|
|
|
|
aReport.size(), &bytesWritten, &overlapped);
|
|
|
|
if (!writeSuccess) {
|
|
|
|
DWORD error = ::GetLastError();
|
|
|
|
if (error == ERROR_IO_PENDING) {
|
|
|
|
// Wait for the write to complete. This causes WriteOutputReport to behave
|
|
|
|
// synchronously but with a timeout.
|
|
|
|
DWORD wait_object = ::WaitForSingleObject(overlapped.hEvent, 100);
|
|
|
|
if (wait_object == WAIT_OBJECT_0) {
|
|
|
|
if (!::GetOverlappedResult(mHidHandle, &overlapped, &bytesWritten,
|
|
|
|
TRUE)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Wait failed, or the timeout was exceeded before the write completed.
|
|
|
|
// Cancel the write request.
|
|
|
|
if (::CancelIo(mHidHandle)) {
|
|
|
|
wait_object = ::WaitForSingleObject(overlapped.hEvent, INFINITE);
|
|
|
|
MOZ_ASSERT(wait_object == WAIT_OBJECT_0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return writeSuccess ? bytesWritten : 0;
|
|
|
|
}
|
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
void WindowsGamepadService::Startup() { ScanForDevices(); }
|
2011-08-03 22:12:08 +04:00
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
void WindowsGamepadService::Shutdown() { Cleanup(); }
|
2014-04-07 22:28:08 +04:00
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
void WindowsGamepadService::Cleanup() {
|
2016-06-28 01:25:00 +03:00
|
|
|
mIsXInputMonitoring = false;
|
2016-12-29 23:00:00 +03:00
|
|
|
if (mDirectInputTimer) {
|
|
|
|
mDirectInputTimer->Cancel();
|
|
|
|
}
|
2016-06-28 01:25:00 +03:00
|
|
|
if (mXInputTimer) {
|
|
|
|
mXInputTimer->Cancel();
|
2014-04-17 03:43:39 +04:00
|
|
|
}
|
2016-06-28 01:25:00 +03:00
|
|
|
if (mDeviceChangeTimer) {
|
|
|
|
mDeviceChangeTimer->Cancel();
|
2016-02-17 04:31:12 +03:00
|
|
|
}
|
2019-05-30 03:21:59 +03:00
|
|
|
|
2016-06-28 01:25:00 +03:00
|
|
|
mGamepads.Clear();
|
2011-08-03 22:12:08 +04:00
|
|
|
}
|
|
|
|
|
2016-06-28 01:25:00 +03:00
|
|
|
void WindowsGamepadService::DevicesChanged(bool aIsStablizing) {
|
|
|
|
if (aIsStablizing) {
|
|
|
|
mDeviceChangeTimer->Cancel();
|
2017-06-29 22:13:25 +03:00
|
|
|
mDeviceChangeTimer->InitWithNamedFuncCallback(
|
|
|
|
DevicesChangeCallback, this, kDevicesChangedStableDelay,
|
|
|
|
nsITimer::TYPE_ONE_SHOT, "DevicesChangeCallback");
|
2016-06-28 01:25:00 +03:00
|
|
|
} else {
|
2014-04-14 21:18:51 +04:00
|
|
|
ScanForDevices();
|
2013-10-24 23:06:19 +04:00
|
|
|
}
|
2011-08-03 22:12:08 +04:00
|
|
|
}
|
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
bool RegisterRawInput(HWND hwnd, bool enable) {
|
|
|
|
nsTArray<RAWINPUTDEVICE> rid(ArrayLength(kUsagePages));
|
|
|
|
rid.SetLength(ArrayLength(kUsagePages));
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < rid.Length(); i++) {
|
|
|
|
rid[i].usUsagePage = kUsagePages[i].usagePage;
|
|
|
|
rid[i].usUsage = kUsagePages[i].usage;
|
|
|
|
rid[i].dwFlags =
|
|
|
|
enable ? RIDEV_EXINPUTSINK | RIDEV_DEVNOTIFY : RIDEV_REMOVE;
|
|
|
|
rid[i].hwndTarget = hwnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!RegisterRawInputDevices(rid.Elements(), rid.Length(),
|
|
|
|
sizeof(RAWINPUTDEVICE))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LRESULT CALLBACK GamepadWindowProc(HWND hwnd, UINT msg, WPARAM wParam,
|
|
|
|
LPARAM lParam) {
|
2013-10-24 23:06:19 +04:00
|
|
|
const unsigned int DBT_DEVICEARRIVAL = 0x8000;
|
|
|
|
const unsigned int DBT_DEVICEREMOVECOMPLETE = 0x8004;
|
|
|
|
const unsigned int DBT_DEVNODES_CHANGED = 0x7;
|
|
|
|
|
2014-04-14 21:18:51 +04:00
|
|
|
switch (msg) {
|
|
|
|
case WM_DEVICECHANGE:
|
|
|
|
if (wParam == DBT_DEVICEARRIVAL || wParam == DBT_DEVICEREMOVECOMPLETE ||
|
|
|
|
wParam == DBT_DEVNODES_CHANGED) {
|
|
|
|
if (gService) {
|
2016-06-28 01:25:00 +03:00
|
|
|
gService->DevicesChanged(true);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2014-04-14 21:18:51 +04:00
|
|
|
case WM_INPUT:
|
|
|
|
if (gService) {
|
2016-06-28 01:25:00 +03:00
|
|
|
gService->HandleRawInput(reinterpret_cast<HRAWINPUT>(lParam));
|
2014-04-14 21:18:51 +04:00
|
|
|
}
|
|
|
|
break;
|
2013-10-24 23:06:19 +04:00
|
|
|
}
|
|
|
|
return DefWindowProc(hwnd, msg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
2016-06-28 01:25:00 +03:00
|
|
|
class StartWindowsGamepadServiceRunnable final : public Runnable {
|
|
|
|
public:
|
2017-06-12 22:34:10 +03:00
|
|
|
StartWindowsGamepadServiceRunnable()
|
|
|
|
: Runnable("StartWindowsGamepadServiceRunnable") {}
|
2013-10-24 23:06:19 +04:00
|
|
|
|
2016-06-28 01:25:00 +03:00
|
|
|
NS_IMETHOD Run() override {
|
|
|
|
MOZ_ASSERT(NS_GetCurrentThread() == gMonitorThread);
|
|
|
|
gService = new WindowsGamepadService();
|
|
|
|
gService->Startup();
|
|
|
|
|
|
|
|
if (sHWnd == nullptr) {
|
|
|
|
WNDCLASSW wc;
|
|
|
|
HMODULE hSelf = GetModuleHandle(nullptr);
|
|
|
|
|
|
|
|
if (!GetClassInfoW(hSelf, L"MozillaGamepadClass", &wc)) {
|
|
|
|
ZeroMemory(&wc, sizeof(WNDCLASSW));
|
|
|
|
wc.hInstance = hSelf;
|
|
|
|
wc.lpfnWndProc = GamepadWindowProc;
|
|
|
|
wc.lpszClassName = L"MozillaGamepadClass";
|
|
|
|
RegisterClassW(&wc);
|
|
|
|
}
|
2013-10-24 23:06:19 +04:00
|
|
|
|
2016-06-28 01:25:00 +03:00
|
|
|
sHWnd = CreateWindowW(L"MozillaGamepadClass", L"Gamepad Watcher", 0, 0, 0,
|
|
|
|
0, 0, nullptr, nullptr, hSelf, nullptr);
|
|
|
|
RegisterRawInput(sHWnd, true);
|
2013-10-24 23:06:19 +04:00
|
|
|
}
|
|
|
|
|
2016-06-28 01:25:00 +03:00
|
|
|
// Explicitly start the message loop
|
2016-12-29 23:00:00 +03:00
|
|
|
gService->StartMessageLoop();
|
2016-06-28 01:25:00 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2013-10-24 23:06:19 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-06-28 01:25:00 +03:00
|
|
|
private:
|
|
|
|
~StartWindowsGamepadServiceRunnable() {}
|
|
|
|
};
|
2011-08-03 22:12:08 +04:00
|
|
|
|
2016-06-28 01:25:00 +03:00
|
|
|
class StopWindowsGamepadServiceRunnable final : public Runnable {
|
|
|
|
public:
|
2017-06-12 22:34:10 +03:00
|
|
|
StopWindowsGamepadServiceRunnable()
|
|
|
|
: Runnable("StopWindowsGamepadServiceRunnable") {}
|
2016-06-28 01:25:00 +03:00
|
|
|
|
|
|
|
NS_IMETHOD Run() override {
|
|
|
|
MOZ_ASSERT(NS_GetCurrentThread() == gMonitorThread);
|
|
|
|
if (sHWnd) {
|
|
|
|
RegisterRawInput(sHWnd, false);
|
|
|
|
DestroyWindow(sHWnd);
|
|
|
|
sHWnd = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
gService->Shutdown();
|
|
|
|
delete gService;
|
|
|
|
gService = nullptr;
|
|
|
|
|
|
|
|
return NS_OK;
|
2014-04-14 21:18:51 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-06-28 01:25:00 +03:00
|
|
|
private:
|
|
|
|
~StopWindowsGamepadServiceRunnable() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
using namespace mozilla::ipc;
|
2011-08-03 22:12:08 +04:00
|
|
|
|
2016-06-28 01:25:00 +03:00
|
|
|
void StartGamepadMonitoring() {
|
|
|
|
AssertIsOnBackgroundThread();
|
|
|
|
|
|
|
|
if (gMonitorThread || gService) {
|
|
|
|
return;
|
2013-10-24 23:06:19 +04:00
|
|
|
}
|
2016-06-28 01:25:00 +03:00
|
|
|
sIsShutdown = false;
|
2016-12-21 13:43:50 +03:00
|
|
|
NS_NewNamedThread("Gamepad", getter_AddRefs(gMonitorThread));
|
2016-06-28 01:25:00 +03:00
|
|
|
gMonitorThread->Dispatch(new StartWindowsGamepadServiceRunnable(),
|
|
|
|
NS_DISPATCH_NORMAL);
|
|
|
|
}
|
2013-10-24 23:06:19 +04:00
|
|
|
|
2016-06-28 01:25:00 +03:00
|
|
|
void StopGamepadMonitoring() {
|
|
|
|
AssertIsOnBackgroundThread();
|
|
|
|
|
|
|
|
if (sIsShutdown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sIsShutdown = true;
|
|
|
|
gMonitorThread->Dispatch(new StopWindowsGamepadServiceRunnable(),
|
|
|
|
NS_DISPATCH_NORMAL);
|
|
|
|
gMonitorThread->Shutdown();
|
|
|
|
gMonitorThread = nullptr;
|
2011-08-03 22:12:08 +04:00
|
|
|
}
|
|
|
|
|
2019-05-30 03:21:59 +03:00
|
|
|
void SetGamepadLightIndicatorColor(uint32_t aControllerIdx,
|
|
|
|
uint32_t aLightColorIndex, uint8_t aRed,
|
|
|
|
uint8_t aGreen, uint8_t aBlue) {
|
|
|
|
MOZ_ASSERT(gService);
|
|
|
|
if (!gService) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gService->SetLightIndicatorColor(aControllerIdx, aLightColorIndex, aRed,
|
|
|
|
aGreen, aBlue);
|
|
|
|
}
|
|
|
|
|
2015-04-24 01:05:29 +03:00
|
|
|
} // namespace dom
|
2011-08-03 22:12:08 +04:00
|
|
|
} // namespace mozilla
|