♻️ refactor(dock/components): update visibility management for batteries and music player components
This commit is contained in:
5 files changed
+26
-28
No files matched your search
+4
-2
@@ -74,7 +74,7 @@ if os.path.exists(CONFIG_FILE):
|
||||
NOTIF_POS = config.get(NOTIF_POS_KEY, NOTIF_POS_DEFAULT)
|
||||
|
||||
DOCK_COMPONENTS_VISIBILITY = {
|
||||
"workspaces": config.get("dock_workspaces_visible", True),
|
||||
"workspace": config.get("dock_workspace_visible", True),
|
||||
"metrics": config.get("dock_metrics_visible", True),
|
||||
"battery": config.get("dock_battery_visible", True),
|
||||
"date_time": config.get("dock_date_time_visible", True),
|
||||
@@ -84,6 +84,7 @@ if os.path.exists(CONFIG_FILE):
|
||||
"systray": config.get("dock_tray_visible", True),
|
||||
"applications": config.get("dock_applications_visible", True),
|
||||
"music_player": config.get("dock_music_player_visible", True),
|
||||
"language": config.get("dock_language_visible", True),
|
||||
}
|
||||
|
||||
METRICS_DISKS = config.get("metrics_disks", ["/"])
|
||||
@@ -106,7 +107,7 @@ else:
|
||||
DOCK_HIDE_SPECIAL_WORKSPACE = True
|
||||
|
||||
DOCK_COMPONENTS_VISIBILITY = {
|
||||
"workspaces": True,
|
||||
"workspace": True,
|
||||
"metrics": True,
|
||||
"battery": True,
|
||||
"date_time": True,
|
||||
@@ -116,6 +117,7 @@ else:
|
||||
"systray": True,
|
||||
"applications": True,
|
||||
"music_player": True,
|
||||
"language": True,
|
||||
}
|
||||
|
||||
METRICS_DISKS = ["/"]
|
||||
|
||||
@@ -19,7 +19,6 @@ from .controls import Controls
|
||||
from .indicators import Indicators
|
||||
from .metrics import Metrics
|
||||
from .music_player import MusicPlayer
|
||||
from .notifications import Notifications
|
||||
from .workspaces import workspace
|
||||
|
||||
import gi
|
||||
@@ -112,7 +111,6 @@ class DockComponents(Box):
|
||||
)
|
||||
self.controls = Controls()
|
||||
self.indicators = Indicators()
|
||||
self.notifications = Notifications()
|
||||
self.music_player = MusicPlayer()
|
||||
self.systray = SystemTray(
|
||||
icon_size=18,
|
||||
@@ -128,7 +126,6 @@ class DockComponents(Box):
|
||||
self.controls,
|
||||
self.applications,
|
||||
self.indicators,
|
||||
self.notifications,
|
||||
self.battery,
|
||||
self.music_player,
|
||||
self.date_time,
|
||||
@@ -155,13 +152,12 @@ class DockComponents(Box):
|
||||
|
||||
def apply_component_props(self):
|
||||
components = {
|
||||
"workspaces": self.workspaces,
|
||||
"workspace": self.workspaces,
|
||||
"metrics": self.metrics,
|
||||
"battery": self.battery,
|
||||
"date_time": self.date_time,
|
||||
"controls": self.controls,
|
||||
"indicators": self.indicators,
|
||||
"notifications": self.notifications,
|
||||
"music_player": self.music_player,
|
||||
"systray": self.systray,
|
||||
"applications": self.applications,
|
||||
@@ -170,30 +166,35 @@ class DockComponents(Box):
|
||||
|
||||
for component_name, widget in components.items():
|
||||
if component_name in self.component_visibility:
|
||||
visibility = self.component_visibility[component_name]
|
||||
# Special handling for applications component - let it manage its own visibility
|
||||
if component_name == "applications":
|
||||
# Only apply config visibility if the component has content
|
||||
if hasattr(widget, "_update_visibility_based_on_content"):
|
||||
widget._update_visibility_based_on_content()
|
||||
else:
|
||||
widget.set_visible(self.component_visibility[component_name])
|
||||
widget.set_visible(visibility)
|
||||
# Special handling for music player - let it manage its own visibility based on media state
|
||||
elif component_name == "music_player":
|
||||
# Music player manages its own visibility based on config and media state
|
||||
# Don't override its visibility here, let it handle it internally
|
||||
pass
|
||||
# Special handling for battery - let it manage its own visibility based on config and battery state
|
||||
elif component_name == "battery":
|
||||
# Battery component manages its own visibility based on config and battery presence
|
||||
# Don't override its visibility here, let it handle it internally
|
||||
pass
|
||||
else:
|
||||
widget.set_visible(self.component_visibility[component_name])
|
||||
widget.set_visible(visibility)
|
||||
|
||||
def toggle_component_visibility(self, component_name):
|
||||
components = {
|
||||
"workspaces": self.workspaces,
|
||||
"workspace": self.workspaces,
|
||||
"metrics": self.metrics,
|
||||
"battery": self.battery,
|
||||
"date_time": self.date_time,
|
||||
"controls": self.controls,
|
||||
"indicators": self.indicators,
|
||||
"notifications": self.notifications,
|
||||
"music_player": self.music_player,
|
||||
"systray": self.systray,
|
||||
"applications": self.applications,
|
||||
|
||||
@@ -240,5 +240,9 @@ class Battery(Box):
|
||||
self.icon.remove_style_class("alert")
|
||||
self.circle.remove_style_class("alert")
|
||||
|
||||
self.set_visible(True)
|
||||
# Only show if enabled in configuration
|
||||
if data.DOCK_COMPONENTS_VISIBILITY.get("battery", True):
|
||||
self.set_visible(True)
|
||||
else:
|
||||
self.set_visible(False)
|
||||
return True
|
||||
@@ -11,6 +11,7 @@ from gi.repository import GLib
|
||||
|
||||
import config.data as data
|
||||
import utils.icons as icons
|
||||
from .notifications import Notifications
|
||||
from services.network import NetworkClient
|
||||
|
||||
|
||||
@@ -234,12 +235,13 @@ class RecordingIndicator(Button):
|
||||
class Indicators(Box):
|
||||
def __init__(self, **kwargs):
|
||||
self.recording_indicator = RecordingIndicator()
|
||||
self.notifications = Notifications()
|
||||
|
||||
super().__init__(
|
||||
name="indicator",
|
||||
orientation="h" if not data.VERTICAL else "v",
|
||||
spacing=4,
|
||||
children=[WifiIndicator(), BluetoothIndicator(), self.recording_indicator],
|
||||
children=[WifiIndicator(), BluetoothIndicator(), self.recording_indicator, self.notifications],
|
||||
**kwargs,
|
||||
)
|
||||
self.show_all()
|
||||
|
||||
@@ -52,9 +52,8 @@ class MusicPlayer(EventBox):
|
||||
self.add(self.main_container)
|
||||
self.connect("button-press-event", self._on_music_player_clicked)
|
||||
|
||||
# Set initial visibility based on configuration
|
||||
initial_visibility = data.DOCK_COMPONENTS_VISIBILITY.get("music_player", True)
|
||||
self.set_visible(initial_visibility)
|
||||
# Start hidden - visibility will be managed by _update_display() based on media availability
|
||||
self.set_visible(False)
|
||||
|
||||
# Ensure visualizer is disabled in vertical mode
|
||||
if data.VERTICAL:
|
||||
@@ -363,18 +362,8 @@ class MusicPlayer(EventBox):
|
||||
self._connect_player_signals(self._current_player)
|
||||
|
||||
if not self._current_player:
|
||||
# Only hide if the component is disabled in settings
|
||||
# If enabled in settings, show a "No Media" state instead of hiding
|
||||
if not data.DOCK_COMPONENTS_VISIBILITY.get("music_player", True):
|
||||
self.set_visible(False)
|
||||
else:
|
||||
# Show "No Media" state when enabled but no player is active
|
||||
self.set_visible(True)
|
||||
# Clear tooltips when no player is active
|
||||
self.set_tooltip_text("No media player active")
|
||||
self.album_thumbnail.set_tooltip_text("No media player active")
|
||||
if not data.VERTICAL:
|
||||
self.track_label.set_tooltip_text("No media player active")
|
||||
# Hide the component when there's no media player available
|
||||
self.set_visible(False)
|
||||
|
||||
if self._update_timeout_id:
|
||||
GLib.source_remove(self._update_timeout_id)
|
||||
|
||||
Reference in new issue
Block a user