added some bar utilities and powermenu

This commit is contained in:
wt
2025-03-10 23:22:47 +07:00
parent 55004d917e
commit b272840eae
7 changed files with 282 additions and 32 deletions
+78 -21
View File
@@ -1,6 +1,9 @@
import { App, Astal, Gtk, Gdk } from "astal/gtk3"
import { Variable, bind } from "astal"
import { Variable, GLib, bind } from "astal"
import Hyprland from "gi://AstalHyprland"
import Tray from "gi://AstalTray"
import PowerMenu from "./PowerMenu"
import Cpu from "./Cpu"
const time = Variable("").poll(1000, "date")
@@ -23,37 +26,91 @@ function Workspaces() {
</box>
}
function FocusedClient() {
const hypr = Hyprland.get_default()
const focused = bind(hypr, "focusedClient")
return <box
className="Focused"
visible={focused.as(Boolean)}>
{focused.as(client => (
client && <label label={bind(client, "title").as(String)} />
))}
{/* {focused.as(client => (
client && <label label={bind(client, "icon").as(String)} />
))} */}
</box>
}
function Time({ format = "%H:%M - %A %e" }) {
const time = Variable<string>("").poll(1000, () =>
GLib.DateTime.new_now_local().format(format)!)
return <label
className="Time"
onDestroy={() => time.drop()}
label={time()}
/>
}
function SysTray() {
const tray = Tray.get_default()
return <box className="SysTray">
{bind(tray, "items").as(items => items.map(item => (
<menubutton
tooltipMarkup={bind(item, "tooltipMarkup")}
usePopover={false}
actionGroup={bind(item, "actionGroup").as(ag => ["dbusmenu", ag])}
menuModel={bind(item, "menuModel")}>
<icon gicon={bind(item, "gicon")} />
</menubutton>
)))}
</box>
}
export default function Bar(gdkmonitor: Gdk.Monitor) {
const { TOP, LEFT, RIGHT } = Astal.WindowAnchor
return <window
return <><window
className="Bar"
name="Bar"
gdkmonitor={gdkmonitor}
exclusivity={Astal.Exclusivity.EXCLUSIVE}
anchor={TOP | LEFT | RIGHT}
application={App}>
<centerbox>
<box hexpand halign={Gtk.Align.START}>
<box hexpand halign={Gtk.Align.START} className="RoudedBlock">
<button
onClicked="/home/tola/dotfiles/rofi/launcher/launcher.sh"
halign={Gtk.Align.START}
className="Menubutton"
>
</button>
<Cpu />
<FocusedClient />
</box>
<box hexpand halign={Gtk.Align.CENTER} className="RoudedBlock">
<Workspaces />
</box>
<button
onClicked="/home/tola/dotfiles/rofi/launcher/launcher.sh"
halign={Gtk.Align.CENTER}
>
Menu
</button>
<button
onClicked="echo hello"
halign={Gtk.Align.CENTER}
>
Welcome to AGS!
</button>
<button
onClicked={() => print("hello")}
halign={Gtk.Align.CENTER}
>
<label label={time()} />
</button>
<box hexpand halign={Gtk.Align.END} className="RoudedBlock">
<SysTray />
{/* <SysTray />
<Wifi />
<AudioSlider />
<BatteryLevel /> */}
<Time />
<button
onClicked={() => App.toggle_window("powermenu")}
halign={Gtk.Align.START}
className="Menubutton"
>
⏻
</button>
</box>
</centerbox>
</window>
<PowerMenu />
</>
}
+34
View File
@@ -0,0 +1,34 @@
import { Variable } from "astal";
import GTop from "gi://GTop"
let previousCpuData = new GTop.glibtop_cpu();
GTop.glibtop_get_cpu(previousCpuData);
const computeCPU = (): string => {
const currentCpuData = new GTop.glibtop_cpu();
GTop.glibtop_get_cpu(currentCpuData);
// Calculate the differences from the previous to current data
const totalDiff = currentCpuData.total - previousCpuData.total;
const idleDiff = currentCpuData.idle - previousCpuData.idle;
const cpuUsagePercentage = totalDiff > 0 ? ((totalDiff - idleDiff) / totalDiff) * 100 : 0;
previousCpuData = currentCpuData;
const cpuUsagePercentageString = " " + cpuUsagePercentage.toFixed(0) + "%";
return cpuUsagePercentageString;
}
export default function Cpu() {
const cpu_usage = Variable<string>("").poll(10000, () =>
computeCPU())
return <box className="cpu">
<label
className="Time"
onDestroy={() => cpu_usage.drop()}
label={cpu_usage()} />
</box>
}
+26
View File
@@ -0,0 +1,26 @@
import { Astal, App } from "astal/gtk3";
export default function PowerMenu() {
const { TOP, RIGHT } = Astal.WindowAnchor
const powermenulist = [
{action: "/home/tola/.config/ags/scripts/powermenu lock", label: ""},
{action: "/home/tola/.config/ags/scripts/powermenu suspend", label: ""},
{action: "/home/tola/.config/ags/scripts/powermenu logout", label: ""},
{action: "/home/tola/.config/ags/scripts/powermenu reboot", label: ""},
{action: "/home/tola/.config/ags/scripts/powermenu poweroff", label: ""}
]
return <window
anchor={TOP | RIGHT}
name="powermenu"
className="Powermenu"
application={App}
visible={false}
>
<box>
{powermenulist.map(data => (
<button onClicked={data.action}>{data.label}</button>
))}
</box>
</window>
}
+13
View File
@@ -0,0 +1,13 @@
import { Variable } from "astal";
export default function Ram() {
const cpu_usage = Variable<string>("").poll(1000, () =>
computeCPU())
return <box className="cpu">
<label
className="Time"
onDestroy={() => cpu_usage.drop()}
label={cpu_usage()} />
</box>
}