This commit is contained in:
sankalp committed 2024-11-16 09:25:15 +05:45
1 parent 4fff766d71
commit 748866777c
10 files changed
+34 -151

No files matched your search

+23 -10
View File
@@ -1,10 +1,23 @@
from .battery import *
from .bluetooth import *
from .idle_indicator import *
from .info import *
from .microphone import *
from .network import *
from .powerprofile import *
from .taskbar import *
from .volume import *
from .workspace import *
from .battery import BatteryLabel
from .bluetooth import Bluetooth
from .idle_indicator import IdleIndicator
from .info import HardwareUsage
from .microphone import MicrophoneIndicator
from .network import Network
from .powerprofile import PowerProfile
from .taskbar import TaskBar
from .volume import VolumeIndicator
from .workspace import workspace
__all__ = [
"BatteryLabel",
"Bluetooth",
"IdleIndicator",
"HardwareUsage",
"MicrophoneIndicator",
"Network",
"PowerProfile",
"TaskBar",
"VolumeIndicator",
"workspace",
]
+1 -1
View File
@@ -3,7 +3,7 @@ import psutil
from fabric.utils import invoke_repeater
from fabric.widgets.box import Box
from fabric.widgets.label import Label
from services.icon import MaterialIcon
from services import MaterialIcon
class BatteryLabel(Box):
@@ -1,6 +1,6 @@
from fabric.bluetooth import BluetoothClient
from fabric.widgets.box import Box
from services.icon import MaterialIcon # Import your MaterialIcon function
from services import MaterialIcon # Import your MaterialIcon function
class Bluetooth(Box):
@@ -1,7 +1,8 @@
from gi.repository import GLib
from fabric.utils import exec_shell_command
from fabric.widgets.box import Box
from gi.repository import GLib
from services.icon import MaterialIcon
from services import MaterialIcon
class IdleIndicator(Box):
+1 -1
View File
@@ -6,7 +6,7 @@ from fabric.widgets.button import Button
from fabric.widgets.circularprogressbar import CircularProgressBar
from fabric.widgets.label import Label
from fabric.widgets.overlay import Overlay
from services.icon import MaterialIcon
from services import MaterialIcon
class HardwareUsage(Button):
@@ -1,6 +1,6 @@
from fabric.audio.service import Audio
from fabric.widgets.box import Box
from services.icon import MaterialIcon # Import your MaterialIcon function
from services import MaterialIcon
class MicrophoneIndicator(Box):
+2 -1
View File
@@ -1,9 +1,10 @@
import subprocess
import psutil
from fabric.utils import invoke_repeater
from fabric.widgets.box import Box
from services.icon import MaterialIcon
from services import MaterialIcon
class Network(Box):
@@ -1,6 +1,6 @@
from fabric.utils import exec_shell_command, invoke_repeater
from fabric.widgets.box import Box
from services.icon import MaterialIcon
from services import MaterialIcon
PROFILE_ICONS = {
"power-saver": "data_saver_on",
+1 -1
View File
@@ -2,7 +2,7 @@ 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
from services.icon import MaterialIcon
from services import MaterialIcon
VOLUME_ICONS = {
"muted": "volume_off",
@@ -1,132 +0,0 @@
import json
from typing import TypedDict
from fabric.hyprland.widgets import get_hyprland_connection
from fabric.utils import DesktopApp, exec_shell_command, get_desktop_applications
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
class PagerClient(TypedDict):
title: str
initialClass: str
mapped: bool
hidden: bool
address: str
class TaskBar(Box):
def __init__(self, icon_size: int = 18, **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:
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 = self.get_application_icon(window_class, fallback_icon)
return Image(pixbuf=icon, size=self.icon_size)
def get_application_icon(
self, window_class: str, fallback_icon: str
) -> GdkPixbuf.Pixbuf:
app = self.get_app_by_window_class(window_class)
if app:
pixbuf = app.get_icon_pixbuf()
if pixbuf:
return pixbuf
return self.load_icon(fallback_icon)
def get_app_by_window_class(self, window_class: str) -> DesktopApp | None:
all_apps = get_desktop_applications()
for app in all_apps:
if window_class.lower() in (app.display_name or "").lower():
return app
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