diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2023-05-31 15:57:38 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-31 15:57:38 +0000 |
commit | 11a6a669d130ca814cca4f8a1f0299c87d29bf1c (patch) | |
tree | ca63bfc12b841a28332380f2e01bf52cd03ac1bd | |
parent | 58dbd0ea4de251256542458a3af9e95854e61be0 (diff) | |
parent | baa81126c485434211cb6d58292f77de00dc2432 (diff) | |
download | stable-diffusion-webui-gfx803-11a6a669d130ca814cca4f8a1f0299c87d29bf1c.tar.gz stable-diffusion-webui-gfx803-11a6a669d130ca814cca4f8a1f0299c87d29bf1c.tar.bz2 stable-diffusion-webui-gfx803-11a6a669d130ca814cca4f8a1f0299c87d29bf1c.zip |
Merge pull request #10814 from missionfloyd/gamepad-disconnect
Only poll gamepads while connected
-rw-r--r-- | javascript/imageviewerGamepad.js | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/javascript/imageviewerGamepad.js b/javascript/imageviewerGamepad.js index 31d226de..a22c7e6e 100644 --- a/javascript/imageviewerGamepad.js +++ b/javascript/imageviewerGamepad.js @@ -1,7 +1,9 @@ +let gamepads = []; + window.addEventListener('gamepadconnected', (e) => { const index = e.gamepad.index; let isWaiting = false; - setInterval(async() => { + gamepads[index] = setInterval(async() => { if (!opts.js_modal_lightbox_gamepad || isWaiting) return; const gamepad = navigator.getGamepads()[index]; const xValue = gamepad.axes[0]; @@ -24,6 +26,10 @@ window.addEventListener('gamepadconnected', (e) => { }, 10); }); +window.addEventListener('gamepaddisconnected', (e) => { + clearInterval(gamepads[e.gamepad.index]); +}); + /* Primarily for vr controller type pointer devices. I use the wheel event because there's currently no way to do it properly with web xr. |