mirror of
https://github.com/vincentbernat/i3wm-configuration.git
synced 2025-07-24 04:45:08 +02:00
i3-companion: moar bluetooth icons
And rearrange the matching code
This commit is contained in:
parent
4d76aedb61
commit
78378278c3
1 changed files with 57 additions and 32 deletions
|
@ -61,6 +61,7 @@ application_icons = {
|
||||||
icons = {
|
icons = {
|
||||||
"access-point": icon(2, ""),
|
"access-point": icon(2, ""),
|
||||||
"bluetooth": icon(2, ""),
|
"bluetooth": icon(2, ""),
|
||||||
|
"camera": icon(2, "⎙"),
|
||||||
"car": icon(2, "🚘"),
|
"car": icon(2, "🚘"),
|
||||||
"gamepad": icon(2, "🎮"),
|
"gamepad": icon(2, "🎮"),
|
||||||
"headphones": icon(2, "🎧"),
|
"headphones": icon(2, "🎧"),
|
||||||
|
@ -74,8 +75,11 @@ icons = {
|
||||||
"notifications-enabled": icon(2, ""),
|
"notifications-enabled": icon(2, ""),
|
||||||
"nowifi": icon(2, ""),
|
"nowifi": icon(2, ""),
|
||||||
"phone": icon(2, "📞"),
|
"phone": icon(2, "📞"),
|
||||||
|
"printer": icon(2, "⎙"),
|
||||||
|
"scanner": icon(2, ""),
|
||||||
"unknown": icon(2, ""),
|
"unknown": icon(2, ""),
|
||||||
"vpn": icon(2, ""),
|
"vpn": icon(2, ""),
|
||||||
|
"webcam": icon(2, ""),
|
||||||
"wifi-high": icon(2, ""),
|
"wifi-high": icon(2, ""),
|
||||||
"wifi-low": icon(2, ""),
|
"wifi-low": icon(2, ""),
|
||||||
"wifi-medium": icon(2, ""),
|
"wifi-medium": icon(2, ""),
|
||||||
|
@ -144,7 +148,9 @@ def retry(max_retries):
|
||||||
retries = max_retries
|
retries = max_retries
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
logger.debug("execute %s (remaining tries: %s)", fn, retries)
|
logger.debug(
|
||||||
|
"execute %s (remaining tries: %s)", fn, retries
|
||||||
|
)
|
||||||
return await fn(*args, **kwargs)
|
return await fn(*args, **kwargs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if retries > 0:
|
if retries > 0:
|
||||||
|
@ -282,7 +288,9 @@ async def workspace_rename(i3, event):
|
||||||
continue
|
continue
|
||||||
for k, v in application_icons.items():
|
for k, v in application_icons.items():
|
||||||
if re.match(rf"^{k}\b", name, re.IGNORECASE):
|
if re.match(rf"^{k}\b", name, re.IGNORECASE):
|
||||||
logger.debug("in %s, found '%s', matching %s", attr, name, k)
|
logger.debug(
|
||||||
|
"in %s, found '%s', matching %s", attr, name, k
|
||||||
|
)
|
||||||
return v
|
return v
|
||||||
return application_icons_nomatch
|
return application_icons_nomatch
|
||||||
|
|
||||||
|
@ -670,38 +678,48 @@ async def bluetooth_status(i3, event, *args):
|
||||||
minor = (device_class & 0xFC) >> 2
|
minor = (device_class & 0xFC) >> 2
|
||||||
devices.append((major, minor))
|
devices.append((major, minor))
|
||||||
|
|
||||||
# Generate output
|
# Choose appropriate icons for output
|
||||||
# See: https://btprodspecificationrefs.blob.core.windows.net/assigned-numbers/Assigned%20Number%20Types/Baseband.pdf
|
# See: https://btprodspecificationrefs.blob.core.windows.net/assigned-numbers/Assigned%20Number%20Types/Baseband.pdf
|
||||||
if not powered:
|
if not powered:
|
||||||
output = ""
|
output = ""
|
||||||
else:
|
else:
|
||||||
output = [icons["bluetooth"]]
|
output = ["bluetooth"]
|
||||||
for major, minor in devices:
|
for major, minor in devices:
|
||||||
if major == 1:
|
classes = {
|
||||||
output.append(icons["laptop"])
|
1: "laptop",
|
||||||
elif major == 2:
|
2: "phone",
|
||||||
output.append(icons["phone"])
|
3: "access-point",
|
||||||
elif major == 3:
|
(4, 1): "headset",
|
||||||
output.append(icons["access-point"])
|
(4, 2): "headset",
|
||||||
elif major == 4 and minor in {1, 2}:
|
(4, 4): "microphone",
|
||||||
output.append(icons["headset"])
|
(4, 5): "loudspeaker",
|
||||||
elif major == 4 and minor == 4:
|
(4, 7): "loudspeaker",
|
||||||
output.append(icons["microphone"])
|
(4, 10): "loudspeaker",
|
||||||
elif major == 4 and minor in {5, 7, 10}:
|
(4, 6): "headphones",
|
||||||
output.append(icons["loudspeaker"])
|
(4, 8): "car",
|
||||||
elif major == 4 and minor == 6:
|
(4, 12): "webcam",
|
||||||
output.append(icons["headphones"])
|
(5, 1): "gamepad",
|
||||||
elif major == 4 and minor == 8:
|
(5, 2): "gamepad",
|
||||||
output.append(icons["car"])
|
5: [
|
||||||
elif major == 5 and minor in {1, 2}:
|
(lambda x: x & 0x10, "keyboard"),
|
||||||
output.append(icons["gamepad"])
|
(lambda x: x & 0x20, "mouse"),
|
||||||
elif major == 5 and minor & 0x10:
|
],
|
||||||
output.append(icons["keyboard"])
|
6: [
|
||||||
elif major == 5 and minor & 0x20:
|
(lambda x: x & 0x8, "camera"),
|
||||||
output.append(icons["mouse"])
|
(lambda x: x & 0x10, "scanner"),
|
||||||
else:
|
(lambda x: x & 0x20, "printer"),
|
||||||
output.append(icons["unknown"])
|
],
|
||||||
output = "|".join(output)
|
}
|
||||||
|
icon = classes.get((major, minor)) or classes.get(major, "unknown")
|
||||||
|
if type(icon) is list:
|
||||||
|
for matcher, name in icon:
|
||||||
|
if matcher(minor):
|
||||||
|
icon = name
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
icon = "unknown"
|
||||||
|
output.append(icon)
|
||||||
|
output = "|".join(icons[o] for o in output)
|
||||||
|
|
||||||
# Update polybar
|
# Update polybar
|
||||||
if bluetooth_status.last != output:
|
if bluetooth_status.last != output:
|
||||||
|
@ -899,11 +917,14 @@ async def main(options):
|
||||||
for fn, events in on.functions.items():
|
for fn, events in on.functions.items():
|
||||||
for event in events:
|
for event in events:
|
||||||
if isinstance(event, I3Event):
|
if isinstance(event, I3Event):
|
||||||
|
|
||||||
def wrapping(fn, event):
|
def wrapping(fn, event):
|
||||||
async def wrapped(i3, event):
|
async def wrapped(i3, event):
|
||||||
logger.debug("received i3 event %s for %s", event, fn)
|
logger.debug("received i3 event %s for %s", event, fn)
|
||||||
return await fn(i3, event)
|
return await fn(i3, event)
|
||||||
|
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
||||||
i3.on(event, wrapping(fn, event))
|
i3.on(event, wrapping(fn, event))
|
||||||
|
|
||||||
# React to some bindings
|
# React to some bindings
|
||||||
|
@ -943,10 +964,14 @@ async def main(options):
|
||||||
)
|
)
|
||||||
async def wrapped(path, args):
|
async def wrapped(path, args):
|
||||||
if event.onlyif is not None and not event.onlyif(args):
|
if event.onlyif is not None and not event.onlyif(args):
|
||||||
logger.debug("received DBus event for %s but not interested",
|
logger.debug(
|
||||||
fn)
|
"received DBus event for %s, not interested",
|
||||||
|
fn,
|
||||||
|
)
|
||||||
return
|
return
|
||||||
logger.debug("received DBus event %s for %s", event, fn)
|
logger.debug(
|
||||||
|
"received DBus event %s for %s", event, fn
|
||||||
|
)
|
||||||
return await fn(i3, event, path, *args)
|
return await fn(i3, event, path, *args)
|
||||||
|
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue