Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/demo/electron-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
</script>
</body>
`)
Expand All @@ -60,8 +65,11 @@ function createWindow () {
OverlayController.attachByTitle(
window,
process.platform === 'darwin' ? 'Untitled' : 'Notepad',
{ hasTitleBarOnMac: true }
)
{
hasTitleBarOnMac: true,
needForwardMouseInput: true
}
);
}

function makeDemoInteractive () {
Expand Down
17 changes: 13 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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')
}
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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()
}

Expand Down