From 2369aca9469cc5abc4c0694c9e0d3dfb8320f728 Mon Sep 17 00:00:00 2001 From: Martin Wagner Date: Sat, 14 May 2022 14:46:46 +0200 Subject: [PATCH] fixed blurry fallback covers --- src/mpdevil.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/mpdevil.py b/src/mpdevil.py index 2239878..fa45f5c 100755 --- a/src/mpdevil.py +++ b/src/mpdevil.py @@ -2868,8 +2868,7 @@ class MainCover(Gtk.DrawingArea): super().__init__() self._client=client self._settings=settings - self._pixbuf=GdkPixbuf.Pixbuf() - self._surface=Gdk.cairo_surface_create_from_pixbuf(self._pixbuf, 0, None) + self._fallback=True # connect self._client.emitter.connect("current_song", self._refresh) @@ -2877,8 +2876,7 @@ class MainCover(Gtk.DrawingArea): self._client.emitter.connect("reconnected", self._on_reconnected) def _clear(self): - self._pixbuf=GdkPixbuf.Pixbuf.new_from_file_at_size(FALLBACK_COVER, 1000, 1000) - self._surface=Gdk.cairo_surface_create_from_pixbuf(self._pixbuf, 0, None) + self._fallback=True self.queue_draw() def _refresh(self, *args): @@ -2887,6 +2885,7 @@ class MainCover(Gtk.DrawingArea): else: self._pixbuf=self._client.current_cover.get_pixbuf() self._surface=Gdk.cairo_surface_create_from_pixbuf(self._pixbuf, 0, None) + self._fallback=False self.queue_draw() def _on_disconnected(self, *args): @@ -2897,8 +2896,14 @@ class MainCover(Gtk.DrawingArea): self.set_sensitive(True) def do_draw(self, context): - height_factor=self.get_allocated_height()/self._pixbuf.get_height() - width_factor=self.get_allocated_width()/self._pixbuf.get_width() + if self._fallback: + size=min(self.get_allocated_height(), self.get_allocated_width()) + self._pixbuf=GdkPixbuf.Pixbuf.new_from_file_at_size(FALLBACK_COVER, size, size) + self._surface=Gdk.cairo_surface_create_from_pixbuf(self._pixbuf, 0, None) + height_factor,width_factor=(1,1) + else: + height_factor=self.get_allocated_height()/self._pixbuf.get_height() + width_factor=self.get_allocated_width()/self._pixbuf.get_width() if height_factor < width_factor: context.scale(height_factor, height_factor) context.set_source_surface(self._surface, ((self.get_allocated_width()/height_factor)-self._pixbuf.get_width())/2, 0)