From 3fd2e3f8c419aa409e66b08d63195d3ec48ff773 Mon Sep 17 00:00:00 2001 From: FliPPeDround <70848683+FliPPeDround@users.noreply.github.com> Date: Wed, 13 Nov 2024 10:23:42 +0800 Subject: [PATCH] feat: add transparent window example and support (#11) --- examples/transparent.mjs | 20 ++++++++++++++++++++ src/browser_window.rs | 9 +++++++++ 2 files changed, 29 insertions(+) create mode 100644 examples/transparent.mjs diff --git a/examples/transparent.mjs b/examples/transparent.mjs new file mode 100644 index 0000000..cb6cce4 --- /dev/null +++ b/examples/transparent.mjs @@ -0,0 +1,20 @@ +import { Application } from "../index.js"; + +const app = new Application(); +const window = app.createBrowserWindow({ + transparent: true, + decorations: false, +}); + +const webview = window.createWebview({ + html: /* html */ ` + + +

Hello, transparent!

+ + `, + transparent: true, + enableDevtools: true, +}); + +app.run(); diff --git a/src/browser_window.rs b/src/browser_window.rs index 4c59077..8683945 100644 --- a/src/browser_window.rs +++ b/src/browser_window.rs @@ -209,6 +209,15 @@ impl BrowserWindow { window = window.with_focused(focused); } + if let Some(transparent) = options.transparent { + window = window.with_transparent(transparent); + #[cfg(target_os = "windows")] + { + use tao::platform::windows::WindowBuilderExtWindows; + window = window.with_undecorated_shadow(false); + } + } + if let Some(fullscreen) = options.fullscreen { let fs = match fullscreen { // Some(FullscreenType::Exclusive) => Some(Fullscreen::Exclusive()),