✨ ags(control-center/bluetooth): add more device management options
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { bind } from "astal";
|
||||
import { bind, Variable } from "astal";
|
||||
import { Gtk, Widget } from "astal/gtk3";
|
||||
import AstalBluetooth from "gi://AstalBluetooth";
|
||||
import { Page, PageButton } from "./Page";
|
||||
@@ -97,6 +97,7 @@ export const BluetoothPage: (() => Page) = () => new Page({
|
||||
Separator({
|
||||
size: .2,
|
||||
orientation: Gtk.Orientation.VERTICAL,
|
||||
cssColor: "gray",
|
||||
alpha: .2
|
||||
} as SeparatorProps),
|
||||
new Widget.Button({
|
||||
@@ -135,18 +136,63 @@ function DeviceWidget(dev: AstalBluetooth.Device): Gtk.Widget {
|
||||
endWidget: new Widget.Box({
|
||||
visible: bind(dev, "batteryPercentage").as((bat: number) =>
|
||||
bat <= -1 ? false : true),
|
||||
children: [
|
||||
new Widget.Label({
|
||||
halign: Gtk.Align.END,
|
||||
label: bind(dev, "batteryPercentage").as((bat: number) =>
|
||||
`${Math.floor(bat * 100)}%`)
|
||||
} as Widget.LabelProps),
|
||||
new Widget.Icon({
|
||||
icon: "battery-symbolic",
|
||||
css: "font-size: 18px; margin-left: 6px;"
|
||||
} as Widget.IconProps)
|
||||
]
|
||||
} as Widget.BoxProps)
|
||||
children: Variable.derive([
|
||||
bind(dev, "connecting"),
|
||||
bind(dev, "connected")
|
||||
], (connecting, connected) => {
|
||||
if(connected) return [
|
||||
new Widget.Label({
|
||||
halign: Gtk.Align.END,
|
||||
label: bind(dev, "batteryPercentage").as((bat: number) =>
|
||||
`${Math.floor(bat * 100)}%`)
|
||||
} as Widget.LabelProps),
|
||||
new Widget.Icon({
|
||||
icon: "battery-symbolic",
|
||||
css: "font-size: 18px; margin-left: 6px;"
|
||||
} as Widget.IconProps)
|
||||
];
|
||||
|
||||
if(connecting) {
|
||||
const spinner = new Gtk.Spinner({
|
||||
visible: true
|
||||
} as Gtk.Spinner.ConstructorProps);
|
||||
spinner.start();
|
||||
|
||||
return spinner;
|
||||
}
|
||||
|
||||
return [];
|
||||
})()
|
||||
} as Widget.BoxProps),
|
||||
extraButtons: Variable.derive([
|
||||
bind(dev, "connected"),
|
||||
bind(dev, "paired"),
|
||||
bind(dev, "trusted")
|
||||
], (connected, paired, trusted) => [
|
||||
new Widget.Button({
|
||||
className: "nf",
|
||||
visible: paired && connected,
|
||||
label: connected ? "" : "",
|
||||
tooltipText: tr("disconnect"),
|
||||
onClick: () => dev.disconnect_device()
|
||||
} as Widget.ButtonProps),
|
||||
new Widget.Button({
|
||||
visible: !connected && paired,
|
||||
className: "nf",
|
||||
label: "",
|
||||
tooltipText: tr("control_center.pages.bluetooth.unpair_device"),
|
||||
onClick: () => AstalBluetooth.get_default().adapter?.remove_device(dev)
|
||||
} as Widget.ButtonProps),
|
||||
new Widget.Button({
|
||||
className: "nf",
|
||||
visible: paired,
|
||||
label: trusted ? "" : "",
|
||||
tooltipText: trusted ?
|
||||
tr("control_center.pages.bluetooth.untrust_device")
|
||||
: tr("control_center.pages.bluetooth.trust_device"),
|
||||
onClick: () => trusted ? dev.set_trusted(false) : dev.set_trusted(true)
|
||||
} as Widget.ButtonProps)
|
||||
])()
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -95,13 +95,13 @@ export function PageButton(props: {
|
||||
className?: string | Binding<string>;
|
||||
icon?: string | Binding<string>;
|
||||
title: string | Binding<string>;
|
||||
endWidget?: Gtk.Widget;
|
||||
extraButtons?: Array<Widget.Button>;
|
||||
endWidget?: Gtk.Widget | Binding<Gtk.Widget>;
|
||||
extraButtons?: Array<Widget.Button> | Binding<Array<Gtk.Widget>>;
|
||||
onClick?: (self: Widget.Button) => void;
|
||||
}): Gtk.Widget {
|
||||
return new Widget.Box({
|
||||
setup: (self) => {
|
||||
self.add(new Widget.Button({
|
||||
children: [
|
||||
new Widget.Button({
|
||||
onClick: props.onClick,
|
||||
className: props.className,
|
||||
hexpand: true,
|
||||
@@ -109,32 +109,36 @@ export function PageButton(props: {
|
||||
className: "page-button",
|
||||
orientation: Gtk.Orientation.HORIZONTAL,
|
||||
expand: true,
|
||||
setup: (box) => {
|
||||
box.set_children([
|
||||
new Widget.Icon({
|
||||
className: "icon",
|
||||
icon: props.icon,
|
||||
visible: props.icon,
|
||||
css: "font-size: 20px; margin-right: 6px;"
|
||||
} as Widget.IconProps),
|
||||
new Widget.Label({
|
||||
className: "title",
|
||||
halign: Gtk.Align.START,
|
||||
hexpand: true,
|
||||
truncate: true,
|
||||
label: props.title
|
||||
} as Widget.LabelProps)
|
||||
]);
|
||||
|
||||
props.endWidget && box.add(props.endWidget);
|
||||
}
|
||||
children: [
|
||||
new Widget.Icon({
|
||||
className: "icon",
|
||||
icon: props.icon,
|
||||
visible: props.icon,
|
||||
css: "font-size: 20px; margin-right: 6px;"
|
||||
} as Widget.IconProps),
|
||||
new Widget.Label({
|
||||
className: "title",
|
||||
halign: Gtk.Align.START,
|
||||
hexpand: true,
|
||||
truncate: true,
|
||||
label: props.title
|
||||
} as Widget.LabelProps),
|
||||
new Widget.Box({
|
||||
visible: (props.endWidget instanceof Binding) ?
|
||||
props.endWidget.as(Boolean)
|
||||
: props.endWidget,
|
||||
child: props.endWidget
|
||||
} as Widget.BoxProps)
|
||||
]
|
||||
} as Widget.BoxProps)
|
||||
} as Widget.ButtonProps));
|
||||
|
||||
props.extraButtons && self.add(new Widget.Box({
|
||||
} as Widget.ButtonProps),
|
||||
new Widget.Box({
|
||||
className: "button-row extra-buttons",
|
||||
visible: (props.extraButtons instanceof Binding) ?
|
||||
props.extraButtons.as(extra => extra.length > 0)
|
||||
: (props.extraButtons ? props.extraButtons.length > 0 : false),
|
||||
children: props.extraButtons
|
||||
} as Widget.BoxProps));
|
||||
}
|
||||
} as Widget.BoxProps)
|
||||
]
|
||||
} as Widget.BoxProps);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user