From c12fca57f42dcfa2cb8e42a2ed24bc52fc67a463 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Fri, 25 Jun 2021 19:07:17 +0200 Subject: [HTML5] Add option to focus canvas on start. Enabled by default. --- platform/javascript/js/engine/config.js | 10 ++++++++++ platform/javascript/js/libs/library_godot_os.js | 3 +++ 2 files changed, 13 insertions(+) (limited to 'platform/javascript/js') diff --git a/platform/javascript/js/engine/config.js b/platform/javascript/js/engine/config.js index 6072782875..ba61b14eb7 100644 --- a/platform/javascript/js/engine/config.js +++ b/platform/javascript/js/engine/config.js @@ -90,6 +90,14 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused- * @default */ args: [], + /** + * When enabled, the game canvas will automatically grab the focus when the engine starts. + * + * @memberof EngineConfig + * @type {boolean} + * @default + */ + focusCanvas: true, /** * When enabled, this will turn on experimental virtual keyboard support on mobile. * @@ -238,6 +246,7 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused- this.persistentPaths = parse('persistentPaths', this.persistentPaths); this.persistentDrops = parse('persistentDrops', this.persistentDrops); this.experimentalVK = parse('experimentalVK', this.experimentalVK); + this.focusCanvas = parse('focusCanvas', this.focusCanvas); this.gdnativeLibs = parse('gdnativeLibs', this.gdnativeLibs); this.fileSizes = parse('fileSizes', this.fileSizes); this.args = parse('args', this.args); @@ -324,6 +333,7 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused- 'locale': locale, 'persistentDrops': this.persistentDrops, 'virtualKeyboard': this.experimentalVK, + 'focusCanvas': this.focusCanvas, 'onExecute': this.onExecute, 'onExit': function (p_code) { cleanup(); // We always need to call the cleanup callback to free memory. diff --git a/platform/javascript/js/libs/library_godot_os.js b/platform/javascript/js/libs/library_godot_os.js index 7414b8cc47..5aa750757c 100644 --- a/platform/javascript/js/libs/library_godot_os.js +++ b/platform/javascript/js/libs/library_godot_os.js @@ -72,6 +72,9 @@ const GodotConfig = { GodotConfig.persistent_drops = !!p_opts['persistentDrops']; GodotConfig.on_execute = p_opts['onExecute']; GodotConfig.on_exit = p_opts['onExit']; + if (p_opts['focusCanvas']) { + GodotConfig.canvas.focus(); + } }, locate_file: function (file) { -- cgit v1.2.3