From 5b073fa9d6292badfcdcd343f68a72c1b3bf10f1 Mon Sep 17 00:00:00 2001 From: Franek Date: Sun, 18 May 2025 20:09:31 +0200 Subject: [PATCH] add(ags/bar): network section + tweak styles --- ags/lib/utils.ts | 20 ++++- ags/lib/widgets/separator.tsx | 8 ++ ags/styles/classes.scss | 5 ++ ags/styles/components/_bar.scss | 6 +- ags/widget/bar/bar.tsx | 20 +++-- ags/widget/bar/components/network_info.tsx | 77 +++++++++++++++++++ ags/widget/bar/{ => components}/tray.tsx | 0 ags/widget/bar/{ => components}/workspace.tsx | 0 ags/widget/launcher/clipboard.tsx | 3 +- 9 files changed, 127 insertions(+), 12 deletions(-) create mode 100644 ags/lib/widgets/separator.tsx create mode 100644 ags/widget/bar/components/network_info.tsx rename ags/widget/bar/{ => components}/tray.tsx (100%) rename ags/widget/bar/{ => components}/workspace.tsx (100%) diff --git a/ags/lib/utils.ts b/ags/lib/utils.ts index 682935e..a815f11 100644 --- a/ags/lib/utils.ts +++ b/ags/lib/utils.ts @@ -60,4 +60,22 @@ export const skip = (list: T[], items: number) => list.filter((_, i) => { if (items > (list.length - 1)) items = list.length; return i > (items - 1); -}); \ No newline at end of file +}); + +export const toHumanReadable = (bytes: number, unit: string, fractionDigits = 1) => { + const div = 1024; + if (Math.abs(bytes) < div) { + return bytes.toFixed(fractionDigits) + unit; + } + + const units = ["ki", "Mi", "Gi", "Ti"]; + let u = -1; + const r = 10 ** fractionDigits; + + while (Math.round(Math.abs(bytes) * r) / r >= div && u < units.length) { + bytes /= div; + u++; + } + + return bytes.toFixed(fractionDigits) + units[u] + unit; +} \ No newline at end of file diff --git a/ags/lib/widgets/separator.tsx b/ags/lib/widgets/separator.tsx new file mode 100644 index 0000000..8be585d --- /dev/null +++ b/ags/lib/widgets/separator.tsx @@ -0,0 +1,8 @@ +import { Gio } from "astal"; + +export default function Separator() { + return +} \ No newline at end of file diff --git a/ags/styles/classes.scss b/ags/styles/classes.scss index ea38489..f325cb0 100644 --- a/ags/styles/classes.scss +++ b/ags/styles/classes.scss @@ -1,6 +1,11 @@ +@use './theme_colors.scss' as *; @use '_variables' as *; @use 'mixins'; .material-icon { @include mixins.material-icon; } + +.separator { + color: $base05; +} \ No newline at end of file diff --git a/ags/styles/components/_bar.scss b/ags/styles/components/_bar.scss index 1f3c2f7..428adf2 100644 --- a/ags/styles/components/_bar.scss +++ b/ags/styles/components/_bar.scss @@ -2,7 +2,7 @@ window.bar { font-weight: bold; - + >box { border-radius: 10px; } @@ -11,10 +11,10 @@ window.bar { border-bottom-left-radius: 0; border-bottom-right-radius: 0; background: $base00; - padding: 0.25rem 1rem; + padding: 0rem 1rem; margin: 0; - * { color: $base0B; } + *:not(.separator) { color: $base0B; } } .tray .item { diff --git a/ags/widget/bar/bar.tsx b/ags/widget/bar/bar.tsx index dc5ddbb..9e8099d 100644 --- a/ags/widget/bar/bar.tsx +++ b/ags/widget/bar/bar.tsx @@ -1,12 +1,13 @@ -import { App, Astal, Gdk, Gtk } from "astal/gtk4" -import { Binding } from "astal" +import { App, Astal, Gdk, Gtk } from "astal/gtk4"; import Battery from "gi://AstalBattery"; +import NetworkInfo from "./components/network_info"; import { BatteryInfo } from "./components/battery"; +import Workspace from "./components/workspace"; import DateTime from "@lib/widgets/datetime"; -import Workspace from "./workspace"; -import TrayView from "./tray"; +import TrayView from "./components/tray"; +import Separator from "@/lib/widgets/separator"; export default function Bar(monitor_id: number) { const { BOTTOM, LEFT, RIGHT } = Astal.WindowAnchor @@ -21,8 +22,8 @@ export default function Bar(monitor_id: number) { return , BatteryInfo({ battery }),