Skip to content

Window Tranparency Not Rendering Correctly #1524

@imgurbot12

Description

@imgurbot12

Describe the bug

Wry fails to rerender properly when transparency is enabled, leaving the old material underneath the new frame.

Related to DioxusLabs/dioxus#3821

Steps To Reproduce

  1. Run the following script
  2. Press a key on the keyboard.
use tao::{
    event::{Event, WindowEvent},
    event_loop::{ControlFlow, EventLoop},
    window::WindowBuilder,
};
use wry::WebViewBuilder;

static HTML1: &'static str = r#"
<html><body><div style="font-size: 100px">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit,
    sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
    Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
    nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
    reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
    pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
    culpa qui officia deserunt mollit anim id est laborum.
</div></body></html>

"#;
static HTML2: &'static str = r#"
<html><body><div style="font-size: 100px">
    Bacon ipsum dolor amet jowl pig pork meatball pork belly.
    Beef ribs buffalo hamburger burgdoggen. Pig pancetta pastrami
    shoulder fatback bacon kevin ham hock doner sirloin prosciutto
    t-bone meatloaf. Sausage swine flank pork, spare ribs pork loin
    ribeye beef ribs hamburger. Tongue pork chuck, biltong spare ribs
    pig jerky salami frankfurter flank drumstick leberkas pork chop
    pastrami jowl. Buffalo cupim alcatra tongue prosciutto, pork chop
    short ribs pancetta meatloaf corned beef chicken flank sirloin
    spare ribs. Boudin meatball andouille tenderloin meatloaf.
</div></body></html>
"#;

fn main() -> wry::Result<()> {
    let event_loop = EventLoop::new();
    let window = WindowBuilder::new()
        .with_decorations(false)
        .with_transparent(false)
        .build(&event_loop)
        .unwrap();

    let builder = WebViewBuilder::new()
        .with_html(HTML1)
        .with_transparent(true);

    let _webview = {
        use tao::platform::unix::WindowExtUnix;
        use wry::WebViewBuilderExtUnix;
        let vbox = window.default_vbox().unwrap();
        builder.build_gtk(vbox)?
    };

    let mut switch = false;
    event_loop.run(move |event, _, control_flow| {
        *control_flow = ControlFlow::Wait;

        if let Event::WindowEvent {
            event: WindowEvent::KeyboardInput { .. },
            ..
        } = event
        {
            switch = !switch;
            let content = if switch { HTML1 } else { HTML2 };
            _webview
                .load_html(content)
                .expect("failed to update content");
        }

        if let Event::WindowEvent {
            event: WindowEvent::CloseRequested,
            ..
        } = event
        {
            *control_flow = ControlFlow::Exit
        }
    });
}

Screenshots

Image

Platform and Versions (please complete the following information):
OS: EndeaverOS (Arch Linux) (Hyprland 0.47.1)
Rustc: rustc 1.85.0 (4d91de4e4 2025-02-17)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions