working bar
This commit is contained in:
parent
ed206ad7e5
commit
2c9ff9db2f
8 changed files with 121 additions and 126 deletions
|
@ -1,85 +1,10 @@
|
|||
import { App, Astal, Gtk, Gdk, Widget, astalify } from "astal/gtk4"
|
||||
import { GLib, Variable } from "astal"
|
||||
import Hyprland from "gi://AstalHyprland"
|
||||
import Tray from "gi://AstalTray"
|
||||
import Battery from "gi://AstalBattery"
|
||||
import Network from "gi://AstalNetwork"
|
||||
import AstalTray from "gi://AstalTray?version=0.1"
|
||||
import { App, Astal, Gtk, Gdk, } from "astal/gtk4"
|
||||
import Workspaces from "./workspaces"
|
||||
import Systray from "./systray"
|
||||
import Battery from "./battery"
|
||||
import Time from "./time"
|
||||
|
||||
|
||||
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) {
|
||||
const { TOP, LEFT, RIGHT } = Astal.WindowAnchor
|
||||
|
||||
|
@ -92,15 +17,14 @@ export default function Bar(gdkmonitor: Gdk.Monitor) {
|
|||
application={App}>
|
||||
<centerbox>
|
||||
<box hexpand halign={Gtk.Align.START}>
|
||||
<Bat />
|
||||
<SysTray />
|
||||
<Battery />
|
||||
</box>
|
||||
<box hexpand halign={Gtk.Align.CENTER}>
|
||||
<Workspaces />
|
||||
</box>
|
||||
<box hexpand halign={Gtk.Align.END}>
|
||||
<Net />
|
||||
<Time />
|
||||
<Systray />
|
||||
</box>
|
||||
|
||||
</centerbox>
|
||||
|
|
14
widget/battery.tsx
Normal file
14
widget/battery.tsx
Normal 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
22
widget/systray.tsx
Normal 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
11
widget/time.tsx
Normal 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
24
widget/workspaces.tsx
Normal 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 >
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue