diff --git a/bar/styles/colors.css b/bar/styles/colors.css index b480613..1c14ada 100644 --- a/bar/styles/colors.css +++ b/bar/styles/colors.css @@ -20,8 +20,9 @@ --window-bg: alpha(var(--background), 0.9); --module-bg: alpha(var(--mid-bg), 0.8); --border-color: var(--light-bg); - --ws-active: var(--pink); - --ws-inactive: var(--blue); + --ws-active: var(--blue); + --ws-visible: var(--violet); + --ws-inactive: var(--light-grey); --ws-empty: var(--dark-grey); --ws-hover: var(--turquoise); --ws-urgent: var(--red); diff --git a/bar/styles/workspaces.css b/bar/styles/workspaces.css index 1821f62..a3fb796 100644 --- a/bar/styles/workspaces.css +++ b/bar/styles/workspaces.css @@ -6,8 +6,8 @@ #workspaces>button { padding: 0px 8px; - transition: padding 0.05s steps(8); - background-color: var(--foreground); + transition: padding 0.05s steps(8), background-color 0.15s ease; + background-color: var(--ws-inactive); border-radius: 100px; } @@ -15,11 +15,24 @@ font-size: 0px; } -#workspaces button.hover { +#workspaces>button:hover { background-color: var(--ws-hover); } -#workspaces button.urgent { +#workspaces>button.empty { + background-color: var(--ws-empty); +} + +#workspaces>button.visible { + background-color: var(--ws-visible); +} + +#workspaces>button.active { + padding: 0px 32px; + background-color: var(--ws-active); +} + +#workspaces>button.urgent { background-color: var(--ws-urgent); color: var(--foreground); font-weight: bold; @@ -31,12 +44,3 @@ 50% { opacity: 0.5; } 100% { opacity: 1.0; } } - -#workspaces>button.empty { - background-color: var(--ws-empty); -} - -#workspaces>button.active { - padding: 0px 32px; - background-color: var(--ws-active); -} diff --git a/bar/widgets/fenster.py b/bar/widgets/fenster.py index 6a01d08..94d0af8 100644 --- a/bar/widgets/fenster.py +++ b/bar/widgets/fenster.py @@ -41,23 +41,23 @@ class FensterWorkspaceButton(Button): def _on_clicked(self, *args): self._i3.send_command(f"workspace {self._workspace_num}") - def set_focused(self, focused: bool): - if focused: - self.add_style_class("focused") + def _toggle_class(self, name: str, on: bool): + if on: + self.add_style_class(name) else: - self.remove_style_class("focused") + self.remove_style_class(name) - def set_visible_on_output(self, visible: bool): - if visible: - self.add_style_class("visible") - else: - self.remove_style_class("visible") + def set_active(self, active: bool): + self._toggle_class("active", active) - def set_has_windows(self, has_windows: bool): - if has_windows: - self.add_style_class("has-windows") - else: - self.remove_style_class("has-windows") + def set_visible_other(self, visible: bool): + self._toggle_class("visible", visible) + + def set_empty(self, empty: bool): + self._toggle_class("empty", empty) + + def set_urgent(self, urgent: bool): + self._toggle_class("urgent", urgent) class FensterWorkspaces(Box): @@ -114,14 +114,7 @@ class FensterWorkspaces(Box): self._update_workspaces(reply.reply) def _update_workspaces(self, workspaces: list): - focused_ws = None - workspace_nums = set() - for ws in workspaces: - ws_num = ws.get("num") - if ws_num is not None: - workspace_nums.add(ws_num) - if ws.get("focused"): - focused_ws = ws_num + workspace_nums = {ws["num"] for ws in workspaces if ws.get("num") is not None} # Remove buttons for workspaces that no longer exist for ws_num in list(self._buttons.keys()): @@ -141,14 +134,17 @@ class FensterWorkspaces(Box): self.add(button) button = self._buttons[ws_num] - button.set_focused(ws_num == focused_ws) - - ws_output = ws.get("output") - is_visible = ws_output == self._output if self._output is not None else False - button.set_visible_on_output(is_visible) + focused = bool(ws.get("focused")) + visible = bool(ws.get("visible")) + urgent = bool(ws.get("urgent")) window_count = ws.get("window_count", 0) - button.set_has_windows(window_count > 0) + + button.set_active(focused) + # "visible on another output": shown on its output but not the focused one + button.set_visible_other(visible and not focused) + button.set_urgent(urgent) + button.set_empty(window_count == 0) # Sort buttons by workspace number sorted_buttons = sorted(self._buttons.values(), key=lambda b: b.workspace_num)