From 579070733cf9605e96f045158ba56dcc5a9fdb80 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Wed, 2 Apr 2025 22:12:06 +1100 Subject: feat: define bar layout via config --- src/modules/bar.tsx | 185 +++++++++++++++++++++++++++++----------------------- 1 file changed, 103 insertions(+), 82 deletions(-) (limited to 'src/modules') diff --git a/src/modules/bar.tsx b/src/modules/bar.tsx index 386a1ba..c5a4fbb 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 { bind, kebabify } from "astal/binding"; -import { App, Astal, Gtk, type Widget } from "astal/gtk3"; +import { App, Astal, Gtk, Widget } from "astal/gtk3"; import { bar as config } from "config"; import AstalBattery from "gi://AstalBattery"; import AstalBluetooth from "gi://AstalBluetooth"; @@ -20,12 +20,14 @@ import AstalNotifd from "gi://AstalNotifd"; import AstalTray from "gi://AstalTray"; import AstalWp from "gi://AstalWp"; -interface SpacerClassNameProps { - beforeSpacer?: boolean; - afterSpacer?: boolean; +interface ClassNameProps { + beforeSpacer: boolean; + afterSpacer: boolean; + first: boolean; + last: boolean; } -interface ModuleProps extends SpacerClassNameProps { +interface ModuleProps extends ClassNameProps { monitor: Monitor; } @@ -83,13 +85,33 @@ const switchPane = (monitor: Monitor, name: string) => { } }; -const spacerClassName = ({ beforeSpacer, afterSpacer }: SpacerClassNameProps) => - `${beforeSpacer ? "before-spacer" : ""} ${afterSpacer ? "after-spacer" : ""}`; +const getClassName = ({ beforeSpacer, afterSpacer, first, last }: ClassNameProps) => + `${beforeSpacer ? "before-spacer" : ""} ${afterSpacer ? "after-spacer" : ""}` + + ` ${first ? "first" : ""} ${last ? "last" : ""}`; + +const getModule = (module: string) => { + module = module.toLowerCase(); + if (module === "osicon") return OSIcon; + if (module === "activewindow") return ActiveWindow; + if (module === "mediaplaying") return MediaPlaying; + if (module === "workspaces") return Workspaces; + if (module === "tray") return Tray; + if (module === "statusicons") return StatusIcons; + if (module === "pkgupdates") return PkgUpdates; + if (module === "notifcount") return NotifCount; + if (module === "battery") return Battery; + if (module === "datetime") return DateTime; + if (module === "power") return Power; + if (module === "brightnessspacer") return BrightnessSpacer; + if (module === "volumespacer") return VolumeSpacer; + return () => null; +}; + +const isSpacer = (module?: string) => module?.toLowerCase().endsWith("spacer") ?? false; const OSIcon = ({ monitor, ...props }: ModuleProps) => ( ); -const BluetoothDevice = (device: AstalBluetooth.Device) => ( +const BluetoothDevice = ({ monitor, device }: { monitor: Monitor; device: AstalBluetooth.Device }) => ( ); -const Bluetooth = () => ( +const Bluetooth = ({ monitor }: { monitor: Monitor }) => ( - {bind(AstalBluetooth.get_default(), "devices").as(d => d.map(BluetoothDevice))} + {bind(AstalBluetooth.get_default(), "devices").as(d => + d.map(d => ) + )} ); const StatusIcons = ({ monitor, ...props }: ModuleProps) => ( - - - + + + ); const PkgUpdates = ({ monitor, ...props }: ModuleProps) => (