From 77228a751cbe0009abba79796c2352f8664063e1 Mon Sep 17 00:00:00 2001 From: fdev31 Date: Fri, 25 Jul 2025 20:27:38 +0200 Subject: [PATCH] basic support for custom workspace icons --- config/data.py | 1 + modules/bar.py | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/config/data.py b/config/data.py index 8f770b4..73e22b0 100644 --- a/config/data.py +++ b/config/data.py @@ -75,6 +75,7 @@ def load_config(): "bar_workspace_use_chinese_numerals", False ) BAR_HIDE_SPECIAL_WORKSPACE = config.get("bar_hide_special_workspace", True) + BAR_WORKSPACE_ICONS = config.get("bar_workspace_icons", {}) BAR_THEME = config.get("bar_theme", "Pills") DOCK_THEME = config.get("dock_theme", "Pills") PANEL_THEME = config.get("panel_theme", "Pills") diff --git a/modules/bar.py b/modules/bar.py index ba5333e..1e9ee2b 100644 --- a/modules/bar.py +++ b/modules/bar.py @@ -45,6 +45,20 @@ tooltip_overview = """Overview""" +def build_caption(i: int): + """Build the label for a given workspace number""" + label = data.BAR_WORKSPACE_ICONS.get(str(i)) or data.BAR_WORKSPACE_ICONS.get('default') + if label is None: + return ( + CHINESE_NUMERALS[i - 1] + if data.BAR_WORKSPACE_USE_CHINESE_NUMERALS + and 1 <= i <= len(CHINESE_NUMERALS) + else str(i) + ) + else: + return label + + class Bar(Window): def __init__(self, **kwargs): super().__init__( @@ -135,12 +149,7 @@ def __init__(self, **kwargs): h_align="center", v_align="center", id=i, - label=( - CHINESE_NUMERALS[i - 1] - if data.BAR_WORKSPACE_USE_CHINESE_NUMERALS - and 1 <= i <= len(CHINESE_NUMERALS) - else str(i) - ), + label=build_caption(i), ) for i in range(1, 11) ], @@ -155,7 +164,7 @@ def __init__(self, **kwargs): name="workspaces-container", children=( self.workspaces - if not data.BAR_WORKSPACE_SHOW_NUMBER + if not (data.BAR_WORKSPACE_SHOW_NUMBER or data.BAR_WORKSPACE_ICONS) else self.workspaces_num ), ) @@ -603,7 +612,7 @@ def toggle_hidden(self): self.bar_inner.remove_style_class("hidden") def chinese_numbers(self): - if data.BAR_WORKSPACE_USE_CHINESE_NUMERALS: + if data.BAR_WORKSPACE_USE_CHINESE_NUMERALS or data.BAR_WORKSPACE_ICONS: self.workspaces_num.add_style_class("chinese") else: self.workspaces_num.remove_style_class("chinese")