最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Create electron transparent window ontop but clickable below programs - Stack Overflow

programmeradmin6浏览0评论

I have created electron app which on button click shows another window which is 100% height and width and has border around its area. It's also transparent so you can see what is behind this window.

Now I'm wondering if I'm able to make things below clickable or I need to create some kind of hack like this new transparent window make it really small and somehow expand border off this window.

Code responsible for creating new transparent window is:

const electron = require('electron');
const { app, BrowserWindow, Menu } = electron;

let mainWindow;
let addWindow;
let createTransparentWindow;

app.on('ready', () => {
    mainWindow = new BrowserWindow({});
    mainWindow.loadURL(`file://${__dirname}/index.html`);
    const mainMenu = Menu.buildFromTemplate(menuTemplate);
    Menu.setApplicationMenu(mainMenu);

    const mainScreen = electron.screen.getPrimaryDisplay();
    createTransparentWindow = () => {
        addWindow = new BrowserWindow({
            width: mainScreen.size.width,
            height: mainScreen.size.height,
            transparent: true,
            frame: false,
            alwaysOnTop: true,
        });
        addWindow.loadURL(`file://${__dirname}/transparentWindow.html`)
    };
});


const menuTemplate = [
    {},
    {
        label: 'Record',
        submenu: [
            {
                label: 'TransparentWindow',
                click() {
                    createTransparentWindow();
                }
            }
        ]
    }
];

If I'm able to make apps which are below this window clickable please tell me how if not what kinda trick I need to introduce here?

I have created electron app which on button click shows another window which is 100% height and width and has border around its area. It's also transparent so you can see what is behind this window.

Now I'm wondering if I'm able to make things below clickable or I need to create some kind of hack like this new transparent window make it really small and somehow expand border off this window.

Code responsible for creating new transparent window is:

const electron = require('electron');
const { app, BrowserWindow, Menu } = electron;

let mainWindow;
let addWindow;
let createTransparentWindow;

app.on('ready', () => {
    mainWindow = new BrowserWindow({});
    mainWindow.loadURL(`file://${__dirname}/index.html`);
    const mainMenu = Menu.buildFromTemplate(menuTemplate);
    Menu.setApplicationMenu(mainMenu);

    const mainScreen = electron.screen.getPrimaryDisplay();
    createTransparentWindow = () => {
        addWindow = new BrowserWindow({
            width: mainScreen.size.width,
            height: mainScreen.size.height,
            transparent: true,
            frame: false,
            alwaysOnTop: true,
        });
        addWindow.loadURL(`file://${__dirname}/transparentWindow.html`)
    };
});


const menuTemplate = [
    {},
    {
        label: 'Record',
        submenu: [
            {
                label: 'TransparentWindow',
                click() {
                    createTransparentWindow();
                }
            }
        ]
    }
];

If I'm able to make apps which are below this window clickable please tell me how if not what kinda trick I need to introduce here?

Share Improve this question asked May 2, 2018 at 20:19 BT101BT101 3,84611 gold badges48 silver badges101 bronze badges 1
  • Doesn't seem to work on linux. – jayarjo Commented Sep 27, 2020 at 7:24
Add a ment  | 

1 Answer 1

Reset to default 7

I found answer to my question here. So what you need to browserWindow is:

addWindow.setIgnoreMouseEvents(true);
addWindow.setFocusable(false);

and then you can click through.

发布评论

评论列表(0)

  1. 暂无评论