electron: 'backgroundMaterial' is not work in frameless window

Preflight Checklist

Electron Version

24.4.0

What operating system are you using?

Windows

Operating System Version

Windows 11 22H2

What arch are you using?

x64

Last Known Working Electron version

No response

Expected Behavior

The feature of backgroundMaterial could work on frameless window, or it can work when the titleBarStyle is hidden.

Actual Behavior

The feature of backgroundMaterial is not work when set frame: false or titleBarStyle: hidden.

Testcase Gist URL

No response

Additional Information

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 9
  • Comments: 22 (2 by maintainers)

Commits related to this issue

Most upvoted comments

bump

It has 0 window animation

I found a work around:

Build your own buttons for the window and instead of Using win.maximize() and win.unmaximize() use win.setBounds()

It does almost the same thing without losing the effect the only Downside is that you have to do your own buttons which is not very difficult

import {
  BrowserWindow,
  screen
} from 'electron'

  const primaryDisplay = screen.getPrimaryDisplay()
  const workAreaSize = primaryDisplay.workAreaSize
  let previousBounds = { width: 1150, height: 766 }; // Default previous size

 const win = new BrowserWindow({
    width: previousBounds.width,
    height: previousBounds.height,
    vibrancy: 'sidebar', // on MacOS
    backgroundMaterial: 'mica', // on Windows 11
    roundedCorners: true,
    frame: false,
    autoHideMenuBar: true
  })

whe you receive the event from render execute something like this

      
        if (
          win.getBounds().width < workAreaSize.width &&
          win.getBounds().height < workAreaSize.height
        ) {
          previousBounds = win.getBounds()
          win.setBounds({ x: 0, y: 0, width: workAreaSize.width, height: workAreaSize.height })
        } else {
          win.setBounds(previousBounds)
        }