refactor: make the whole thing more generic

This commit is contained in:
2024-04-02 16:28:57 +02:00
parent 7b648e1955
commit 651f3ad808
193 changed files with 763 additions and 521 deletions

View File

@@ -0,0 +1,31 @@
import Hyprland from "resource:///com/github/Aylur/ags/service/hyprland.js";
import Applications from "resource:///com/github/Aylur/ags/service/applications.js";
import Widget from "resource:///com/github/Aylur/ags/widget.js";
import PanelButton from "../PanelButton.js";
import { launchApp } from "../../utils.js";
import icons from "../../icons.js";
const focus = ({ address }) =>
Hyprland.sendMessage(`dispatch focuswindow address:${address}`);
/** @param {import('types/widgets/box').default} box */
const setChildren = (box) =>
(box.children = Hyprland.clients.map((client) => {
if (Hyprland.active.workspace.id !== client.workspace.id) return;
for (const app of Applications.list) {
if (client.class && app.match(client.class)) {
return PanelButton({
content: Widget.Icon(app.icon_name || icons.fallback.executable),
tooltip_text: app.name,
on_primary_click: () => focus(client),
on_middle_click: () => launchApp(app),
});
}
}
}));
export default () =>
Widget.Box()
.hook(Hyprland, setChildren, "notify::clients")
.hook(Hyprland, setChildren, "notify::active");