window-vibrancy

repository·dev·Indexed 21 days ago

https://github.com/tauri-apps/window-vibrancy

A Rust crate for applying platform-specific visual effects to application windows, designed for frameworks like Tauri. It supports blur, acrylic, and mica effects on Windows, as well as vibrancy and liquid glass effects (macOS 26+) on macOS. Version 0.8.0 provides tools to configure transparency and visual styles, with a specific requirement to use version 0.4 for tauri@v1.

Tokens
4.4K
Snippets
25
Records
29
Agent score
76%

What's inside window-vibrancy

  1. Configure Tauri for window vibrancy

    dev

    To use window-vibrancy with Tauri, you must configure your frontend and Tauri settings to allow transparency:

    1. CSS: Set html, body { background: transparent } in your web assets.
    2. tauri.conf.json: Set "transparent": true in your window configuration.
    3. macOS specific: Set "macOSPrivateApi": true in your tauri.conf.json.
  2. Apply window vibrancy and blur effects

    dev

    Use window-vibrancy to apply platform-specific visual effects like blur, acrylic, mica, or vibrancy to your application windows.

    Platform Support:

    • Windows: Supports apply_blur, apply_acrylic, and apply_mica.
    • macOS: Supports apply_vibrancy (macOS 10.10+) and apply_liquid_glass (macOS 26+).
    • Linux: Not supported; effects are managed by the system compositor.

    Important Version Note: If you are using tauri@v1, you must use version 0.4 of this crate.

    use window_vibrancy::{apply_blur, apply_vibrancy, NSVisualEffectMaterial};
    
    #[cfg(target_os = "macos")]
    apply_vibrancy(&window, NSVisualEffectMaterial::HudWindow, None, None)
        .expect("Unsupported platform! 'apply_vibrancy' is only supported on macOS");
    
    #[cfg(target_os = "windows")]
    apply_blur(&window, Some((18, 18, 18, 125)))
        .expect("Unsupported platform! 'apply_blur' is only supported on Windows");
  3. Use macOS Liquid Glass Effect (macOS 26+)

    dev

    For macOS 26 and newer, use apply_liquid_glass to achieve a modern glass effect with customizable radius, opacity, and view styles. You can use LiquidGlassOptions to configure the effect.

    Advanced WebView Integration: If you are managing the primary content view (e.g., a WKWebView), you can pass its pointer via .content_view(webview) to reparent it into the glass view's contentView.

    use window_vibrancy::{apply_liquid_glass, LiquidGlassOptions, NSGlassEffectViewStyle};
    
    #[cfg(target_os = "macos")]
    {
        let options = LiquidGlassOptions::new(NSGlassEffectViewStyle::Clear)
            .radius(26.0)
            .opaque(false);
    
        apply_liquid_glass(&window, options)
            .expect("Unsupported platform! 'apply_liquid_glass' is only supported on macOS 26+");
    }
  4. Reference of available vibrancy functions

    dev

    The following functions are available for applying and clearing window effects. Note that some effects may have performance implications during window resizing or dragging.

    | Function | Supported platforms | Notes |
    |:---|:---|:---|
    | `apply_blur` & `clear_blur` | Windows 7/10/11 (22H1 only) | Bad performance when resizing/dragging on Windows 11 build 22621+ |
    | `apply_acrylic` & `clear_acrylic` | Windows 10/11 | Bad performance when resizing/dragging on Windows 10 v1903+ and Windows 11 build 22000 |
    | `apply_mica` & `clear_mica` | Windows 11 | |
    | `apply_vibrancy` & `clear_vibrancy` | macOS 10.10 and newer | |
    | `apply_liquid_glass` & `clear_liquid_glass` | macOS 26 and newer | Modern glass effect with customizable radius, tint color, and opacity options |
  5. Liquid Glass compatibility and errors

    dev

    When using the Liquid Glass API, be aware of the following error conditions:

    • Error::NotMainThread: Occurs if apply_liquid_glass is called from a background thread. All macOS UI manipulations must happen on the main thread.
    • Error::UnsupportedPlatformVersion: Occurs if the system is running a version of macOS older than 26.0.
  6. Apply tabbed effect on Windows

    dev

    Applies the Tabbed effect (optimized for tabbed interfaces) to the specified window.

    • Windows 11 (v22523+): Uses DwmSetWindowAttribute with DWMSBT_TABBEDWINDOW.

    Parameters:

    • hwnd: The window handle.
    • dark: An optional boolean to enable/disable immersive dark mode.

    Supported Platforms: Windows 11 only.

    apply_tabbed(hwnd, Some(false))?
  7. Clear liquid glass effect on macOS

    dev

    Removes the liquid glass effect from a macOS window. This is only supported on macOS 26.0+.

    Returns:

    • Ok(true) if the liquid glass effect was cleared.
    • Ok(false) if the liquid glass effect was not previously applied by this crate.
    // Only available on macOS
    #[cfg(target_os = "macos")]
    use window_vibrancy::clear_liquid_glass;
    
    let cleared = clear_liquid_glass(&window).expect("Failed to clear liquid glass");
  8. Clear vibrancy effect on macOS

    dev

    Removes the vibrancy effect from a macOS window. This is only supported on macOS 10.10 or newer.

    Returns:

    • Ok(true) if the vibrancy effect was cleared.
    • Ok(false) if the vibrancy effect was not previously applied by this crate.
    use window_vibrancy::clear_vibrancy;
    
    let cleared = clear_vibrancy(&window).expect("Failed to clear vibrancy");
  9. Clear blur effect on Windows

    dev

    Removes the blur effect from the specified window.

    • Windows 7: Disables blur via DwmEnableBlurBehindWindow.
    • Windows 10 (v1809+): Disables the accent via SetWindowCompositionAttribute with ACCENT_DISABLED.

    Supported Platforms: Windows 7, Windows 10 v1809 or newer, and Windows 11.

    clear_blur(hwnd)?
  10. Apply mica effect on Windows

    dev

    Applies the Mica effect to the specified window.

    • Windows 11 (v22523+): Uses DwmSetWindowAttribute with DWMSBT_MAINWINDOW.
    • Windows 11 (v22000+): Uses the undocumented DWMWA_MICA_EFFECT attribute.

    Parameters:

    • hwnd: The window handle.
    • dark: An optional boolean to enable/disable immersive dark mode for the effect.

    Supported Platforms: Windows 11 only.

    apply_mica(hwnd, Some(true))?
  11. Apply liquid glass effect on macOS

    dev

    Applies the liquid glass effect to a window. This is only supported on macOS 26.0+.

    Arguments:

    • options: A LiquidGlassOptions<'_> object.
    // Only available on macOS
    #[cfg(target_os = "macos")]
    use window_vibrancy::apply_liquid_glass;
    
    apply_liquid_glass(&window, options).expect("Failed to apply liquid glass");