feat(agsV2): implement battery widget
All checks were successful
Discord / discord commits (push) Has been skipped
All checks were successful
Discord / discord commits (push) Has been skipped
This commit is contained in:
parent
56e2caf76e
commit
79e6a55583
5 changed files with 51 additions and 5 deletions
|
@ -2,7 +2,7 @@ import { App } from 'astal';
|
||||||
|
|
||||||
import style from 'inline:./style.scss';
|
import style from 'inline:./style.scss';
|
||||||
|
|
||||||
import Bar from './widgets/bar/main';
|
import Bar from './widgets/bar/wim';
|
||||||
|
|
||||||
|
|
||||||
App.start({
|
App.start({
|
||||||
|
|
|
@ -112,7 +112,6 @@ export default ({
|
||||||
const vertical = anchor >= (Astal.WindowAnchor.LEFT | Astal.WindowAnchor.RIGHT);
|
const vertical = anchor >= (Astal.WindowAnchor.LEFT | Astal.WindowAnchor.RIGHT);
|
||||||
const isBottomOrLeft = (
|
const isBottomOrLeft = (
|
||||||
anchor === (Astal.WindowAnchor.LEFT | Astal.WindowAnchor.RIGHT | Astal.WindowAnchor.BOTTOM)
|
anchor === (Astal.WindowAnchor.LEFT | Astal.WindowAnchor.RIGHT | Astal.WindowAnchor.BOTTOM)
|
||||||
|
|
||||||
) || (
|
) || (
|
||||||
anchor === (Astal.WindowAnchor.LEFT | Astal.WindowAnchor.TOP | Astal.WindowAnchor.BOTTOM)
|
anchor === (Astal.WindowAnchor.LEFT | Astal.WindowAnchor.TOP | Astal.WindowAnchor.BOTTOM)
|
||||||
);
|
);
|
||||||
|
@ -158,8 +157,8 @@ export default ({
|
||||||
>
|
>
|
||||||
<box
|
<box
|
||||||
css="min-height: 1px; padding: 1px;"
|
css="min-height: 1px; padding: 1px;"
|
||||||
hexpand={true}
|
hexpand
|
||||||
hpack="fill"
|
halign={Gtk.Align.FILL}
|
||||||
vertical={vertical}
|
vertical={vertical}
|
||||||
>
|
>
|
||||||
{isBottomOrLeft ?
|
{isBottomOrLeft ?
|
||||||
|
|
31
nixosModules/ags/v2/widgets/bar/items/battery.tsx
Normal file
31
nixosModules/ags/v2/widgets/bar/items/battery.tsx
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
import { bind, Widget } from 'astal';
|
||||||
|
|
||||||
|
import AstalBattery from 'gi://AstalBattery';
|
||||||
|
const Battery = AstalBattery.get_default();
|
||||||
|
|
||||||
|
import Separator from '../../misc/separator';
|
||||||
|
|
||||||
|
|
||||||
|
const LOW_BATT = 20;
|
||||||
|
const SPACING = 5;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<box className="toggle-off battery">
|
||||||
|
<icon
|
||||||
|
class_name="battery-indicator"
|
||||||
|
icon={bind(Battery, 'batteryIconName')}
|
||||||
|
|
||||||
|
setup={(self: Widget.Icon) => {
|
||||||
|
Battery.connect('notify::percentage', () => {
|
||||||
|
self.toggleClassName('charging', Battery.get_charging());
|
||||||
|
self.toggleClassName('charged', Battery.get_percentage() === 100);
|
||||||
|
self.toggleClassName('low', Battery.get_percentage() < LOW_BATT);
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Separator size={SPACING} />
|
||||||
|
|
||||||
|
<label label={bind(Battery, 'percentage').as((v) => `${v}%`)} />
|
||||||
|
</box>
|
||||||
|
);
|
|
@ -1,5 +1,7 @@
|
||||||
import { Astal } from 'astal';
|
import { Astal } from 'astal';
|
||||||
|
|
||||||
|
import Battery from './items/battery';
|
||||||
|
|
||||||
import BarRevealer from './fullscreen';
|
import BarRevealer from './fullscreen';
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,7 +18,7 @@ export default () => {
|
||||||
<box
|
<box
|
||||||
className="Bar"
|
className="Bar"
|
||||||
>
|
>
|
||||||
<label label="hi" />
|
<Battery />
|
||||||
</box>
|
</box>
|
||||||
</BarRevealer>
|
</BarRevealer>
|
||||||
);
|
);
|
14
nixosModules/ags/v2/widgets/misc/separator.tsx
Normal file
14
nixosModules/ags/v2/widgets/misc/separator.tsx
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
import { Widget } from 'astal';
|
||||||
|
|
||||||
|
|
||||||
|
export default ({
|
||||||
|
size,
|
||||||
|
vertical = false,
|
||||||
|
css = '',
|
||||||
|
...rest
|
||||||
|
}: { size: number } & Widget.BoxProps) => (
|
||||||
|
<box
|
||||||
|
css={`${vertical ? 'min-height' : 'min-width'}: ${size}px; ${css}`}
|
||||||
|
{...rest}
|
||||||
|
/>
|
||||||
|
);
|
Loading…
Reference in a new issue