Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparent Windows on Linux (Electron)

Using the transparent argument and setting it to true when creating a new BrowserWindow in Electron usually gives the window a transparent background... But on Linux that isn't the case for my knowledge

Now I heard you can set some Command Line Arguments... But that isn't working... It just displays black or white no matter what...

// Should set the commandLine arguments and work...

const {app} = require('electron')

app.commandLine.appendSwitch('enable-transparent-visuals');
app.commandLine.appendSwitch('disable-gpu');

Now i have heard this is no problem with electron rather a problem with hardware... But i just needed to make sure therefore creating this question!

like image 239
undefinedChar Avatar asked Feb 19 '19 10:02

undefinedChar


People also ask

How do I make file explorer transparent in Linux?

2 Answers. Press Alt + F2 , type ccsm on field to launch Compiz Setting. On Accessibility section, click Opacity Brightness & Saturation plugin. On the current tab, expand Window Specific Settings.


3 Answers

There do seem to be multiple issues with transparency, on different distributions with differing hardware. There are various suggested workarounds. You might not be able to make transparency work acceptably for your scenario on all hardware and distributions.

Examples

  • https://github.com/electron/electron/issues/2170
  • https://github.com/zeit/hyper/pull/842
  • https://github.com/electron/electron/issues/15947
  • Can't succeed in making transparent window in Electron (javascript)

From the Electron docs:

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.

https://github.com/electron/electron/blob/master/docs/api/frameless-window.md

like image 97
GrahamMc Avatar answered Oct 06 '22 03:10

GrahamMc


I have encounter the same problem as you and so I have written :

  • this StackOverFlow question : Can't succeed in making transparent window in Electron (javascript)
  • this Electron issue : https://github.com/electron/electron/issues/15947
  • and finally request this feature : https://github.com/electron/electron/issues/16809

Till the requested feature is implemented, the solution is simple just add a delay before launching the window.

You can clone this git repo, put the delay to 500, and normally magic will appear.

EDIT 1 : Use this repo : https://gitlab.com/doom-fr/electron-transparency-demo

git clone https://gitlab.com/doom-fr/electron-transparency-demo
cd electron-transparency-demo
npm install
npm start
# or npm run startWithTransparentOption
# or npm run startWithAllOptions

For me, it works out of the box with Debian Jessie and electron 4.0.5, for npm start, npm run startWithTransparentOption but not with npm run startWithAllOptions.

NB : be carefull to set at least 500ms to have chance it works. After you can reduce the delay but it is not stable. It is why an event on transparentReady is needed.

Doom

like image 42
doom Avatar answered Oct 06 '22 04:10

doom


This worked to me:

if(process.platform === "linux") {
  app.commandLine.appendSwitch('enable-transparent-visuals');
  app.disableHardwareAcceleration();

  app.on('ready', () => setTimeout(createWindow, 400));
}
like image 23
Cris Avatar answered Oct 06 '22 03:10

Cris