css update

This commit is contained in:
sankalp committed 2024-12-01 13:19:20 +05:45
1 parent ed814fff03
commit 31a191acc9
14 files changed
+218 -204

No files matched your search

+6 -32
View File
@@ -1,5 +1,4 @@
import json
import os
from typing import TypedDict
from fabric.hyprland.widgets import get_hyprland_connection
@@ -8,7 +7,7 @@ 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
from snippets import IconResolver
class PagerClient(TypedDict):
@@ -30,6 +29,7 @@ class TaskBar(Box):
self.connection = get_hyprland_connection()
self.icon_size = icon_size
self.icon_theme = Gtk.IconTheme.get_default()
self.icon_resolver = IconResolver()
self.set_visible(False)
self._icon_cache = {}
@@ -93,37 +93,11 @@ class TaskBar(Box):
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:
icon_name = self.icon_resolver.get_icon_name(window_class) or fallback_icon
if icon_name not in self._icon_cache:
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
self._icon_cache[icon_name] = pixbuf
return Image(pixbuf=self._icon_cache[icon_name], size=self.icon_size)
def load_icon(
self, icon_name: str, fallback_icon: str = "image-missing"
+2 -6
View File
@@ -100,7 +100,6 @@ class Launcher(Window):
def create_scrolled_window(self):
return ScrolledWindow(
name="launcher-scroll",
style=" transition: min-height 50s cubic-bezier(0.42, 0, 0.58, 1);",
child=self.get_viewport(),
h_scrollbar_policy="never",
@@ -197,7 +196,7 @@ class Launcher(Window):
for command, description in filtered_help:
button = Button(
child=self.create_help_button_content(command, description),
name="help-item",
name="launcher-item",
)
self.get_viewport().add(button)
@@ -206,13 +205,10 @@ class Launcher(Window):
orientation="h",
spacing=10,
children=[
Label(
label=command, h_expand=True, name="command-label", h_align="start"
),
Label(label=command, h_expand=True, h_align="start"),
Label(
label=description,
h_expand=True,
name="description-label",
h_align="end",
),
],
@@ -32,7 +32,6 @@ class BluetoothMenu:
h_align="center",
v_align="center",
on_clicked=lambda *_: self.client.toggle_scan(),
style="min-height:50px; min-width:50px;",
)
def bt_toggle(self, *_):
@@ -41,7 +40,7 @@ class BluetoothMenu:
def update_bt_button_style(self):
style = (
"background-color: transparent; min-height: 50px; min-width: 50px;"
"background-color: transparent;"
if self.client.enabled
else "background-color: @surfaceVariant; min-height: 50px; min-width: 50px;"
)
@@ -72,7 +71,7 @@ class BluetoothMenu:
],
),
on_clicked=lambda _, device=device: self.connect_to_device(device),
name="sh-item",
name="launcher-item",
)
def connect_to_device(self, device):
@@ -125,7 +125,7 @@ class ClipboardManager:
h_align="start",
),
on_clicked=lambda _, clip_id=item["id"]: self.handle_clip_click(clip_id),
name="cliphist-item",
name="launcher-item",
)
viewport.add(label_button)
@@ -8,9 +8,7 @@ from loguru import logger
from snippets import MaterialIcon
IDLE_BUTTON_ACTIVE_STYLE = "background-color: @surfaceVariant; min-width:50px; min-height:50px; border-radius:100px;"
IDLE_BUTTON_INACTIVE_STYLE = (
"background-color: transparent; min-width:50px; min-height:50px;"
)
IDLE_BUTTON_INACTIVE_STYLE = "background-color: transparent;"
class PowerMenu:
@@ -81,7 +79,7 @@ class PowerMenu:
],
),
on_clicked=lambda _, action=option["action"]: action(),
name="sh-item",
name="launcher-item",
)
viewport.add(button)
@@ -61,7 +61,7 @@ class ShellCommandManager:
h_align="start",
),
on_clicked=lambda _, cmd=command: self.execute_command(cmd),
name="sh-item",
name="launcher-item",
)
viewport.add(button)
@@ -47,7 +47,7 @@ class WallpaperManager:
style = (
"background-color: @surfaceVariant; border-radius:100px; min-height:50px; min-width:50px;"
if self.check_dark_mode_state()
else "background-color: transparent; border-radius:100px; min-height:50px; min-width:50px;"
else "background-color: transparent; border-radius:100px;"
)
self.theme_toggle_button.set_style(style)
@@ -26,19 +26,16 @@ class WifiMenu:
h_align="center",
v_align="center",
on_clicked=self.scan_for_networks,
style=" min-height:50px; min-width:50px;",
)
self.client.device_ready.connect(self.on_device_added)
def update_wifi_button_style(self):
if self.check_wifi_state():
self.wifi_toggle_button.set_style(
"background-color: transparent; min-height:50px; min-width:50px;"
)
self.wifi_toggle_button.set_style("background-color: transparent;")
else:
self.wifi_toggle_button.set_style(
"background-color: @surfaceVariant; min-height:50px; min-width:50px;"
"background-color: @surfaceVariant; border-radius:100px; min-height:50px; min-width:50px;"
)
def check_wifi_state(self):
@@ -75,7 +72,7 @@ class WifiMenu:
self.connect_to_ap(ap, is_connected),
self.launcher.set_visible(False),
),
name="sh-item",
name="launcher-item",
)
devices_box.add(device_button)
+2
View File
@@ -6,6 +6,7 @@ from .functions import (
username,
)
from .icon import MaterialIcon
from .icon_resolver import IconResolver
__all__ = [
"Animator",
@@ -13,5 +14,6 @@ __all__ = [
"read_config",
"get_profile_picture_path",
"username",
"IconResolver",
"get_current_uptime",
]
+100
View File
@@ -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 = "image-missing"):
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
)
+65 -13
View File
@@ -2,34 +2,49 @@
background-color: @surface;
padding: 3px;
}
#bar label {
font-weight: bold;
}
#progress {
color: transparent;
background-color: transparent;
/*
* ── bar moudles ───────────────────────────────────────────────────────
*/
#start-container,
#center-container,
#end-container {
padding-top: 6px;
padding-bottom: 6px;
margin-left: 12px;
margin-right: 12px;
}
#progress {
border: solid 0px @outlineVariant;
}
/*
* ── workspace ─────────────────────────────────────────────────────────
*/
#workspaces {
border-radius: 100px;
font-weight: bold;
font-style: normal;
color: @onSurface;
background: @surfaceContainer;
padding: 0px 10px 0px 10px;
}
/*
* ── Clock ─────────────────────────────────────────────────────────────
*/
#datetime {
background-color: @surfaceContainer;
border-radius: 100px;
padding: 8px;
}
/*
* ── battery ───────────────────────────────────────────────────────────
*/
#battery {
background-color: @surfaceContainer;
border-radius: 100px;
@@ -55,6 +70,10 @@
color: @onError;
}
/*
* ── tray ──────────────────────────────────────────────────────────────
*/
#tray {
background-color: @surfaceContainer;
border-radius: 100px;
@@ -70,11 +89,36 @@
color: @onSurface;
}
#progress {
color: lighter(@outlineVariant);
border: 2px solid @onSecondaryContainer;
menu {
background-color: @surfaceContainer;
}
menu > menuitem {
border-radius: 0px;
padding: 6px;
margin-left: 2px;
margin-right: 2px;
color: @onSurface;
}
menu > menuitem:first-child {
margin-top: 1px;
border-radius: 8px 8px 0px 0px;
}
menu > menuitem:last-child {
margin-bottom: 1px;
border-radius: 0px 0px 8px 8px;
}
menu > menuitem:hover {
background-color: mix(@onSurface, @surface, 0.85);
}
/*
* ── applets ───────────────────────────────────────────────────────────
*/
#applets {
background-color: @surfaceContainer;
border-radius: 100px;
@@ -93,6 +137,10 @@
padding: 0px;
}
/*
* ── taskbar ───────────────────────────────────────────────────────────
*/
#taskbar {
border-radius: 100px;
font-weight: bold;
@@ -109,12 +157,16 @@
}
#taskbar > button {
padding: 0px 5px;
padding: 0px 4px;
margin: 4px 0px;
margin-right: 3px;
border-radius: 100px;
border: 0px;
}
#taskbar > button:last-child {
margin-right: 0px;
}
#progress {
color: lighter(@outlineVariant);
border: 2px solid @onSecondaryContainer;
}
+18 -90
View File
@@ -7,23 +7,6 @@
min-width: 480px;
}
#launcher button {
border-radius: 100px;
background-color: transparent;
background-image: none;
box-shadow: none;
}
#launcher button:focus {
box-shadow: inset 0 0 0 1px @primary;
background-color: @background;
}
#launcher button:hover {
box-shadow: inset 0 0 0 1px @background;
background-color: @background;
}
#launcher entry {
transition: all 0.1s ease;
border-radius: 11px;
@@ -45,22 +28,14 @@
background-color: transparent;
}
#launcher button#fav-item {
border-radius: 10px;
padding: 10px;
background-image: none;
box-shadow: none;
}
#launcher button#fav-item:hover image,
#launcher button#fav-item:focus image {
-gtk-icon-shadow: 2px 2px @primary;
}
#launcher button#fav-item:active {
#profile-pic {
background-color: transparent;
border-radius: 11px;
box-shadow: inset 0 0 0 1px rgba(158, 142, 130, 0.04);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
border-radius: 100px;
padding: 20px;
margin: 4px;
}
#launcher button#app-item {
@@ -74,7 +49,7 @@
#launcher button#app-item:hover #title,
#launcher button#app-item:focus #title {
color: @primary;
color: @primar;
}
#launcher button#app-item:hover #description,
@@ -94,6 +69,7 @@
}
#launcher button#app-item:active #title {
color: @foreground;
}
#launcher button#emoji-item {
@@ -117,22 +93,6 @@
text-shadow: 2px 2px 2px @primary;
}
#launcher button#cliphist-item {
border-radius: 11px;
background-color: transparent;
background-image: none;
box-shadow: none;
}
window#launcher button#cliphist-item:disabled {
color: mix(@onSurface, transparent, 0.38);
}
#launcher button#cliphist-item:hover,
#launcher button#cliphist-item:focus {
text-shadow: 2px 2px 2px @primary;
}
#launcher button#cliphist-img-item {
background-size: cover;
background-position: center;
@@ -147,59 +107,22 @@ window#launcher button#cliphist-item:disabled {
box-shadow: 2px 2px 2px @primary;
}
#launcher button#exit-button {
/* background-color: red; */
border-radius: 100px;
}
#launcher button#exit-button:active {
text-shadow: 2px 2px 2px @primary;
}
#launcher button#power-item {
#launcher button#launcher-item {
border-radius: 11px;
background-color: transparent;
background-image: none;
box-shadow: none;
}
#launcher button#power-item:disabled {
#launcher button#launcher-item:disabled {
color: mix(@onSurface, transparent, 0.38);
}
#launcher button#power-item:hover,
#launcher button#power-item:focus {
#launcher button#launcher-item:hover,
#launcher button#launcher-item:focus {
text-shadow: 2pt 2pt 2pt @primary;
}
#launcher button#sh-item {
border-radius: 11px;
background-color: transparent;
background-image: none;
box-shadow: none;
}
#launcher button#sh-item:disabled {
color: mix(@onSurface, transparent, 0.38);
}
#launcher button#sh-item:hover,
#launcher button#sh-item:focus {
text-shadow: 2pt 2pt 2pt @primary;
}
#launcher button#help-item {
border-radius: 11px;
background-color: transparent;
background-image: none;
box-shadow: none;
}
#launcher button#help-item:hover label,
#launcher button#help-item:focus label {
text-shadow: 2px 2px 2px @primary;
}
#launcher button#wall-item {
border-radius: 0px;
background-color: transparent;
@@ -216,3 +139,8 @@ window#launcher button#cliphist-item:disabled {
#launcher button#wall-item:focus {
box-shadow: 2pt 2pt 2pt @primary;
}
.activated {
background-color: @surfaceVariant;
border-radius: 100px;
}
+6 -44
View File
@@ -12,32 +12,9 @@
sans-serif;
}
menu {
border-radius: 10px;
background-color: @surfaceContainer;
}
menu > menuitem {
border-radius: 0px;
padding: 6px;
margin-left: 2px;
margin-right: 2px;
color: @onSurface;
}
menu > menuitem:first-child {
margin-top: 1px;
border-radius: 8px 8px 0px 0px;
}
menu > menuitem:last-child {
margin-bottom: 1px;
border-radius: 0px 0px 8px 8px;
}
menu > menuitem:hover {
background-color: mix(@onSurface, @surface, 0.85);
}
/*
* ── tooltip ───────────────────────────────────────────────────────────
*/
tooltip {
background-color: @surfaceContainer;
@@ -55,24 +32,9 @@ tooltip label {
font-weight: normal;
}
#profile-pic {
background-color: transparent;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
border-radius: 100px;
padding: 20px;
margin: 4px;
}
#start-container,
#center-container,
#end-container {
padding-top: 6px;
padding-bottom: 6px;
margin-left: 12px;
margin-right: 12px;
}
/*
* ── icon ──────────────────────────────────────────────────────────────
*/
#material_icon,
#material_icon * {
+9 -3
View File
@@ -4,17 +4,23 @@
border-radius: 20px;
margin-bottom: 12px;
background-color: @surfaceContainerLow;
min-width: 400px;
}
#notification .summary {
font-size: 20px;
font-size: 0.92rem;
font-weight: bold;
}
#notification .body {
color: darker(@foreground);
font-weight: normal;
font-weight: 600;
font-size: 0.92rem;
}
#notification .close-button:hover {
background: alpha(@foreground, 0.2);
transition: background 0.15s ease-in-out;
border-radius: 100px;
}
#notification_action_button button.start-action {