feat(modules): restructure battery UI and add dynamic layout rebuilding
New Features - Introduce `get_battery_icon_file` to generate battery icons based on percentage and charging state. - Add fallback Bluetooth control using `rfkill` when Fabric Bluetooth fails. Enhancements - Refactor layout management with `_rebuild_layout_from_config` and dynamic indicator instantiation. - Replace large `EnergyModeButton` class with lightweight utility functions. - Simplify notification icon updates using `dynamic_file`. Bug Fixes - No explicit bug fixes; changes focus on feature additions and refactoring.
This commit is contained in:
18 files changed
+2373
-2233
No files matched your search
@@ -0,0 +1,79 @@
|
||||
from fabric.hyprland.widgets import HyprlandWorkspaces, WorkspaceButton
|
||||
from fabric.widgets.box import Box
|
||||
|
||||
from services.config import get_config, on_config_change
|
||||
from utils.functions import is_special_workspace_id
|
||||
from utils.utils import setup_cursor_hover
|
||||
|
||||
# TODO: Support multi-monitor setups
|
||||
|
||||
|
||||
class WorkspaceIndicator(Box):
|
||||
def __init__(self, **kwargs):
|
||||
Box.__init__(
|
||||
self, name="workspace-indicator", orientation="h", spacing=4, **kwargs
|
||||
)
|
||||
self._current_config = {"hide_special_workspace": True}
|
||||
on_config_change(self._on_config_changed)
|
||||
|
||||
self.workspaces = HyprlandWorkspaces(
|
||||
name="workspaces",
|
||||
spacing=4,
|
||||
buttons_factory=self._get_button_factory(),
|
||||
)
|
||||
|
||||
self.add(self.workspaces)
|
||||
self.show_all()
|
||||
|
||||
self._apply_initial_config()
|
||||
|
||||
def _apply_initial_config(self):
|
||||
new_value = get_config("hide_special_workspace", True)
|
||||
if new_value != self._current_config["hide_special_workspace"]:
|
||||
self._current_config["hide_special_workspace"] = new_value
|
||||
self.update_config({"hide_special_workspace": new_value})
|
||||
|
||||
def _on_config_changed(self, new_config: dict, old_config: dict):
|
||||
if "hide_special_workspace" in new_config and new_config.get(
|
||||
"hide_special_workspace"
|
||||
) != old_config.get("hide_special_workspace"):
|
||||
self._current_config["hide_special_workspace"] = new_config.get(
|
||||
"hide_special_workspace", True
|
||||
)
|
||||
self.update_config(
|
||||
{
|
||||
"hide_special_workspace": self._current_config[
|
||||
"hide_special_workspace"
|
||||
]
|
||||
}
|
||||
)
|
||||
|
||||
def _get_button_factory(self):
|
||||
if self._current_config.get("hide_special_workspace", True):
|
||||
return self._create_filtered_button
|
||||
else:
|
||||
return lambda ws_id: self._create_button_with_hover(ws_id)
|
||||
|
||||
def _create_filtered_button(self, ws_id):
|
||||
if self._current_config.get(
|
||||
"hide_special_workspace", True
|
||||
) and is_special_workspace_id(ws_id):
|
||||
return None
|
||||
return self._create_button_with_hover(ws_id)
|
||||
|
||||
def _create_button_with_hover(self, ws_id):
|
||||
button = WorkspaceButton(id=ws_id, label=str(ws_id))
|
||||
setup_cursor_hover(button, "pointer")
|
||||
return button
|
||||
|
||||
def update_config(self, new_config: dict):
|
||||
if "hide_special_workspace" in new_config:
|
||||
button_factory = self._get_button_factory()
|
||||
self.remove(self.workspaces)
|
||||
self.workspaces = HyprlandWorkspaces(
|
||||
name="workspaces",
|
||||
spacing=4,
|
||||
buttons_factory=button_factory,
|
||||
)
|
||||
self.add(self.workspaces)
|
||||
self.workspaces.show_all()
|
||||
Reference in new issue
Block a user