ags(bar/status, control-center/tiles): hide bluetooth when no adapter found

This commit is contained in:
retrozinndev
2025-05-13 15:09:34 -03:00
parent 36d65e58ea
commit 028244adaa
3 changed files with 20 additions and 5 deletions
+8 -4
View File
@@ -2,7 +2,7 @@ import AstalBluetooth from "gi://AstalBluetooth";
import AstalNetwork from "gi://AstalNetwork";
import AstalWp from "gi://AstalWp";
import { bind, Variable } from "astal";
import { bind, Binding, Variable } from "astal";
import { Gtk, Widget } from "astal/gtk3";
import { Wireplumber } from "../../scripts/volume";
import { Notifications } from "../../scripts/notifications";
@@ -22,12 +22,14 @@ export function Status(): Gtk.Widget {
volumeStatus({
className: "sink",
endpoint: Wireplumber.getDefault().getDefaultSink(),
icon: "󰕾"
icon: bind(Wireplumber.getDefault().getDefaultSink(), "mute").as((muted) =>
!muted ? "󰕾" : "󰖁")
}),
volumeStatus({
className: "source",
endpoint: Wireplumber.getDefault().getDefaultSource(),
icon: "󰍬"
icon: bind(Wireplumber.getDefault().getDefaultSource(), "mute").as((muted) =>
!muted ? "󰍬" : "󰍭")
}),
StatusIcons()
]
@@ -35,7 +37,7 @@ export function Status(): Gtk.Widget {
} as Widget.EventBoxProps);
}
function volumeStatus(props: { className?: string, endpoint: AstalWp.Endpoint, icon: string }): Gtk.Widget {
function volumeStatus(props: { className?: string, endpoint: AstalWp.Endpoint, icon?: (string|Binding<string>) }): Gtk.Widget {
return new Widget.EventBox({
className: props.className,
onScroll: (_, event) =>
@@ -47,6 +49,7 @@ function volumeStatus(props: { className?: string, endpoint: AstalWp.Endpoint, i
children: [
new Widget.Label({
className: "nf",
visible: props.icon,
label: props.icon,
} as Widget.LabelProps),
new Widget.Label({
@@ -113,6 +116,7 @@ function StatusIcons(): Gtk.Widget {
children: [
new Widget.Label({
className: "bluetooth nf state",
visible: bind(AstalBluetooth.get_default(), "adapter").as(Boolean),
label: bluetoothIcon(),
onDestroy: () => bluetoothIcon.drop()
} as Widget.LabelProps),
+11 -1
View File
@@ -5,6 +5,7 @@ import { TileDND } from "./tiles/DoNotDisturb";
import { TileRecording } from "./tiles/Recording";
import { TileNightLight } from "./tiles/NightLight";
import { Pages } from "./Pages";
import { GObject } from "astal";
export const tileList: Array<() => Gtk.Widget> = [
TileNetwork,
@@ -29,10 +30,19 @@ export function Tiles(): Gtk.Widget {
} as Gtk.FlowBox.ConstructorProps);
tileList.map((item: (() => Gtk.Widget)) => {
tilesFlowBox.insert(item(), -1);
const tile = item();
tilesFlowBox.insert(tile, -1);
const children = tilesFlowBox.get_children();
children[children.length-1]!.set_can_focus(false);
const binding: GObject.Binding = tile.bind_property("visible",
children[children.length-1], "visible",
GObject.BindingFlags.SYNC_CREATE);
const destroyId: number = tile.connect("destroy-event", (self: typeof tile) => {
binding.unbind();
self.disconnect(destroyId);
});
});
return new Widget.Box({
@@ -7,6 +7,7 @@ import { TilesPages } from "../Tiles";
export const TileBluetooth = Tile({
title: "Bluetooth",
visible: bind(AstalBluetooth.get_default(), "adapter").as(Boolean),
description: bind(AstalBluetooth.get_default(), "isConnected").as((connected) => {
const connectedDev = AstalBluetooth.get_default().devices.filter(dev => dev.connected)?.[0];
return connected && connectedDev ? connectedDev.get_alias() : ""