From 33e1ab078501436b0d634b6f3f2f23687783894b Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Wed, 2 Apr 2025 18:43:01 +1100 Subject: bar: embedded style --- src/modules/bar.tsx | 113 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 74 insertions(+), 39 deletions(-) (limited to 'src/modules/bar.tsx') diff --git a/src/modules/bar.tsx b/src/modules/bar.tsx index 2aa45b6..9d65191 100644 --- a/src/modules/bar.tsx +++ b/src/modules/bar.tsx @@ -10,7 +10,7 @@ import { setupCustomTooltip } from "@/utils/widgets"; import ScreenCorner from "@/widgets/screencorner"; import { execAsync, Variable } from "astal"; import Binding, { bind, kebabify } from "astal/binding"; -import { App, Astal, Gtk } from "astal/gtk3"; +import { App, Astal, Gtk, type Widget } from "astal/gtk3"; import { bar as config } from "config"; import AstalBattery from "gi://AstalBattery"; import AstalBluetooth from "gi://AstalBluetooth"; @@ -20,6 +20,11 @@ import AstalNotifd from "gi://AstalNotifd"; import AstalTray from "gi://AstalTray"; import AstalWp from "gi://AstalWp"; +interface SpacerClassNameProps { + beforeSpacer?: boolean; + afterSpacer?: boolean; +} + const hyprland = AstalHyprland.get_default(); const getBatteryIcon = (perc: number) => { @@ -74,19 +79,22 @@ const switchPane = (name: string) => { } }; -const OSIcon = () => ( +const spacerClassName = ({ beforeSpacer, afterSpacer }: SpacerClassNameProps) => + `${beforeSpacer ? "before-spacer" : ""} ${afterSpacer ? "after-spacer" : ""}`; + +const OSIcon = (props: SpacerClassNameProps) => ( ); -const ActiveWindow = () => ( +const ActiveWindow = (props: SpacerClassNameProps) => ( { const title = Variable(""); const updateTooltip = (c: AstalHyprland.Client | null) => @@ -124,7 +132,7 @@ const ActiveWindow = () => ( ); -const MediaPlaying = () => { +const MediaPlaying = (props: SpacerClassNameProps) => { const players = Players.get_default(); const getLabel = (fallback = "") => players.lastPlayer ? `${players.lastPlayer.title} - ${players.lastPlayer.artist}` : fallback; @@ -141,7 +149,7 @@ const MediaPlaying = () => { setupCustomTooltip(self, bind(label)); }} > - + players.hookLastPlayer(self, "notify::identity", () => { @@ -211,7 +219,7 @@ const Workspace = ({ idx }: { idx: number }) => { ); }; -const Workspaces = () => ( +const Workspaces = (props: SpacerClassNameProps) => ( { const activeWs = hyprland.focusedClient?.workspace.name; @@ -220,7 +228,7 @@ const Workspaces = () => ( hyprland.dispatch("workspace", (event.delta_y < 0 ? "-" : "+") + 1); }} > - + {bind(config.modules.workspaces.shown).as( n => Array.from({ length: n }).map((_, idx) => ) // Start from 1 )} @@ -241,10 +249,10 @@ const TrayItem = (item: AstalTray.TrayItem) => ( ); -const Tray = () => ( +const Tray = (props: SpacerClassNameProps) => ( i.length > 0)} > {bind(AstalTray.get_default(), "items").as(i => i.map(TrayItem))} @@ -420,14 +428,14 @@ const Bluetooth = () => ( ); -const StatusIcons = () => ( - +const StatusIcons = (props: SpacerClassNameProps) => ( + ); -const PkgUpdates = () => ( +const PkgUpdates = (props: SpacerClassNameProps) => ( ); -const NotifCount = () => ( +const NotifCount = (props: SpacerClassNameProps) => ( ); -const Battery = () => { +const Battery = (props: SpacerClassNameProps) => { const className = Variable.derive( [bind(AstalBattery.get_default(), "percentage"), bind(AstalBattery.get_default(), "charging")], - (p, c) => `module battery ${c ? "charging" : p < 0.2 ? "low" : ""}` + (p, c) => `module battery ${c ? "charging" : p < 0.2 ? "low" : ""} ${spacerClassName(props)}` ); const tooltip = Variable.derive( [bind(AstalBattery.get_default(), "timeToEmpty"), bind(AstalBattery.get_default(), "timeToFull")], @@ -500,14 +508,14 @@ const Battery = () => { ); }; -const DateTime = () => ( +const DateTime = (props: SpacerClassNameProps) => ( ); -const DateTimeVertical = () => ( +const DateTimeVertical = (props: SpacerClassNameProps) => ( ); -const Power = () => ( +const Power = (props: SpacerClassNameProps) => (