From 1a0f86be4eb23b76ab8384db0b61879ab51d5096 Mon Sep 17 00:00:00 2001 From: Aljaz Gantar Date: Wed, 31 Mar 2021 13:47:36 +0200 Subject: [PATCH] refactor icon_for_window function --- contrib/autoname-workspaces.py | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/contrib/autoname-workspaces.py b/contrib/autoname-workspaces.py index 2b634eee..3ec39928 100755 --- a/contrib/autoname-workspaces.py +++ b/contrib/autoname-workspaces.py @@ -22,24 +22,17 @@ DEFAULT_ICON = "󰀏" def icon_for_window(window): - app_id = window.app_id - if app_id is not None and len(app_id) > 0: - app_id = app_id.lower() - if app_id in WINDOW_ICONS: - return WINDOW_ICONS[app_id] - logging.info("No icon available for window with app_id: %s" % str(app_id)) - else: - # xwayland support - class_name = window.window_class - if class_name is not None and len(class_name) > 0: - class_name = class_name.lower() - if class_name in WINDOW_ICONS: - return WINDOW_ICONS[class_name] - logging.info( - "No icon available for window with class_name: %s" % str(class_name) - ) - return DEFAULT_ICON + name = None + if window.app_id is not None and len(window.app_id) > 0: + name = window.app_id.lower() + elif window.window_class is not None and len(window.window_class) > 0: + name = window.window_class.lower() + if name in WINDOW_ICONS: + return WINDOW_ICONS[name] + + logging.info("No icon available for window with name: %s" % str(name)) + return DEFAULT_ICON def rename_workspaces(ipc): for workspace in ipc.get_tree().workspaces(): @@ -128,3 +121,4 @@ if __name__ == "__main__": rename_workspaces(ipc) ipc.main() +