117 lines
4.1 KiB
TypeScript
117 lines
4.1 KiB
TypeScript
import { App, Astal, Gdk, Gtk } from "astal/gtk3"
|
|
import Workspaces from "./Workspaces"
|
|
import Logo from "./Logo"
|
|
import Clock from "./Clock"
|
|
import { BatteryWidget } from "./Battery"
|
|
import QuickSettings from "./QuickSettings"
|
|
|
|
const RADIUS = 12
|
|
|
|
// paints the concave sliver below the bar at the screen edge: the r x r
|
|
// square minus the quarter disk where the wallpaper shows through
|
|
function Corner({ side }: { side: "left" | "right" }) {
|
|
return (
|
|
<drawingarea
|
|
className="corner"
|
|
widthRequest={RADIUS}
|
|
heightRequest={RADIUS}
|
|
halign={side === "left" ? Gtk.Align.START : Gtk.Align.END}
|
|
onDraw={(self, cr) => {
|
|
const w = self.get_allocated_width()
|
|
const h = self.get_allocated_height()
|
|
// bar color comes from the parent strip so the sliver gets the
|
|
// same bar-bg + module-bg stack as the pills
|
|
const bar = self
|
|
.get_parent()!
|
|
.get_style_context()
|
|
.get_color(Gtk.StateFlags.NORMAL)
|
|
const mod = self
|
|
.get_style_context()
|
|
.get_color(Gtk.StateFlags.NORMAL)
|
|
|
|
const trace = () => {
|
|
if (side === "left") {
|
|
cr.moveTo(0, 0)
|
|
cr.lineTo(w, 0)
|
|
cr.arcNegative(w, h, w, -Math.PI / 2, -Math.PI)
|
|
} else {
|
|
cr.moveTo(w, 0)
|
|
cr.lineTo(0, 0)
|
|
cr.arc(0, h, w, -Math.PI / 2, 0)
|
|
}
|
|
cr.closePath()
|
|
}
|
|
|
|
cr.setSourceRGBA(bar.red, bar.green, bar.blue, bar.alpha)
|
|
trace()
|
|
cr.fillPreserve()
|
|
cr.setSourceRGBA(mod.red, mod.green, mod.blue, mod.alpha)
|
|
cr.fill()
|
|
}}
|
|
/>
|
|
)
|
|
}
|
|
|
|
export default function Bar(gdkmonitor: Gdk.Monitor) {
|
|
const { TOP, LEFT, RIGHT } = Astal.WindowAnchor
|
|
const battery = BatteryWidget(gdkmonitor)
|
|
const quicksettings = QuickSettings(gdkmonitor)
|
|
|
|
const right: Array<JSX.Element> = []
|
|
if (battery.button) right.push(battery.button)
|
|
right.push(quicksettings.button)
|
|
|
|
const popups: Array<JSX.Element> = []
|
|
if (battery.popup) popups.push(battery.popup)
|
|
popups.push(quicksettings.popup)
|
|
|
|
return [
|
|
(
|
|
<window
|
|
className="Bar"
|
|
namespace="ags-bar"
|
|
gdkmonitor={gdkmonitor}
|
|
exclusivity={Astal.Exclusivity.EXCLUSIVE}
|
|
anchor={TOP | LEFT | RIGHT}
|
|
application={App}
|
|
>
|
|
<box vertical>
|
|
<centerbox className="bar">
|
|
<box
|
|
className="bar-left"
|
|
halign={Gtk.Align.START}
|
|
valign={Gtk.Align.FILL}
|
|
>
|
|
<Logo />
|
|
<box className="center">
|
|
<Workspaces />
|
|
</box>
|
|
</box>
|
|
<box
|
|
className="bar-center"
|
|
halign={Gtk.Align.CENTER}
|
|
valign={Gtk.Align.CENTER}
|
|
/>
|
|
<box
|
|
className="bar-right"
|
|
halign={Gtk.Align.END}
|
|
valign={Gtk.Align.FILL}
|
|
>
|
|
{right}
|
|
<box className="clock last">
|
|
<Clock />
|
|
</box>
|
|
</box>
|
|
</centerbox>
|
|
<box className="bar-corners">
|
|
<Corner side="left" />
|
|
<box hexpand />
|
|
<Corner side="right" />
|
|
</box>
|
|
</box>
|
|
</window>
|
|
),
|
|
...popups,
|
|
]
|
|
}
|