feat(modules/panel): hide tray items when empty and sync visibility on config changes
This update ensures the panel's tray is hidden when there are no visible items and updatesits visibility automatically when the configuration changes or when notifications are added or removed. New Features: - Add `_update_tray_visibility` method that hides the tray when empty and updates UI accordingly. - Connect `tray` "add" and "remove" signals to trigger visibility updates. - Adjust chevron button visibility, icon, and left margin based on tray state. Enhancements: - Invoke visibility update on panel initialization, DND changes, and configuration changes. - Reset visual elements (chevron icon, margin) when the tray becomes hidden. - Preserve layout spacing improvements when tray is hidden. Bug Fixes: - Prevent stale tray visibility state after configuration updates.
This commit is contained in:
1 file changed
+28
@@ -63,6 +63,10 @@ class Panel(Window):
|
||||
)
|
||||
setup_cursor_hover(self.chevron_button, "pointer")
|
||||
|
||||
# Hide tray elements if empty
|
||||
self.tray.connect("add", self._update_tray_visibility)
|
||||
self.tray.connect("remove", self._update_tray_visibility)
|
||||
|
||||
self.indicators = Box(
|
||||
name="indicators",
|
||||
orientation="h",
|
||||
@@ -138,6 +142,7 @@ class Panel(Window):
|
||||
# Live updates
|
||||
on_config_change(self._on_config_changed)
|
||||
|
||||
self._update_tray_visibility()
|
||||
self.show_all()
|
||||
|
||||
def on_dnd_changed(self, _, dnd_state):
|
||||
@@ -208,6 +213,7 @@ class Panel(Window):
|
||||
right_children.append(self.notification_center_btn)
|
||||
|
||||
self.right_box.children = right_children
|
||||
self._update_tray_visibility()
|
||||
self.show_all()
|
||||
|
||||
def _on_config_changed(self, new_config, old_config):
|
||||
@@ -227,6 +233,28 @@ class Panel(Window):
|
||||
if any(new_config.get(k) != old_config.get(k) for k in keys):
|
||||
self._rebuild_layout_from_config()
|
||||
|
||||
# Always update tray visibility on config change just in case
|
||||
self._update_tray_visibility()
|
||||
|
||||
def _update_tray_visibility(self, *_):
|
||||
# We check if there are any visible children in the tray
|
||||
visible_children = [
|
||||
child for child in self.tray.get_children() if child.get_visible()
|
||||
]
|
||||
has_items = len(visible_children) > 0
|
||||
|
||||
self.tray_revealer.set_visible(has_items)
|
||||
self.chevron_button.set_visible(has_items)
|
||||
|
||||
if not has_items:
|
||||
# Reset state if it becomes hidden
|
||||
self.tray_revealer.child_revealed = False
|
||||
self.chevron_button.get_child().dynamic_file("misc/chevron-right.svg")
|
||||
# Add extra spacing between workspace indicator and indicators when tray is hidden
|
||||
self.indicators.set_margin_left(10)
|
||||
else:
|
||||
self.indicators.set_margin_left(0)
|
||||
|
||||
def toggle_tray(self, *_):
|
||||
current_state = self.tray_revealer.child_revealed
|
||||
self.tray_revealer.child_revealed = not current_state
|
||||
|
||||
Reference in new issue
Block a user