-
Notifications
You must be signed in to change notification settings - Fork 15.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support click-through of transparency #1335
Comments
While nw.js does support it, it comes with some pretty hefty drawbacks. First of all it requires disabling GPU acceleration, and secondly it only works on OS X and Windows (based on their documentation). |
+1, this one's plaguing Slack too, since we display all of our notifications in a transparent window. |
+1, this is critical for the project I'm working on. |
+1, this would be excellent. |
Interested in hearing the latest on this. For my purposes, I'd love if we could set a transparent window to have no click area. So you could have an always-on-top full screen overlay that didn't catch clicks. |
I'm interested too, i'm building an app with a semi transparent window that's on top of other applications but mouseevents need to get through to the other applications. |
+1 Any news about it? |
the linked chromium bug is marked wont-fix the last comment is:
so nothing is currently going to happen until someone on the atom team decides to do it or persuades the chrome team it is worth putting on their backlog (and they said it was low priority). |
Just ran into this today, It has put a -massive- issues into my plans of using a new window has an overlay. (in fact, it is now impossible) I would love a fix for this! |
Is there any work in progress for this? Will there be a chance for the Electron team to make this possible without being added to Chromium? |
+1 Assuming this won't be resolved through the Chromium code, is there a plausible way to have the application listen for a click event and then trigger the proper counterpart in GTK or similar? |
i use ahkscript #c::
WinSet, ExStyle, ^0x20, A
WinSet, Transparent, 255, A
return press Win+C on active window, and its click-through now |
@zcbenz Any update on this? 😄 |
To people watching this issue: if you simply want to make the whole window click-though, you can use the new win.setIgnoreMouseEvents API introduced in v1.2.2. |
Also on making specified regions transparent, I have come up with some ideas on the implementation (but do not assume it would be done in near future): For Linux, it is actually very easy by using the For Windows, it is easy to set the shape of window, but there is no API to control which regions can accept mouse events. For OS X, either setting window shape or setting click-though regions is impossible if you don't have control to the rendering code. And since Chromium does complex hardware acceleration, it becomes super hard to implement custom click-through regions. NW.js does it by disabling hardware acceleration, and patching the rendering code, this is an approach that I definitely don't want to take. My idea for the implementation on OS X/Windows is, we just make the whole window click-through, and then create a transparent window as child window, and use it to capture all mouse events. Since we have full control of the child window, we can set it to the shape of the regions that users do not want to be click-though, and then send all mouse and keyboard events received in the child window to the parent window. In this way we don't have to patch Chromium, so it is easy to maintain and hardware acceleration works. The downside is we have to very carefully redirect mouse and keyboard events, to make the window behave as if it there is no child window. |
During the development of my Windows gadget project which requires click-thru, I have unintentionally come up with a somewhat fancy but practical solution which works to define a clickcable area of truly arbitrary shape. In the renderer process, use "screen.getCursorScreenPoint()" to keep tracking the cursor position, and then send the coordinates to the main process regularly. On the main process, use "webContents.capturePage()" to capture the image of that exact 1x1 pixel on the renderer window. Since it's just 1 pixel, the performance cost is ignorable, and then you can define whether that pixel is clickable or not by looking at the opacity value. This way, you can practically define a truly pixel-correct clickable area. The only issue left here is a function to detect the mousedown state regardless of the cursor position. |
Electron click through transparency example |
@ButzYung Could you please tell me that how can I get opacity value from NativeImage (webContents.capturePage() return NativeImage)? Thanks. |
@varavut Capturing a 1x1 image as an example, it would be something like this.
|
@ButzYung Thanks for your solution. I tried it, the key is the interval of tracking. 100ms for my computer, looks well. If I used |
@cecilpeng In my case I give a 200ms delay after the current webContents.capturePage has finished, instead of doing another capture immediately. That's roughly 4-5 captures/second, enough for the purpose of checking transparency, and the CPU usage is ignorable. |
@ButzYung yes, it is better to do another capture after last has finished. I'm still worried about the timeout solution, it's not smart enough. We can't know what happens on the users' computer. I recommend that javascript is a good languague to observe instead of inspect. |
I'm very much a HTML noob but is it not possible to simply:
Due to my lack of HTML knowledge there may be an issue with this in certain scenarios... But in my head it seems to be the, currently, ideal workaround. Except for the extra setup time required of course? |
@nikkwong Your example was the only one that mostly worked. The problem is that, if you rest you mouse for more than the timeout amount, you are unable to click through. I made another example (See below), which is a modified version of yours. main.js
preload.js added a bridge function
handle mouse move
|
I was able to use @LauraAubin's approach with a couple tweaks!
|
Any updates on this? I'd also be interested to see the My use case is to overlay a game, and the only way the click through would work is by disabling GPU compositing or acceleration, but the click/hover goes through everything - even non-transparent elements. |
+1 on adding functionality for propagating My use case is rendering a custom animated cursor in a transparent overlaid window, and the cursor has different states depending on what element it is hovering. |
I think that if you combine :not(.click-through) .my-elem:hover {
background-color: pink;
} I had an npm lib for it, but it's outdated and won't get an update soon. Someone got my v2 draft version working recently though. The trick it uses is that if your pointer event target (and every element below) has |
We always stand on the shoulders of giants. setInterval(() => {
const point = screen.getCursorScreenPoint();
const [x, y] = win.getPosition();
const [w, h] = win.getSize();
if (point.x > x && point.x < x + w && point.y > y && point.y < y + h) {
updateIgnoreMouseEvents(point.x - x, point.y - y);
}
}, 300);
const updateIgnoreMouseEvents = async (x, y) => {
console.log("updateIgnoreMouseEvents");
// capture 1x1 image of mouse position.
const image = await win.webContents.capturePage({
x,
y,
width: 1,
height: 1,
});
var buffer = image.getBitmap();
// set ignore mouse events by alpha.
win.setIgnoreMouseEvents(!buffer[3]);
console.log("setIgnoreMouseEvents", !buffer[3]);
}; |
@LZQCN I tried to follow your suggestion here: #1335 (comment) but , but I guess I'm making something wrong because nothing happens:
declare const SEARCH_WINDOW_PRELOAD_WEBPACK_ENTRY: string; let SearchWindow: BrowserWindow let child_window: BrowserWindow const createSearchWindow = (): void => {
How to make it work ? |
I found that in your code |
Yes. the transparent window is I've put in your code the right window :
The and I'm getting this error : The error message points to this line:
|
|
@LZQCN With This is the output The |
Following the indications found here: https://stackoverflow.com/questions/53357428/how-to-make-mouse-pass-through-window-in-electron I've put
Now the top But, still, I'm not able to get the correct mouse position with |
@raphael10-collab My code works for this scenario: |
Wow ...... I do not understand how you are actually using the |
@raphael10-collab Also, if you want to get the clicked position, you should get the clicked position from the window that was actually clicked. |
@LZQCN I've set :
According to what we read here: https://www.electronjs.org/docs/latest/api/browser-window#winsetignoremouseeventsignore-options :
should be fine.... Is this not enough for Linux ? |
I do not understand why this message sent from the
React.useEffect(() => {
in
This is how I defined and created the bottom window (
} |
It is ignored by Microsoft because of incompatibilities BUT you can use my fork: https://github.com/lnxx-kernel/electron_touch |
win.SetShape is currently only supported (experimentally) on Windows and Linux. Are there any efforts towards implementing this on macOS? (and removing it from its 'experimental' state) |
As commented here, #949 (comment) - transparent windows unfortunately are of limited use unless you can click through the transparent area.
I noticed that in the documentation it is stated that this is blocked by an upstream bug. The nw.js project DOES have support for this, but i'm not sure how different their implementation is...
I think this is worth the issue to track discussion and implementation, so here it is.
The text was updated successfully, but these errors were encountered: