i3-companion: only consider instance/class for icon

Name may be too random. Straighten a bit the regex too to avoid
matching on prefixes.
This commit is contained in:
Vincent Bernat 2021-07-08 14:25:14 +02:00
parent 396ca23b33
commit 7f17d6f397

View file

@ -50,9 +50,9 @@ application_icons = {
"steam": "",
"vbeterm": "",
"zathura": "",
"zoom": "",
"NOMATCH": ""
"zoom": ""
}
application_icons_nomatch = ""
application_icons_alone = {
application_icons[k] for k in {
"vbeterm"
@ -69,17 +69,16 @@ async def workspace_rename(i3, event):
def application_icon(window):
"""Get application icon for a window."""
for attr in ('name',
'window_instance',
for attr in ('window_instance',
'window_class'):
name = getattr(window, attr, None)
if name is None:
continue
for k, v in application_icons.items():
if re.match(k, name, re.IGNORECASE):
if re.match(rf"^{k}\b", name, re.IGNORECASE):
logger.debug(f"in {attr}, found '{name}', matching {k}")
return v
return application_icons["NOMATCH"]
return application_icons_nomatch
for workspace in workspaces:
icons = set()