diff --git a/config/fabric/__init__.py b/config/fabric/__init__.py deleted file mode 100644 index 010ae6ce..00000000 --- a/config/fabric/__init__.py +++ /dev/null @@ -1,77 +0,0 @@ -import os -import subprocess -import psutil -import json -import socket -import fabric -import glob -from pathlib import Path -from fabric.widgets.image import Image -from fabric import Application -from fabric.hyprland.widgets import Language, WorkspaceButton, Workspaces -from fabric.system_tray.widgets import SystemTray -from fabric.utils import ( - FormattedString, - bulk_connect, - bulk_replace, - exec_shell_command, - exec_shell_command_async, - get_relative_path, - invoke_repeater, - monitor_file, - DesktopApp, - get_desktop_applications, - idle_add, - remove_handler, -) -from fabric.widgets.box import Box -from fabric.widgets.button import Button -from fabric.widgets.revealer import Revealer -from fabric.widgets.centerbox import CenterBox -from fabric.widgets.datetime import DateTime -from fabric.widgets.eventbox import EventBox -from fabric.widgets.label import Label -from fabric.widgets.overlay import Overlay -from fabric.widgets.wayland import WaylandWindow as Window -from gi.repository import GLib, Gtk, Gdk, GdkPixbuf -from typing import TypedDict -from fabric.hyprland.widgets import get_hyprland_connection -from fabric.bluetooth.service import BluetoothClient -from loguru import logger -from fabric.widgets.scrolledwindow import ScrolledWindow -from fabric.widgets.entry import Entry -from collections.abc import Iterator - -AUDIO_WIDGET = True - -if AUDIO_WIDGET is True: - try: - from fabric.audio.service import Audio - except Exception as e: - print(e) - AUDIO_WIDGET = False - - -from modules.bar.widgets.TaskBar import TaskBar -from modules.bar.widgets.VolumeIndicator import VolumeIndicator -from modules.bar.widgets.MicrophoneIndicator import MicrophoneIndicator -from modules.bar.widgets.BatteryIndicator import BatteryLabel -from modules.bar.widgets.WifiIndicator import Wifi -from modules.bar.widgets.BluetoothIndicator import Bluetooth -from modules.bar.widgets.SystemInfo import RAMUsage, CPUUsage, SwapMemoryUsage -from modules.bar.widgets.PowerMenu import PowerMenu - - -from services.brightness import Brightness -from services.screen_record import ScreenRecorder -from services.emoji import EmojiService, EmojiItem -from services.sh import Sh - -from modules.launcher.clipboard import ClipboardManager -from modules.launcher.emoji import EmojiManager -from modules.launcher.shell import ShellCommandManager -from modules.launcher.wallpaper import WallpaperManager -from modules.launcher.app import handle_application_search, bake_favorite_slot -from modules.launcher.launcher import Launcher - -from modules.bar.bar import Bar # Should always be the last module diff --git a/config/fabric/main.py b/config/fabric/main.py index c84333e5..b17a9088 100644 --- a/config/fabric/main.py +++ b/config/fabric/main.py @@ -1,4 +1,14 @@ -from __init__ import * +import os + +from loguru import logger + +from fabric import Application +from fabric.utils import get_relative_path, monitor_file +from modules.bar.bar import Bar +from modules.launcher.launcher import Launcher +from modules.osd import SystemOSD +from services.brightness import Brightness +from services.screen_record import ScreenRecorder def apply_style(app: Application): @@ -16,15 +26,12 @@ if __name__ == "__main__": launcher = Launcher() launcher.hide() - - setting = Settings() - setting.hide() - + systemOverlay = SystemOSD() app = Application( "fabric-bar", bar, launcher, - setting, + systemOverlay, ) # Monitor main.css file for changes diff --git a/config/fabric/modules/bar/__pycache__/bar.cpython-312.pyc b/config/fabric/modules/bar/__pycache__/bar.cpython-312.pyc new file mode 100644 index 00000000..d409c751 Binary files /dev/null and b/config/fabric/modules/bar/__pycache__/bar.cpython-312.pyc differ diff --git a/config/fabric/modules/bar/__pycache__/battery.cpython-312.pyc b/config/fabric/modules/bar/__pycache__/battery.cpython-312.pyc new file mode 100644 index 00000000..4b30e07e Binary files /dev/null and b/config/fabric/modules/bar/__pycache__/battery.cpython-312.pyc differ diff --git a/config/fabric/modules/bar/__pycache__/bluetooth.cpython-312.pyc b/config/fabric/modules/bar/__pycache__/bluetooth.cpython-312.pyc new file mode 100644 index 00000000..118482f2 Binary files /dev/null and b/config/fabric/modules/bar/__pycache__/bluetooth.cpython-312.pyc differ diff --git a/config/fabric/modules/bar/__pycache__/glance.cpython-312.pyc b/config/fabric/modules/bar/__pycache__/glance.cpython-312.pyc new file mode 100644 index 00000000..7d999b20 Binary files /dev/null and b/config/fabric/modules/bar/__pycache__/glance.cpython-312.pyc differ diff --git a/config/fabric/modules/bar/__pycache__/icon_resolver.cpython-312.pyc b/config/fabric/modules/bar/__pycache__/icon_resolver.cpython-312.pyc new file mode 100644 index 00000000..9c3cb943 Binary files /dev/null and b/config/fabric/modules/bar/__pycache__/icon_resolver.cpython-312.pyc differ diff --git a/config/fabric/modules/bar/__pycache__/microphone.cpython-312.pyc b/config/fabric/modules/bar/__pycache__/microphone.cpython-312.pyc new file mode 100644 index 00000000..160ecd7c Binary files /dev/null and b/config/fabric/modules/bar/__pycache__/microphone.cpython-312.pyc differ diff --git a/config/fabric/modules/bar/__pycache__/powerprofile.cpython-312.pyc b/config/fabric/modules/bar/__pycache__/powerprofile.cpython-312.pyc new file mode 100644 index 00000000..176fe517 Binary files /dev/null and b/config/fabric/modules/bar/__pycache__/powerprofile.cpython-312.pyc differ diff --git a/config/fabric/modules/bar/__pycache__/taskbar.cpython-312.pyc b/config/fabric/modules/bar/__pycache__/taskbar.cpython-312.pyc new file mode 100644 index 00000000..47aa6ece Binary files /dev/null and b/config/fabric/modules/bar/__pycache__/taskbar.cpython-312.pyc differ diff --git a/config/fabric/modules/bar/__pycache__/volume.cpython-312.pyc b/config/fabric/modules/bar/__pycache__/volume.cpython-312.pyc new file mode 100644 index 00000000..39dd770b Binary files /dev/null and b/config/fabric/modules/bar/__pycache__/volume.cpython-312.pyc differ diff --git a/config/fabric/modules/bar/__pycache__/wifi.cpython-312.pyc b/config/fabric/modules/bar/__pycache__/wifi.cpython-312.pyc new file mode 100644 index 00000000..0044a899 Binary files /dev/null and b/config/fabric/modules/bar/__pycache__/wifi.cpython-312.pyc differ diff --git a/config/fabric/modules/bar/bar.py b/config/fabric/modules/bar/bar.py index 7450a3db..34b27e43 100644 --- a/config/fabric/modules/bar/bar.py +++ b/config/fabric/modules/bar/bar.py @@ -1,8 +1,27 @@ -from __init__ import * +from fabric.hyprland.widgets import Language, WorkspaceButton, Workspaces +from fabric.system_tray.widgets import SystemTray +from fabric.utils import FormattedString, bulk_replace +from fabric.widgets.box import Box +from fabric.widgets.centerbox import CenterBox +from fabric.widgets.datetime import DateTime +from fabric.widgets.wayland import WaylandWindow as Window +from modules.bar.widgets import ( + BatteryLabel, + Bluetooth, + MicrophoneIndicator, + PowerProfile, + TaskBar, + VolumeIndicator, + Wifi, +) + +from .glance import OpenAppsBar class Bar(Window): - def __init__(self): + def __init__( + self, + ): super().__init__( layer="top", anchor="left bottom right", @@ -15,8 +34,7 @@ class Bar(Window): spacing=4, buttons=[WorkspaceButton(id=i, label=str(i)) for i in range(1, 11)], ) - - self.kb_layout = Language( + self.language = Language( formatter=FormattedString( "{replace_lang(language)}", replace_lang=lambda lang: bulk_replace( @@ -26,93 +44,57 @@ class Bar(Window): regex=True, ), ), - name="kb_layout", ) + self.date_time = DateTime(formatters=["%-I:%M 󰧞 %a %d %b"], name="datetime") + self.system_tray = SystemTray(spacing=4, icon_size=18) - self.clock = DateTime( - formatters=["%-I:%M %p %b %-d", "%-I:%M:%S %p %b %-d", "%a %-d %Y"], - name="datetime", - ) - - self.system_tray = SystemTray(name="tray", spacing=4, icon_size=16) - - self.battery = BatteryLabel(name="battery") - - self.ram = RAMUsage() - - self.cpu = CPUUsage() - - self.swap = SwapMemoryUsage() - - self.wifi = Wifi() - - self.bluetooth = Bluetooth() - - self.TaskBar = TaskBar(name="tray", icon_size=16) - + self.TaskBar = TaskBar(icon_size=18) self.volume = VolumeIndicator() - + self.wifi = Wifi() + self.bluetooth = Bluetooth() + self.battery = BatteryLabel(name="battery") self.microphone = MicrophoneIndicator() - - self.system_info = Box( - name="tray", - spacing=4, - children=[ - self.ram, - self.swap, - self.cpu, - ], - ) - - self.logo = Button( - name="logo", - child=Label("󰍉"), - on_clicked=lambda _: exec_shell_command("fabric_send 'luancher.toggle()"), - ) + self.power = PowerProfile() + self.open_apps_bar = OpenAppsBar() self.applets = Box( name="applets", spacing=4, children=[ - self.kb_layout, + self.language, + self.power, self.bluetooth, self.wifi, self.volume, self.microphone, + # self.battery, ], ) - self.power = PowerMenu() - self.children = CenterBox( name="bar", start_children=Box( - name="modules_left", + name="start-container", spacing=8, orientation="h", - children=[ - self.logo, - self.TaskBar, - ], + children=self.TaskBar, ), center_children=Box( - name="modules_center", + name="center-container", spacing=8, orientation="h", children=[ - # self.system_info, self.workspaces, ], ), end_children=Box( - name="modules_right", + name="end-container", spacing=8, orientation="h", children=[ self.system_tray, self.battery, self.applets, - self.clock, - self.power, + self.date_time, ], ), ) diff --git a/config/fabric/modules/bar/glance.py b/config/fabric/modules/bar/glance.py new file mode 100644 index 00000000..be006b70 --- /dev/null +++ b/config/fabric/modules/bar/glance.py @@ -0,0 +1,54 @@ +import gi +from fabric.widgets.box import Box +from fabric.widgets.button import Button +from fabric.widgets.image import Image + +from .icon_resolver import IconResolver + +gi.require_version("Glace", "0.1") +from gi.repository import Glace + + +class OpenAppsBar(Box): + def __init__(self): + self.client_buttons = {} + super().__init__(spacing=10) + self.icon_resolver = IconResolver() + self._manager = Glace.Manager() + self._manager.connect("client-added", self.on_client_added) + + def on_active_window(self, _, event): + print(event.data) + print(self.client_buttons) + # client_buttons[] + + def on_client_added(self, _, client: Glace.Client): + client_image = Image() + client_button = Button( + name="panel-button", + image=client_image, + on_button_press_event=lambda *_: client.activate(), + ) + self.client_buttons[client.get_id()] = client_button + + client.connect( + "notify::app-id", + lambda *_: [ + client_image.set_from_pixbuf( + self.icon_resolver.get_icon_pixbuf(client.get_app_id(), 24) + ), + print(client.get_id()), + ], + ) + + client.connect( + "notify::activated", + lambda *_: ( + client_button.add_style_class("activated") + if client.get_activated() + else client_button.remove_style_class("activated") + ), + ) + client.bind_property("title", client_button, "tooltip-text", 0) + client.connect("close", lambda *_: self.remove(client_button)) + self.add(client_button) diff --git a/config/fabric/modules/bar/icon_resolver.py b/config/fabric/modules/bar/icon_resolver.py new file mode 100644 index 00000000..883ed1a1 --- /dev/null +++ b/config/fabric/modules/bar/icon_resolver.py @@ -0,0 +1,100 @@ +import json +import os +import re + +import gi + +gi.require_version("Gtk", "3.0") +from gi.repository import GLib, Gtk +from loguru import logger + +# TODO WIP +# Idea: nearest string matching algorithm +# if already exists: retrieve from json +# if found: stor in json: app_id -> icon_name +# if not found: store in json -> misisng-icon + + +CACHE_DIR = str(GLib.get_user_cache_dir()) + "/fabric" +ICON_CACHE_FILE = CACHE_DIR + "/icons.json" +if not os.path.exists(CACHE_DIR): + os.makedirs(CACHE_DIR) + + +class IconResolver: + def __init__(self, default_applicaiton_icon: str = "application-x-symbolic"): + if os.path.exists(ICON_CACHE_FILE): + f = open(ICON_CACHE_FILE) + try: + self._icon_dict = json.load(f) + except json.JSONDecodeError: + logger.info("[ICONS] Cache file does not exist or is corrupted") + f.close() + else: + self._icon_dict = {} + + self.default_applicaiton_icon = default_applicaiton_icon + + def get_icon_name(self, app_id: str): + if app_id in self._icon_dict: + return self._icon_dict[app_id] + new_icon = self._compositor_find_icon(app_id) + logger.info( + f"[ICONS] found new icon: '{new_icon}' for app id: '{app_id}', storing..." + ) + self._store_new_icon(app_id, new_icon) + return new_icon + + def get_icon_pixbuf(self, app_id: str, size: int = 16): + return Gtk.IconTheme.get_default().load_icon( + self.get_icon_name(app_id), + size, + Gtk.IconLookupFlags.FORCE_SIZE, + ) + + def _store_new_icon(self, app_id: str, icon: str): + self._icon_dict[app_id] = icon + with open(ICON_CACHE_FILE, "w") as f: + json.dump(self._icon_dict, f) + f.close() + + def _get_icon_from_desktop_file(self, desktop_file_path: str): + # TODO: get icon in the [Desktop Entry] section only + with open(desktop_file_path) as f: + for line in f.readlines(): + if "Icon=" in line: + return "".join(line[5:].split()) + return self.default_applicaiton_icon + + def _get_desktop_file(self, app_id: str) -> str | None: + data_dirs = GLib.get_system_data_dirs() + for data_dir in data_dirs: + data_dir = data_dir + "/applications/" + if os.path.exists(data_dir): + # Do name resolving here + + files = os.listdir(data_dir) + matching = [ + s for s in files if "".join(app_id.lower().split()) in s.lower() + ] + if matching: + return data_dir + matching[0] + + for word in list(filter(None, re.split(r"-|\.|_|\s", app_id))): + matching = [s for s in files if word.lower() in s.lower()] + if matching: + return data_dir + matching[0] + + return None + + def _compositor_find_icon(self, app_id: str): + if Gtk.IconTheme.get_default().has_icon(app_id): + return app_id + if Gtk.IconTheme.get_default().has_icon(app_id + "-desktop"): + return app_id + "-desktop" + desktop_file = self._get_desktop_file(app_id) + return ( + self._get_icon_from_desktop_file(desktop_file) + if desktop_file + else self.default_applicaiton_icon + ) diff --git a/config/fabric/modules/bar/widgets/BatteryIndicator.py b/config/fabric/modules/bar/widgets/BatteryIndicator.py deleted file mode 100644 index e59f266f..00000000 --- a/config/fabric/modules/bar/widgets/BatteryIndicator.py +++ /dev/null @@ -1,40 +0,0 @@ -from __init__ import * - - -class BatteryLabel(Box): - def __init__(self, **kwargs): - super().__init__(**kwargs) - self.battery_icon = Label( - label="󰁹", - style="font-size: 16px; margin-right: 4px;", - ) - self.battery_label = Label( - label="N/A", - style="font-size: 12px; margin-left: 4px;", - ) - - invoke_repeater(1000, self.update_battery_status, initial_call=True) - - self.children = self.battery_icon, self.battery_label - - def update_battery_status(self): - battery_percent = round( - sensor.percent if (sensor := psutil.sensors_battery()) else 0.0 - ) - self.battery_label.set_label(f"{(battery_percent or 'N/A')}%") - - is_charging = bool( - psutil.sensors_battery().power_plugged - if psutil.sensors_battery() is not None - else False - ) - if is_charging: - icons = ["󰢟", "󰂆", "󰂇", "󰂈", "󰢝", "󰂉", "󰢞", "󰂊", "󰂋", "󰂅"] - else: - icons = ["󱃍", "󰁻", "󰁼", "󰁽", "󰁾", "󰁿", "󰂀", "󰂁", "󰂂", "󰁹"] - - index = min(max(battery_percent // 10, 0), 9) - - self.battery_icon.set_label(icons[index]) - - return True diff --git a/config/fabric/modules/bar/widgets/PowerMenu.py b/config/fabric/modules/bar/widgets/PowerMenu.py deleted file mode 100644 index f0651a96..00000000 --- a/config/fabric/modules/bar/widgets/PowerMenu.py +++ /dev/null @@ -1,144 +0,0 @@ -from __init__ import * - - -class PowerMenu(EventBox): - def __init__(self): - super().__init__(name="power-event") - - icons_map = { - "power-lock": "", - "power-suspend": "", - "power-logout": "", - "power-reboot": "", - "power-shutdown": "", - } - - self.buttons = { - name: Button(name=name, child=Label(label=f"{icon}")) - for name, icon in icons_map.items() - } - - self.power_box = Box( - name="power-box", - orientation="h", - children=[ - self.buttons[name] - for name in [ - "power-lock", - "power-suspend", - "power-logout", - "power-reboot", - ] - ], - ) - - self.accept_button = Button(name="accept", child=Label(label="✔")) - self.cancel_button = Button(name="cancel", child=Label(label="✘")) - - self.revealer_buttons_box = Box( - name="confirm-box", - orientation="h", - children=[self.accept_button, self.cancel_button], - ) - - self.revealer = Revealer( - name="power-revealer", - transition_type="slide-right", - transition_duration=300, - child=self.power_box, - reveal_child=False, - ) - - self.shutdown_box = Box( - name="shutdown-box", - orientation="h", - children=[self.buttons["power-shutdown"]], - ) - - self.super_box = Box( - name="super-box", - orientation="h", - children=[self.revealer, self.shutdown_box], - ) - - self.confirm_revealer = Revealer( - name="confirm-revealer", - transition_type="slide-right", - transition_duration=300, - child=self.revealer_buttons_box, - reveal_child=False, - ) - - self.full_power = Box( - name="full-power", - orientation="h", - children=[self.super_box, self.confirm_revealer], - ) - - self.add(self.full_power) - self.buttons["self"] = self - self.current_command = None - self.confirmation_active = False - - for btn in self.buttons.values(): - bulk_connect( - btn, - { - "button-press-event": self.on_button_press, - "enter-notify-event": self.on_button_hover, - "leave-notify-event": self.on_button_unhover, - }, - ) - - self.accept_button.connect("button-press-event", self.on_accept_press) - self.cancel_button.connect("button-press-event", self.on_cancel_press) - - def on_button_hover(self, button, event): - if button == self and not self.confirmation_active: - self.revealer.set_reveal_child(True) - - def on_button_unhover(self, button, event): - if button == self and not self.confirmation_active: - self.revealer.set_reveal_child(False) - - def on_button_press(self, button, event): - commands = { - self.buttons["power-lock"]: "hyprlock", - self.buttons[ - "power-suspend" - ]: "hyprctl dispatch exec hyprlock && systemctl suspend", - self.buttons["power-logout"]: "hyprctl dispatch exit", - self.buttons["power-reboot"]: "systemctl reboot", - self.buttons["power-shutdown"]: "systemctl poweroff", - } - if button in commands: - if button != self.buttons["power-lock"]: - self.current_command = commands[button] - self.revealer.set_reveal_child(False) - self.confirm_revealer.set_reveal_child(True) - self.shutdown_box.hide() - self.confirmation_active = True - - else: - exec_shell_command_async(commands[button], lambda *_: None) - return True - - def on_accept_press(self, button, event): - if self.current_command: - exec_shell_command_async(self.current_command, lambda *_: None) - self.current_command = None - self.confirm_revealer.set_reveal_child(False) - self.revealer.set_reveal_child(True) - self.shutdown_box.show() - self.confirmation_active = False - - return True - - def on_cancel_press(self, button, event): - self.current_command = None - self.confirm_revealer.set_reveal_child(False) - self.revealer.set_reveal_child(True) - self.shutdown_box.show() - self.confirmation_active = False - - return True diff --git a/config/fabric/modules/bar/widgets/SystemInfo.py b/config/fabric/modules/bar/widgets/SystemInfo.py deleted file mode 100644 index 6a59926b..00000000 --- a/config/fabric/modules/bar/widgets/SystemInfo.py +++ /dev/null @@ -1,70 +0,0 @@ -from __init__ import * - - -class RAMUsage(Box): - def __init__(self, **kwargs): - super().__init__(**kwargs) - self.ram_icon = Label( - label="󰍛", - style="font-size: 16px; margin-right: 4px;", - ) - self.ram_label = Label( - label="N/A%", - style="font-size: 12px; margin-left: 4px;", - ) - - invoke_repeater(1000, self.update_ram_status, initial_call=True) - - self.children = self.ram_icon, self.ram_label - - def update_ram_status(self): - ram_percent = int(psutil.virtual_memory().percent) - self.ram_label.set_label(f"{ram_percent}%") - - return True - - -class CPUUsage(Box): - def __init__(self, **kwargs): - super().__init__(**kwargs) - self.cpu_icon = Label( - label="󰻠", - style="font-size: 16px; margin-right: 4px;", - ) - self.cpu_label = Label( - label="N/A%", - style="font-size: 12px; margin-left: 4px;", - ) - - invoke_repeater(1000, self.update_cpu_status, initial_call=True) - - self.children = self.cpu_icon, self.cpu_label - - def update_cpu_status(self): - cpu_percent = int(psutil.cpu_percent()) - self.cpu_label.set_label(f"{cpu_percent}%") - - return True - - -class SwapMemoryUsage(Box): - def __init__(self, **kwargs): - super().__init__(**kwargs) - self.swap_icon = Label( - label="󰓡", - style="font-size: 16px; margin-right: 4px;", - ) - self.swap_label = Label( - label="N/A%", style="font-size: 12px; margin-left: 4px;" - ) - - invoke_repeater(1000, self.update_swap_memory_status, initial_call=True) - - self.children = self.swap_icon, self.swap_label - - def update_swap_memory_status(self): - swap_info = psutil.swap_memory() - swap_percent = int(swap_info.percent) - self.swap_label.set_label(f"{swap_percent}%") - - return True diff --git a/config/fabric/modules/bar/widgets/TaskBar.py b/config/fabric/modules/bar/widgets/TaskBar.py deleted file mode 100644 index adfe399b..00000000 --- a/config/fabric/modules/bar/widgets/TaskBar.py +++ /dev/null @@ -1,118 +0,0 @@ -from __init__ import * - - -class PagerClient(TypedDict): - title: str - initialClass: str - mapped: bool - hidden: bool - address: str - - -class TaskBar(Box): - def __init__(self, icon_size: int = 16, **kwargs): - super().__init__(orientation="h", spacing=6, **kwargs) - self.connection = get_hyprland_connection() - self.icon_size = icon_size - self.icon_theme = Gtk.IconTheme.get_default() - self.displayed_classes = set() - - 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(100, self.render) - - def render(self, *_): - self.children = [] - self.displayed_classes.clear() - - clients = self.fetch_clients() - - 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() - if window_class not in self.displayed_classes: - icon = self.bake_window_icon(window_class) - - button = Button(image=icon, tooltip_text=client["title"]) - - button.connect( - "button-press-event", self.on_icon_click, client["address"] - ) - - self.add(button) - self.displayed_classes.add(window_class) - - self.set_visible(True) - self.show_all() - else: - self.set_visible(False) - - def on_icon_click(self, widget, event, address): - command = ["hyprctl", "dispatch", "focuswindow", f"address:{address}"] - subprocess.run(command, check=True) - - 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: - # First, try to get the icon from the desktop entry - icon_name = self.get_icon_from_desktop_entry(window_class) - - if icon_name: - pixbuf = self.load_icon(icon_name) - else: - # Fallback to the icon theme if not found - 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: - desktop_files = glob.glob("/usr/share/applications/*.desktop") - for desktop_file in desktop_files: - with open(desktop_file, "r") as f: - for line in f: - if line.startswith("Name="): - app_name = line.split("=", 1)[1].strip().lower() - if window_class in app_name: - # If a matching app name is found, return the Icon - for line in f: - if line.startswith("Icon="): - return line.split("=", 1)[1].strip() - 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 diff --git a/config/fabric/modules/bar/widgets/WifiIndicator (copy 1).py b/config/fabric/modules/bar/widgets/WifiIndicator (copy 1).py deleted file mode 100644 index 1f34f740..00000000 --- a/config/fabric/modules/bar/widgets/WifiIndicator (copy 1).py +++ /dev/null @@ -1,52 +0,0 @@ -from __init__ import * - - -class Wifi(Box): - def __init__(self, **kwargs): - super().__init__(**kwargs) - self.wifi_icon = Label( - label="󰤭", - style="font-size: 16px; ", - ) - - self.wifi_icon.set_tooltip_text("Unknown") - - invoke_repeater(1000, self.update_wifi_status, initial_call=True) - - self.children = (self.wifi_icon,) - - def update_wifi_status(self): - wifi_name = self.get_connected_wifi_name() - wifi_on = self.check_wifi_status() - - if wifi_on: - self.wifi_icon.set_label("󰤥") - self.wifi_icon.set_tooltip_text(wifi_name) - else: - self.wifi_icon.set_label("󰤭") - self.wifi_icon.set_tooltip_text("Unknown") - - return True - - def check_wifi_status(self): - for interface, addrs in psutil.net_if_addrs().items(): - if "wlan" in interface or "wifi" in interface: - if ( - interface in psutil.net_if_stats() - and psutil.net_if_stats()[interface].isup - ): - return True - return False - - def get_connected_wifi_name(self): - try: - output = exec_shell_command( - "nmcli -t -f active,ssid dev wifi | grep '^yes' | cut -d: -f2" - ) - for line in output.splitlines(): - if line.startswith("yes:"): - return line.split(":")[1] - except Exception as e: - print(f"Error retrieving Wi-Fi name: {e}") - - return None diff --git a/config/fabric/modules/bar/widgets/__init__.py b/config/fabric/modules/bar/widgets/__init__.py new file mode 100644 index 00000000..b5bc916d --- /dev/null +++ b/config/fabric/modules/bar/widgets/__init__.py @@ -0,0 +1,7 @@ +from .battery import * +from .bluetooth import * +from .microphone import * +from .powerprofile import * +from .taskbar import * +from .volume import * +from .wifi import * diff --git a/config/fabric/modules/bar/widgets/__pycache__/BatteryIndicator.cpython-312.pyc b/config/fabric/modules/bar/widgets/__pycache__/BatteryIndicator.cpython-312.pyc deleted file mode 100644 index b4191742..00000000 Binary files a/config/fabric/modules/bar/widgets/__pycache__/BatteryIndicator.cpython-312.pyc and /dev/null differ diff --git a/config/fabric/modules/bar/widgets/__pycache__/BluetoothIndicator.cpython-312.pyc b/config/fabric/modules/bar/widgets/__pycache__/BluetoothIndicator.cpython-312.pyc deleted file mode 100644 index 618ba227..00000000 Binary files a/config/fabric/modules/bar/widgets/__pycache__/BluetoothIndicator.cpython-312.pyc and /dev/null differ diff --git a/config/fabric/modules/bar/widgets/__pycache__/MicrophoneIndicator.cpython-312.pyc b/config/fabric/modules/bar/widgets/__pycache__/MicrophoneIndicator.cpython-312.pyc deleted file mode 100644 index 17b36371..00000000 Binary files a/config/fabric/modules/bar/widgets/__pycache__/MicrophoneIndicator.cpython-312.pyc and /dev/null differ diff --git a/config/fabric/modules/bar/widgets/__pycache__/PowerMenu.cpython-312.pyc b/config/fabric/modules/bar/widgets/__pycache__/PowerMenu.cpython-312.pyc deleted file mode 100644 index f1d5e122..00000000 Binary files a/config/fabric/modules/bar/widgets/__pycache__/PowerMenu.cpython-312.pyc and /dev/null differ diff --git a/config/fabric/modules/bar/widgets/__pycache__/SystemInfo.cpython-312.pyc b/config/fabric/modules/bar/widgets/__pycache__/SystemInfo.cpython-312.pyc deleted file mode 100644 index d5c93384..00000000 Binary files a/config/fabric/modules/bar/widgets/__pycache__/SystemInfo.cpython-312.pyc and /dev/null differ diff --git a/config/fabric/modules/bar/widgets/__pycache__/TaskBar.cpython-312.pyc b/config/fabric/modules/bar/widgets/__pycache__/TaskBar.cpython-312.pyc deleted file mode 100644 index fca48cbb..00000000 Binary files a/config/fabric/modules/bar/widgets/__pycache__/TaskBar.cpython-312.pyc and /dev/null differ diff --git a/config/fabric/modules/bar/widgets/__pycache__/Taskbar.cpython-312.pyc b/config/fabric/modules/bar/widgets/__pycache__/Taskbar.cpython-312.pyc deleted file mode 100644 index 34f09818..00000000 Binary files a/config/fabric/modules/bar/widgets/__pycache__/Taskbar.cpython-312.pyc and /dev/null differ diff --git a/config/fabric/modules/bar/widgets/__pycache__/VolumeIndicator.cpython-312.pyc b/config/fabric/modules/bar/widgets/__pycache__/VolumeIndicator.cpython-312.pyc deleted file mode 100644 index df40b197..00000000 Binary files a/config/fabric/modules/bar/widgets/__pycache__/VolumeIndicator.cpython-312.pyc and /dev/null differ diff --git a/config/fabric/modules/bar/widgets/__pycache__/WifiIndicator.cpython-312.pyc b/config/fabric/modules/bar/widgets/__pycache__/WifiIndicator.cpython-312.pyc deleted file mode 100644 index 51684d21..00000000 Binary files a/config/fabric/modules/bar/widgets/__pycache__/WifiIndicator.cpython-312.pyc and /dev/null differ diff --git a/config/fabric/modules/bar/widgets/__pycache__/__init__.cpython-312.pyc b/config/fabric/modules/bar/widgets/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 00000000..9e77496a Binary files /dev/null and b/config/fabric/modules/bar/widgets/__pycache__/__init__.cpython-312.pyc differ diff --git a/config/fabric/modules/bar/widgets/__pycache__/battery.cpython-312.pyc b/config/fabric/modules/bar/widgets/__pycache__/battery.cpython-312.pyc new file mode 100644 index 00000000..ab4bd549 Binary files /dev/null and b/config/fabric/modules/bar/widgets/__pycache__/battery.cpython-312.pyc differ diff --git a/config/fabric/modules/bar/widgets/__pycache__/bluetooth.cpython-312.pyc b/config/fabric/modules/bar/widgets/__pycache__/bluetooth.cpython-312.pyc new file mode 100644 index 00000000..f16dd677 Binary files /dev/null and b/config/fabric/modules/bar/widgets/__pycache__/bluetooth.cpython-312.pyc differ diff --git a/config/fabric/modules/bar/widgets/__pycache__/idle.cpython-312.pyc b/config/fabric/modules/bar/widgets/__pycache__/idle.cpython-312.pyc new file mode 100644 index 00000000..a1a4dec2 Binary files /dev/null and b/config/fabric/modules/bar/widgets/__pycache__/idle.cpython-312.pyc differ diff --git a/config/fabric/modules/bar/widgets/__pycache__/microphone.cpython-312.pyc b/config/fabric/modules/bar/widgets/__pycache__/microphone.cpython-312.pyc new file mode 100644 index 00000000..2219aaed Binary files /dev/null and b/config/fabric/modules/bar/widgets/__pycache__/microphone.cpython-312.pyc differ diff --git a/config/fabric/modules/bar/widgets/__pycache__/powerprofile.cpython-312.pyc b/config/fabric/modules/bar/widgets/__pycache__/powerprofile.cpython-312.pyc new file mode 100644 index 00000000..b4a67f44 Binary files /dev/null and b/config/fabric/modules/bar/widgets/__pycache__/powerprofile.cpython-312.pyc differ diff --git a/config/fabric/modules/bar/widgets/__pycache__/taskbar.cpython-312.pyc b/config/fabric/modules/bar/widgets/__pycache__/taskbar.cpython-312.pyc new file mode 100644 index 00000000..55acc716 Binary files /dev/null and b/config/fabric/modules/bar/widgets/__pycache__/taskbar.cpython-312.pyc differ diff --git a/config/fabric/modules/bar/widgets/__pycache__/volume.cpython-312.pyc b/config/fabric/modules/bar/widgets/__pycache__/volume.cpython-312.pyc new file mode 100644 index 00000000..f2bad3db Binary files /dev/null and b/config/fabric/modules/bar/widgets/__pycache__/volume.cpython-312.pyc differ diff --git a/config/fabric/modules/bar/widgets/__pycache__/wifi.cpython-312.pyc b/config/fabric/modules/bar/widgets/__pycache__/wifi.cpython-312.pyc new file mode 100644 index 00000000..7b57e62e Binary files /dev/null and b/config/fabric/modules/bar/widgets/__pycache__/wifi.cpython-312.pyc differ diff --git a/config/fabric/modules/bar/widgets/battery.py b/config/fabric/modules/bar/widgets/battery.py new file mode 100644 index 00000000..1bc0d2ce --- /dev/null +++ b/config/fabric/modules/bar/widgets/battery.py @@ -0,0 +1,49 @@ +import psutil +from fabric.utils import invoke_repeater +from fabric.widgets.box import Box +from fabric.widgets.label import Label + + +class BatteryLabel(Box): + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.battery_icon = Label( + label="󰁹", + name="symbol", + # style="font-size: 16px; margin-right: 4px;", + ) + self.battery_label = Label( + label="N/A", + style="font-size: 16px; margin-left: 4px;", + ) + + invoke_repeater(1000, self.update_battery_status, initial_call=True) + + self.children = self.battery_icon, self.battery_label + + def update_battery_status(self): + battery = psutil.sensors_battery() + if battery is None: + self.hide() + return + + battery_percent = round(battery.percent) if battery else 0.0 + self.battery_label.set_label(f"{(battery_percent or 'N/A')}%") + + is_charging = battery.power_plugged if battery else False + + icons = ( + ["󰢟", "󰂆", "󰂇", "󰂈", "󰢝", "󰂉", "󰢞", "󰂊", "󰂋", "󰂅"] + if is_charging + else ["󱃍", "󰁻", "󰁼", "󰁽", "󰁾", "󰁿", "󰂀", "󰂁", "󰂂", "󰁹"] + ) + index = min(max(battery_percent // 10, 0), 9) + + self.battery_icon.set_label(icons[index]) + + if battery_percent == 100: + self.hide() + else: + self.show() + + return True diff --git a/config/fabric/modules/bar/widgets/BluetoothIndicator.py b/config/fabric/modules/bar/widgets/bluetooth.py similarity index 76% rename from config/fabric/modules/bar/widgets/BluetoothIndicator.py rename to config/fabric/modules/bar/widgets/bluetooth.py index bd74398c..ba8c2566 100644 --- a/config/fabric/modules/bar/widgets/BluetoothIndicator.py +++ b/config/fabric/modules/bar/widgets/bluetooth.py @@ -1,14 +1,17 @@ -from __init__ import * +from fabric.bluetooth import BluetoothClient +from fabric.widgets.box import Box +from fabric.widgets.label import Label -class Bluetooth(Gtk.Box): +class Bluetooth(Box): def __init__(self, **kwargs): super().__init__(**kwargs) self.bluetooth_client = BluetoothClient() self.bluetooth_icon = Label( label="󰂲", - style="font-size: 16px;", + # name="symbol", + style="font-size: 18px;", ) self.bluetooth_client.connect("changed", self.update_bluetooth_status) diff --git a/config/fabric/modules/bar/widgets/idle.py b/config/fabric/modules/bar/widgets/idle.py new file mode 100644 index 00000000..f55f0065 --- /dev/null +++ b/config/fabric/modules/bar/widgets/idle.py @@ -0,0 +1,35 @@ +from fabric.widgets.box import Box +from fabric.widgets.label import Label +from services.inhibit import Inhibit # Importing Inhibit from the services module + + +class IdleIndicator(Box): + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.inhibit_service = Inhibit() # Use the imported Inhibit service + self.idle_icon = Label( + label="󰅐", # Icon symbol for idle/inhibit indication + name="symbol", + ) + + # Add the idle icon as a child widget + self.children = (self.idle_icon,) + + # Check the initial inhibition state and update the icon visibility + self.update_idle_status() + + def update_idle_status(self): + """Update the idle status based on inhibition state.""" + print( + f"Inhibition state: {self.inhibit_service.is_inhibit}" + ) # Debugging output + + if self.inhibit_service.is_inhibit: + self.idle_icon.set_visible(True) # Show the idle icon when inhibited + else: + self.idle_icon.set_visible(False) # Hide the idle icon when not inhibited + + def toggle_idle(self): + """Toggle the idle state by interacting with the inhibit service.""" + self.inhibit_service.toggle() # Toggle the inhibition state + self.update_idle_status() # Refresh the icon visibility diff --git a/config/fabric/modules/bar/widgets/MicrophoneIndicator.py b/config/fabric/modules/bar/widgets/microphone.py similarity index 80% rename from config/fabric/modules/bar/widgets/MicrophoneIndicator.py rename to config/fabric/modules/bar/widgets/microphone.py index 818e7bbf..97835264 100644 --- a/config/fabric/modules/bar/widgets/MicrophoneIndicator.py +++ b/config/fabric/modules/bar/widgets/microphone.py @@ -1,4 +1,6 @@ -from __init__ import * +from fabric.audio.service import Audio +from fabric.widgets.box import Box +from fabric.widgets.label import Label class MicrophoneIndicator(Box): @@ -8,7 +10,8 @@ class MicrophoneIndicator(Box): self.audio_service = audio_service self.microphone_icon = Label( label="󰍭", - style="font-size: 16px; margin-left:4px;", + name="symbol", + # style="font-size: 16px; margin-left:4px;", ) self.audio_service.connect("microphone_changed", self.update_microphone_status) diff --git a/config/fabric/modules/bar/widgets/powerprofile.py b/config/fabric/modules/bar/widgets/powerprofile.py new file mode 100644 index 00000000..30dfe4fa --- /dev/null +++ b/config/fabric/modules/bar/widgets/powerprofile.py @@ -0,0 +1,40 @@ +from fabric.utils import exec_shell_command, invoke_repeater +from fabric.widgets.box import Box +from fabric.widgets.label import Label + +PROFILE_ICONS = { + "power-saver": "󰡳", + "balanced": None, + "performance": "󰡴", +} + + +class PowerProfile(Box): + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.profile_icon = Label( + label="󰡳", + name="symbol", + # style="font-size: 16px; margin-right: 4px;", + ) + + invoke_repeater(1000, self.update_power_profile, initial_call=True) + + self.children = (self.profile_icon,) + + def update_power_profile(self): + profile = self.get_power_profile() + self.update_icon(profile) + return True + + def get_power_profile(self): + result = exec_shell_command("powerprofilesctl get") + return result.strip() if result else "power-saver" + + def update_icon(self, profile): + if profile in ["power-saver", "performance"]: + icon = PROFILE_ICONS[profile] + self.profile_icon.set_label(icon) + self.profile_icon.show() + else: + self.profile_icon.hide() diff --git a/config/fabric/modules/bar/widgets/taskbar.py b/config/fabric/modules/bar/widgets/taskbar.py new file mode 100644 index 00000000..5122802a --- /dev/null +++ b/config/fabric/modules/bar/widgets/taskbar.py @@ -0,0 +1,146 @@ +import json +import os +from typing import TypedDict + +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 +from gi.repository import GdkPixbuf, GLib, Gtk +from loguru import logger + + +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:101px;" + ) + 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 diff --git a/config/fabric/modules/bar/widgets/taskbar11.py b/config/fabric/modules/bar/widgets/taskbar11.py new file mode 100644 index 00000000..3e176ee7 --- /dev/null +++ b/config/fabric/modules/bar/widgets/taskbar11.py @@ -0,0 +1,180 @@ +import glob +import json +import subprocess +from typing import TypedDict + +from fabric.hyprland.widgets import get_hyprland_connection +from fabric.widgets.box import Box +from fabric.widgets.button import Button +from fabric.widgets.image import Image +from fabric.widgets.label import Label +from gi.repository import GdkPixbuf, GLib, Gtk + + +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=6, 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(100, self.render) + + def render(self, *_): + self.children = [] + + clients = self.fetch_clients() + active_window_address = self.get_active_window_address() + + # Group clients by initialClass + grouped_clients = {} + for client in clients: + if client["mapped"] and not client["hidden"]: + window_class = client["initialClass"].lower() + if window_class not in grouped_clients: + grouped_clients[window_class] = [] + grouped_clients[window_class].append(client) + + if grouped_clients: + for window_class, client_group in grouped_clients.items(): + # Fetch the icon for the application (one icon per group) + icon = self.bake_window_icon(window_class) + + # Create a vertical box inside the button for the icon and the dots + icon_box = Box(orientation="v", spacing=0) + icon_box.set_halign(Gtk.Align.CENTER) + + # Add the icon at the top + icon_box.add(icon) + + # Add dot(s) directly below the icon to indicate the number of open instances + if len(client_group) > 1: + dots_box = Box(orientation="h", spacing=2) # Box to hold the dots + dots_box.set_halign(Gtk.Align.CENTER) + + for _ in range(len(client_group)): + dot = Label( + label="•" + ) # Each dot represents one window instance + dot.set_style( + "font-size: 7px; color: rgba(255, 255, 255, 0.6);" + ) # Lighter dot color + dots_box.add(dot) + + icon_box.add(dots_box) + + # Create a button and add the icon_box (icon + dots) inside the button + button = Button(child=icon_box, tooltip_text=client_group[0]["title"]) + + # Highlight the active window + if any( + client["address"] == active_window_address + for client in client_group + ): + button.set_style( + "background-color: @surfaceVariant; transition-duration: 0.3s; border-radius:100px;" + ) + + # Connect click event to focus the application window + button.connect( + "button-press-event", self.on_icon_click, client_group[0]["address"] + ) + + # Add the button to the taskbar + 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() + ) + print(f"Active window address: {active_window_info.get('address', '')}") + return active_window_info.get("address", "") + + def on_icon_click(self, widget, event, address): + command = ["hyprctl", "dispatch", "focuswindow", f"address:{address}"] + subprocess.run(command, check=True) + + 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: + desktop_files = glob.glob("/usr/share/applications/*.desktop") + for desktop_file in desktop_files: + with open(desktop_file, "r") as f: + for line in f: + if line.startswith("Name="): + app_name = line.split("=", 1)[1].strip().lower() + if window_class in app_name: + for line in f: + if line.startswith("Icon="): + return line.split("=", 1)[1].strip() + 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,ecode + raise JSONDecodeError("Expecting value", s, err.value) from None +json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) +Active window address: 0x60d8e93ecf50 +Active window address: 0x60d8e93ecf50 +Active window address: 0x60d8e93ecf50 +^C2024-10-22 13:47:53.414 | INFO | fabric.core.application:on_exit:316 - [Fabric] exiting... + +sankalp on 53ur!tyD3m0n fabric/rework/bar via 🐍 v3.12.7 [⏱ 1m4s]✔ +╰─λ + 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 + diff --git a/config/fabric/modules/bar/widgets/VolumeIndicator.py b/config/fabric/modules/bar/widgets/volume.py similarity index 84% rename from config/fabric/modules/bar/widgets/VolumeIndicator.py rename to config/fabric/modules/bar/widgets/volume.py index 26eee220..8bf5d568 100644 --- a/config/fabric/modules/bar/widgets/VolumeIndicator.py +++ b/config/fabric/modules/bar/widgets/volume.py @@ -1,4 +1,7 @@ -from __init__ import * +from fabric.audio.service import Audio +from fabric.utils import exec_shell_command, invoke_repeater +from fabric.widgets.box import Box +from fabric.widgets.button import Button class VolumeIndicator(Box): @@ -10,7 +13,8 @@ class VolumeIndicator(Box): self.audio_service = audio_service self.volume_icon = Button( label="󰖁", - style="font-size: 16px;", + style="margin-left:6px; font-size:18px;", + # name="symbol", ) # Connect mouse button events to handle clicks @@ -28,17 +32,17 @@ class VolumeIndicator(Box): elif event.button == 2: self.on_middle_clicked() - def on_clicked(self): + def on_right_clicked(self): exec_shell_command("pavucontrol") - def on_right_clicked(self): + def on_clicked(self): current_stream = self.audio_service.speaker if current_stream: current_stream.muted = not current_stream.muted self.update_volume_status() - def on_middle_clicked(self): - exec_shell_command("pavucontrol") + # def on_middle_clicked(self): + # exec_shell_command("pavucontrol") def update_volume_status(self, *args): current_stream = self.audio_service.speaker diff --git a/config/fabric/modules/bar/widgets/WifiIndicator.py b/config/fabric/modules/bar/widgets/wifi.py similarity index 81% rename from config/fabric/modules/bar/widgets/WifiIndicator.py rename to config/fabric/modules/bar/widgets/wifi.py index c1700640..5b782f6b 100644 --- a/config/fabric/modules/bar/widgets/WifiIndicator.py +++ b/config/fabric/modules/bar/widgets/wifi.py @@ -1,4 +1,9 @@ -from __init__ import * +import socket + +import psutil +from fabric.utils import invoke_repeater +from fabric.widgets.box import Box +from fabric.widgets.label import Label class Wifi(Box): @@ -6,7 +11,8 @@ class Wifi(Box): super().__init__(**kwargs) self.wifi_icon = Label( label="󰤭", - style="font-size: 16px; margin-right: 6px;", + name="symbol", + # style="font-size: 16px; margin-right: 6px;", ) invoke_repeater(1000, self.update_wifi_status, initial_call=True) diff --git a/config/fabric/modules/launcher/__pycache__/app.cpython-312.pyc b/config/fabric/modules/launcher/__pycache__/app.cpython-312.pyc index 2c31405d..b1e3c876 100644 Binary files a/config/fabric/modules/launcher/__pycache__/app.cpython-312.pyc and b/config/fabric/modules/launcher/__pycache__/app.cpython-312.pyc differ diff --git a/config/fabric/modules/launcher/__pycache__/clipboard.cpython-312.pyc b/config/fabric/modules/launcher/__pycache__/clipboard.cpython-312.pyc index 08ec92b2..633001d9 100644 Binary files a/config/fabric/modules/launcher/__pycache__/clipboard.cpython-312.pyc and b/config/fabric/modules/launcher/__pycache__/clipboard.cpython-312.pyc differ diff --git a/config/fabric/modules/launcher/__pycache__/control.cpython-312.pyc b/config/fabric/modules/launcher/__pycache__/control.cpython-312.pyc new file mode 100644 index 00000000..3564de8b Binary files /dev/null and b/config/fabric/modules/launcher/__pycache__/control.cpython-312.pyc differ diff --git a/config/fabric/modules/launcher/__pycache__/emoji.cpython-312.pyc b/config/fabric/modules/launcher/__pycache__/emoji.cpython-312.pyc index b10249d3..a774f4b3 100644 Binary files a/config/fabric/modules/launcher/__pycache__/emoji.cpython-312.pyc and b/config/fabric/modules/launcher/__pycache__/emoji.cpython-312.pyc differ diff --git a/config/fabric/modules/launcher/__pycache__/emojiss.cpython-312.pyc b/config/fabric/modules/launcher/__pycache__/emojiss.cpython-312.pyc new file mode 100644 index 00000000..f1442e28 Binary files /dev/null and b/config/fabric/modules/launcher/__pycache__/emojiss.cpython-312.pyc differ diff --git a/config/fabric/modules/launcher/__pycache__/inhibit.cpython-312.pyc b/config/fabric/modules/launcher/__pycache__/inhibit.cpython-312.pyc new file mode 100644 index 00000000..d0a11d7f Binary files /dev/null and b/config/fabric/modules/launcher/__pycache__/inhibit.cpython-312.pyc differ diff --git a/config/fabric/modules/launcher/__pycache__/launcher.cpython-312.pyc b/config/fabric/modules/launcher/__pycache__/launcher.cpython-312.pyc index 0ad9a16b..f8a499b3 100644 Binary files a/config/fabric/modules/launcher/__pycache__/launcher.cpython-312.pyc and b/config/fabric/modules/launcher/__pycache__/launcher.cpython-312.pyc differ diff --git a/config/fabric/modules/launcher/__pycache__/main.cpython-312.pyc b/config/fabric/modules/launcher/__pycache__/main.cpython-312.pyc new file mode 100644 index 00000000..a51e3d8f Binary files /dev/null and b/config/fabric/modules/launcher/__pycache__/main.cpython-312.pyc differ diff --git a/config/fabric/modules/launcher/__pycache__/sh.cpython-312.pyc b/config/fabric/modules/launcher/__pycache__/sh.cpython-312.pyc new file mode 100644 index 00000000..a91d4c27 Binary files /dev/null and b/config/fabric/modules/launcher/__pycache__/sh.cpython-312.pyc differ diff --git a/config/fabric/modules/launcher/__pycache__/shell.cpython-312.pyc b/config/fabric/modules/launcher/__pycache__/shell.cpython-312.pyc index 0bfcef6e..f8fba89f 100644 Binary files a/config/fabric/modules/launcher/__pycache__/shell.cpython-312.pyc and b/config/fabric/modules/launcher/__pycache__/shell.cpython-312.pyc differ diff --git a/config/fabric/modules/launcher/__pycache__/wallpaper.cpython-312.pyc b/config/fabric/modules/launcher/__pycache__/wallpaper.cpython-312.pyc index f59355b0..3bc974c0 100644 Binary files a/config/fabric/modules/launcher/__pycache__/wallpaper.cpython-312.pyc and b/config/fabric/modules/launcher/__pycache__/wallpaper.cpython-312.pyc differ diff --git a/config/fabric/modules/launcher/launcher.py b/config/fabric/modules/launcher/launcher.py index dc429243..e6ca9b79 100644 --- a/config/fabric/modules/launcher/launcher.py +++ b/config/fabric/modules/launcher/launcher.py @@ -1,4 +1,20 @@ -from __init__ import * +from fabric.utils import get_desktop_applications, idle_add, remove_handler +from fabric.widgets.box import Box +from fabric.widgets.button import Button +from fabric.widgets.entry import Entry +from fabric.widgets.label import Label +from fabric.widgets.revealer import Revealer +from fabric.widgets.scrolledwindow import ScrolledWindow +from fabric.widgets.wayland import WaylandWindow as Window +from modules.launcher.widgets import ( + ClipboardManager, + DesktopButtonManager, + EmojiManager, + ShellCommandManager, + WallpaperManager, + bake_favorite_slot, + handle_application_search, +) class Launcher(Window): @@ -6,6 +22,7 @@ class Launcher(Window): "Firefox", "Discord", "materialgram", + "Spotify", "kitty", "Neovim", "Thunar File Manager", @@ -27,6 +44,7 @@ class Launcher(Window): all_visible=False, **kwargs, ) + self.all_apps = get_desktop_applications() self.initialize_managers() self.setup_ui() self.connect("key-press-event", self.on_key_press) @@ -36,46 +54,59 @@ class Launcher(Window): self.emoji_manager = EmojiManager(self) self.shell_command_manager = ShellCommandManager(self) self.wallpaper_manager = WallpaperManager() - self.all_apps = get_desktop_applications() + self.desktop_button_manager = DesktopButtonManager(self.get_viewport()) def setup_ui(self): - self.fav_apps_box = self.create_favorites_box() - self.viewport = Box(spacing=10, orientation="v") - self.scrolled_window = ScrolledWindow( - name="appmenu-scroll", child=self.viewport - ) - self.scrolled_revealer = Revealer( - child=self.scrolled_window, transition_duration=500 - ) + self.scrolled_window = self.create_scrolled_window() + self.scrolled_revealer = self.create_revealer() self.search_entry = self.create_search_entry() - self.add( - Box( - orientation="v", - size=(550, 0), - name="launcher", - children=[ - Box(spacing=10, orientation="h", children=[self.search_entry]), - self.fav_apps_box, - self.scrolled_revealer, - ], - ) + launcher_box = Box( + orientation="v", + size=(550, 0), + name="launcher", + children=[ + Box(spacing=10, orientation="h", children=[self.search_entry]), + self.get_favorites_box(), + self.scrolled_revealer, + ], ) - + self.add(launcher_box) self.show_favorites() self.show_all() def create_search_entry(self): - entry = Entry( + return Entry( placeholder="Search.....", h_expand=True, notify_text=lambda entry, *_: self.debounce_search(entry.get_text()), + icon_name="preferences-system-search-symbolic", ) - entry.set_icon_from_icon_name(0, "preferences-system-search-symbolic") - return entry - def create_favorites_box(self): - return Box(spacing=10, orientation="h") + def get_favorites_box(self): + if not hasattr(self, "fav_apps_box"): + self.fav_apps_box = Box(spacing=10, orientation="h") + return self.fav_apps_box + + def create_scrolled_window(self): + return ScrolledWindow( + name="launcher-scroll", + child=self.get_viewport(), + h_scrollbar_policy="never", + # v_scrollbar_policy="never", + ) + + def create_revealer(self): + return Revealer( + child=self.scrolled_window, + transition_duration=300, + transition_type="slide-down", + ) + + def get_viewport(self): + if not hasattr(self, "viewport"): + self.viewport = Box(spacing=10, orientation="v") + return self.viewport def on_key_press(self, widget, event): from gi.repository import Gdk @@ -94,16 +125,17 @@ class Launcher(Window): for app_name in self.FAVORITE_APPS: app = next((a for a in self.all_apps if a.name == app_name), None) if app: - self.fav_apps_box.add(bake_favorite_slot(self, app)) + self.get_favorites_box().add(bake_favorite_slot(self, app)) def arrange_viewport(self, query: str = ""): - self.viewport.children = [] + self.get_viewport().children = [] self.scrolled_window.min_content_size = (-1, -1) self.scrolled_window.max_content_size = (-1, -1) command_handlers = { ":em": self.show_emojis, ":ch": self.show_clipboard_history, + ":db": self.show_desktop_buttons, ":sh": self.show_shell_commands, ":wl": self.show_wallpapers, } @@ -114,7 +146,7 @@ class Launcher(Window): return if query.startswith(":"): - self.fav_apps_box.set_visible(False) + self.get_favorites_box().set_visible(False) self.show_help() self.adjust_scrolled_window_size("help") self.scrolled_revealer.reveal() @@ -122,13 +154,18 @@ class Launcher(Window): handle_application_search(self, query) + def show_desktop_buttons(self, query: str = None): + self.desktop_button_manager.show_desktop_buttons(query) + self.adjust_scrolled_window_size("default") + self.scrolled_revealer.reveal() + def show_emojis(self, query: str): - self.emoji_manager.show_emojis(self.viewport, query) + self.emoji_manager.show_emojis(self.get_viewport(), query) self.adjust_scrolled_window_size("emoji") self.scrolled_revealer.reveal() def show_clipboard_history(self, query: str): - self.clipboard_manager.show_clipboard_history(self.viewport, query) + self.clipboard_manager.show_clipboard_history(self.get_viewport(), query) self.adjust_scrolled_window_size("default") self.scrolled_revealer.reveal() @@ -136,7 +173,7 @@ class Launcher(Window): if not query: self.scrolled_revealer.unreveal() return - self.shell_command_manager.show_shell_commands(self.viewport, query) + self.shell_command_manager.show_shell_commands(self.get_viewport(), query) self.adjust_scrolled_window_size("default") self.scrolled_revealer.reveal() @@ -144,13 +181,14 @@ class Launcher(Window): if query == "random": self.wallpaper_manager.apply_wallpaper_random() else: - self.wallpaper_manager.show_wallpaper_thumbnails(self.viewport, query) + self.wallpaper_manager.show_wallpaper_thumbnails(self.get_viewport(), query) self.adjust_scrolled_window_size("emoji") self.scrolled_revealer.reveal() def show_help(self): help_commands = [ (":ch", "Copy a clipboard history entry", self.reveal_clipboard_history), + (":db", "Control System", lambda: self.show_desktop_buttons()), (":em", "Copy an emoji", self.reveal_emojis), (":sh", "Run a binary", self.reveal_shell_commands), (":wl", "Change or show wallpapers", self.reveal_wallpapers), @@ -158,43 +196,43 @@ class Launcher(Window): for command, description, action in help_commands: button = Button( - child=Box( - orientation="h", - spacing=10, - children=[ - Label( - label=command, - h_expand=True, - name="command-label", - h_align="start", - ), - Label( - label=description, - h_expand=True, - name="description-label", - h_align="end", - ), - ], - ), + child=self.create_help_button_content(command, description), on_clicked=lambda _, cmd=command, act=action: ( self.search_entry.set_text(cmd), act(), ), name="help-item", ) - self.viewport.add(button) + self.get_viewport().add(button) + + def create_help_button_content(self, command, description): + return Box( + orientation="h", + spacing=10, + children=[ + Label( + label=command, h_expand=True, name="command-label", h_align="start" + ), + Label( + label=description, + h_expand=True, + name="description-label", + h_align="end", + ), + ], + ) def reveal_clipboard_history(self): - self.clipboard_manager.show_clipboard_history(self.viewport, "") + self.clipboard_manager.show_clipboard_history(self.get_viewport(), "") def reveal_emojis(self): - self.emoji_manager.show_emojis(self.viewport, "") + self.emoji_manager.show_emojis(self.get_viewport(), "") def reveal_shell_commands(self): - self.shell_command_manager.show_shell_commands(self.viewport, "") + self.shell_command_manager.show_shell_commands(self.get_viewport(), "") def reveal_wallpapers(self): - self.wallpaper_manager.show_wallpaper_thumbnails(self.viewport, "") + self.wallpaper_manager.show_wallpaper_thumbnails(self.get_viewport(), "") def adjust_scrolled_window_size(self, content_type: str): if content_type in self.CONTENT_SIZES: @@ -203,4 +241,8 @@ class Launcher(Window): self.scrolled_window.max_content_size = (-1, max_height) def toggle(self): - self.set_visible(not self.is_visible()) + if self.is_visible(): + self.set_visible(False) + else: + self.search_entry.set_text("") + self.set_visible(True) diff --git a/config/fabric/modules/launcher/widgets/__init__.py b/config/fabric/modules/launcher/widgets/__init__.py new file mode 100644 index 00000000..9f2c0774 --- /dev/null +++ b/config/fabric/modules/launcher/widgets/__init__.py @@ -0,0 +1,6 @@ +from .app import * +from .clipboard import * +from .control import * +from .emoji import * +from .shell import * +from .wallpaper import * diff --git a/config/fabric/modules/launcher/widgets/__pycache__/__init__.cpython-312.pyc b/config/fabric/modules/launcher/widgets/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 00000000..ad7f4f12 Binary files /dev/null and b/config/fabric/modules/launcher/widgets/__pycache__/__init__.cpython-312.pyc differ diff --git a/config/fabric/modules/launcher/widgets/__pycache__/app.cpython-312.pyc b/config/fabric/modules/launcher/widgets/__pycache__/app.cpython-312.pyc new file mode 100644 index 00000000..6415f943 Binary files /dev/null and b/config/fabric/modules/launcher/widgets/__pycache__/app.cpython-312.pyc differ diff --git a/config/fabric/modules/launcher/widgets/__pycache__/clipboard.cpython-312.pyc b/config/fabric/modules/launcher/widgets/__pycache__/clipboard.cpython-312.pyc new file mode 100644 index 00000000..f83bfb8e Binary files /dev/null and b/config/fabric/modules/launcher/widgets/__pycache__/clipboard.cpython-312.pyc differ diff --git a/config/fabric/modules/launcher/widgets/__pycache__/control.cpython-312.pyc b/config/fabric/modules/launcher/widgets/__pycache__/control.cpython-312.pyc new file mode 100644 index 00000000..a9e31756 Binary files /dev/null and b/config/fabric/modules/launcher/widgets/__pycache__/control.cpython-312.pyc differ diff --git a/config/fabric/modules/launcher/widgets/__pycache__/emoji.cpython-312.pyc b/config/fabric/modules/launcher/widgets/__pycache__/emoji.cpython-312.pyc new file mode 100644 index 00000000..8883a4f7 Binary files /dev/null and b/config/fabric/modules/launcher/widgets/__pycache__/emoji.cpython-312.pyc differ diff --git a/config/fabric/modules/launcher/widgets/__pycache__/shell.cpython-312.pyc b/config/fabric/modules/launcher/widgets/__pycache__/shell.cpython-312.pyc new file mode 100644 index 00000000..a0bf2270 Binary files /dev/null and b/config/fabric/modules/launcher/widgets/__pycache__/shell.cpython-312.pyc differ diff --git a/config/fabric/modules/launcher/widgets/__pycache__/wallpaper.cpython-312.pyc b/config/fabric/modules/launcher/widgets/__pycache__/wallpaper.cpython-312.pyc new file mode 100644 index 00000000..f71ab875 Binary files /dev/null and b/config/fabric/modules/launcher/widgets/__pycache__/wallpaper.cpython-312.pyc differ diff --git a/config/fabric/modules/launcher/app.py b/config/fabric/modules/launcher/widgets/app.py similarity index 93% rename from config/fabric/modules/launcher/app.py rename to config/fabric/modules/launcher/widgets/app.py index aafeda84..b5060043 100644 --- a/config/fabric/modules/launcher/app.py +++ b/config/fabric/modules/launcher/widgets/app.py @@ -1,4 +1,7 @@ -from __init__ import * +from fabric.widgets.box import Box +from fabric.widgets.button import Button +from fabric.widgets.image import Image +from fabric.widgets.label import Label def handle_application_search(launcher, query: str): diff --git a/config/fabric/modules/launcher/clipboard.py b/config/fabric/modules/launcher/widgets/clipboard.py similarity index 92% rename from config/fabric/modules/launcher/clipboard.py rename to config/fabric/modules/launcher/widgets/clipboard.py index ee510375..65b14ca1 100644 --- a/config/fabric/modules/launcher/clipboard.py +++ b/config/fabric/modules/launcher/widgets/clipboard.py @@ -1,4 +1,7 @@ -from __init__ import * +import subprocess +from fabric.widgets.button import Button +from fabric.widgets.label import Label +from fabric.widgets.box import Box class ClipboardManager: diff --git a/config/fabric/modules/launcher/widgets/control.py b/config/fabric/modules/launcher/widgets/control.py new file mode 100644 index 00000000..a706d75e --- /dev/null +++ b/config/fabric/modules/launcher/widgets/control.py @@ -0,0 +1,202 @@ +import os + +from fabric.utils import exec_shell_command +from fabric.widgets.box import Box +from fabric.widgets.button import Button +from fabric.widgets.label import Label +from loguru import logger +from services.inhibit import Inhibit + + +class DesktopButtonManager: + def __init__(self, viewport): + self.viewport = viewport + self.inhibit_service = Inhibit() + + def show_desktop_buttons(self, search_query: str = ""): + self.viewport.children = [] + parent_box = Box(orientation="h", spacing=10) + column1 = Box(orientation="v", spacing=10) + column2 = Box(orientation="v", spacing=10) + + desktop_controls = [ + { + "name": "Wi-Fi", + "icon": ("󰤨", "󰤭"), + "toggle": self.toggle_wifi, + "state": self.check_wifi_state, + }, + { + "name": "Bluetooth", + "icon": ("󰂯", "󰂲"), + "toggle": self.toggle_bluetooth, + "state": self.check_bluetooth_state, + }, + { + "name": "Dark Mode", + "icon": ("󱎖", "󱎖"), + "toggle": self.toggle_dark_mode, + "state": self.check_dark_mode_state, + }, + { + "name": "Idle", + "icon": ("󱑁", "󱑁"), + "toggle": self.toggle_idle_mode, + "state": lambda: self.inhibit_service.is_inhibit, + }, + { + "name": "Do Not Disturb", + "icon": ("󰂚", "󰂛"), + "toggle": self.toggle_dnd, + "state": None, + }, + { + "name": "Power Profile", + "icons": ( + "󰡳", + "󰊚", + "󰡴", + ), + "toggle": self.toggle_power_profile, + "state": self.check_power_profile_state, + }, + ] + + for i, control in enumerate(desktop_controls): + if search_query.lower() not in control["name"].lower(): + continue + current_state = ( + control["state"]() + if control["state"] and callable(control["state"]) + else False + ) + + if "icons" in control: + if current_state == "performance": + icon = control["icons"][2] + is_active = True + elif current_state == "balanced": + icon = control["icons"][1] + is_active = False + else: + icon = control["icons"][0] + is_active = True + else: # Two-state control + icon = control["icon"][0] if current_state else control["icon"][1] + is_active = current_state + + button = Button( + child=Box( + orientation="h", + spacing=10, + children=[ + Label( + label=icon, + name="icon-label", + style="font-size:32px; margin:0 12px 0 0; padding:12px;", + ), + Label( + label=control["name"], + name="name-label", + style="font-size:16px; padding:12px;", + ), + ], + ), + on_clicked=control["toggle"], + name="db-item", + tooltip_text=f"{control['name']} is {'on' if current_state else 'off'}", + ) + if is_active: + button.set_style( + "background-color: @surfaceVariant; transition-duration: 0.3s; border-radius:999px;" + ) + else: + button.set_style("background-color: transparent; ") + + if i % 2 == 0: + column1.add(button) + else: + column2.add(button) + + parent_box.add(column1) + parent_box.add(column2) + self.viewport.add(parent_box) + + def toggle_power_profile(self, *_): + current_mode = self.check_power_profile_state() + if current_mode == "performance": + command = "powerprofilesctl set balanced" + elif current_mode == "balanced": + command = "powerprofilesctl set power-saver" + else: # Power Saver + command = "powerprofilesctl set performance" + + exec_shell_command(command) + self.show_desktop_buttons() + logger.info("Toggled Power Profile to:", command.split()[-1]) + + def check_power_profile_state(self): + result = exec_shell_command("powerprofilesctl get") + current_mode = result.strip().lower() # Ensure uniform casing + return current_mode + + def toggle_wifi(self, *_): + state = self.check_wifi_state() + command = "nmcli radio wifi on" if not state else "nmcli radio wifi off" + exec_shell_command(command) + self.show_desktop_buttons() + logger.info("Toggled Wi-Fi.") + + def check_wifi_state(self): + result = exec_shell_command("nmcli radio wifi") + return "enabled" in result + + def toggle_bluetooth(self, *_): + state = self.check_bluetooth_state() + command = "bluetoothctl power on" if not state else "bluetoothctl power off" + exec_shell_command(command) + self.show_desktop_buttons() + logger.info("Toggled Bluetooth.") + + def check_bluetooth_state(self): + result = exec_shell_command("bluetoothctl show") + return "Powered: yes" in result + + def toggle_dark_mode(self, *_): + command = os.path.expanduser("~/fabric/assets/scripts/dark-theme.sh --toggle") + exec_shell_command(command) + self.show_desktop_buttons() + logger.info("Toggled Dark Mode.") + + def check_dark_mode_state(self): + result = exec_shell_command( + "gsettings get org.gnome.desktop.interface color-scheme" + ) + current_mode = result.strip().replace("'", "") + return current_mode == "prefer-dark" + + def toggle_idle_mode(self, *_): + self.inhibit_service.toggle() + self.show_desktop_buttons() + logger.info( + "Idle mode activated." + if self.inhibit_service.is_inhibit + else "Idle mode deactivated." + ) + + def toggle_dnd(self, *_): + current_state = self.check_dnd_state() + command = ( + "gsettings set org.gnome.desktop.notifications show-banners true" + if current_state + else "gsettings set org.gnome.desktop.notifications show-banners false" + ) + exec_shell_command(command) + self.show_desktop_buttons() + logger.info("Toggled Do Not Disturb.") + + def check_dnd_state(self): + result = exec_shell_command( + "gsettings get org.gnome.desktop.notifications show-banners" + ) + return result.strip() == "false" diff --git a/config/fabric/modules/launcher/emoji.py b/config/fabric/modules/launcher/widgets/emoji.py similarity index 87% rename from config/fabric/modules/launcher/emoji.py rename to config/fabric/modules/launcher/widgets/emoji.py index 00a4e6b0..51c200b2 100644 --- a/config/fabric/modules/launcher/emoji.py +++ b/config/fabric/modules/launcher/widgets/emoji.py @@ -1,4 +1,7 @@ -from __init__ import * +from fabric.widgets.box import Box +from fabric.widgets.button import Button +from fabric.widgets.label import Label +from services.emoji import EmojiItem, EmojiService class EmojiManager: diff --git a/config/fabric/modules/launcher/shell.py b/config/fabric/modules/launcher/widgets/shell.py similarity index 92% rename from config/fabric/modules/launcher/shell.py rename to config/fabric/modules/launcher/widgets/shell.py index 0d8afc89..f81058a1 100644 --- a/config/fabric/modules/launcher/shell.py +++ b/config/fabric/modules/launcher/widgets/shell.py @@ -1,4 +1,6 @@ -from __init__ import * +from fabric.widgets.button import Button +from fabric.widgets.label import Label +from services.sh import Sh class ShellCommandManager: diff --git a/config/fabric/modules/launcher/wallpaper.py b/config/fabric/modules/launcher/widgets/wallpaper.py similarity index 94% rename from config/fabric/modules/launcher/wallpaper.py rename to config/fabric/modules/launcher/widgets/wallpaper.py index bb96e7b2..8f7978a3 100644 --- a/config/fabric/modules/launcher/wallpaper.py +++ b/config/fabric/modules/launcher/widgets/wallpaper.py @@ -1,4 +1,11 @@ -from __init__ import * +import os +from pathlib import Path + +from fabric.utils import exec_shell_command_async +from fabric.widgets.box import Box +from fabric.widgets.button import Button +from fabric.widgets.label import Label +from loguru import logger class WallpaperManager: diff --git a/config/fabric/modules/osd.py b/config/fabric/modules/osd.py new file mode 100644 index 00000000..60791b3c --- /dev/null +++ b/config/fabric/modules/osd.py @@ -0,0 +1,229 @@ +import os +from typing import Literal + +from fabric.audio import Audio +from fabric.widgets.box import Box +from fabric.widgets.image import Image +from fabric.widgets.revealer import Revealer +from fabric.widgets.shapes import Corner +from fabric.widgets.wayland import WaylandWindow as Window +from fabric.widgets.widget import Widget +from gi.repository import GLib +from services.brightness import Brightness + +audio = Audio() +brightness = Brightness() +# TODO: use progressbar or custom cairo widget so that I can update the accent color with css +accent = "#82C480" + + +# This is only for OSD, I don' want or need an inhibitor for this +class PopupWindow(Window): + def __init__( + self, + child: Widget | None = None, + transition_type: Literal[ + "none", + "crossfade", + "slide-right", + "slide-left", + "slide-up", + "slide-down", + ] = "none", + transition_duration: int = 100, + visible: bool = False, + anchor: str = "top right", + keyboard_mode: Literal["none", "exclusive", "on-demand"] = "on-demand", + timeout: int = 1000, + decorations: str = "margin: 1px", + **kwargs, + ): + self.timeout = timeout + self.currtimeout = 0 + self.popup_running = False + + self.revealer = Revealer( + child=child, + transition_type=transition_type, + transition_duration=transition_duration, + visible=False, + ) + self.visible = visible + super().__init__( + layer="overlay", + anchor=anchor, + all_visible=False, + visible=False, + exclusive=False, + child=Box(style=decorations, children=self.revealer), + keyboard_mode=keyboard_mode, + **kwargs, + ) + self.set_can_focus = False + + self.revealer.connect( + "notify::child-revealed", + lambda revealer, is_reveal: ( + revealer.hide() if not revealer.get_child_revealed() else None + ), + ) + + self.show() + + def toggle_popup(self): + if not self.visible: + self.revealer.show() + self.visible = not self.visible + self.revealer.set_reveal_child(self.visible) + + def toggle_popup_offset(self, offset, toggle_width): + if not self.visible: + self.revealer.show() + self.visible = not self.visible + self.revealer.set_reveal_child(self.visible) + self.revealer.set_margin_start( + offset - (self.revealer.get_allocated_width() - toggle_width) / 2 + ) + + def popup_timeout(self): + if not self.visible: + self.revealer.show() + if self.popup_running: + self.currtimeout = 0 + return + self.visible = True + self.revealer.set_reveal_child(self.visible) + self.popup_running = True + + def popup_func(): + if self.currtimeout >= self.timeout: + self.visible = False + self.revealer.set_reveal_child(self.visible) + self.currtimeout = 0 + self.popup_running = False + return False + self.currtimeout += 500 + return True + + GLib.timeout_add(500, popup_func) + + +class ProgressBar(Box): + def __init__(self, progress_ticks: int = 10): + self.progress_filled_class = "filled" + self.total_progress_ticks = progress_ticks + self.visible_progress_ticks = progress_ticks + self.tick_boxes = [ + Box(v_expand=True, h_expand=True) for _ in range(self.total_progress_ticks) + ] + super().__init__( + name="osd-progress-bar", + spacing=5, + v_expand=True, + h_expand=True, + orientation="v", + children=self.tick_boxes, + ) + + def set_tick_number(self, ticks: int): + self.visible_progress_ticks = ticks + for child in super().children: + child.set_visible(True) + for i in range(self.total_progress_ticks - ticks): + super().children[i].set_visible(False) + + def set_progress_filled(self, percent: float): + # TODO: rework this later, just to get it working, am sleepy frfr + for child in super().children: + child.remove_style_class(self.progress_filled_class) + for tick in range(int(self.visible_progress_ticks * percent)): + super().children[-(tick + 1)].add_style_class(self.progress_filled_class) + + +class SystemOSD(PopupWindow): + def __init__(self, **kwargs): + self.disp_backlight_path = "/sys/class/backlight/intel_backlight/" + self.kbd_backlight_path = "/sys/class/leds/tpacpi::kbd_backlight/" + self.max_disp_backlight = brightness.max_screen + self.max_kbd_backlight = brightness.max_kbd + self.brightness = brightness + self.disp_backlight = 0 + self.kbd_backlight = 0 + self.vol = 0 + self.progress_bar = ProgressBar(progress_ticks=20) + self.overlay_fill_box = Box(name="osd-box") + self.icon = Image() + + super().__init__( + transition_duration=150, + anchor="right", + transition_type="crossfade", + keyboard_mode="none", + decorations="margin: 1px 0px 1px 1px;", + child=Box( + orientation="v", + h_align="end", + children=[ + Box( + name="osd-corner", + children=Corner( + h_align="end", + orientation="bottom-right", + size=50, + ), + ), + Box( + name="on-screen-display", + orientation="v", + spacing=10, + h_align="end", + children=[ + self.progress_bar, + Box(name="osd-icon", children=self.icon), + ], + ), + Box( + name="osd-corner", + children=Corner( + h_align="end", + orientation="top-right", + size=50, + ), + ), + ], + ), + **kwargs, + ) + + def update_label_audio(self, *args): + icon_name = "-".join(str(audio.speaker.icon_name).split("-")[0:2]) + self.icon.set_from_icon_name(icon_name + "-symbolic", 50) + self.vol = audio.speaker.volume + self.progress_bar.set_progress_filled(round(self.vol) / 100) + + def update_label_brightness(self): + self.icon.set_from_icon_name("display-brightness-symbolic", 50) + brightness = self.brightness.screen_brightness / self.max_disp_backlight + self.progress_bar.set_progress_filled(brightness) + + def update_label_keyboard(self, *args): + self.icon.set_from_icon_name("keyboard-brightness-symbolic", 50) + brightness = ( + int( + os.read( + os.open(self.kbd_backlight_path + "brightness", os.O_RDONLY), 50 + ), + ) + / self.max_kbd_backlight + ) + self.progress_bar.set_progress_filled(brightness) + + def enable_popup(self, type: str): + if type == "sound": + self.update_label_audio() + elif type == "brightness": + self.update_label_brightness() + elif type == "kbd": + self.update_label_keyboard() + + self.popup_timeout() diff --git a/config/fabric/style/main.css b/config/fabric/style/main.css index 90f8b76d..fca55959 100644 --- a/config/fabric/style/main.css +++ b/config/fabric/style/main.css @@ -1,4 +1,3 @@ - * { all: unset; color: @foreground; @@ -15,9 +14,16 @@ font-weight: bold; } -#modules_left, -#modules_center, -#modules_right { +#symbol, +#symbol * { + all: unset; + margin: 2px; + font-size: 18px; +} + +#start-container, +#center-container, +#end-container { padding-top: 6px; padding-bottom: 6px; margin-left: 12px; @@ -25,7 +31,7 @@ } #workspaces { - border-radius: 16px; + border-radius: 100px; font-weight: bold; font-style: normal; color: @onSurface; @@ -43,7 +49,6 @@ border: 0px; } - #workspaces > button:last-child { margin-right: 0px; } @@ -73,15 +78,35 @@ #datetime { background-color: @surfaceContainer; - border-radius: 16px; - padding: 2px 10px 0px 10px; + border-radius: 100px; + padding: 8px; } -#kb_layout { - font-size: 12px; +#battery { + background-color: @surfaceContainer; + border-radius: 100px; + padding: 2px 10px 2px 10px; +} + +#battery label { + color: @onSurface; + font-size: 16px; + font-weight: 300; +} + +#battery .icon { + color: @onSurface; +} + +#battery.critical { + background-color: @error; +} + +#battery.critical label, +#battery.critical .icon { + color: @onError; } -/* system tray */ #tray { background-color: @surfaceContainer; border-radius: 100px; @@ -97,7 +122,24 @@ color: @onSurface; } -/* menu and menu items (written for the system tray) */ +#applets { + background-color: @surfaceContainer; + border-radius: 100px; + padding: 2px 10px 2px 10px; + margin: 0px; +} + +#applets .icon { + color: @onSurface; + font-weight: 900; +} + +#applets > button { + color: @onSurface; + margin: 0px; + padding: 0px; +} + menu { border-radius: 10px; background-color: @surfaceContainer; @@ -141,131 +183,44 @@ tooltip label { font-weight: normal; } -#logo { - background-color: @secondaryContainer; - color: @onSecondaryContainer; +#panel-button { + margin: 0px 2px 0px 2px; + padding: 0px 5px 0px 5px; + border-style: solid; + border-width: 2px; + border-radius: 10px; + border-color: transparent; +} + +#panel-button.activated { + background-color: alpha(white, 0.15); + border-style: solid; + border-color: transparent; + border-bottom-style: solid; + border-bottom-color: alpha(white, 0.5); +} + +#taskbar { border-radius: 100px; - min-width: 38px; - padding: 0px; -} -#logo label, -#logo .icon, -#logo image { - color: @onSecondaryContainer; - font-weight: 400; - margin: 0px 3px 0px 0px; + font-weight: bold; + font-style: normal; + color: @onSurface; + background: @surfaceContainer; + padding-left: 4px; + padding-right: 4px; } -#logo:hover { - background-color: mix(@secondaryContainer, @onSecondaryContainer, 0.05); - box-shadow: 00px 3px 3px -2px rgba(0, 0, 0, 0.2); -} - -#applets { - background-color: @surfaceContainer; +#taskbar > button { + padding: 0px 5px; + margin: 4px 0px; + margin-right: 3px; border-radius: 100px; - padding: 2px 10px 2px 10px; - margin: 0px; + border: 0px; } - -#applets .icon { - color: @onSurface; - font-weight: 600; +#taskbar > button:last-child { + margin-right: 0px; } -#applets > button { - color: @onSurface; - margin: 0px; - padding: 0px; -} - -#battery { - background-color: @surfaceContainer; - border-radius: 100px; - padding: 2px 10px 2px 10px; -} - -#battery label { - color: @onSurface; - font-size: 16px; - font-weight: 300; -} - -#battery .icon { - color: @onSurface; -} - -#battery.critical { - background-color: @error; -} - -#battery.critical label, -#battery.critical .icon { - color: @onError; -} - -#power-event { - transition: all 0.1s ease; - background-color: @surfaceContainer; - border-radius: 999px; - padding: 7px; -} - - -#power-shutdown > *, -#power-reboot > *, -#power-logout > *, -#power-suspend > *, -#power-lock > *{ - color: @foreground; - padding:4px; - margin: 4px; - border-radius: 999px; -} - -#power-shutdown:hover > *, #power-shutdown:focus > *, -#power-reboot:hover > *, #power-reboot:focus > *, -#power-logout:hover > *, #power-logout:focus > *, -#power-suspend:hover > *, #power-suspend:focus > *, -#power-lock:hover > *, #power-lock:focus > *{ - color: @onSurface; - background-color: mix(@onSurface, @surface, 0.85); -} - -#shutdown-confirm > *, #reboot-confirm > *, #logout-confirm > *, #suspend-confirm > * { - color: @background; - font-size: 20px; - font-weight: normal; - padding: 4px; - margin: 4px; - border-radius: 999px; - border-radius: 999px; -} - -#shutdown-confirm:hover > *, #reboot-confirm:hover > *, #logout-confirm:hover > *, #suspend-confirm:hover > * { - color: @onSurface; - background-color: mix(@onSurface, @surface, 0.85); -} - -#confirm-box { - background-color: @surfaceContainer; - margin: 3px; - border-radius: 999px; -} - -#accept, #cancel { - color: @foreground; - padding: 2px; - margin: 4px; - border-radius: 999px; -} - -#accept:hover, #cancel:hover { - color: @onSurface; - background-color: mix(@onSurface, @surface, 0.85); -} - - #launcher { margin: 18px; border: 1px solid @outlineVariant; @@ -282,7 +237,6 @@ tooltip label { padding: 7px; } - #launcher button:focus { box-shadow: inset 0 0 0 1px @primary; background-color: @background; @@ -294,11 +248,11 @@ tooltip label { background-color: @background; } -#launcher entry { +#launcher entry { transition: all 0.1s ease; border-radius: 11px; color: @foreground; - background-color:@surfaceContainer; + background-color: @surfaceContainer; box-shadow: inset 0 0 0 @background; padding: 10px; margin: 12px; @@ -330,12 +284,12 @@ tooltip label { } #launcher button#app-item:hover #title, -#launcher button#app-item:focus #title { +#launcher button#app-item:focus #title { color: @primary; } #launcher button#app-item:hover #description, -#launcher button#app-item:focus #description { +#launcher button#app-item:focus #description { color: @inversePrimary; } @@ -350,13 +304,15 @@ tooltip label { box-shadow: inset 0 0 0 1px rgba(158, 142, 130, 0.04); } -#launcher button#app-item:active #title { +#launcher button#app-item:active #title { color: @foreground; } -#launcher button#fav-item{ - border-radius: 10px; +#launcher button#fav-item { + border-radius: 10px; padding: 10px; + background-image: none; + box-shadow: none; } #launcher button#fav-item:hover image, @@ -382,7 +338,7 @@ tooltip label { color: mix(@onSurface, transparent, 0.38); } -#launcher button#emoji-item label { +#launcher button#emoji-item label { font-size: 27px; } @@ -402,7 +358,7 @@ window#launcher button#cliphist-item:disabled { color: mix(@onSurface, transparent, 0.38); } -#launcher button#cliphist-item:hover, +#launcher button#cliphist-item:hover, #launcher button#cliphist-item:focus { text-shadow: 2px 2px 2px @primary; } @@ -431,113 +387,85 @@ window#launcher button#cliphist-item:disabled { } #launcher button#help-item:hover label, -#launcher button#help-item:focus label{ +#launcher button#help-item:focus label { text-shadow: 2px 2px 2px @primary; } +:vars { + --accent: #009cd4; -#settings-button { - padding-left: 12px; - padding-right: 12px; - padding-top: 5px; - padding-bottom: 5px; - min-width: 250px; - background-color: @surfaceContainerLow; - border-radius: 24px 0 0 24px; - border-right:0.1px solid; - } + --bg_h: #1d2021; + --bg: #1e1e1e; + --bg_s: #32302f; + --bg1: #3c3836; + --bg2: #504945; + --bg3: #665c54; + --bg4: #7c6f64; -#settings-button:hover { - background-color: mix(@onSurface, @surface, 0.92); + --fg: #e2e2e0; + --fg1: #ebdbb2; + --fg2: #d5c4a1; + --fg3: #bdae93; + --fg4: #a89984; + + --red: #fb4934; + --green: #4bbb26; + --yellow: #ffe600; + --blue: #83a598; + --purple: #d3869b; + --aqua: #8ec07c; + --gray: #928374; + --orange: #fe8019; + + --red-dim: #cc2412; + --green-dim: #98971a; + --yellow-dim: #d79921; + --blue-dim: #458588; + --purple-dim: #b16286; + --aqua-dim: #689d6a; + --gray-dim: #a89984; + --orange-dim: #d65d0e; + + --placeholder_text_color: rgb(255, 255, 255); } -#settings-button:active { - background-image: radial-gradient(circle, mix(@onSurface, @surface, 0.9) 10%, transparent 0%); +#osd-corner { + padding-left: 45px; } -#hello { - border-radius: 100px; - padding: 0px; - padding-right: 24px; - padding-left: 16px; - min-height: 56px; - background-color: @surfaceContainerLow; +#osd-icon image { + color: @foreground; } -#hello:hover { - background-color: mix(@onSurface, @surface, 0.92); +#osd-corner * { + background-color: alpha(@background, 0.9); } - -#hello label { - color: @onSurfaceVariant; - font-weight: normal; - font-size: 16px; -} -#hello.active label { - color: @onSecondaryContainer; +#osd-progress-bar *.filled { + background-color: @foreground; + box-shadow: 0px 0px 2px 1px @foreground; } - - -#settings-content { - background-color: @surface; - font-weight: normal; - padding-left: 16px; - padding-top: 6px; - padding-bottom: 6px; - font-size: 20px; - border-bottom: 1px solid; - border-radius: 0 24px 24px 0; - border-color: @outlineVariant; - color: @onSurfaceVariant; +#osd-progress-bar * { + border-radius: 30px; + background-color: #202020; + transition-property: background-color, box-shadow; + transition-duration: 0.25s; + transition-timing-function: cubic-bezier(0.42, 0, 0.58, 1); + /* transition: background-color 0.3s cubic-bezier(.42,0,.58,1); */ +} +#osd-progress-bar { + margin: 10px 5px 10px 5px; + border-radius: 30px; } - - -#row { - background: transparent; - transition-timing-function: ease-out; - outline: none; - background-image: radial-gradient(circle, transparent 10%, transparent 0%); - background-repeat: no-repeat; - background-position: center; - background-size: 1000% 1000%; - background-color: transparent; - - padding-left: 16px; - padding-right: 16px; - padding-top: 12px; - padding-bottom: 12px; - margin: 0px; - border-radius: 0px; +#on-screen-display { + border-left-width: 5px; + border-color: var(--accent); + border-style: solid; + min-height: 300px; + background-color: alpha(@background, 0.9); + padding: 20px; + border-top-left-radius: 50px; + border-bottom-left-radius: 50px; } - -#title { - font-weight: normal; - font-size: 19px; - color: @onSurface; -} - - #description { - font-weight: normal; - font-size: 14px; - color: @onSurfaceVariant; -} - - -#row:hover { - background-color: mix(@onSurface, @surface, 0.92); - border-radius: 24px; -} - -#row:active:not(.focused) { - transition-duration: 0.3s, 0ms, 0ms, 0.2s, 0.2s, 0.2s; - animation: ripple 0.3s ease-out forwards; - background-size: 0% 0%; - background-image: radial-gradient(circle, mix(@onSurface, @surface, 0.9) 10%, transparent 0%); -} - -#row.focused { - background-color: mix(@onSurface, @surface, 0.8); -} \ No newline at end of file