GithubHelp home page GithubHelp logo

m5150 / electronmacosclickthrough Goto Github PK

View Code? Open in Web Editor NEW

This project forked from loomhq/electronmacosclickthrough

0.0 0.0 0.0 8 KB

An Add On workaround for transparent window click through issues on electron v8 and above

JavaScript 1.84% Python 11.34% Objective-C++ 86.82%

electronmacosclickthrough's Introduction

Electron click-through workaround

Overview

This is an addon fix for window click through in transparent regions that was broken in electron 7.0.0beta5 electron/electron#23042 (comment)

By default, a borderless NSWindow will register clicks in opaque regions AND pass clicks through in transparent regions UNLESS you set ignoresMouseEvents at which point all clicks register, regardless of colour, or all clicks pass through.

At some point in electron 7, new BrowserWindow started calling calling the harmless seeming setIgnoreMouseEvents: NO method, which forever disables transparent click through for the new window.

This add-on fixes the problem by patching setIgnoreMouseEvents to be a no-op for ALL NSWindows. It also adds a function MakeWindowIgnoreMouseEvents() which calls the unpatched setIgnoreMouseEvents: YES.

Usage

Call InstallClickThroughPatch() before the new BrowserWindow you want to have the default transparent clickthrough behaviour. Call MakeWindowIgnoreMouseEvents(win.getNativeWindowHandle()) on any BrowserWindow on which you want to all clicks to pass through.

if (process.platform === 'darwin') {
  require('@loomhq/electron-click-through-workaround').InstallClickThroughPatch();
}
...

Future improvements

Hopefully chromium (I guess it's chromium) will stop doing setIgnoreMouseEvents: NO on its windows and this add-on will become obsolete. Failing that, I don't like the indiscriminate way the code disables setIgnoreMouseEvents for all windows, nor the fact that setIgnoreMouseEvents: NO becomes completely unreachable.

Ideally the API would be just this:

DisableSetIgnoreMouseEventsForTheNextWindowToBeCreated() (this "flag-style" API is necessary because by the time we get the BrowserWindow it's too late to apply the patch, the damage has been done). With this implementation you would be free to call BrowserWindow.setIgnoreMouseEvents on other windows for no or full click through.

This cleaner approach would require dynamically subclassing the incoming NSWindow, making setIgnoreMouseEvents a no-op, but I haven't had time to implement and test this.

More info in this SO answer, and take note of the comment in which the surprising tri-state ignoresMouseEvents boolean is explained. https://stackoverflow.com/a/29451199/22147

electronmacosclickthrough's People

Contributors

gchilds avatar m5150 avatar sapkra avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.