Skip to content

Commit

Permalink
ManagerDeviceList: Fix broken fallback in _load_surface
Browse files Browse the repository at this point in the history
Loading the surface directly from the Gtk.IconTheme raises an GError. We
look up the icon first and check for None like we used to.
  • Loading branch information
infirit committed Apr 2, 2024
1 parent 86126cf commit 7f003d5
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions blueman/gui/manager/ManagerDeviceList.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,20 @@ def _on_key_pressed(self, _widget: Gtk.Widget, event: Gdk.EventKey) -> bool:
def _load_surface(self, icon_name: str, size: int) -> cairo.ImageSurface:
window = self.get_window()
scale = self.get_scale_factor()
surface = self.icon_theme.load_surface(icon_name, size, scale, window, Gtk.IconLookupFlags.FORCE_SIZE)
if surface is None:
surface = self.icon_theme.load_surface("image-missing", size, scale, window, Gtk.IconLookupFlags.FORCE_SIZE)
assert surface is not None

return cast(cairo.ImageSurface, surface)
icon_info = self.icon_theme.lookup_icon_for_scale(icon_name, size, scale, Gtk.IconLookupFlags.FORCE_SIZE)

if icon_info is None:
logging.error(f"Failed to look up icon \"{icon_name}\" likely due to broken icon theme.")
missing_icon_info = self.icon_theme.lookup_icon_for_scale(
"image-missing",
size,
scale,
Gtk.IconLookupFlags.FORCE_SIZE
)
assert missing_icon_info is not None
return cast(cairo.ImageSurface, missing_icon_info.load_surface(window))
else:
return cast(cairo.ImageSurface, icon_info.load_surface(window))

def _make_device_icon(self, icon_name: str, is_paired: bool, is_connected: bool, is_trusted: bool,
is_blocked: bool) -> cairo.ImageSurface:
Expand Down

0 comments on commit 7f003d5

Please sign in to comment.