refactor(bluetooth): resolve device icons from GTK icon theme
_check_icon_to_type now queries Gtk.IconTheme for the icon name (with -symbolic suffix) before falling back to a hardcoded mapping. _get_icon_for_device simplified since type property now returns GTK icon names directly.
This commit is contained in:
2 files changed
+25
-22
No files matched your search
+24
-11
@@ -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")
|
||||
@@ -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."""
|
||||
|
||||
Reference in new issue
Block a user