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

I have created electron app which on button click shows another window which is 100% height and width a

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744367542a4570780.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信