shitty g4 like background blur

This commit is contained in:
Erica Z 2024-11-13 18:06:24 +01:00
parent 418cf01884
commit 2f510c55ac
2 changed files with 39 additions and 4 deletions

View file

@ -7,8 +7,6 @@ template $AudreyUiWindow: Adw.ApplicationWindow {
default-height: 600; default-height: 600;
Adw.ToolbarView { Adw.ToolbarView {
top-bar-style: raised;
bottom-bar-style: raised;
[top] [top]
Adw.HeaderBar { Adw.HeaderBar {

View file

@ -38,6 +38,8 @@ mod imp {
#[property(get, set, nullable)] #[property(get, set, nullable)]
playing_cover_art: RefCell<Option<gdk::Paintable>>, playing_cover_art: RefCell<Option<gdk::Paintable>>,
#[property(get, set, nullable)]
background: RefCell<Option<gdk::Paintable>>,
#[property(type = Option<Song>, get = Self::song, nullable)] #[property(type = Option<Song>, get = Self::song, nullable)]
_song: (), _song: (),
@ -112,6 +114,7 @@ mod imp {
play_queue: Default::default(), play_queue: Default::default(),
can_click_shuffle_all: Cell::new(false), can_click_shuffle_all: Cell::new(false),
playing_cover_art: Default::default(), playing_cover_art: Default::default(),
background: Default::default(),
_song: (), _song: (),
setup: Default::default(), setup: Default::default(),
api: Default::default(), api: Default::default(),
@ -273,7 +276,18 @@ mod imp {
} }
} }
impl WidgetImpl for Window {} impl WidgetImpl for Window {
fn snapshot(&self, snapshot: &gtk::Snapshot) {
if let Some(background) = self.background.borrow().as_ref() {
background.snapshot(
snapshot,
self.obj().width() as f64,
self.obj().height() as f64,
);
}
self.parent_snapshot(snapshot);
}
}
impl WindowImpl for Window {} impl WindowImpl for Window {}
@ -533,7 +547,30 @@ mod imp {
Some(song) if song.id() == song_id => { Some(song) if song.id() == song_id => {
let texture = gdk::Texture::from_bytes(&glib::Bytes::from_owned(bytes)) let texture = gdk::Texture::from_bytes(&glib::Bytes::from_owned(bytes))
.expect("could not create texture from cover art for {song_id}"); .expect("could not create texture from cover art for {song_id}");
window.set_playing_cover_art(Some(texture)); window.set_playing_cover_art(Some(&texture.clone().into()));
// from g4music
let snapshot = gtk::Snapshot::new();
snapshot.push_blur(512.0 * 0.2);
snapshot.push_opacity(0.5);
texture.snapshot(&snapshot, 512.0, 512.0);
snapshot.pop();
snapshot.pop();
use gtk::graphene;
let rect = graphene::Rect::new(0.0, 0.0, 512.0, 512.0);
if let Some(node) = snapshot.clone().to_node() {
window.set_background(Some(
window
.native()
.unwrap()
.renderer()
.unwrap()
.render_texture(node, Some(&rect)),
));
} else {
todo!();
}
} }
_ => { _ => {
event!( event!(