Skip to content

[Bug]: Maximized window with the "backgroundMaterial" property #42393

Closed

Description

@QuadVector

Preflight Checklist

Electron Version

30.1.0

What operating system are you using?

Windows

Operating System Version

Windows 11 version 10.0.22631

What arch are you using?

x64

Last Known Working Electron version

No response

Expected Behavior

When I want to maximize my window without a title bar and with the Windows 11 background material (mica, acrylic, etc.), I expect to see a default maximized window with these materials.

For example, I use these parameters to enable the maximize button and the background material:

    backgroundMaterial: "mica",
    titleBarOverlay: {
      height: 32
    },
    frame: false,
    maximizable: true,
    titleBarStyle: "hidden"

Actual Behavior

When I'm trying to make a BrowserWindow with the activated title bar overlay and background material, I can maximize it (even if I can't maximize the window with the disabled title bar overlay), but the background material becomes black, and the borders lose their border radius.

A window before maximizing:
A window before maximizing

A window after maximizing:
A window after maximizing

A maximized window:
A maximized window

A window with backgroundMaterial - mica and default title bar:
image

Testcase Gist URL

No response

Additional Information

Here's my code of the BrowserWindow init, which has the subject issue:

  const mainWindow = new BrowserWindow({
    width: 1280,
    height: 800,
    minWidth: 300,
    minHeight: 300,
    fullscreenable: true,
    webPreferences: {
      nodeIntegration: true,
      contextIsolation: false,
      devTools: true,
      webSecurity: false
    },
    resizable: true,
    autoHideMenuBar: true,
    show: true,

   //pay attention on this params below
    backgroundMaterial: "mica",
    titleBarOverlay: {
      height: 32
    },
    frame: false,
    maximizable: true,
    titleBarStyle: "hidden"
  });

Activity

  1. moved this to 👀 Unsorted Items in 30-x-yon Jun 7, 2024
  2. aleversn commented on Jun 8, 2024

    @aleversn

    same here

  3. added a commit that references this issue on Jul 1, 2024
  4. kingyue737 commented on Aug 17, 2024

    @kingyue737

    Duplicate #41824

  5. electron-issue-triage commented on Nov 16, 2024

    @electron-issue-triage

    This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

  6. kingyue737 commented on Nov 16, 2024

    @kingyue737

    bump

  7. reitowo commented on Nov 28, 2024

    @reitowo
    Member

    A partial workaround:

    I managed to restore the backdrop effect + rounded corner by manually calling these API after win.on('unmaximize').

       public static void SetWindowRoundedBorder(long handle, bool enable) {
          var h = new IntPtr(handle);
          var m = new MARGINS() {
             cxLeftWidth = -1,
             cxRightWidth = -1,
             cyTopHeight = -1,
             cyBottomHeight = -1
          };
          DwmExtendFrameIntoClientArea(h, ref m);
          
          var attribute = DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE;
          var preference =
             (uint)(enable ? DWM_WINDOW_CORNER_PREFERENCE.DWMWCP_ROUND : DWM_WINDOW_CORNER_PREFERENCE.DWMWCP_DONOTROUND);
          DwmSetWindowAttribute(h, attribute, ref preference, sizeof(uint));
       }

    However when maximized it still turned completely black without effect no matter acrylic or mica.

  8. reitowo commented on Nov 28, 2024

    @reitowo
    Member

    Another strange thing is when electron is in maximized state with acrylic, it has this extra pixels with acrylic effect below the whole window.

    Image

    On Spy++ it says the rectangle is 2099 height which confirms it.

    Image

  9. reitowo commented on Nov 29, 2024

    @reitowo
    Member

    I think the wierd padding of the window is the shadow part of the window, and if I set background material to 'none' the wierd acrylic padding are gone.

    By setting WindowPos to ClientRect it client area shrinks and it seems only the client area doens't have that backdrop effect.

    Image

  10. reitowo commented on Nov 29, 2024

    @reitowo
    Member

    Just poking around I managed to revive some of this by

          var margins = new Windows.Win32.UI.Controls.MARGINS() {
             cxLeftWidth = enable ? -1 : 0,
             cxRightWidth = enable ? -1 : 0,
             cyTopHeight = enable ? -1 : 0,
             cyBottomHeight = enable ? -1 : 0
          };
          PInvoke.DwmExtendFrameIntoClientArea(new HWND(h), margins);
             var preference =
                (uint)(enable
                   ? Windows.Win32.Graphics.Dwm.DWM_SYSTEMBACKDROP_TYPE.DWMSBT_TRANSIENTWINDOW
                   : Windows.Win32.Graphics.Dwm.DWM_SYSTEMBACKDROP_TYPE.DWMSBT_NONE);
             PInvoke.DwmSetWindowAttribute(new HWND(h),
                Windows.Win32.Graphics.Dwm.DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE, &preference, sizeof(uint));

    after 100ms of 'maximize' event

        const refreshAcrylic = () => {
            const handle = main.getNativeWindowHandle().readUInt32LE()
            SetWindowRoundedBorder(handle, true)
            ExtendFrameIntoClientArea(handle, true)
            EnableWindowAcrylic(handle, true)
        }
    
        main.on('maximize', () => {
            setTimeout(() => {
                refreshAcrylic()
            }, 1)
        })
    
        main.on('focus', () => {
            refreshAcrylic()
        })
    
        main.on('unmaximize', () => {
            refreshAcrylic()
        })

    Image

  11. xyloflake commented on Jan 11, 2025

    @xyloflake

    bump. i have the exact same issue with v33.

  12. Schneegans commented on Jan 19, 2025

    @Schneegans

    I am now calling the following from a native module after showing the window:

    DWM_BLURBEHIND bb = {0};
    bb.dwFlags = DWM_BB_ENABLE;
    bb.fEnable = TRUE;
    bb.hRgnBlur = NULL;
    DwmEnableBlurBehindWindow(hwnd, &bb);
    
    // DWMWCP_ROUND = 2 and DWMWA_WINDOW_CORNER_PREFERENCE = 33 are not always defined.
    unsigned p = 2;
    DwmSetWindowAttribute(hwnd, 33, &p, sizeof(p));

    At least for me, this seems to fix the behavior when the background material is set to 'acrylic'. I am not sure about any negative side, though...

    Edit: I just noticed that the blur looks different after maximizing the window. But maybe that's acceptable...

  13. codebytere commented on Feb 2, 2025

    @codebytere
    Member

    Combining with #41824.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions