Skip to content

Commit

Permalink
GlobalShortcut_win: only poll XboxInput if there are XInput devices p…
Browse files Browse the repository at this point in the history
…resent.

As reported in #2166, on some systems, polling
XInput devices when no devices are connected can make Mumble lag.

This patch implements a small optimization: don't try to poll
the XboxInput backend if no XInput devices are attached.

Hopefully this will fix the issue for the affected people.
  • Loading branch information
mkrautz committed May 1, 2016
1 parent 0288120 commit 8dbc793
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/mumble/GlobalShortcut_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ GlobalShortcutWin::GlobalShortcutWin()
#endif
#ifdef USE_XBOXINPUT
, xboxinput(NULL)
, nxboxinput(0)
#endif
, uiHardwareDevices(0) {

Expand Down Expand Up @@ -456,6 +457,8 @@ BOOL GlobalShortcutWin::EnumDevicesCB(LPCDIDEVICEINSTANCE pdidi, LPVOID pContext
// See issues mumble-voip/mumble#2104 and mumble-voip/mumble#2147
// for more information.
if (XInputCheck_IsGuidProductXInputDevice(&id->guidproduct)) {
nxboxinput += 1;

qWarning("GlobalShortcutWin: excluded XInput device '%s' (%s) from DirectInput", qPrintable(id->name), qPrintable(id->vguid.toString()));
delete id;
return DIENUM_CONTINUE;
Expand Down Expand Up @@ -573,6 +576,7 @@ void GlobalShortcutWin::timeTicked() {
uiHardwareDevices = g.mw->uiNewHardware;

XInputCheck_ClearDeviceCache();
nxboxinput = 0;

pDI->EnumDevices(DI8DEVCLASS_ALL, EnumDevicesCB, static_cast<void *>(this), DIEDFL_ATTACHEDONLY);
}
Expand Down Expand Up @@ -657,7 +661,7 @@ void GlobalShortcutWin::timeTicked() {
#endif

#ifdef USE_XBOXINPUT
if (g.s.bEnableXboxInput && xboxinput->isValid()) {
if (g.s.bEnableXboxInput && xboxinput->isValid() && nxboxinput > 0) {
XboxInputState state;
for (uint32_t i = 0; i < XBOXINPUT_MAX_DEVICES; i++) {
if (xboxinput->GetState(i, &state) == 0) {
Expand Down
4 changes: 4 additions & 0 deletions src/mumble/GlobalShortcut_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ class GlobalShortcutWin : public GlobalShortcutEngine {
/// different than last time we queried it.
uint32_t xboxinputLastPacket[XBOXINPUT_MAX_DEVICES];
XboxInput *xboxinput;
/// nxboxinput holds the number of XInput devices
/// available on the system. It is filled out by
/// our EnumDevices callback.
int nxboxinput;
#endif

static BOOL CALLBACK EnumSuitableDevicesCB(LPCDIDEVICEINSTANCE, LPDIRECTINPUTDEVICE8, DWORD, DWORD, LPVOID);
Expand Down

0 comments on commit 8dbc793

Please sign in to comment.