From e2785566c69d43f003896b7b5da79b29d2966c13 Mon Sep 17 00:00:00 2001 From: "Ngo Iok Ui (Wu Yu Wei)" Date: Wed, 28 Apr 2021 11:47:19 +0800 Subject: [PATCH] fix: transparency on Windows (#217) * Fix transparency on Windows * Fix transparency on Windows * Add change file * Fix custom titlebar example --- .changes/transparent.md | 5 +++++ Cargo.toml | 5 +++-- examples/custom_titlebar.rs | 7 +++---- examples/transparent.rs | 6 +++++- rustfmt.toml | 2 +- src/webview/win32/mod.rs | 16 +++++++++++++--- 6 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 .changes/transparent.md diff --git a/.changes/transparent.md b/.changes/transparent.md new file mode 100644 index 000000000..1693a752f --- /dev/null +++ b/.changes/transparent.md @@ -0,0 +1,5 @@ +--- +"wry": minor +--- + +Fix transparency on Windows diff --git a/Cargo.toml b/Cargo.toml index ba235bf83..e559cbec6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ default = [ "file-drop", "protocol", "win32" ] file-drop = [ ] protocol = [ ] winrt = [ "windows-webview2", "windows" ] -win32 = [ "webview2", "winapi" ] +win32 = [ "webview2", "winapi", "webview2-sys" ] [dependencies] libc = "0.2" @@ -50,7 +50,8 @@ gdk = "0.13" gdk-pixbuf = "0.9" [target."cfg(target_os = \"windows\")".dependencies] -webview2 = { version = "0.1.0-beta.1", optional = true } +webview2 = { version = "0.1.0", optional = true } +webview2-sys = { version = "0.1.0", optional = true } winapi = { version = "0.3", features = [ "libloaderapi", "oleidl" ], optional = true } windows-webview2 = { version = "0.1", optional = true } windows = { version = "0.7", optional = true } diff --git a/examples/custom_titlebar.rs b/examples/custom_titlebar.rs index 66f6c7dd9..2278647cc 100644 --- a/examples/custom_titlebar.rs +++ b/examples/custom_titlebar.rs @@ -131,8 +131,8 @@ fn main() -> wry::Result<()> { } } - match event { - Event::WindowEvent { event, window_id } => match event { + if let Event::WindowEvent { event, window_id } = event { + match event { WindowEvent::CloseRequested => { webviews.remove(&window_id); if webviews.is_empty() { @@ -143,8 +143,7 @@ fn main() -> wry::Result<()> { let _ = webviews[&window_id].resize(); } _ => (), - }, - _ => (), + } } }); } diff --git a/examples/transparent.rs b/examples/transparent.rs index 01996f2a6..51dd69ec1 100644 --- a/examples/transparent.rs +++ b/examples/transparent.rs @@ -15,17 +15,21 @@ fn main() -> wry::Result<()> { let event_loop = EventLoop::new(); let window = WindowBuilder::new() .with_decorations(false) + // There are actually three layer of background color when creating webview window. + // The first is window background... .with_transparent(true) .build(&event_loop) .unwrap(); let webview = WebViewBuilder::new(window)? + // The second is on webview... .with_transparent(true) + // And the last is in html. .with_url( r#"data:text/html, - hello + hello