summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2021-11-19 08:12:13 +0100
committerGitHub <noreply@github.com>2021-11-19 08:12:13 +0100
commit6357412cbcd7ee9c1c2b6902f49127c7230aaaaf (patch)
treeb05dce86f7b85f2efe20087d942716cb19f0de67
parentba798d585c0cda62f5388d0636ed38e63fdb13ed (diff)
parent91dbc288ccd7cab7d50feccba82ebfb99b5f2b69 (diff)
Merge pull request #55111 from Faless/js/4.x_input_fix_focus
[HTML5] Fix input not focusing canvas, Gamepad API errors.
-rw-r--r--platform/javascript/js/libs/library_godot_input.js14
1 files changed, 12 insertions, 2 deletions
diff --git a/platform/javascript/js/libs/library_godot_input.js b/platform/javascript/js/libs/library_godot_input.js
index 587c320f35..d85d0d5335 100644
--- a/platform/javascript/js/libs/library_godot_input.js
+++ b/platform/javascript/js/libs/library_godot_input.js
@@ -104,10 +104,14 @@ const GodotInputGamepads = {
}
}
GodotEventListeners.add(window, 'gamepadconnected', function (evt) {
- add(evt.gamepad);
+ if (evt.gamepad) {
+ add(evt.gamepad);
+ }
}, false);
GodotEventListeners.add(window, 'gamepaddisconnected', function (evt) {
- onchange(evt.gamepad.index, 0);
+ if (evt.gamepad) {
+ onchange(evt.gamepad.index, 0);
+ }
}, false);
},
@@ -389,6 +393,9 @@ const GodotInput = {
const rect = canvas.getBoundingClientRect();
const pos = GodotInput.computePosition(evt, rect);
const modifiers = GodotInput.getModifiers(evt);
+ if (p_pressed && document.activeElement !== GodotConfig.canvas) {
+ GodotConfig.canvas.focus();
+ }
if (func(p_pressed, evt.button, pos[0], pos[1], modifiers)) {
evt.preventDefault();
}
@@ -405,6 +412,9 @@ const GodotInput = {
const func = GodotRuntime.get_func(callback);
const canvas = GodotConfig.canvas;
function touch_cb(type, evt) {
+ if (type === 0 && document.activeElement !== GodotConfig.canvas) {
+ GodotConfig.canvas.focus();
+ }
const rect = canvas.getBoundingClientRect();
const touches = evt.changedTouches;
for (let i = 0; i < touches.length; i++) {