home/natto/ags: init

Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
2024-06-01 17:59:52 +05:30
parent 00ea23f65c
commit c86fb8b6d3
37 changed files with 1658 additions and 33 deletions

View File

@@ -0,0 +1,19 @@
const bluetooth = await Service.import("bluetooth");
export default () =>
Widget.Icon({
setup: (self) =>
self.hook(
bluetooth,
(self) => {
self.tooltipText = bluetooth.connected_devices
.map(({ name }) => name)
.join("\n");
self.visible = bluetooth.connected_devices.length > 0;
},
"notify::connected-devices",
),
icon: bluetooth
.bind("enabled")
.as((on) => `bluetooth-${on ? "active" : "disabled"}-symbolic`),
});

View File

@@ -0,0 +1,38 @@
const hyprland = await Service.import("hyprland");
const gurmukhiNums = {
1: "",
2: "੨",
3: "੩",
4: "",
5: "੫",
6: "੬",
7: "੭",
8: "੮",
9: "੯",
10: "",
};
export default () => {
const activeId = hyprland.active.workspace.bind("id");
const workspaces = hyprland.bind("workspaces").as((ws) =>
ws
.sort((a, b) => a.id - b.id)
.map(({ id }) =>
Widget.Button({
onClicked: () => hyprland.messageAsync(`dispatch workspace ${id}`),
child: Widget.Label(gurmukhiNums[id]),
className: activeId.as(
(i) => `${i === id ? "focused" : "unfocused"}`,
),
cursor: "pointer",
}),
),
);
return Widget.Box({
css: "padding: 1px;",
className: "hyprland",
children: workspaces,
});
};

View File

@@ -0,0 +1,56 @@
import Hyprland from "./hyprland.js";
import Music from "./music.js";
import Tray from "./tray.js";
import Time from "./time.js";
import Network from "./network.js";
import Bluetooth from "./bluetooth.js";
import Settings from "./settings.js";
import { WindowNames } from "../../constants.js";
const { BAR } = WindowNames;
const Left = () => {
return Widget.Box({
className: "bar-left",
spacing: 8,
children: [Hyprland()],
});
};
const Center = (monitor) => {
return Widget.Box({
className: "bar-center",
spacing: 8,
children: [Music(monitor)],
});
};
const Right = (monitor) => {
return Widget.Box({
className: "bar-right",
hpack: "end",
spacing: 10,
children: [
Tray(),
Bluetooth(),
Network(),
Time(monitor),
Settings(monitor),
],
});
};
export default (monitor = 0) =>
Widget.Window({
name: `${BAR}-${monitor}`,
className: BAR,
monitor,
anchor: ["top", "left", "right"],
exclusivity: "exclusive",
child: Widget.CenterBox({
startWidget: Left(),
centerWidget: Center(monitor),
endWidget: Right(monitor),
}),
});

View File

@@ -0,0 +1,65 @@
import Controls from "../music-box/music-controls.js";
import { shrinkText } from "../../utils/text.js";
import { findPlayer } from "../../utils/music.js";
import { WindowNames } from "../../constants.js";
const mpris = await Service.import("mpris");
const players = mpris.bind("players");
/** @param {import('types/service/mpris').MprisPlayer} player */
const Player = (player, monitor) => {
const revealer = Widget.Revealer({
revealChild: false,
transitionDuration: 300,
transition: "slide_left",
child: Controls(player),
});
return Widget.EventBox({
visible: player.bus_name === findPlayer(mpris.players).bus_name,
cursor: "pointer",
setup: (self) => {
self.on("leave-notify-event", () => {
revealer.reveal_child = false;
});
self.on("enter-notify-event", () => {
revealer.reveal_child = true;
});
},
child: Widget.Box({
className: "music",
children: [
Widget.Button({
onClicked: () =>
App.toggleWindow(`${WindowNames.MUSIC_BOX}-${monitor}`),
className: "music-title",
child: Widget.Label().hook(player, (self) => {
self.tooltip_text = player.track_title;
self.label = shrinkText(self.tooltip_text, 50);
}),
}),
revealer,
],
}),
})
.hook(
mpris,
(self, bus_name) => {
self.visible = player.bus_name === bus_name;
},
"player-changed",
)
.hook(
mpris,
(self) => {
self.visible = player === findPlayer(mpris.players);
},
"player-closed",
);
};
export default (monitor) =>
Widget.Box({
visible: players.as((p) => p.length > 0),
children: players.as((ps) => ps.map((p) => Player(p, monitor))),
});

View File

@@ -0,0 +1,40 @@
const network = await Service.import("network");
const WifiIndicator = () =>
Widget.Box({
tooltipText: network.wifi.bind("state").as((s) => `State: ${s}`),
children: [
Widget.Icon({
className: "network-icon",
icon: network.wifi.bind("icon_name"),
}),
Widget.Label({
visible: network.wifi.bind("ssid"),
label: network.wifi.bind("ssid"),
}),
],
});
const WiredIndicator = () =>
Widget.Icon({
className: "network-icon",
tooltipText: network.wired.bind("internet").as((a) => `Internet: ${a}`),
icon: network.wired.bind("icon_name"),
});
export default () =>
Widget.Stack({
className: "network",
children: {
wifi: WifiIndicator(),
wired: WiredIndicator(),
},
shown: Utils.merge(
[network.bind("primary"), network.wired.bind("state")],
(primary, wired) => {
if (primary) return primary;
if (wired == "activated") return "wired";
return "wifi";
},
),
});

View File

@@ -0,0 +1,8 @@
import { WindowNames } from "../../constants.js";
export default (monitor) =>
Widget.Button({
child: Widget.Icon("open-menu-symbolic"),
onPrimaryClick: () =>
App.toggleWindow(`${WindowNames.SETTINGS}-${monitor}`),
});

View File

@@ -0,0 +1,42 @@
const time = Variable("", {
poll: [1000, 'date "+%H:%M:%S"'],
});
const getDate = () => " " + Utils.exec('date "+%a, %b %e"');
const date = Variable(getDate());
export default () => {
const revealer = Widget.Revealer({
revealChild: false,
transitionDuration: 300,
transition: "slide_left",
child: Widget.Label({
label: date.bind(),
}),
});
return Widget.EventBox({
cursor: "pointer",
setup: (self) => {
self.on("leave-notify-event", () => {
revealer.reveal_child = false;
});
self.on("enter-notify-event", () => {
date.value = getDate();
revealer.reveal_child = true;
});
},
child: Widget.Button({
className: "date-wrapper",
onPrimaryClick: () => App.toggleWindow("calendar-0"),
child: Widget.Box({
children: [
Widget.Label({
label: time.bind(),
}),
revealer,
],
}),
}),
});
};

View File

@@ -0,0 +1,17 @@
const systemtray = await Service.import("systemtray");
const SysTrayItem = (item) =>
Widget.Button({
className: "system-tray-item",
child: Widget.Icon().bind("icon", item, "icon"),
tooltipMarkup: item.bind("tooltip_markup"),
onPrimaryClick: (_, event) => item.activate(event),
onSecondaryClick: (_, event) => item.openMenu(event),
cursor: "pointer",
});
export default () =>
Widget.Box({
className: "system-tray-unwrapped",
children: systemtray.bind("items").as((i) => i.map(SysTrayItem)),
});