testing ags
This commit is contained in:
52
home/core/gui/ags/windows/system-menu/battery_info.js
Normal file
52
home/core/gui/ags/windows/system-menu/battery_info.js
Normal file
@@ -0,0 +1,52 @@
|
||||
import { App, Battery, Icons, Utils, Widget } from "../../imports.js";
|
||||
import { batteryTime } from "../../utils/battery.js";
|
||||
|
||||
const batteryEnergy = () => {
|
||||
return Battery.energyRate > 0.1 ? `${Battery.energyRate.toFixed(1)} W ` : "";
|
||||
};
|
||||
|
||||
const BatteryIcon = () =>
|
||||
Widget.Icon()
|
||||
.bind("icon", Battery, "percent", () => Battery.iconName)
|
||||
.bind("tooltip-text", Battery, "energy-rate", batteryEnergy);
|
||||
|
||||
const BatteryPercent = () =>
|
||||
Widget.Label().bind("label", Battery, "percent", (percent) => `${percent}%`);
|
||||
|
||||
const BatteryTime = () =>
|
||||
Widget.Label({
|
||||
className: "time",
|
||||
vexpand: true,
|
||||
vpack: "center",
|
||||
})
|
||||
.bind("label", Battery, "charging", batteryTime)
|
||||
.bind("label", Battery, "energy-rate", batteryTime);
|
||||
|
||||
const BatteryBox = () =>
|
||||
Widget.Box({
|
||||
className: "battery-box",
|
||||
visible: Battery.available,
|
||||
|
||||
children: [BatteryIcon(), BatteryPercent(), BatteryTime()],
|
||||
});
|
||||
|
||||
const PowerButton = () =>
|
||||
Widget.Button({
|
||||
className: "button disabled",
|
||||
hexpand: true,
|
||||
hpack: "end",
|
||||
|
||||
onPrimaryClick: () => {
|
||||
App.toggleWindow("system-menu");
|
||||
Utils.exec("wlogout");
|
||||
},
|
||||
|
||||
child: Widget.Icon(Icons.powerButton),
|
||||
});
|
||||
|
||||
export default () =>
|
||||
Widget.Box({
|
||||
className: "battery-info",
|
||||
|
||||
children: [BatteryBox(), PowerButton()],
|
||||
});
|
||||
22
home/core/gui/ags/windows/system-menu/main.js
Normal file
22
home/core/gui/ags/windows/system-menu/main.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Widget } from "../../imports.js";
|
||||
import PopupWindow from "../../utils/popup_window.js";
|
||||
|
||||
import Toggles from "./toggles.js";
|
||||
import Sliders from "./sliders.js";
|
||||
import BatteryInfo from "./battery_info.js";
|
||||
|
||||
const SystemMenuBox = () =>
|
||||
Widget.Box({
|
||||
className: "system-menu",
|
||||
vertical: true,
|
||||
|
||||
children: [Toggles(), Sliders(), BatteryInfo()],
|
||||
});
|
||||
|
||||
export default () =>
|
||||
PopupWindow({
|
||||
monitor: 0,
|
||||
anchor: ["top", "right"],
|
||||
name: "system-menu",
|
||||
child: SystemMenuBox(),
|
||||
});
|
||||
74
home/core/gui/ags/windows/system-menu/sliders.js
Normal file
74
home/core/gui/ags/windows/system-menu/sliders.js
Normal file
@@ -0,0 +1,74 @@
|
||||
import { App, Audio, Icons, Utils, Widget } from "../../imports.js";
|
||||
import Brightness from "../../services/brightness.js";
|
||||
import { audioIcon } from "../../utils/audio.js";
|
||||
|
||||
const Slider = (args) =>
|
||||
Widget.Box({
|
||||
...(args.props ?? {}),
|
||||
className: args.name,
|
||||
|
||||
children: [
|
||||
Widget.Button({
|
||||
onPrimaryClick: args.icon.action ?? null,
|
||||
child: Widget.Icon({
|
||||
icon: args.icon.icon ?? "",
|
||||
setup: args.icon.setup,
|
||||
}),
|
||||
}),
|
||||
Widget.Slider({
|
||||
drawValue: false,
|
||||
hexpand: true,
|
||||
setup: args.slider.setup,
|
||||
onChange: args.slider.onChange ?? null,
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
const vol = () => {
|
||||
return {
|
||||
name: "volume",
|
||||
icon: {
|
||||
icon: "",
|
||||
action: () => {
|
||||
App.toggleWindow("system-menu");
|
||||
Utils.execAsync("pwvucontrol");
|
||||
},
|
||||
setup: (self) =>
|
||||
self
|
||||
.bind("icon", Audio.speaker, "volume", audioIcon)
|
||||
.bind("icon", Audio.speaker.stream, "is-muted", audioIcon),
|
||||
},
|
||||
slider: {
|
||||
setup: (self) => self.bind("value", Audio.speaker, "volume"),
|
||||
onChange: ({ value }) => (Audio.speaker.volume = value),
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
const brightness = () => {
|
||||
return {
|
||||
name: "brightness",
|
||||
icon: {
|
||||
icon: Icons.brightness,
|
||||
},
|
||||
slider: {
|
||||
setup: (self) => self.bind("value", Brightness, "screen-value"),
|
||||
onChange: ({ value }) => (Brightness.screenValue = value),
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default () =>
|
||||
Widget.Box({
|
||||
className: "sliders",
|
||||
vertical: true,
|
||||
|
||||
// The Audio service is ready later than ags is done parsing the config,
|
||||
// so only build the widget when we receive a signal from it.
|
||||
setup: (self) => {
|
||||
const connID = Audio.connect("notify::speaker", () => {
|
||||
Audio.disconnect(connID);
|
||||
self.children = [Slider(vol()), Slider(brightness())];
|
||||
});
|
||||
},
|
||||
});
|
||||
102
home/core/gui/ags/windows/system-menu/toggles.js
Normal file
102
home/core/gui/ags/windows/system-menu/toggles.js
Normal file
@@ -0,0 +1,102 @@
|
||||
import { App, Bluetooth, Network, Utils, Widget } from "../../imports.js";
|
||||
|
||||
import { getNetIcon, getNetText } from "../../utils/net.js";
|
||||
import { getBluetoothIcon, getBluetoothText } from "../../utils/bluetooth.js";
|
||||
|
||||
const Toggle = (args) =>
|
||||
Widget.Box({
|
||||
...(args.props ?? {}),
|
||||
className: `toggle ${args.name}`,
|
||||
hexpand: true,
|
||||
hpack: "start",
|
||||
|
||||
children: [
|
||||
Widget.Button({
|
||||
className: "button",
|
||||
|
||||
child: Widget.Icon({
|
||||
setup: args.icon.setup,
|
||||
}),
|
||||
setup: args.icon.buttonSetup,
|
||||
}),
|
||||
Widget.Button({
|
||||
hexpand: true,
|
||||
child: Widget.Label({
|
||||
hpack: "start",
|
||||
setup: args.label.setup,
|
||||
}),
|
||||
setup: args.label.buttonSetup,
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
const net = {
|
||||
name: "net",
|
||||
icon: {
|
||||
setup: (self) =>
|
||||
self
|
||||
.bind("icon", Network, "connectivity", getNetIcon)
|
||||
.bind("icon", Network.wifi, "icon-name", getNetIcon),
|
||||
|
||||
buttonSetup: (self) => {
|
||||
self.onPrimaryClick = () => Network.toggleWifi();
|
||||
self.hook(
|
||||
Network,
|
||||
(btn) =>
|
||||
btn.toggleClassName("disabled", Network.connectivity != "full"),
|
||||
"notify::connectivity",
|
||||
);
|
||||
},
|
||||
},
|
||||
label: {
|
||||
setup: (self) =>
|
||||
self
|
||||
.bind("label", Network, "connectivity", () => getNetText())
|
||||
.bind("label", Network.wifi, "ssid", () => getNetText()),
|
||||
|
||||
buttonSetup: (self) => {
|
||||
self.onPrimaryClick = () => {
|
||||
App.toggleWindow("system-menu");
|
||||
Utils.execAsync([
|
||||
"sh",
|
||||
"-c",
|
||||
"XDG_CURRENT_DESKTOP=GNOME gnome-control-center",
|
||||
]);
|
||||
};
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const bt = {
|
||||
name: "bluetooth",
|
||||
icon: {
|
||||
setup: (self) =>
|
||||
self.bind("icon", Bluetooth, "connected-devices", getBluetoothIcon),
|
||||
buttonSetup: (self) => {
|
||||
self.onPrimaryClick = () => Bluetooth.toggle();
|
||||
self.hook(
|
||||
Bluetooth,
|
||||
(btn) => btn.toggleClassName("disabled", !Bluetooth.enabled),
|
||||
"notify::enabled",
|
||||
);
|
||||
},
|
||||
},
|
||||
label: {
|
||||
setup: (self) =>
|
||||
self.bind("label", Bluetooth, "connected-devices", getBluetoothText),
|
||||
buttonSetup: (self) => {
|
||||
self.onPrimaryClick = () => {
|
||||
App.toggleWindow("system-menu");
|
||||
Utils.execAsync("overskride");
|
||||
};
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default () =>
|
||||
Widget.Box({
|
||||
className: "toggles",
|
||||
vertical: true,
|
||||
|
||||
children: [Toggle(net), Toggle(bt)],
|
||||
});
|
||||
Reference in New Issue
Block a user