feat: add astal status bar

This commit is contained in:
2025-06-22 20:59:41 -07:00
parent adc21bdc69
commit 2ac6585c55
14 changed files with 606 additions and 8 deletions

2
astal/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
node_modules/
@girs/

10
astal/app.ts Normal file
View File

@@ -0,0 +1,10 @@
import { App } from "astal/gtk3";
import style from "./style.scss";
import Bar from "./widget/Bar";
App.start({
css: style,
main() {
App.get_monitors().map(Bar);
},
});

21
astal/env.d.ts vendored Normal file
View File

@@ -0,0 +1,21 @@
declare const SRC: string
declare module "inline:*" {
const content: string
export default content
}
declare module "*.scss" {
const content: string
export default content
}
declare module "*.blp" {
const content: string
export default content
}
declare module "*.css" {
const content: string
export default content
}

70
astal/flake.lock generated Normal file
View File

@@ -0,0 +1,70 @@
{
"nodes": {
"ags": {
"inputs": {
"astal": "astal",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1744557573,
"narHash": "sha256-XAyj0iDuI51BytJ1PwN53uLpzTDdznPDQFG4RwihlTQ=",
"owner": "aylur",
"repo": "ags",
"rev": "3ed9737bdbc8fc7a7c7ceef2165c9109f336bff6",
"type": "github"
},
"original": {
"owner": "aylur",
"repo": "ags",
"type": "github"
}
},
"astal": {
"inputs": {
"nixpkgs": [
"ags",
"nixpkgs"
]
},
"locked": {
"lastModified": 1742571008,
"narHash": "sha256-5WgfJAeBpxiKbTR/gJvxrGYfqQRge5aUDcGKmU1YZ1Q=",
"owner": "aylur",
"repo": "astal",
"rev": "dc0e5d37abe9424c53dcbd2506a4886ffee6296e",
"type": "github"
},
"original": {
"owner": "aylur",
"repo": "astal",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1750365781,
"narHash": "sha256-XE/lFNhz5lsriMm/yjXkvSZz5DfvKJLUjsS6pP8EC50=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "08f22084e6085d19bcfb4be30d1ca76ecb96fe54",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"ags": "ags",
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

62
astal/flake.nix Normal file
View File

@@ -0,0 +1,62 @@
{
description = "Desktop widgets";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
ags = {
url = "github:aylur/ags";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
ags,
}:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
extraPkgs = with ags.packages.${system}; [
hyprland
battery
wireplumber
network
];
in
{
packages.${system} = {
status-bar = ags.lib.bundle {
inherit pkgs;
src = ./.;
name = "status-bar";
entry = "app.ts";
extraPackages =
with pkgs;
extraPkgs
++ [
libgtop
];
};
};
devShells.${system} = {
default = pkgs.mkShell {
buildInputs = [
(ags.packages.${system}.default.override {
extraPackages =
with pkgs;
extraPkgs
++ [
libgtop
];
})
];
};
};
};
}

21
astal/package-lock.json generated Normal file
View File

@@ -0,0 +1,21 @@
{
"name": "astal-shell",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "astal-shell",
"dependencies": {
"astal": "/nix/store/pvb3x021mr6xknm91gqq76gy32n96vj0-astal-gjs/share/astal/gjs"
}
},
"../../../../nix/store/pvb3x021mr6xknm91gqq76gy32n96vj0-astal-gjs/share/astal/gjs": {
"name": "astal",
"license": "LGPL-2.1"
},
"node_modules/astal": {
"resolved": "../../../../nix/store/pvb3x021mr6xknm91gqq76gy32n96vj0-astal-gjs/share/astal/gjs",
"link": true
}
}
}

6
astal/package.json Normal file
View File

@@ -0,0 +1,6 @@
{
"name": "astal-shell",
"dependencies": {
"astal": "/nix/store/pvb3x021mr6xknm91gqq76gy32n96vj0-astal-gjs/share/astal/gjs"
}
}

122
astal/style.scss Normal file
View File

@@ -0,0 +1,122 @@
@use "sass:color";
$bg: #212223;
$fg: #f1f1f1;
$accent: #378DF7;
$accent-white: #ffffff;
$radius: 7px;
$bg-color-6: rgb(40, 42, 54);
$inactive-bg-color: rgb(68, 71, 90);
window.Bar {
border: none;
box-shadow: none;
font-family: Dejavu Sans Mono;
background-color: color.adjust($bg, $alpha: -0.2);
color: $fg;
font-size: 1.1em;
label {
margin: 0 8px;
}
.status-box {
background-color: $bg-color-6;
padding: 0 4px;
margin: 0 4px;
font-size: 16px;
}
.inactive {
background-color: $inactive-bg-color;
}
.workspaces {
font-weight: bold;
button {
all: unset;
background-color: transparent;
&:hover label {
background-color: color.adjust($fg, $alpha: -0.84);
border-color: color.adjust($accent, $alpha: -0.8);
}
&:active label {
background-color: color.adjust($fg, $alpha: -0.8)
}
}
label {
transition: 200ms;
padding: 3px 8px;
margin: 0px;
border-radius: 0;
border: 3px solid transparent;
}
.focused label {
background-color: color.adjust($accent-white, $alpha: -0.84);
border-bottom: 3px solid $accent-white;
}
}
.SysTray {
margin-right: 8px;
button {
padding: 0 4px;
}
}
.FocusedClient {
color: $accent;
}
.Media .Cover {
min-height: 1.2em;
min-width: 1.2em;
border-radius: $radius;
background-position: center;
background-size: contain;
}
.Battery label {
padding-left: 0;
margin-left: 0;
}
.AudioSlider {
* {
all: unset;
}
icon {
margin-right: .6em;
}
& {
margin: 0 1em;
}
trough {
background-color: color.adjust($fg, $alpha: -0.8);
border-radius: $radius;
}
highlight {
background-color: $accent;
min-height: .8em;
border-radius: $radius;
}
slider {
background-color: $fg;
border-radius: $radius;
min-height: 1em;
min-width: 1em;
margin: -.2em;
}
}
}

14
astal/tsconfig.json Normal file
View File

@@ -0,0 +1,14 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"experimentalDecorators": true,
"strict": true,
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "Bundler",
// "checkJs": true,
// "allowJs": true,
"jsx": "react-jsx",
"jsxImportSource": "astal/gtk3",
}
}

156
astal/widget/Bar.tsx Normal file
View File

@@ -0,0 +1,156 @@
import { App, Astal, Gtk, Gdk } from "astal/gtk3"
import { bind, derive, GLib, Variable } from "astal"
import Hyprland from "gi://AstalHyprland"
import Wp from "gi://AstalWp"
import Network from "gi://AstalNetwork"
import GTop from "gi://GTop"
import { calc_cpu_usage, get_cpu_snapshot, get_disk_space, get_ram_info } from "./cpu"
import AstalBattery from "gi://AstalBattery"
const time = Variable("").poll(1000, "date")
function Workspaces() {
const hypr = Hyprland.get_default()
return <box className="workspaces">
{bind(hypr, "workspaces").as(wss => wss.filter(ws => !(ws.id >= -99 && ws.id <= -2))
.sort((a, b) => a.id - b.id)
.map(ws => (
//@ts-ignore
<button
className={bind(hypr, "focusedWorkspace").as(fw =>
ws === fw ? "focused" : "")}
onClicked={() => ws.focus()}>
{ws.id}
</button>
)))}
</box>
}
function Audio() {
const speaker = Wp.get_default()?.default_speaker!
const derived = Variable.derive([bind(speaker, "volume"), bind(speaker, "mute")], (volume: number, muted: boolean) => {
if (muted) {
return { label: ` (muted)`, muted }
}
return { label: `${Math.floor(volume * 100)}% ` }
})
return <box className={derived((v) => ["status-box", v.muted && "inactive"].filter(Boolean).join(" "))}>
<label
label={derived((v) => v.label)} />
</box>
}
function NetworkModule() {
const network = Network.get_default()
const wifi = network.wifi;
const wired = network.wired
const derived = Variable.derive([bind(network, "primary"), bind(wifi, "ssid"), bind(wifi, "strength")], (primary, ssid, strength) => {
if (primary === Network.Primary.WIRED) {
return { label: "🖧 Wired" }
}
if (wifi.active_access_point !== null) {
return { label: `${ssid} (${strength}%) ` }
}
return { label: `Disconnected ⚠` }
})
return (
<box className="status-box">
<label
label={derived((v) => v.label)} />
</box>
)
}
let s1 = get_cpu_snapshot();
let cpu_usage_percent = Variable(0);
GLib.timeout_add(GLib.PRIORITY_DEFAULT, 1000, () => {
const s2 = get_cpu_snapshot();
cpu_usage_percent.set(calc_cpu_usage(s1, s2));
s1 = s2;
return true;
});
function Cpu() {
return <box className="status-box">
<label label={bind(cpu_usage_percent).as((u) => `${u}% `)} />
</box>
}
let info = Variable(get_ram_info())
GLib.timeout_add(GLib.PRIORITY_DEFAULT, 1000, () => {
info.set(get_ram_info())
return true
})
function Ram() {
return <box className="status-box">
<label label={bind(info).as((i) => `${Math.round((i.used / i.total) * 100)}% `)} />
</box>
}
let disk_space = Variable(get_disk_space())
function Disk() {
return <box className="status-box">
<label label={bind(disk_space).as((s) => `${s}GiB`)} />
</box>
}
function Battery() {
const battery = AstalBattery.get_default()
const battery_info = Variable.derive([bind(battery, "percentage"), bind(battery, "charging")], (percentage, charging) => {
const full_percentage = Math.floor(percentage * 100)
if (charging) {
return { label: `${full_percentage == 100 ? "FULL" : "CHR"}: ${full_percentage}%` }
}
return { label: `${full_percentage == 100 ? "FULL" : "BAT"}: ${full_percentage}` }
})
return <box className="status-box">
<label label={battery_info((i) => i.label)} />
</box>
}
let current_time = Variable(GLib.DateTime.new_now_local().format("%H:%M"))
GLib.timeout_add(GLib.PRIORITY_DEFAULT, 1000, () => {
const now = GLib.DateTime.new_now_local()
current_time.set(now.format("%H:%M"))
return true
})
function Time() {
return <box className="status-box">
<label label={bind(current_time)} />
</box>
}
export default function Bar(gdkmonitor: Gdk.Monitor) {
const { BOTTOM, LEFT, RIGHT } = Astal.WindowAnchor
//@ts-ignore
return <window
className="Bar"
gdkmonitor={gdkmonitor}
exclusivity={Astal.Exclusivity.EXCLUSIVE}
anchor={BOTTOM | LEFT | RIGHT}
application={App}>
<centerbox>
<box hexpand halign={Gtk.Align.START} >
<Workspaces />
</box>
<box></box>
<box hexpand halign={Gtk.Align.END}>
<Audio />
<NetworkModule />
<Cpu />
<Ram />
<Disk />
<Battery />
<Time />
</box>
</centerbox>
</window>
}

46
astal/widget/cpu.ts Normal file
View File

@@ -0,0 +1,46 @@
import { GLib, Variable } from "astal";
import GTop from "gi://GTop";
type Snapshot = {
total: number;
user: number;
sys: number;
idle: number;
};
export function get_cpu_snapshot() {
const cpu = new GTop.glibtop_cpu();
GTop.glibtop_get_cpu(cpu);
return {
total: cpu.total,
user: cpu.user + cpu.nice,
sys: cpu.sys,
idle: cpu.idle,
};
}
export function calc_cpu_usage(a: Snapshot, b: Snapshot) {
const total_diff = b.total - a.total;
const active_diff = b.user + b.sys - (a.user + a.sys);
return Math.round(total_diff > 0 ? (100 * active_diff) / total_diff : 0);
}
export function get_ram_info() {
const mem = new GTop.glibtop_mem();
GTop.glibtop_get_mem(mem);
return {
total: mem.total,
used: mem.total - mem.free - mem.cached - mem.buffer,
free: mem.free,
};
}
export function get_disk_space() {
const usage = new GTop.glibtop_fsusage();
GTop.glibtop_get_fsusage(usage, "/");
const free_bytes = usage.bavail * usage.block_size;
const free_gib = free_bytes / 1024 ** 3;
return free_gib.toFixed(2);
}

76
nix/flake.lock generated
View File

@@ -1,5 +1,49 @@
{
"nodes": {
"ags": {
"inputs": {
"astal": "astal",
"nixpkgs": [
"status-bar",
"nixpkgs"
]
},
"locked": {
"lastModified": 1744557573,
"narHash": "sha256-XAyj0iDuI51BytJ1PwN53uLpzTDdznPDQFG4RwihlTQ=",
"owner": "aylur",
"repo": "ags",
"rev": "3ed9737bdbc8fc7a7c7ceef2165c9109f336bff6",
"type": "github"
},
"original": {
"owner": "aylur",
"repo": "ags",
"type": "github"
}
},
"astal": {
"inputs": {
"nixpkgs": [
"status-bar",
"ags",
"nixpkgs"
]
},
"locked": {
"lastModified": 1742571008,
"narHash": "sha256-5WgfJAeBpxiKbTR/gJvxrGYfqQRge5aUDcGKmU1YZ1Q=",
"owner": "aylur",
"repo": "astal",
"rev": "dc0e5d37abe9424c53dcbd2506a4886ffee6296e",
"type": "github"
},
"original": {
"owner": "aylur",
"repo": "astal",
"type": "github"
}
},
"custom-fonts": {
"inputs": {
"nixpkgs": [
@@ -39,11 +83,11 @@
]
},
"locked": {
"lastModified": 1750304462,
"narHash": "sha256-Mj5t4yX05/rXnRqJkpoLZTWqgStB88Mr/fegTRqyiWc=",
"lastModified": 1750650158,
"narHash": "sha256-cGdpDr/OUjS5rfl0lH7CjnIFWtpOFQOcRkvBu9CV+Cs=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "863842639722dd12ae9e37ca83bcb61a63b36f6c",
"rev": "3bd646138a9c71f244a9293dde6f59ae1c6875ab",
"type": "github"
},
"original": {
@@ -110,11 +154,11 @@
},
"nixpkgs_2": {
"locked": {
"lastModified": 1750134718,
"narHash": "sha256-v263g4GbxXv87hMXMCpjkIxd/viIF7p3JpJrwgKdNiI=",
"lastModified": 1750506804,
"narHash": "sha256-VLFNc4egNjovYVxDGyBYTrvVCgDYgENp5bVi9fPTDYc=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "9e83b64f727c88a7711a2c463a7b16eedb69a84c",
"rev": "4206c4cb56751df534751b058295ea61357bbbaa",
"type": "github"
},
"original": {
@@ -172,8 +216,26 @@
"nixos-wsl": "nixos-wsl",
"nixpkgs": "nixpkgs_2",
"pesde": "pesde",
"rokit": "rokit"
"rokit": "rokit",
"status-bar": "status-bar"
}
},
"status-bar": {
"inputs": {
"ags": "ags",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"path": "../astal",
"type": "path"
},
"original": {
"path": "../astal",
"type": "path"
},
"parent": []
}
},
"root": "root",

View File

@@ -14,6 +14,10 @@
rokit.inputs.nixpkgs.follows = "nixpkgs";
custom-fonts.url = "path:./fonts";
custom-fonts.inputs.nixpkgs.follows = "nixpkgs";
status-bar = {
url = "path:../astal";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
@@ -72,6 +76,7 @@
inputs.pesde.packages.${host.architecture}.default
inputs.mantle.packages.${host.architecture}.default
inputs.rokit.packages.${host.architecture}.default
inputs.status-bar.packages.${host.architecture}.status-bar
];
fonts.packages = [
inputs.custom-fonts.packages.${host.architecture}.default

View File

@@ -40,6 +40,7 @@
services.tumbler.enable = true;
services.displayManager.ly.enable = true;
rofi.enable = true;
services.upower.enable = true;
home-manager.users.luca = {
programs = {
@@ -139,7 +140,7 @@
];
exec-once = [
"swaybg -i ~/.config/wallpaper/bg.jpg"
"waybar"
"status-bar"
];
monitor = [
"eDP-1, 1920x1080, 0x0, 1"