From f13c7fc83e767da72accea125482fa130fb52cd3 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Fri, 19 Nov 2021 03:46:04 +0100 Subject: [HTML5] Fix input not focusing canvas. mousedown and touchstart should focus the canvas to ensure correct application lifecycle. --- platform/javascript/js/libs/library_godot_input.js | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'platform/javascript/js') diff --git a/platform/javascript/js/libs/library_godot_input.js b/platform/javascript/js/libs/library_godot_input.js index 587c320f35..5c7400d599 100644 --- a/platform/javascript/js/libs/library_godot_input.js +++ b/platform/javascript/js/libs/library_godot_input.js @@ -389,6 +389,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 +408,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++) { -- cgit v1.2.3 From 91dbc288ccd7cab7d50feccba82ebfb99b5f2b69 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Fri, 19 Nov 2021 02:53:23 +0100 Subject: [HTML5] Add checks to Gamepad API events. In some conditions the events might be generated even when the `gamepad` object is not accessible due to Security Context requirements. This commit adds a check to avoid firing the handler in those cases. --- platform/javascript/js/libs/library_godot_input.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'platform/javascript/js') diff --git a/platform/javascript/js/libs/library_godot_input.js b/platform/javascript/js/libs/library_godot_input.js index 5c7400d599..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); }, -- cgit v1.2.3