Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transparent frame doesn't work anymore on latest webview-sys's commit #38

Closed
dizda opened this issue Nov 12, 2018 · 5 comments
Closed

Comments

@dizda
Copy link

dizda commented Nov 12, 2018

Hey there,

The full window transparency doesn't work anymore on https://github.com/zserge/webview 's latest commit.

It used to work with an old revision:

cd webview-sys/webview
git checkout 02aa1dcf62a15f2c1e2197a07642e9c474ac32fa

Code to reproduce:

#![windows_subsystem = "windows"]

extern crate web_view;

use web_view::*;

fn main() {
    let mut web_view = WebViewBuilder::new()
        .title("Page load example")
        .content(Content::Html(HTML))
        .size(800, 600)
        .resizable(true)
        .debug(true)
        .user_data(())
        .invoke_handler(|_webview, _arg| Ok(()))
        .build()
        .unwrap();

    web_view.set_color((122, 44, 200, 0));

    let res = web_view.run().unwrap();

    println!("final state: {:?}", res);
}

const HTML: &str = r#"
<!doctype html>
<html>
    <head>
        <style>
        html, body {
            background: transparent;
            color: pink;
        }
        </style>
    </head>
	<body>
	  <h1>Hello, world</h1>
	</body>
</html>
"#;

FYI with the latest commit, only the titlebar is transparent, but the frame remains white:
screenshot 2018-11-12 14 17 10

But should be (the frame is over my terminal):
screenshot 2018-11-12 14 17 42

Which is useful to make beautiful HTML widgets.

@richardhozak
Copy link
Collaborator

richardhozak commented Nov 12, 2018

This seems like https://github.com/zserge/webview issue. Have you reported it there? This is just binding library, meaning we wrap webview and cannot fix regressions directly here.

@dizda
Copy link
Author

dizda commented Nov 12, 2018

Thanks, I'll do it and link the issue to that one to keep track of it.

@gcstr
Copy link

gcstr commented Jan 16, 2021

I can still reproduce this behavior. Is there a workaround to create transparent windows?

@imgurbot12
Copy link

Bump. Issue seems to have come back. No transparency when running example code in this issue.

@imgurbot12
Copy link

imgurbot12 commented Dec 15, 2023

After pouring over the documentation across multiple apps and platforms using gtk and webkit2 I built a hack using the crates already used within web-view that provides transparency (at least for linux):

/// Update Gtk's Screen w/ Custom CSS to make Transparent
fn transparency_hack() {
    use gdk_sys::gdk_screen_get_default;
    use gtk_sys::*;
    use std::ffi::CString;
    // generate css-provider
    let provider = unsafe { gtk_css_provider_new() };
    // apply css to css-provider
    let css = CString::new("* { background: transparent }").unwrap();
    let clen = css.as_bytes().len();
    let mut error = std::ptr::null_mut();
    unsafe { gtk_css_provider_load_from_data(provider, css.as_ptr() as _, clen as _, &mut error) };
    // retrieve screen and apply css- provider to screen
    let prio = GTK_STYLE_PROVIDER_PRIORITY_APPLICATION;
    let screen = unsafe { gdk_screen_get_default() };
    unsafe { gtk_style_context_add_provider_for_screen(screen, provider as _, prio as _) };
}

Make sure to run this after building the web-view instance since gtk has to be initialized first before this can work.

Might be the wrong way to go about it but it works lol.
It might be years late, but if you wanted to know @gcstr here it is. :)

Edit: had to tweak the code a gazillion times to fix a few glib errors that were logging to stderr when they could be avoided. fixed how hopefully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants