From 573b9c472cf23d57aa0def207aa29460c111212f Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Thu, 4 Jul 2024 17:33:08 +0200 Subject: [PATCH] i3-companion: add support for BT devices without a class but with icon --- bin/i3-companion | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/bin/i3-companion b/bin/i3-companion index 996a317..6a1d0fb 100755 --- a/bin/i3-companion +++ b/bin/i3-companion @@ -815,7 +815,7 @@ async def bluetooth_status(i3, event, *args): powered = True elif "org.bluez.Device1" in interfaces: # We have a device! - device = types.SimpleNamespace(major=0, minor=0, battery=None) + device = types.SimpleNamespace(major=0, minor=0, battery=None, icon=None) interface = interfaces["org.bluez.Device1"] if not interface["Connected"][1]: continue @@ -823,9 +823,16 @@ async def bluetooth_status(i3, event, *args): device_class = interface["Class"][1] device.major = (device_class & 0x1F00) >> 8 device.minor = (device_class & 0xFC) >> 2 + except KeyError: + pass + try: device.battery = interfaces["org.bluez.Battery1"]["Percentage"][1] except KeyError: pass + try: + device.icon = interface["Icon"][1] + except KeyError: + pass devices.append(device) # Choose appropriate icons for output @@ -861,8 +868,13 @@ async def bluetooth_status(i3, event, *args): (lambda x: x & 0x20, "printer"), ], } - icon = classes.get((device.major, device.minor)) or classes.get( - device.major, "unknown" + bicons = { + "input-mouse": "mouse", + } + icon = ( + bicons.get(device.icon) + or classes.get((device.major, device.minor)) + or classes.get(device.major, "unknown") ) if type(icon) is list: for matcher, name in icon: