updates
This commit is contained in:
19 files changed
+16034
-149
No files matched your search
@@ -14,7 +14,7 @@ from utils.icon_resolver import IconResolver
|
||||
|
||||
def read_config():
|
||||
"""Read and return the full configuration from the JSON file, handling missing file."""
|
||||
config_path = get_relative_path("../../config/dock.json")
|
||||
config_path = get_relative_path("../../../config/dock.json")
|
||||
try:
|
||||
with open(config_path, "r") as file:
|
||||
config_data = json.load(file)
|
||||
@@ -69,15 +69,15 @@ class Applications(Box):
|
||||
super().__init__(
|
||||
name="applications-dock", orientation=orientation_val, spacing=4, **kwargs
|
||||
)
|
||||
|
||||
|
||||
# Store reference to the dock instance
|
||||
self.dock_instance = dock_instance
|
||||
|
||||
|
||||
self.config = read_config()
|
||||
self.conn = get_hyprland_connection()
|
||||
self.icon_resolver = IconResolver()
|
||||
self.pinned = self.config.get("pinned_apps", [])
|
||||
self.config_path = get_relative_path("../../config/dock.json")
|
||||
self.config_path = get_relative_path("../../../config/dock.json")
|
||||
self.app_map = {}
|
||||
self._all_apps = get_desktop_applications()
|
||||
self.app_identifiers = self._build_app_identifiers_map()
|
||||
@@ -240,7 +240,7 @@ class Applications(Box):
|
||||
exec_shell_command(f"hyprctl dispatch focuswindow address:{address}")
|
||||
|
||||
def update_pinned_apps_file(self):
|
||||
config_path = get_relative_path("../../config/dock.json")
|
||||
config_path = get_relative_path("../../../config/dock.json")
|
||||
try:
|
||||
with open(config_path, "w") as file:
|
||||
json.dump(self.config, file, indent=4)
|
||||
@@ -426,7 +426,7 @@ class Applications(Box):
|
||||
def on_drag_begin(self, widget, drag_context):
|
||||
self._drag_in_progress = True
|
||||
Gtk.drag_set_icon_surface(drag_context, createSurfaceFromWidget(widget))
|
||||
|
||||
|
||||
# Prevent dock from hiding during drag
|
||||
if self.dock_instance:
|
||||
self.dock_instance.prevent_hiding(True)
|
||||
@@ -454,22 +454,22 @@ class Applications(Box):
|
||||
if child.get_name() == "dock-separator":
|
||||
separator_index = i
|
||||
break
|
||||
|
||||
|
||||
# Check if we're dragging from unpinned to pinned section
|
||||
cross_section_drag_to_pin = separator_index != -1 and (
|
||||
(source_index > separator_index and target_index < separator_index)
|
||||
source_index > separator_index and target_index < separator_index
|
||||
)
|
||||
|
||||
|
||||
# Check if we're dragging from pinned to unpinned section
|
||||
cross_section_drag_to_unpin = separator_index != -1 and (
|
||||
(source_index < separator_index and target_index > separator_index)
|
||||
source_index < separator_index and target_index > separator_index
|
||||
)
|
||||
|
||||
|
||||
# If dragging from unpinned to pinned, add to pinned apps
|
||||
if cross_section_drag_to_pin:
|
||||
source_widget = children[source_index]
|
||||
app_identifier = source_widget.app_identifier
|
||||
|
||||
|
||||
# Add to pinned apps if not already pinned
|
||||
if hasattr(source_widget, "desktop_app") and source_widget.desktop_app:
|
||||
app = source_widget.desktop_app
|
||||
@@ -483,7 +483,7 @@ class Applications(Box):
|
||||
self.pinned.insert(target_index, app_data_obj)
|
||||
else:
|
||||
self.pinned.insert(target_index, app_identifier)
|
||||
|
||||
|
||||
self.config["pinned_apps"] = self.pinned
|
||||
self.update_pinned_apps_file()
|
||||
self.update_applications()
|
||||
@@ -509,7 +509,7 @@ class Applications(Box):
|
||||
# since unpinned apps aren't stored in config
|
||||
child_to_move = children.pop(source_index)
|
||||
children.insert(target_index, child_to_move)
|
||||
|
||||
|
||||
# Update the UI
|
||||
for child in self.get_children():
|
||||
self.remove(child)
|
||||
@@ -520,11 +520,11 @@ class Applications(Box):
|
||||
def on_drag_end(self, widget, drag_context):
|
||||
if not self._drag_in_progress:
|
||||
return
|
||||
|
||||
|
||||
# Process drag end...
|
||||
|
||||
|
||||
self._drag_in_progress = False
|
||||
|
||||
|
||||
# Allow dock to hide again
|
||||
if self.dock_instance:
|
||||
self.dock_instance.prevent_hiding(False)
|
||||
File renamed without changes.
@@ -5,12 +5,12 @@ from fabric.widgets.box import Box
|
||||
from fabric.widgets.button import Button
|
||||
from fabric.widgets.datetime import DateTime
|
||||
from fabric.system_tray.widgets import SystemTray
|
||||
from modules.dock.battery import Battery
|
||||
from modules.dock.metrics import Metrics
|
||||
from modules.dock.controls import Controls
|
||||
from modules.dock.workspaces import workspace
|
||||
from modules.dock.indicators import Indicators
|
||||
from modules.dock.applications import Applications
|
||||
from .battery import Battery
|
||||
from .metrics import Metrics
|
||||
from .controls import Controls
|
||||
from .workspaces import workspace
|
||||
from .indicators import Indicators
|
||||
from .applications import Applications
|
||||
|
||||
|
||||
class DockComponents(Box):
|
||||
@@ -30,10 +30,7 @@ class DockComponents(Box):
|
||||
self.component_visibility = data.DOCK_COMPONENTS_VISIBILITY
|
||||
|
||||
# Create components
|
||||
self.workspaces = Button(
|
||||
child=workspace,
|
||||
name="workspaces",
|
||||
)
|
||||
self.workspaces = workspace # Use the workspace instance directly
|
||||
self.metrics = Metrics()
|
||||
self.battery = Battery()
|
||||
self.date_time = DateTime(
|
||||
@@ -53,7 +50,6 @@ class DockComponents(Box):
|
||||
orientation="h" if not data.VERTICAL else "v",
|
||||
)
|
||||
|
||||
|
||||
# Create list of components to add
|
||||
self.themed_children = [
|
||||
self.workspaces,
|
||||
@@ -65,21 +61,21 @@ class DockComponents(Box):
|
||||
self.date_time,
|
||||
self.systray,
|
||||
]
|
||||
|
||||
|
||||
# Add each child individually
|
||||
for child in self.themed_children:
|
||||
self.add(child)
|
||||
|
||||
# Apply initial visibility
|
||||
self.apply_component_props()
|
||||
|
||||
if data.DOCK_THEME == "Dense" or data.DOCK_THEME == "Edge":
|
||||
for child in self.themed_children:
|
||||
if hasattr(child, "add_style_class"):
|
||||
child.add_style_class("invert")
|
||||
|
||||
# Apply invert style for Pills theme when dock is on left or right
|
||||
if data.DOCK_THEME == "Pills" and (data.DOCK_POSITION == "Left" or data.DOCK_POSITION == "Right"):
|
||||
# Apply invert style for specific themes and positions
|
||||
should_invert = (
|
||||
data.DOCK_THEME in ["Dense", "Edge"] or
|
||||
(data.DOCK_THEME == "Pills" and data.DOCK_POSITION in ["Left", "Right"])
|
||||
)
|
||||
|
||||
if should_invert:
|
||||
for child in self.themed_children:
|
||||
if hasattr(child, "add_style_class"):
|
||||
child.add_style_class("invert")
|
||||
@@ -140,5 +136,3 @@ class DockComponents(Box):
|
||||
return self.component_visibility[component_name]
|
||||
|
||||
return None
|
||||
|
||||
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,148 @@
|
||||
import json
|
||||
import subprocess
|
||||
from fabric.hyprland.service import Hyprland
|
||||
from fabric.hyprland.widgets import Workspaces, WorkspaceButton
|
||||
from fabric.widgets.button import Button
|
||||
import config.data as data
|
||||
from fabric.widgets.box import Box
|
||||
|
||||
|
||||
CHINESE_NUMERALS = ["一", "二", "三", "四", "五", "六", "七", "八", "九", "〇"]
|
||||
|
||||
|
||||
class Workspace(Button):
|
||||
def __init__(self):
|
||||
# Determine if invert style should be applied
|
||||
should_invert = (
|
||||
data.DOCK_THEME in ["Dense", "Edge"] or
|
||||
(data.DOCK_THEME == "Pills" and data.DOCK_POSITION in ["Left", "Right"])
|
||||
)
|
||||
|
||||
super().__init__(
|
||||
name="workspace-single",
|
||||
can_focus=True,
|
||||
receives_default=True,
|
||||
relief="none",
|
||||
style_classes="invert" if should_invert else None,
|
||||
)
|
||||
|
||||
self.connection = Hyprland()
|
||||
self.activeWorkspace = str(self._get_active_workspace())
|
||||
|
||||
self.set_label(str(self.activeWorkspace))
|
||||
self.connect("clicked", self._on_click)
|
||||
self.connection.connect("event::workspace", self._on_workspace_changed)
|
||||
|
||||
self.set_sensitive(True)
|
||||
self.show_all()
|
||||
|
||||
def _get_active_workspace(self):
|
||||
active = self.connection.send_command("j/activeworkspace").reply
|
||||
return json.loads(active.decode("utf-8"))["name"]
|
||||
|
||||
def _get_active_workspaces(self):
|
||||
"""Get list of workspaces that have windows"""
|
||||
clients_data = self.connection.send_command("j/clients").reply
|
||||
clients = json.loads(clients_data.decode("utf-8"))
|
||||
|
||||
active_workspaces = set()
|
||||
for client in clients:
|
||||
if "workspace" in client and "name" in client["workspace"]:
|
||||
workspace_name = str(client["workspace"]["name"])
|
||||
active_workspaces.add(workspace_name)
|
||||
|
||||
return sorted(
|
||||
list(active_workspaces), key=lambda x: int(x) if x.isdigit() else x
|
||||
)
|
||||
|
||||
def _on_click(self, _widget):
|
||||
"""Handle button click to cycle through workspaces"""
|
||||
self._cycle_workspace()
|
||||
|
||||
def _cycle_workspace(self):
|
||||
"""Core logic to cycle through workspaces"""
|
||||
active_workspaces = self._get_active_workspaces()
|
||||
|
||||
if not active_workspaces:
|
||||
return
|
||||
|
||||
if str(self.activeWorkspace) not in active_workspaces:
|
||||
active_workspaces.append(str(self.activeWorkspace))
|
||||
active_workspaces.sort(key=lambda x: int(x) if x.isdigit() else x)
|
||||
|
||||
current_index = active_workspaces.index(self.activeWorkspace)
|
||||
next_index = (current_index + 1) % len(active_workspaces)
|
||||
next_workspace = active_workspaces[next_index]
|
||||
|
||||
cmd = ["hyprctl", "dispatch", "workspace", str(next_workspace)]
|
||||
subprocess.run(cmd, capture_output=True, text=True, timeout=2)
|
||||
|
||||
self.activeWorkspace = str(next_workspace)
|
||||
self.set_label(str(self.activeWorkspace))
|
||||
|
||||
def _on_workspace_changed(self, _obj, signal):
|
||||
"""Handle workspace change events from Hyprland"""
|
||||
workspace_data = json.loads(signal.data[0])
|
||||
self.activeWorkspace = str(workspace_data)
|
||||
self.set_label(str(self.activeWorkspace))
|
||||
|
||||
|
||||
# Create workspace components using Workspaces widget
|
||||
workspaces = Workspaces(
|
||||
name="workspaces",
|
||||
invert_scroll=True,
|
||||
empty_scroll=True,
|
||||
v_align="fill",
|
||||
orientation="h" if not data.VERTICAL else "v",
|
||||
spacing=8,
|
||||
buttons=[
|
||||
WorkspaceButton(
|
||||
h_expand=False,
|
||||
v_expand=False,
|
||||
h_align="center",
|
||||
v_align="center",
|
||||
id=i,
|
||||
label=None,
|
||||
style_classes=["vertical"] if data.VERTICAL else None,
|
||||
)
|
||||
for i in range(1, 11)
|
||||
],
|
||||
)
|
||||
|
||||
workspaces_num = Workspaces(
|
||||
name="workspaces-num",
|
||||
invert_scroll=True,
|
||||
empty_scroll=True,
|
||||
v_align="fill",
|
||||
orientation="h" if not data.VERTICAL else "v",
|
||||
spacing=0 if not data.WORKSPACE_USE_CHINESE_NUMERAL else 4,
|
||||
buttons=[
|
||||
WorkspaceButton(
|
||||
h_expand=False,
|
||||
v_expand=False,
|
||||
h_align="center",
|
||||
v_align="center",
|
||||
id=i,
|
||||
label=CHINESE_NUMERALS[i - 1]
|
||||
if data.WORKSPACE_USE_CHINESE_NUMERAL and 1 <= i <= len(CHINESE_NUMERALS)
|
||||
else str(i),
|
||||
)
|
||||
for i in range(1, 11)
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
# Create the workspace button instance
|
||||
workspaceactive = Workspace()
|
||||
|
||||
# Export the workspace widget based on configuration
|
||||
workspace = Box(
|
||||
name="workspaces-container",
|
||||
children=[
|
||||
workspaces
|
||||
if data.WORKSPACE_DOTS
|
||||
else workspaces_num
|
||||
if data.WORKSPACE_NUMS
|
||||
else workspaceactive
|
||||
],
|
||||
)
|
||||
@@ -9,7 +9,7 @@ from gi.repository import Gdk, GLib, Gtk
|
||||
from modules.corners import MyCorner
|
||||
from utils.occlusion import check_occlusion
|
||||
from utils.wayland import WaylandWindow as Window
|
||||
from modules.dock.components import DockComponents
|
||||
from modules.dock.components.components import DockComponents
|
||||
|
||||
|
||||
class Dock(Window):
|
||||
@@ -106,10 +106,8 @@ class Dock(Window):
|
||||
|
||||
# Create components using DockComponents
|
||||
self.components = DockComponents(
|
||||
orientation_val="h" if not data.VERTICAL else "v",
|
||||
dock_instance=self
|
||||
orientation_val="h" if not data.VERTICAL else "v", dock_instance=self
|
||||
)
|
||||
|
||||
|
||||
# Add components based on position
|
||||
if self.actual_dock_is_horizontal: # Bottom dock
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
import json
|
||||
|
||||
from fabric.hyprland.service import Hyprland
|
||||
from fabric.widgets.label import Label
|
||||
|
||||
connection = Hyprland()
|
||||
|
||||
workspaceData = connection.send_command("j/activeworkspace").reply
|
||||
activeWorkspace = json.loads(workspaceData.decode("utf-8"))["name"]
|
||||
workspace = Label(label=f"{activeWorkspace}")
|
||||
|
||||
|
||||
def on_workspace(obj, signal):
|
||||
global activeWorkspace
|
||||
activeWorkspace = json.loads(signal.data[0])
|
||||
workspace.set_label(f"{activeWorkspace}")
|
||||
|
||||
|
||||
connection.connect("event::workspace", on_workspace)
|
||||
Reference in new issue
Block a user