Skip to content

Commit 1540788

Browse files
authored
fix(webkitgtk): normalize u8 color values to 0.0–1.0 for gdk::RGBA (#1692)
gdk::RGBA::new() expects values in the 0.0–1.0 range, but the u8 color components (0–255) were cast directly to f64 without dividing by 255.0. GDK clamps values >1.0 to 1.0, so any non-zero color ended up as white. Fixes #1690
1 parent a4def18 commit 1540788

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wry": patch
3+
---
4+
5+
fix(webkitgtk): normalize background color values to 0.0–1.0

src/webkitgtk/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,10 @@ impl InnerWebView {
292292
// background color
293293
if let Some((red, green, blue, alpha)) = attributes.background_color {
294294
webview.set_background_color(&gtk::gdk::RGBA::new(
295-
red as _, green as _, blue as _, alpha as _,
295+
red as f64 / 255.0,
296+
green as f64 / 255.0,
297+
blue as f64 / 255.0,
298+
alpha as f64 / 255.0,
296299
));
297300
}
298301
}
@@ -763,7 +766,10 @@ impl InnerWebView {
763766

764767
pub fn set_background_color(&self, (red, green, blue, alpha): RGBA) -> Result<()> {
765768
self.webview.set_background_color(&gtk::gdk::RGBA::new(
766-
red as _, green as _, blue as _, alpha as _,
769+
red as f64 / 255.0,
770+
green as f64 / 255.0,
771+
blue as f64 / 255.0,
772+
alpha as f64 / 255.0,
767773
));
768774
Ok(())
769775
}

0 commit comments

Comments
 (0)