diff --git a/src/core/Config.js b/src/core/Config.js index 2f11a2493..2ec695b70 100644 --- a/src/core/Config.js +++ b/src/core/Config.js @@ -275,6 +275,11 @@ var Config = new Class({ */ this.inputQueue = GetValue(config, 'input.queue', false); + /** + * @const {boolean} Phaser.Core.Config#inputWindowEvents - Should Phaser listen for input events on the Window? + */ + this.inputWindowEvents = GetValue(config, 'input.windowEvents', true); + /** * @const {boolean} Phaser.Core.Config#inputGamepad - Enable the Gamepad Plugin. This can be disabled in games that don't need gamepad input. */ diff --git a/src/input/mouse/MouseManager.js b/src/input/mouse/MouseManager.js index 30f79f657..d8983354d 100644 --- a/src/input/mouse/MouseManager.js +++ b/src/input/mouse/MouseManager.js @@ -116,6 +116,28 @@ var MouseManager = new Class({ */ this.onMouseUp = NOOP; + /** + * The Mouse Down Event handler specifically for events on the Window. + * This function is sent the native DOM MouseEvent. + * Initially empty and bound in the `startListeners` method. + * + * @name Phaser.Input.Mouse.MouseManager#onMouseDownWindow + * @type {function} + * @since 3.16.3 + */ + this.onMouseDownWindow = NOOP; + + /** + * The Mouse Up Event handler specifically for events on the Window. + * This function is sent the native DOM MouseEvent. + * Initially empty and bound in the `startListeners` method. + * + * @name Phaser.Input.Mouse.MouseManager#onMouseUpWindow + * @type {function} + * @since 3.16.3 + */ + this.onMouseUpWindow = NOOP; + /** * The Mouse Over Event handler. * This function is sent the native DOM MouseEvent. @@ -282,6 +304,8 @@ var MouseManager = new Class({ this.onMouseDown = function (event) { + console.log('down'); + if (autoFocus) { window.focus(); @@ -301,6 +325,25 @@ var MouseManager = new Class({ } }; + this.onMouseDownWindow = function (event) + { + console.log('window down'); + + if (event.defaultPrevented || !_this.enabled || !_this.manager) + { + // Do nothing if event already handled + return; + } + + if (event.target !== canvas) + { + console.log('window process'); + + // Only process the event if the target isn't the canvas + _this.manager.queueMouseDown(event); + } + }; + this.onMouseUp = function (event) { if (event.defaultPrevented || !_this.enabled || !_this.manager) @@ -317,6 +360,21 @@ var MouseManager = new Class({ } }; + this.onMouseUpWindow = function (event) + { + if (event.defaultPrevented || !_this.enabled || !_this.manager) + { + // Do nothing if event already handled + return; + } + + if (event.target !== canvas) + { + // Only process the event if the target isn't the canvas + _this.manager.queueMouseUp(event); + } + }; + this.onMouseOver = function (event) { if (event.defaultPrevented || !_this.enabled || !_this.manager) @@ -355,10 +413,10 @@ var MouseManager = new Class({ target.addEventListener('mouseover', this.onMouseOver, (this.capture) ? nonPassive : passive); target.addEventListener('mouseout', this.onMouseOut, (this.capture) ? nonPassive : passive); - if (window) + if (window && this.manager.game.config.inputWindowEvents) { - window.addEventListener('mousedown', this.onMouseDown, nonPassive); - window.addEventListener('mouseup', this.onMouseUp, nonPassive); + window.addEventListener('mousedown', this.onMouseDownWindow, nonPassive); + window.addEventListener('mouseup', this.onMouseUpWindow, nonPassive); } if (Features.pointerLock)