From bce6decd745a17faefb13147cdee676a035450bc Mon Sep 17 00:00:00 2001 From: Victor Rache Date: Thu, 12 Oct 2023 13:27:35 +0200 Subject: [PATCH] Add forward mouse option on AttachOptions and use it --- src/demo/electron-demo.ts | 12 ++++++++++-- src/index.ts | 17 +++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/demo/electron-demo.ts b/src/demo/electron-demo.ts index f87bd6f..aede343 100644 --- a/src/demo/electron-demo.ts +++ b/src/demo/electron-demo.ts @@ -48,6 +48,11 @@ function createWindow () { document.body.style.display = 'none' } }); + + // NOTE: this is just for demo purposes + document.addEventListener('mousemove', (e) => { + console.log(e); + }); `) @@ -60,8 +65,11 @@ function createWindow () { OverlayController.attachByTitle( window, process.platform === 'darwin' ? 'Untitled' : 'Notepad', - { hasTitleBarOnMac: true } - ) + { + hasTitleBarOnMac: true, + needForwardMouseInput: true + } + ); } function makeDemoInteractive () { diff --git a/src/index.ts b/src/index.ts index 110a11f..3c54c39 100644 --- a/src/index.ts +++ b/src/index.ts @@ -49,6 +49,7 @@ export interface MoveresizeEvent { export interface AttachOptions { // Whether the Window has a title bar. We adjust the overlay to not cover it hasTitleBarOnMac?: boolean + needForwardMouseInput?: boolean } const isMac = process.platform === 'darwin' @@ -86,7 +87,9 @@ class OverlayControllerGlobal { this.events.on('attach', (e: AttachEvent) => { this.targetHasFocus = true if (this.electronWindow) { - this.electronWindow.setIgnoreMouseEvents(true) + this.electronWindow.setIgnoreMouseEvents(true, { + forward: this.attachOptions.needForwardMouseInput + }) this.electronWindow.showInactive() this.electronWindow.setAlwaysOnTop(true, 'screen-saver') } @@ -128,7 +131,9 @@ class OverlayControllerGlobal { this.targetHasFocus = true if (this.electronWindow) { - this.electronWindow.setIgnoreMouseEvents(true) + this.electronWindow.setIgnoreMouseEvents(true, { + forward: this.attachOptions.needForwardMouseInput, + }) if (!this.electronWindow.isVisible()) { this.electronWindow.showInactive() this.electronWindow.setAlwaysOnTop(true, 'screen-saver') @@ -238,13 +243,17 @@ class OverlayControllerGlobal { throw new Error('You are using the library in tracking mode') } this.focusNext = 'overlay' - this.electronWindow.setIgnoreMouseEvents(false) + this.electronWindow.setIgnoreMouseEvents(false, { + forward: this.attachOptions.needForwardMouseInput, + }); this.electronWindow.focus() } focusTarget () { this.focusNext = 'target' - this.electronWindow?.setIgnoreMouseEvents(true) + this.electronWindow?.setIgnoreMouseEvents(true, { + forward: this.attachOptions.needForwardMouseInput, + }); lib.focusTarget() }