From bcd37ad40d9f1089339e81ff47d0df7fbe21744c Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Sat, 30 Nov 2024 00:19:36 +0545 Subject: [PATCH] remove unused code --- config/fabric/modules/bar/widgets/taskbar.py | 147 ------------------- 1 file changed, 147 deletions(-) delete mode 100644 config/fabric/modules/bar/widgets/taskbar.py diff --git a/config/fabric/modules/bar/widgets/taskbar.py b/config/fabric/modules/bar/widgets/taskbar.py deleted file mode 100644 index 67291067..00000000 --- a/config/fabric/modules/bar/widgets/taskbar.py +++ /dev/null @@ -1,147 +0,0 @@ -import json -import os -from typing import TypedDict - -from gi.repository import GdkPixbuf, GLib, Gtk -from loguru import logger - -from fabric.hyprland.widgets import get_hyprland_connection -from fabric.utils import exec_shell_command -from fabric.widgets.box import Box -from fabric.widgets.button import Button -from fabric.widgets.image import Image - - -class PagerClient(TypedDict): - title: str - initialClass: str - mapped: bool - hidden: bool - address: str - - -class TaskBar(Box): - def __init__(self, icon_size: int = 24, **kwargs): - super().__init__( - orientation="h", - spacing=7, - name="taskbar", - **kwargs, - ) - self.connection = get_hyprland_connection() - self.icon_size = icon_size - self.icon_theme = Gtk.IconTheme.get_default() - - self.set_visible(False) - - if self.connection.ready: - self.render_with_delay() - else: - self.connection.connect("event::ready", lambda *_: self.render_with_delay()) - - for event in ( - "activewindow", - "openwindow", - "closewindow", - "changefloatingmode", - ): - self.connection.connect("event::" + event, lambda *_: self.render(None)) - - def render_with_delay(self, *_): - GLib.timeout_add(101, self.render) - - def render(self, *_): - self.children = [] - - clients = self.fetch_clients() - active_window_address = self.get_active_window_address() - - visible_clients = [ - client for client in clients if client["mapped"] and not client["hidden"] - ] - - if visible_clients: - for client in visible_clients: - window_class = client["initialClass"].lower() - icon = self.bake_window_icon(window_class) - - button = Button(image=icon, tooltip_text=client["title"]) - if client["address"] == active_window_address: - button.set_style( - "background-color: @surfaceVariant; border-radius:100px;" - ) - button.connect( - "button-press-event", self.on_icon_click, client["address"] - ) - - self.add(button) - - self.set_visible(True) - self.show_all() - else: - self.set_visible(False) - - def get_active_window_address(self) -> str: - # Fetch the address of the currently active window - active_window_info = json.loads( - self.connection.send_command("j/activewindow").reply.decode() - ) - return active_window_info.get("address", "") - - def on_icon_click(self, widget, event, address): - exec_shell_command(f"hyprctl dispatch focuswindow address:{address}") - - def fetch_clients(self) -> list[PagerClient]: - return json.loads(self.connection.send_command("j/clients").reply.decode()) - - def bake_window_icon( - self, window_class: str, fallback_icon: str = "image-missing" - ) -> Image: - icon_name = self.get_icon_from_desktop_entry(window_class) - - if icon_name: - pixbuf = self.load_icon(icon_name) - else: - pixbuf = self.load_icon(window_class, fallback_icon) - - return Image(pixbuf=pixbuf, size=self.icon_size) - - def get_icon_from_desktop_entry(self, window_class: str) -> str: - for data_dir in GLib.get_system_data_dirs(): - applications_dir = os.path.join(data_dir, "applications") - - if os.path.isdir(applications_dir): - for desktop_file in os.listdir(applications_dir): - if desktop_file.endswith(".desktop"): - file_path = os.path.join(applications_dir, desktop_file) - try: - with open(file_path, "r") as f: - app_name = None - icon_name = None - for line in f: - if line.startswith("Name="): - app_name = line.split("=", 2)[1].strip().lower() - elif line.startswith("Icon=") and app_name: - icon_name = line.split("=", 2)[1].strip() - if window_class in app_name: - return icon_name - except Exception as e: - logger.error(f"Error reading {file_path}: {e}") - return None - - def load_icon( - self, icon_name: str, fallback_icon: str = "image-missing" - ) -> GdkPixbuf.Pixbuf: - try: - pixbuf = self.icon_theme.load_icon( - icon_name, - self.icon_size, - Gtk.IconLookupFlags.FORCE_SIZE, - ) - except Exception: - pixbuf = self.icon_theme.load_icon( - fallback_icon, - self.icon_size, - Gtk.IconLookupFlags.FORCE_SIZE, - ) - return pixbuf