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 AstalNetwork from "gi://AstalNetwork";
import AstalWp from "gi://AstalWp"; import AstalWp from "gi://AstalWp";
import { bind, Variable } from "astal"; import { bind, Binding, Variable } from "astal";
import { Gtk, Widget } from "astal/gtk3"; import { Gtk, Widget } from "astal/gtk3";
import { Wireplumber } from "../../scripts/volume"; import { Wireplumber } from "../../scripts/volume";
import { Notifications } from "../../scripts/notifications"; import { Notifications } from "../../scripts/notifications";
@@ -22,12 +22,14 @@ export function Status(): Gtk.Widget {
volumeStatus({ volumeStatus({
className: "sink", className: "sink",
endpoint: Wireplumber.getDefault().getDefaultSink(), endpoint: Wireplumber.getDefault().getDefaultSink(),
icon: "󰕾" icon: bind(Wireplumber.getDefault().getDefaultSink(), "mute").as((muted) =>
!muted ? "󰕾" : "󰖁")
}), }),
volumeStatus({ volumeStatus({
className: "source", className: "source",
endpoint: Wireplumber.getDefault().getDefaultSource(), endpoint: Wireplumber.getDefault().getDefaultSource(),
icon: "󰍬" icon: bind(Wireplumber.getDefault().getDefaultSource(), "mute").as((muted) =>
!muted ? "󰍬" : "󰍭")
}), }),
StatusIcons() StatusIcons()
] ]
@@ -35,7 +37,7 @@ export function Status(): Gtk.Widget {
} as Widget.EventBoxProps); } 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({ return new Widget.EventBox({
className: props.className, className: props.className,
onScroll: (_, event) => onScroll: (_, event) =>
@@ -47,6 +49,7 @@ function volumeStatus(props: { className?: string, endpoint: AstalWp.Endpoint, i
children: [ children: [
new Widget.Label({ new Widget.Label({
className: "nf", className: "nf",
visible: props.icon,
label: props.icon, label: props.icon,
} as Widget.LabelProps), } as Widget.LabelProps),
new Widget.Label({ new Widget.Label({
@@ -113,6 +116,7 @@ function StatusIcons(): Gtk.Widget {
children: [ children: [
new Widget.Label({ new Widget.Label({
className: "bluetooth nf state", className: "bluetooth nf state",
visible: bind(AstalBluetooth.get_default(), "adapter").as(Boolean),
label: bluetoothIcon(), label: bluetoothIcon(),
onDestroy: () => bluetoothIcon.drop() onDestroy: () => bluetoothIcon.drop()
} as Widget.LabelProps), } as Widget.LabelProps),
+11 -1
View File
@@ -5,6 +5,7 @@ import { TileDND } from "./tiles/DoNotDisturb";
import { TileRecording } from "./tiles/Recording"; import { TileRecording } from "./tiles/Recording";
import { TileNightLight } from "./tiles/NightLight"; import { TileNightLight } from "./tiles/NightLight";
import { Pages } from "./Pages"; import { Pages } from "./Pages";
import { GObject } from "astal";
export const tileList: Array<() => Gtk.Widget> = [ export const tileList: Array<() => Gtk.Widget> = [
TileNetwork, TileNetwork,
@@ -29,10 +30,19 @@ export function Tiles(): Gtk.Widget {
} as Gtk.FlowBox.ConstructorProps); } as Gtk.FlowBox.ConstructorProps);
tileList.map((item: (() => Gtk.Widget)) => { tileList.map((item: (() => Gtk.Widget)) => {
tilesFlowBox.insert(item(), -1); const tile = item();
tilesFlowBox.insert(tile, -1);
const children = tilesFlowBox.get_children(); const children = tilesFlowBox.get_children();
children[children.length-1]!.set_can_focus(false); 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({ return new Widget.Box({
@@ -7,6 +7,7 @@ import { TilesPages } from "../Tiles";
export const TileBluetooth = Tile({ export const TileBluetooth = Tile({
title: "Bluetooth", title: "Bluetooth",
visible: bind(AstalBluetooth.get_default(), "adapter").as(Boolean),
description: bind(AstalBluetooth.get_default(), "isConnected").as((connected) => { description: bind(AstalBluetooth.get_default(), "isConnected").as((connected) => {
const connectedDev = AstalBluetooth.get_default().devices.filter(dev => dev.connected)?.[0]; const connectedDev = AstalBluetooth.get_default().devices.filter(dev => dev.connected)?.[0];
return connected && connectedDev ? connectedDev.get_alias() : "" return connected && connectedDev ? connectedDev.get_alias() : ""