Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I blur an electron BrowserWindow with transparency

Question

Is it possible to make a BrowserWindow, in electron, transparent with blur? In that it blurs all background content, including apps and the wallpaper.

And if possible, how would I accomplish this?

Examples

Here are some code I've tried.
index.js:

let win = new BrowserWindow({
    fullscreen: true,
    fullscreenable: false,
    frame: false,
    skipTaskbar: true,
    resizable: false,
    movable: false,
    show: false,
    alwaysOnTop: true,
    transparent: true
})

style.css:

html, body {
    width: 100vw;
    height: 100vh;
    margin: 0;
    padding: 0;
    background-color: rgba(0, 0, 0, 0.5);
    color: rgb(255, 255, 255);
    backdrop-filter: blur(4px);
}

The html is just a body with a h1 tag with text in it.
Although this only creates a black background in the window.

I read something about this:

webPreferences: {
    experimentalFeatures: true
}

But can't get it to work.

Environment

  • Ubuntu: 18.04.2
  • Node: v10.15.3
  • npm: 6.4.1
  • i3wm. 4.14.1

I have compton running. Maybey it has to do with that. Or the compositing engine in general?

Thanks in advance!

like image 859
Emil Walser Avatar asked Apr 21 '19 18:04

Emil Walser


People also ask

How do you blur the background in a container?

If you want to use CSS (CSS3) do this: filter: blur(5px) brightness(0.5); just set the values to whatever you want.. put all your text in the div whose class is "text" and leave the div with class "background" empty..

How do I make the electron app full screen?

To make an Electron app run in full-screen mode when it's started, pass the following configuration option when creating the BrowserWindow instance: mainWindow = new BrowserWindow({fullscreen: true});

How do I make a window transparent using electron?

In order to make our window transparent, we need to provide the transparent and frame property to true and false respectively: const {BrowserWindow} = require('electron') let win = new BrowserWindow({ width: 800, height: 600, transparent:true, frame: false }) win.show()

Can I blur the content under a transparent window?

Transparent windows are not resizable. Setting resizable to true may make a transparent window stop working on some platforms. The blur filter only applies to the web page, so there is no way to apply blur effect to the content below the window (i.e. other applications open on the user's system).

Why are transparent windows not working on my platform?

Setting resizable to true may make a transparent window stop working on some platforms. The blur filter only applies to the web page, so there is no way to apply blur effect to the content below the window (i.e. other applications open on the user's system). On Windows operating systems, transparent windows will not work when DWM is disabled.

How to enable transparent windows when DWM is disabled?

On Windows operating systems, transparent windows will not work when DWM is disabled. On Linux users have to put --enable-transparent-visuals --disable-gpu in the command line to disable GPU and allow ARGB to make transparent window, this is caused by an upstream bug that alpha channel doesn't work on some NVidia drivers on Linux.


2 Answers

electron-acrylic-window

Actually, it is possible, with a little bit of magic. I have no idea why nobody pointed that out, but there exists a small utility called electron-acrylic-window, which allows you to do exactly that. You can choose between the acrylic ("frosted") and blur effects, as well as change the color of the window and the opacity.

Under the hood, it uses node-gyp and low-level C++ code to render the page however you like. It's pretty easy to implement in Javascript.

The major drawback is that anything that is remotely transparent (and not above anything with a solid color) will be rendered as totally transparent.

Sample usage

index.js

const { BrowserWindow } = require('electron-acrylic-window');
// import { BrowserWindow } from 'electron-acrylic-window';

win = new BrowserWindow({
  ...,
  frame: false,
  vibrancy: {
    theme: 'light', // (default) or 'dark' or '#rrggbbaa'
    effect: 'acrylic', // (default) or 'blur'
    disableOnBlur: true, // (default)
  }
});

// alternatively use these to
// dynamically change vibrancy
win.setVibrancy([options])
// or
setVibrancy(win, [options])

style.css

body {
  background-color: transparent;
}

.watev {
  background-color: black;
}
like image 112
AirOne Avatar answered Sep 21 '22 13:09

AirOne


It's not possible to blur other apps in the background. https://www.electronjs.org/docs/api/frameless-window#limitations

The blur filter only applies to the web page, so there is no way to apply blur effect to the content below the window (i.e. other applications open on the user's system).

like image 22
Freedruk Avatar answered Sep 19 '22 13:09

Freedruk