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