ags: optimizations, add media and separator widgets

This commit is contained in:
retrozinndev
2025-01-23 14:06:33 -03:00
parent b533e830a0
commit 017619f62b
9 changed files with 151 additions and 31 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
import { bind } from "astal";
import { Widget } from "astal/gtk3";
import { Gtk, Widget } from "astal/gtk3";
import AstalWp from "gi://AstalWp?version=0.1";
const wp = AstalWp.get_default();
+7 -5
View File
@@ -1,14 +1,16 @@
import { Box, Button } from "astal/gtk3/widget";
import { GLib, Variable } from "astal";
import { Widget } from "astal/gtk3";
const dateTimeFormat = "%A %d, %H:%M"
const time = new Variable<string>("").poll(600, () =>
GLib.DateTime.new_now_local().format(dateTimeFormat)!);
export function Clock(): JSX.Element {
return (
<Box className={"clock"}>
<Button label={time()} />
</Box>
)
return new Widget.Box({
className: "clock",
child: new Widget.Button({
label: time()
} as Widget.ButtonProps)
} as Widget.BoxProps);
}
+4 -3
View File
@@ -7,10 +7,11 @@ const hyprland = AstalHyprland.get_default();
export function FocusedWindow() {
return new Widget.Box({
className: "focused-window",
visible: bind(hyprland, "focusedClient").as(Boolean),
children: [
new Widget.Icon({
className: "icon",
icon: bind(hyprland, "focusedClient").as((client: AstalHyprland.Client) => {
icon: bind(hyprland, "focusedClient").as(Boolean) && bind(hyprland, "focusedClient").as((client: AstalHyprland.Client) => {
switch(client.initialClass) {
case "zen":
return "zen-browser";
@@ -28,12 +29,12 @@ export function FocusedWindow() {
new Widget.Label({
className: "class",
xalign: 0,
label: bind(hyprland, "focusedClient").as((client: AstalHyprland.Client) => client.get_class())
label: bind(hyprland, "focusedClient").as(Boolean) && bind(hyprland, "focusedClient").as((client: AstalHyprland.Client) => client.get_class())
} as Widget.LabelProps),
new Widget.Label({
className: "title",
xalign: 0,
label: bind(hyprland, "focusedClient").as((client: AstalHyprland.Client) => client.get_title())
label: bind(hyprland, "focusedClient").as(Boolean) && bind(hyprland, "focusedClient").as((client: AstalHyprland.Client) => client.get_title())
} as Widget.LabelProps)
]
})
+62
View File
@@ -0,0 +1,62 @@
import { bind } from "astal";
import { Gtk, Widget } from "astal/gtk3";
import AstalMpris from "gi://AstalMpris";
import { Separator, SeparatorProps } from "../Separator";
import { Wal } from "../../scripts/pywal";
const mpris: AstalMpris.Mpris = AstalMpris.get_default();
let defaultPlayer: (AstalMpris.Player|undefined) = mpris.get_players()?.[0];
const playerIcons = {
spotify: '󰓇',
clapper: '󰿎',
spotube: '󰋋',
firefox: '󰈹'
}
export function Media(): JSX.Element {
bind(mpris, "players")?.as((players: Array<AstalMpris.Player>) => {
defaultPlayer = players?.[0] as AstalMpris.Player;
});
return new Widget.EventBox({
className: "media-eventbox",
visible: bind(mpris, "players").as((players: Array<AstalMpris.Player>) => players?.[0]).as(Boolean),
child: new Widget.Box({
className: "media",
children: [
new Widget.Box({
children: [
new Widget.Label({
className: "icon",
label: defaultPlayer && bind(defaultPlayer, "busName")?.as((name: string) => {
const banana: Array<string> = name.split('.');
const playerName: string = banana[banana.length-1];
return playerIcons[playerName as keyof typeof playerIcons] || '󰎇';
})
} as Widget.LabelProps),
new Widget.Label({
className: "title",
label: defaultPlayer && bind(defaultPlayer, "title")?.as((title: string) => title)
} as Widget.LabelProps),
Separator({
size: 2,
cssColor: `rgb(150, 150, 150)`,
alpha: 1
} as SeparatorProps),
new Widget.Label({
className: "artist",
label: defaultPlayer && bind(defaultPlayer, "artist")?.as((artist: string) => artist)
} as Widget.LabelProps)
]
} as Widget.BoxProps),
new Widget.Revealer({
transitionType: Gtk.RevealerTransitionType.SLIDE_RIGHT,
transitionDuration: 400,
revealChild: false //FIXME
} as Widget.RevealerProps)
]
} as Widget.BoxProps)
} as Widget.EventBoxProps);
}