i3-companion: display notifications for Bluetooth

This is a good example of using PropertiesChanged. I don't know if
it's possible to filter the interface we want to receive.
This commit is contained in:
Vincent Bernat 2021-07-12 13:18:34 +02:00
parent a30c4a5aa9
commit 33e59c769a

View file

@ -404,6 +404,37 @@ async def output_update(i3, event):
output_update.running = asyncio.create_task(output_update_now())
@on(
DBusSignal(
path="/org/bluez",
interface="org.freedesktop.DBus.Properties",
member="PropertiesChanged",
signature="sa{sv}as",
)
)
async def bluetooth_notifications(
i3, event, path, interface, changed, invalid
):
"""Display notifications related to Bluetooth state."""
if interface != "org.bluez.Device1":
return
if not "Connected" in changed:
return
logger.info(changed["Connected"])
peer = i3.system_bus["org.bluez"][path]
obd = await peer.get_async_interface(interface)
name = await obd.Name
icon = await obd.Icon
state = await obd.Connected
state = "connected" if state else "disconnected"
await notify(
i3,
app_icon=icon,
summary=name,
body=f"Bluetooth device {state}",
)
@on(
DBusSignal(
path="/",
@ -546,7 +577,7 @@ async def network_manager_status(i3, event, *args):
if vpn:
state = await nma.State
if state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED:
status.append(icons['vpn'])
status.append(icons["vpn"])
status.append(await nma.Id)
# Final status line