diff --git a/src/services/bluetooth.py b/src/services/bluetooth.py index eaf802e..9d5a424 100644 --- a/src/services/bluetooth.py +++ b/src/services/bluetooth.py @@ -2,7 +2,7 @@ from collections.abc import Callable from typing import Any, Concatenate, ParamSpec from fabric.core.service import Property, Service, Signal -from fabric.utils import Gio, GLib, logger +from fabric.utils import Gio, GLib, Gtk, logger P = ParamSpec("P") @@ -784,14 +784,27 @@ def _path_to_addr(object_path: str) -> str: def _icon_to_type(icon: str) -> str: + """Resolve a Bluez icon name to a GTK symbolic icon via the current theme. + + Checks the icon theme for the icon (with ``-symbolic`` suffix) and falls + back to a hardcoded mapping when the theme doesn't provide it. + """ + if icon: + icon_theme = Gtk.IconTheme.get_default() + symbolic = f"{icon}-symbolic" + if icon_theme.has_icon(symbolic): + return symbolic + if icon_theme.has_icon(icon): + return icon + return { - "audio-headset": "Headset", - "audio-headphones": "Headphones", - "audio-speakers": "Speaker", - "audio-card": "Speaker", - "input-keyboard": "Keyboard", - "input-mouse": "Mouse", - "input-gaming": "Joypad", - "phone": "Phone", - "printer": "Printer", - }.get(icon, icon) + "audio-headset": "audio-headset-symbolic", + "audio-headphones": "audio-headphones-symbolic", + "audio-speakers": "audio-speakers-symbolic", + "audio-card": "audio-speakers-symbolic", + "input-keyboard": "input-keyboard-symbolic", + "input-mouse": "input-mouse-symbolic", + "input-gaming": "input-gaming-symbolic", + "phone": "phone-symbolic", + "printer": "printer-symbolic", + }.get(icon, "bluetooth-symbolic") diff --git a/src/window/controlcenter/bluetooth.py b/src/window/controlcenter/bluetooth.py index b022c09..b344679 100644 --- a/src/window/controlcenter/bluetooth.py +++ b/src/window/controlcenter/bluetooth.py @@ -143,19 +143,9 @@ class BluetoothDeviceSlot(Box): self.device.emit("changed") def _get_icon_for_device(self, device) -> str: - dtype = getattr(device, "type", None) or getattr( + return getattr(device, "type", None) or getattr( device, "icon_name", "bluetooth" ) - return { - "Headset": "audio-headset-symbolic", - "Headphones": "audio-headphones-symbolic", - "Speaker": "audio-speakers-symbolic", - "Keyboard": "input-keyboard-symbolic", - "Mouse": "input-mouse-symbolic", - "Joypad": "input-gaming-symbolic", - "Phone": "phone-symbolic", - "Printer": "printer-symbolic", - }.get(dtype, dtype + "-symbolic" if not dtype.endswith("-symbolic") else dtype) def destroy(self): """Clean up device signal connections to prevent memory leaks."""