working bar

This commit is contained in:
Bloxx12 2025-04-21 09:35:17 +02:00
commit 2c9ff9db2f
8 changed files with 121 additions and 126 deletions

View file

@ -31,56 +31,38 @@
src = ./.; src = ./.;
name = "my-shell"; name = "my-shell";
entry = "app.ts"; entry = "app.ts";
# additional libraries and executables to add to gjs' runtime
extraPackages = [
# ags.packages.${system}.battery
# pkgs.fzf
];
}; };
}; };
devShells.${system} = { devShells.${system} = {
default = pkgs.mkShell { default = pkgs.mkShell {
buildInputs = with pkgs; [ buildInputs = with pkgs; [
nodejs_23
gobject-introspection
json-glib
gjs
# includes astal3 astal4 astal-io by default # includes astal3 astal4 astal-io by default
(ags.packages.${system}.default.override { (ags.packages.${system}.default.override {
extraPackages = builtins.attrValues { extraPackages = builtins.attrValues {
inherit inherit
(astal.packages.${system}) (astal.packages.${system})
hyprland io
tray astal4
network
battery battery
wireplumber
network
mpris
powerprofiles
tray
bluetooth
hyprland
; ;
}; };
}) })
wrapGAppsHook nodejs_23
gobject-introspection
meson meson
pkg-config
ninja ninja
vala pkg-config
gtk3 gobject-introspection
gtk4 wrapGAppsHook4
gtk-layer-shell
gtk4-layer-shell
json-glib
pam
gvfs
networkmanager
gdk-pixbuf
wireplumber
libdbusmenu-gtk3
wayland
blueprint-compiler blueprint-compiler
libadwaita
wayland-scanner
dart-sass dart-sass
esbuild esbuild
gjs gjs

View file

@ -1,5 +1,5 @@
{ {
"watch": ["app.ts", "widget/"], "watch": ["app.ts", "style.scss", "widget/"],
"ext": "ts, tsx", "ext": "ts, tsx, scss",
"exec": "ags run --gtk4 ." "exec": "ags run --gtk4 ."
} }

View file

@ -1,17 +1,18 @@
// https://gitlab.gnome.org/GNOME/gtk/-/blob/gtk-3-24/gtk/theme/Adwaita/_colors-public.scss // https://gitlab.gnome.org/GNOME/gtk/-/blob/gtk-3-24/gtk/theme/Adwaita/_colors-public.scss
$fg-color: #{"@theme_fg_color"}; $fg-color: #{"@theme_fg_color"};
$bg-color: #{"@theme_bg_color"}; $bg-color: #{"@theme_bg_color"};
$corner-size: 7;
$notch-color: #222;
window.Bar { window.Bar {
background: transparent; background: transparent;
color: $fg-color; color: $fg-color;
font-weight: bold; /* font-weight: bold; */
font-size: 25px; font-size: 25px;
>centerbox { >centerbox {
background: $bg-color; background: $bg-color;
border-radius: 10px; border-radius: 10px;
margin: 8px;
} }
button { button {
@ -19,25 +20,42 @@ window.Bar {
margin: 2px; margin: 2px;
} }
.AudioSlider {
min-width: 200px;
}
.Workspaces { .Workspaces {
background-color: black;
margin: 0 60px 10px 60px;
border-radius: 0 0 20px 20px;
button { button {
all: unset; all: unset;
background-color: transparent; color: white;
margin: 2px;
padding: 2px; &.focused {
color: red;
border-color: blue;
}
label {
transition: 200ms;
padding: 0 8px;
margin: 2px;
border-radius: 10px;
border: 1pt solid transparent;
}
&:hover label { &:hover label {
background-color: red; background-color: blue;
border-color: $bg-color; border-color: $bg-color;
} }
&:active label { &:active label {
background-color: $fg-color; background-color: green;
border-color: red;
} }
.focused {
color: red;
}
} }
} }
} }

View file

@ -1,85 +1,10 @@
import { App, Astal, Gtk, Gdk, Widget, astalify } from "astal/gtk4" import { App, Astal, Gtk, Gdk, } from "astal/gtk4"
import { GLib, Variable } from "astal" import Workspaces from "./workspaces"
import Hyprland from "gi://AstalHyprland" import Systray from "./systray"
import Tray from "gi://AstalTray" import Battery from "./battery"
import Battery from "gi://AstalBattery" import Time from "./time"
import Network from "gi://AstalNetwork"
import AstalTray from "gi://AstalTray?version=0.1"
type Workspace = {
id: number
focus: () => void
}
type Hyprland = {
workspaces: Workspace[]
focusedWorkspace: Workspace | null
}
function Bat() {
const bat = Battery.get_default()
return <box cssClasses={["Battery"]}>
Battery: {bat.get_percentage() * 100}%
</box>
}
function Net() {
const network = Network.get_default()
return <box cssClasses={["Network"]} >
{network.wifi.enabled}
</box>
}
function Workspaces() {
const hypr = Hyprland.get_default()
return <box cssClasses={["Workspaces"]} >
{
hypr.workspaces.filter(ws => !(ws.id >= -99 && ws.id < -2))
.sort((a, b) => a.id - b.id)
.map(ws => (
<button
cssClasses={
ws === hypr.focusedWorkspace ? ["focused"] : []}
onClicked={() => ws.focus()}>
{ws.id}
</button>
))
}
</box >
}
function SysTray() {
const tray = AstalTray.get_default()
print(tray.get_items.length)
return <box
cssClasses={["SysTray"]}
>
{tray.get_items().map(item => (
<menubutton
tooltipMarkup={item.tooltipMarkup}
menuModel={item.menuModel}
>
<image gicon={item.get_gicon()} />
</menubutton>
))}
</box>
}
function Time({ }) {
const time = Variable<string>("").poll(1000, () => GLib.DateTime.new_now_local().format("%H:%M")!)
return <label
cssName="Time"
onDestroy={() => time.drop()}
label={time()} />
}
export default function Bar(gdkmonitor: Gdk.Monitor) { export default function Bar(gdkmonitor: Gdk.Monitor) {
const { TOP, LEFT, RIGHT } = Astal.WindowAnchor const { TOP, LEFT, RIGHT } = Astal.WindowAnchor
@ -92,15 +17,14 @@ export default function Bar(gdkmonitor: Gdk.Monitor) {
application={App}> application={App}>
<centerbox> <centerbox>
<box hexpand halign={Gtk.Align.START}> <box hexpand halign={Gtk.Align.START}>
<Bat /> <Battery />
<SysTray />
</box> </box>
<box hexpand halign={Gtk.Align.CENTER}> <box hexpand halign={Gtk.Align.CENTER}>
<Workspaces /> <Workspaces />
</box> </box>
<box hexpand halign={Gtk.Align.END}> <box hexpand halign={Gtk.Align.END}>
<Net />
<Time /> <Time />
<Systray />
</box> </box>
</centerbox> </centerbox>

14
widget/battery.tsx Normal file
View file

@ -0,0 +1,14 @@
import { bind } from "astal"
import Battery from "gi://AstalBattery"
export default function BatteryLevel() {
const bat = Battery.get_default()
return <box
cssClasses={["Battery"]}
visible={bind(bat, "isPresent")}>
<image iconName={bind(bat, "batteryIconName")} />
<label label={bind(bat, "percentage").as(p => `${Math.floor(p * 100)}%`)} />
</box>
}

22
widget/systray.tsx Normal file
View file

@ -0,0 +1,22 @@
import { bind } from "astal"
import AstalTray from "gi://AstalTray?version=0.1"
export default function Systray() {
const tray = AstalTray.get_default()
return <box cssClasses={["SysTray"]} >
{
bind(tray, "items").as(items => items.map(item => (
<menubutton
tooltipMarkup={bind(item, "tooltipMarkup")}
menuModel={bind(item, "menuModel")}
setup={(self) => {
self.insert_action_group("dbusmenu", item.actionGroup)
}}
>
<image gicon={bind(item, "gicon")} />
</menubutton>
)))
}
</box >
}

11
widget/time.tsx Normal file
View file

@ -0,0 +1,11 @@
import { GLib, Variable, } from "astal"
export default function Time({ }) {
const time = Variable<string>("").poll(1000, () => GLib.DateTime.new_now_local().format("%H:%M")!)
return <label
cssName="Time"
onDestroy={() => time.drop()}
label={time()} />
}

24
widget/workspaces.tsx Normal file
View file

@ -0,0 +1,24 @@
import Hyprland from "gi://AstalHyprland"
import { bind, } from "astal"
export default function Workspaces() {
const hypr = Hyprland.get_default()
return <box cssClasses={["Workspaces"]}>
{bind(hypr, "workspaces").as((workspaces) =>
workspaces
.filter(ws => !(ws.id >= -99 && ws.id < -2))
.sort((a, b) => a.id - b.id)
.map((ws) => (
<button
onClicked={() => ws.focus()}
cssClasses={bind(hypr, "focusedWorkspace").as((active) =>
ws === active ? ["focused"] : [],
)}
>
{ws.id}
</button>
)),
)}
</box >
}