Skip to content

[Feature Request]: Use new 'Mica' material for BrowserWindow vibrancy in Windows 11 #29937

Closed

Description

@MehediH

Preflight Checklist

Problem Description

At the moment, setVibrancy() for BrowserWindow only supports macOS. Windows 10 has had a similar material called Acrylic, but Electron is yet to add support for it.

Proposed Solution

With Windows 11, Microsoft is introducing a more performant material dubbed Mica.

From Microsoft:

Mica is an opaque, dynamic material that incorporates theme and desktop wallpaper to paint the background of long-lived windows such as apps and settings. You can apply Mica to your application backdrop to delight users and create visual hierarchy, aiding productivity, by increasing clarity about which window is in focus. Mica is specifically designed for app performance as it only samples the desktop wallpaper once to create its visualization.

The new Mica material is a prominent part of the Windows 11 visual design. Adding support for Mica to setVibrancy() in Electron would greatly elevate the design of many apps, and enable the visual look of Electron apps to be in line with modern Windows experiences.

Alternatives Considered

The following libraries currently allow apps to use Acrylic as an alternative to vibrancy in Windows 10:

Additional Information

N/A

Activity

  1. paulobrien commented on Jun 29, 2021

    @paulobrien

    Good plan, it definitely makes a lot of sense to support this in Electron natively.

  2. codebytere commented on Jun 29, 2021

    @codebytere
    Member

    Interesting! i can try to poke into this if i have some time :)

  3. self-assigned this
    on Jul 27, 2021
  4. codebytere commented on Jul 28, 2021

    @codebytere
    Member

    hey folks - put up a PR to get this added into Electron 🌟

  5. MehediH commented on Jul 28, 2021

    @MehediH
    ContributorAuthor

    hi @codebytere, this is amazing -- thank you so much! After having a quick look over the code for the PR, it seems this is adding Acrylic support for vibrancy.

    Can we expect Mica support in the future? Having an option to choose between Acrylic and Mica for vibrancy would be ideal. I am not sure if Microsoft even provides the APIs for implementing Mica on Win32 apps yet, so I understand if it's simply not possible to add Mica support yet :)

  6. just1a-person commented on Jul 28, 2021

    @just1a-person

    Mica for long lived surfaces (like app background) and Acrylic for short lived surfaces (like context menus) is how Microsoft's documentation recommends to use them.

  7. codebytere commented on Jul 28, 2021

    @codebytere
    Member

    @MehediH yeah that's the constraint for now sadly - Mica isn't yet available for Win32 apps yet. Once it becomes possible i'd plan to update that codepath to take it into account and allow you all to select it :)

  8. MehediH commented on Jul 28, 2021

    @MehediH
    ContributorAuthor

    @codebytere Understood. Thank you for the work on this!!

  9. riverar commented on Jul 28, 2021

    @riverar

    I wrote those Acrylic hacks; they are not supported by Microsoft and introduce a number of problems. DO NOT use them in mainline Electron.

    Mica should get supported APIs soon. Perhaps as part of that effort, the correct Acrylic path will get documented. (I'm connected to the team and will continue to be a very loud squeaky wheel.)

  10. thomassth commented on Jul 28, 2021

    @thomassth

    I think the latest MS edge (dev?) builds uses Mica already, so electron should be able to tap into the same API?

  11. gaetandezeiraud commented on Oct 21, 2021

    @gaetandezeiraud

    API available with dwmapi.dll for win32.

    enum DWMWINDOWATTRIBUTE
    {
        DWMWA_MICA_EFFECT = 1029
    };
    
    enum DWM_MICA_PREFERENCE
    {
        DWMWCP_FALSE = 0,
        DWMWCP_TRUE = 1
    };
    
    DWM_MICA_PREFERENCE preference = DWMWCP_TRUE;
    DwmSetWindowAttribute(hWnd, DWMWA_MICA_EFFECT, &preference, sizeof(preference));
    

    Just not documented and define in dwmapi.h.

  12. mitchchn commented on Oct 22, 2021

    @mitchchn
    Member

    I threw together a native module that sets DWMWA_MICA_EFFECT as @Brouilles described, and sure enough... Mica in Electron:

    image

    But there are some issues to resolve:

    1. The BrowserWindow has to be set to {transparent: true, frame: true} which is an invalid combination for Windows.
    2. If the window is made frameless and transparent, Mica only appears in the inactive (solid colour) state, as if the window is never focused.
    3. Transparent frameless windows don't have nice round corners on Windows 11 anyway. :)
  13. gaetandezeiraud commented on Oct 22, 2021

    @gaetandezeiraud

    Great job @mitchchn! I have also seen in my test than the title in the title bar have a solid background color. Don't know why.

  14. 11 remaining items

  15. decahedron1 commented on Jun 30, 2022

    @decahedron1

    I was able to get Mica/Acrylic working in an Electron fork but I ran into a few issues.

    • Electron disables resizing and maximizing for windows with transparent: true, which is required for acrylic effects to work.
    • titleBarStyle: hidden breaks acrylic effects. I'm not sure how exactly Electron hides the titlebar in a way that breaks it, but I've gotten Mica working with hidden titlebars in another project using these window styles:
      • style = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_SYSMENU | WS_SIZEBOX | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_VISIBLE
      • style_ex = WS_EX_WINDOWEDGE
  16. sylveon commented on Jul 23, 2022

    @sylveon

    transparent: true is not required for the effects to work. In my experience, simply not setting a background color to the web page and ensuring every element on top does not use a non transparent color is sufficient. Not using transparent: true also allows window snapping and shadows to keep working.

  17. decahedron1 commented on Jul 23, 2022

    @decahedron1

    transparent: true is not required for the effects to work. In my experience, simply not setting a background color to the web page and ensuring every element on top does not use a non transparent color is sufficient. Not using transparent: true also allows window snapping and shadows to keep working.

    Sure enough, setting backgroundColor: '#00000000' in JS and background: unset !important for <html> and <body> gave me a resizable window!

    image

    Though the titlebar is missing (even with titleBarStyle: 'default'), the window cannot be moved with -webkit-app-region: drag, there is a ~6px space of nothing at the top of the window, and any titleBarStyle other than default breaks it completely:
    image

  18. deleted a comment from aleversn on Sep 25, 2022
  19. GregVido commented on Sep 29, 2022

    @GregVido
  20. GregVido commented on Sep 29, 2022

    @GregVido

    what is your windows 11 version ?

  21. GregVido commented on Oct 7, 2022

    @GregVido

    what is your windows 11 version ?

    21H2

    And if you update windows to 22h2 and try with last version of mica electron, no work too ?

  22. Stanzilla commented on Nov 2, 2023

    @Stanzilla

    I was able to get Mica/Acrylic working in an Electron fork but I ran into a few issues.

    • titleBarStyle: hidden breaks acrylic effects. I'm not sure how exactly Electron hides the titlebar in a way that breaks it, but I've gotten Mica working with hidden titlebars in another project using these window styles:

    That's the bummer here, any way to get mica to work with a hidden title bar?

  23. d-o0o-b commented on Feb 19, 2024

    @d-o0o-b

    image
    It might be help you!

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions