summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2021-11-19 03:46:04 +0100
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2021-11-19 04:06:55 +0100
commitf13c7fc83e767da72accea125482fa130fb52cd3 (patch)
tree96794a1b819b3e2f68216c5eca43eea85bfe69bd
parentba798d585c0cda62f5388d0636ed38e63fdb13ed (diff)
[HTML5] Fix input not focusing canvas.
mousedown and touchstart should focus the canvas to ensure correct application lifecycle.
-rw-r--r--platform/javascript/js/libs/library_godot_input.js6
1 files changed, 6 insertions, 0 deletions
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++) {