From 11223860f7e3fed9058e8008fbebc80db97321fa Mon Sep 17 00:00:00 2001 From: matt1432 Date: Fri, 27 Sep 2024 13:56:39 -0400 Subject: [PATCH] fix(agsV2): use agsV1 logic for battery icons --- .../ags/v2/widgets/bar/items/battery.tsx | 24 ++++++++++++++----- nixosModules/ags/v2/widgets/bar/wim.tsx | 16 +++++++++---- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/nixosModules/ags/v2/widgets/bar/items/battery.tsx b/nixosModules/ags/v2/widgets/bar/items/battery.tsx index 880a5633..18d1040c 100644 --- a/nixosModules/ags/v2/widgets/bar/items/battery.tsx +++ b/nixosModules/ags/v2/widgets/bar/items/battery.tsx @@ -12,16 +12,28 @@ const SPACING = 5; export default () => ( { - Battery.connect('notify::percentage', () => { + const update = () => { const percent = Math.round(Battery.get_percentage() * 100); + const level = Math.floor(percent / 10) * 10; + const isCharging = Battery.get_charging(); + const charged = percent === 100 && isCharging; + const iconName = charged ? + 'battery-level-100-charged-symbolic' : + `battery-level-${level}${isCharging ? + '-charging' : + ''}-symbolic`; - self.toggleClassName('charging', Battery.get_charging()); - self.toggleClassName('charged', percent === 100); + self.set_icon(iconName); + + self.toggleClassName('charging', isCharging); + self.toggleClassName('charged', charged); self.toggleClassName('low', percent < LOW_BATT); - }); + }; + + update(); + + Battery.connect('notify::percentage', () => update()); }} /> diff --git a/nixosModules/ags/v2/widgets/bar/wim.tsx b/nixosModules/ags/v2/widgets/bar/wim.tsx index f090c785..558b9948 100644 --- a/nixosModules/ags/v2/widgets/bar/wim.tsx +++ b/nixosModules/ags/v2/widgets/bar/wim.tsx @@ -1,4 +1,4 @@ -import { Astal } from 'astal'; +import { Astal, Gtk } from 'astal'; import Battery from './items/battery'; @@ -15,9 +15,17 @@ export default () => { Astal.WindowAnchor.RIGHT } > - - - + + + + + + + + + + + ); };