3.3 KiB
Frameless Window
A frameless window is a window that has no chrome, the parts of the window, like toolbars, that are not a part of the webp page. These are options on the BrowserWindow
class.
Create a frameless window
To create a frameless window, you need to set frame
to false
in
BrowserWindow's options
:
var BrowserWindow = require('browser-window');
var win = new BrowserWindow({ width: 800, height: 600, frame: false });
Transparent window
By setting the transparent
option to true
, you can also make the frameless
window transparent:
var win = new BrowserWindow({ transparent: true, frame: false });
Limitations
- You can not click through the transparent area. We are going to introduce an API to set window shape to solve this, but currently blocked at an upstream bug.
- Transparent windows are not resizable. Setting
resizable
totrue
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 operation shystems, 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. - On Mac the native window shadow will not be shown on a transparent window.
Draggable region
By default, the frameless window is non-draggable. Apps need to specify
-webkit-app-region: drag
in CSS to tell Electron which regions are draggable
(like the OS's standard titlebar), and apps can also use
-webkit-app-region: no-drag
to exclude the non-draggable area from the
draggable region. Note that only rectangular shapes are currently supported.
To make the whole window draggable, you can add -webkit-app-region: drag
as
body
's style:
<body style="-webkit-app-region: drag">
</body>
And note that if you have made the whole window draggable, you must also mark buttons as non-draggable, otherwise it would be impossible for users to click on them:
button {
-webkit-app-region: no-drag;
}
If you're setting just a custom titlebar as draggable, you also need to make all buttons in titlebar non-draggable.
Text selection
In a frameless window the dragging behaviour may conflict with selecting text. For example, when you drag the titlebar you may accidentally select the text on the titlebar. To prevent this, you need to disable text selection within a draggable area like this:
.titlebar {
-webkit-user-select: none;
-webkit-app-region: drag;
}
Context menu
On some platforms, the draggable area will be treated as a non-client frame, so when you right click on it a system menu will pop up. To make the context menu behave correctly on all platforms you should never use a custom context menu on draggable areas.