iced icon indicating copy to clipboard operation
iced copied to clipboard

Window transparency does not work under Windows

Open doums opened this issue 1 year ago • 9 comments

Is your issue REALLY a bug?

  • [X] My issue is indeed a bug!
  • [X] I am not crazy! I will not fill out this form just to ask a question or request a feature. Pinky promise.

Is there an existing issue for this?

  • [X] I have searched the existing issues.

Is this issue related to iced?

  • [X] My hardware is compatible and my graphics drivers are up-to-date.

What happened?

Window transparent background does not work, it renders as solid black color, under Windows11. Setting wgpu in features changes nothing. Note: My gpu is an Nvidia card 4070, driver uptodate

Test program: Cargo.toml

[package]
name = "transparency"
version = "0.1.0"
edition = "2021"

[dependencies]
iced = { version = "0.12", features = ["wgpu", "debug"] }

main.rs

use iced::theme::Palette;
use iced::widget::container;
use iced::window::Level;
use iced::{
    executor, mouse, Application, Color, Command, Element, Length, Rectangle, Renderer, Sandbox,
    Settings, Size, Theme,
};

pub fn main() -> iced::Result {
    let settings = Settings {
        id: Some("test".into()),
        window: iced::window::Settings {
            size: Size::new(200f32, 200f32),
            transparent: true,
            level: Level::AlwaysOnTop,
            ..iced::window::Settings::default()
        },
        antialiasing: true,
        ..Settings::default()
    };
    TestApp::run(settings)
}

struct TestApp {
    theme: Theme,
}

#[derive(Debug, Clone, Copy)]
enum Message {}

impl Application for TestApp {
    type Executor = executor::Default;
    type Flags = ();
    type Message = Message;
    type Theme = Theme;

    fn new(_flags: ()) -> (TestApp, Command<Self::Message>) {
        (
            TestApp {
                theme: Theme::custom(
                    "main".to_string(),
                    Palette {
                        background: Color::TRANSPARENT,
                        ..Theme::default().palette()
                    },
                ),
            },
            Command::none(),
        )
    }

    fn title(&self) -> String {
        String::from("test")
    }

    fn update(&mut self, _message: Self::Message) -> Command<Self::Message> {
        Command::none()
    }

    fn view(&self) -> Element<Self::Message> {
        container("1234")
            .height(Length::Fill)
            .center_x()
            .center_y()
            .into()
    }

    fn theme(&self) -> Theme {
        self.theme.clone()
    }
}

What is the expected behavior?

Window transparency should work

Version

crates.io release

Operating System

Windows

Do you have any log output?

No response

doums avatar Jul 27 '24 10:07 doums

Same issue on windows 10 with an rx 6700 xt on the latest drivers (24.10.1)

FaisalAhmedAlghamdi avatar Oct 24 '24 00:10 FaisalAhmedAlghamdi

Same for me Setting the window style to transpartent makes it black

grafik grafik

#![windows_subsystem = "windows"]
use iced::{Element, Result, Background, Color, Border, Shadow, Length, Alignment};
use iced::widget::{button, container, Column, Space, Text};
use iced::window::Settings;

pub fn main() -> Result {

    let window_setting = Settings {
        decorations: false,
        size: iced::Size::new(500.0, 450.0),
        transparent: true,
        ..Settings::default()
    };

    iced::application("Test", TextInputApp::update, TextInputApp::view)
        .window(window_setting)
        .style(|_state, _theme| iced::application::Appearance {
            background_color: Color::TRANSPARENT,
            text_color: Color::WHITE,
        })
        .run()
}


#[derive(Default)]
struct TextInputApp {}
#[derive(Debug, Clone)]
enum Message {}

impl TextInputApp {

    fn update(&mut self, message: Message) {}

    fn view(&self) -> Element<'_, Message> {
        container(self.view_success())
            .style(|theme| container::Style {
                background: Some(Background::Color(Color::from_rgba(0.1, 0.1, 0.1, 0.95))),
                border: Border {
                    radius: 20.0.into(),
                    width: 0.0,
                    color: Color::TRANSPARENT,
                },
                text_color: None,
                shadow: Shadow::default(),
            })
            .padding(1)
            .into()
    }

    fn view_success(&self) -> Element<'_, Message> {
        let content = Column::new()
            .width(Length::Fill)
            .height(Length::Fill)
            .align_x(Alignment::Center)
            .push(Space::with_height(Length::FillPortion(1)))
            .push(Text::new("Test").size(24))
            .push(Space::with_height(Length::Fixed(20.0)))
            .push(Space::with_height(Length::FillPortion(1)));

        container(content)
            .width(Length::Fill)
            .height(Length::Fill)
            .into()
    }

}

Jackolix avatar Nov 24 '24 17:11 Jackolix

same issue on windows 11 24H2 with the previous version was all fine

sh1zen avatar Dec 17 '24 11:12 sh1zen

Same on MacOS. I just tried the gradient example and it gives me a dark gray background instead of becoming transparent.

nightscape avatar Dec 30 '24 00:12 nightscape

version 0.13.1: Same on macOS 15.2 & Windows 24H2

version Github master branch: fixed

ChenghaoQ avatar Jan 21 '25 10:01 ChenghaoQ

Same issue. Tested on 0.13.1 and https://github.com/iced-rs/iced/commit/97f1db3783dca5a4f60a9f89668613de4dfe9edd

jafkc2 avatar Feb 25 '25 23:02 jafkc2

I also cannot make the window transparent on version 0.13.1

Syst3mz avatar Mar 06 '25 20:03 Syst3mz

The following steps seem to fix this issue for me on an Nvidia graphics card:

  1. Go to Nvidia control panel
  2. Manage 3D settings
  3. Find something like "Vulkan/OpenGL Presentation Mode"
  4. It allows "Auto" , "Native" and "Layered". I had to choose "Native". After that transparency started working...

alex-ds13 avatar Mar 07 '25 22:03 alex-ds13

Not a recent issue, but the problem didn't just disappear. Could any/everyone try running their should-be-transparent iced app with ICED_BACKEND=tiny-skia cargo run ...? WGPU has more than one still-open issue regarding alpha modes being detected incorrectly.

pml68 avatar Jun 06 '25 22:06 pml68

Running with $env:ICED_BACKEND="tiny-skia"; cargo run ... (powershell) does seem to get the transparency working for me on 0.13.1

Zonalhaz avatar Jun 18 '25 12:06 Zonalhaz

Same issue, using iced 0.14-dev, is there a solution or something? it has been already a year since the open of this

GPeaky avatar Jul 25 '25 01:07 GPeaky

Have you tried running with the tiny-skia backend? See the previous comment.

pml68 avatar Jul 25 '25 06:07 pml68

Yeah and it works, but tini-skia is a cpu based backend. No Hardware Aceleration (GPU).

It algo works in windows with vulkan + doing what @alex-ds13 said. But doesn't work for dx12 and changing to cpu based backend it's not a solution. and vulkan uses more GPU usage than dx12

GPeaky avatar Jul 25 '25 17:07 GPeaky

I wasn't suggesting tiny-skia because it's the solution, but rather because this further suggests that it's on wgpu and/or windows and/or GPU drivers but probably not iced itself. Users of other wgpu-based software (bevy, for instance) have reported similar problems, it seemingly can't automatically detect that it's able to draw a < 1.0

pml68 avatar Jul 25 '25 18:07 pml68

That's fair, it's there an incoming patch for this, or I should just switch to skia and pray for someone to fix this, I would do it myself, but I have no idea about gpus

GPeaky avatar Jul 25 '25 19:07 GPeaky

https://github.com/gfx-rs/wgpu/pull/7550

GPeaky avatar Jul 25 '25 19:07 GPeaky

Interesting (that it works with vulkan and only fails with dx12). On my Linux desktop (X11), transparency doesn't work with wgpu (with vulkan), but does with tiny-skia. Probably related to my settings but still quite interesting.

pml68 avatar Jul 25 '25 20:07 pml68

Vulkan works for me in linux with 0.14.0-dev

GPeaky avatar Jul 26 '25 16:07 GPeaky

X11 or Wayland? If X11, what compositor are you using and what GPU?

pml68 avatar Jul 26 '25 20:07 pml68

I am currently using wayland with xfce

GPeaky avatar Jul 27 '25 16:07 GPeaky

Yeah I'd assume it works somewhat more consistently on Wayland, where blurring also works (at least on KDE). Also, I didn't know Xfce supports Wayland; has it been that way for a while, or is it some new experimental feature?

pml68 avatar Jul 27 '25 16:07 pml68

just fyi this should probably be closed. its not an iced issue in anyway. wgpu does not at current have portable transparency and as such its expected to not work on some driver back ends. the dx12 backend for wgpu doesnt have transparency due dx12 not directly supporting it(no idea why dx11 did). I have a pr open in wgpu to add a easy method to use dcomp which allows transparency easily but until that is merged dx12 wont work. if you want transparency on window you can just use Vulkan backend and you probably wont even notice any differences

n1ght-hunter avatar Aug 01 '25 08:08 n1ght-hunter

The changes that @n1ght-hunter did have been pushed into wgpu version 0.27

https://github.com/gfx-rs/wgpu/releases/tag/v27.0.0

GPeaky avatar Oct 02 '25 10:10 GPeaky