This commit is contained in:
Nico
2024-10-31 10:33:46 +01:00
commit ad6d893cb0
237 changed files with 19793 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
# Application Launcher
setup
```bash
mkdir -p ~/.config/ags
git clone https://github.com/Aylur/ags.git /tmp/ags
cp -r /tmp/ags/example/applauncher/* ~/.config/ags
# optionally setup types
ags --init -c ~/.config/ags/config.js
```
running
```bash
ags -c ~/.config/ags/config.js &
ags -t applauncher
```

View File

@@ -0,0 +1,107 @@
const { query } = await Service.import("applications")
const WINDOW_NAME = "applauncher"
/** @param {import('resource:///com/github/Aylur/ags/service/applications.js').Application} app */
const AppItem = app => Widget.Button({
on_clicked: () => {
App.closeWindow(WINDOW_NAME)
app.launch()
},
attribute: { app },
child: Widget.Box({
children: [
Widget.Icon({
icon: app.icon_name || "",
size: 42,
}),
Widget.Label({
class_name: "title",
label: app.name,
xalign: 0,
vpack: "center",
truncate: "end",
}),
],
}),
})
const Applauncher = ({ width = 500, height = 500, spacing = 12 }) => {
// list of application buttons
let applications = query("").map(AppItem)
// container holding the buttons
const list = Widget.Box({
vertical: true,
children: applications,
spacing,
})
// repopulate the box, so the most frequent apps are on top of the list
function repopulate() {
applications = query("").map(AppItem)
list.children = applications
}
// search entry
const entry = Widget.Entry({
hexpand: true,
css: `margin-bottom: ${spacing}px;`,
// to launch the first item on Enter
on_accept: () => {
// make sure we only consider visible (searched for) applications
const results = applications.filter((item) => item.visible);
if (results[0]) {
App.toggleWindow(WINDOW_NAME)
results[0].attribute.app.launch()
}
},
// filter out the list
on_change: ({ text }) => applications.forEach(item => {
item.visible = item.attribute.app.match(text ?? "")
}),
})
return Widget.Box({
vertical: true,
css: `margin: ${spacing * 2}px;`,
children: [
entry,
// wrap the list in a scrollable
Widget.Scrollable({
hscroll: "never",
css: `min-width: ${width}px;`
+ `min-height: ${height}px;`,
child: list,
}),
],
setup: self => self.hook(App, (_, windowName, visible) => {
if (windowName !== WINDOW_NAME)
return
// when the applauncher shows up
if (visible) {
repopulate()
entry.text = ""
entry.grab_focus()
}
}),
})
}
// there needs to be only one instance
export const applauncher = Widget.Window({
name: WINDOW_NAME,
setup: self => self.keybind("Escape", () => {
App.closeWindow(WINDOW_NAME)
}),
visible: false,
keymode: "exclusive",
child: Applauncher({
width: 500,
height: 500,
spacing: 12,
}),
})

View File

@@ -0,0 +1,5 @@
import { applauncher } from "./applauncher.js"
App.config({
windows: [applauncher],
})

View File

@@ -0,0 +1,6 @@
# Icon Browser
```bash
chmod +x icon-browser.js
./icon-browser.js
```

View File

@@ -0,0 +1,73 @@
#!/usr/bin/env -S ags -b icon-browser -c
import Gtk from "gi://Gtk?version=3.0"
const IconPicker = () => {
const selected = Widget.Label({
css: "font-size: 1.2em;",
label: "Click on an icon te get its name",
selectable: true,
})
const flowbox = Widget.FlowBox({
min_children_per_line: 7,
row_spacing: 12,
column_spacing: 12,
vpack: "start",
hpack: "start",
setup: self => {
self.connect("child-activated", (_, child) => {
selected.label = child.get_child()?.iconName || ""
})
Gtk.IconTheme.get_default().list_icons(null).sort().map(icon => {
!icon.endsWith(".symbolic") && self.insert(Widget.Icon({
icon,
size: 38,
}), -1)
})
self.show_all()
},
})
const entry = Widget.Entry({
placeholder_text: "Type to seach...",
primary_icon_name: "system-search-symbolic",
on_change: ({ text }) => flowbox.get_children().forEach(child => {
child.visible = child.get_child().iconName.includes(text)
}),
})
return Widget.Box({
css: "padding: 30px;",
spacing: 20,
vertical: true,
children: [
entry,
Widget.Scrollable({
hscroll: "never",
vscroll: "always",
hexpand: true,
vexpand: true,
css: "min-width: 400px;"
+ "min-height: 500px;",
child: flowbox,
}),
selected,
],
})
}
const win = new Gtk.Window({
name: "icon-browser",
child: IconPicker(),
})
win.show_all()
win.connect("delete-event", () => {
App.quit()
return true
})
export default { windows: [win] }

View File

@@ -0,0 +1,153 @@
const mpris = await Service.import("mpris")
const players = mpris.bind("players")
const FALLBACK_ICON = "audio-x-generic-symbolic"
const PLAY_ICON = "media-playback-start-symbolic"
const PAUSE_ICON = "media-playback-pause-symbolic"
const PREV_ICON = "media-skip-backward-symbolic"
const NEXT_ICON = "media-skip-forward-symbolic"
/** @param {number} length */
function lengthStr(length) {
const min = Math.floor(length / 60)
const sec = Math.floor(length % 60)
const sec0 = sec < 10 ? "0" : ""
return `${min}:${sec0}${sec}`
}
/** @param {import('types/service/mpris').MprisPlayer} player */
function Player(player) {
const img = Widget.Box({
class_name: "img",
vpack: "start",
css: player.bind("cover_path").transform(p => `
background-image: url('${p}');
`),
})
const title = Widget.Label({
class_name: "title",
wrap: true,
hpack: "start",
label: player.bind("track_title"),
})
const artist = Widget.Label({
class_name: "artist",
wrap: true,
hpack: "start",
label: player.bind("track_artists").transform(a => a.join(", ")),
})
const positionSlider = Widget.Slider({
class_name: "position",
draw_value: false,
on_change: ({ value }) => player.position = value * player.length,
visible: player.bind("length").as(l => l > 0),
setup: self => {
function update() {
const value = player.position / player.length
self.value = value > 0 ? value : 0
}
self.hook(player, update)
self.hook(player, update, "position")
self.poll(1000, update)
},
})
const positionLabel = Widget.Label({
class_name: "position",
hpack: "start",
setup: self => {
const update = (_, time) => {
self.label = lengthStr(time || player.position)
self.visible = player.length > 0
}
self.hook(player, update, "position")
self.poll(1000, update)
},
})
const lengthLabel = Widget.Label({
class_name: "length",
hpack: "end",
visible: player.bind("length").transform(l => l > 0),
label: player.bind("length").transform(lengthStr),
})
const icon = Widget.Icon({
class_name: "icon",
hexpand: true,
hpack: "end",
vpack: "start",
tooltip_text: player.identity || "",
icon: player.bind("entry").transform(entry => {
const name = `${entry}-symbolic`
return Utils.lookUpIcon(name) ? name : FALLBACK_ICON
}),
})
const playPause = Widget.Button({
class_name: "play-pause",
on_clicked: () => player.playPause(),
visible: player.bind("can_play"),
child: Widget.Icon({
icon: player.bind("play_back_status").transform(s => {
switch (s) {
case "Playing": return PAUSE_ICON
case "Paused":
case "Stopped": return PLAY_ICON
}
}),
}),
})
const prev = Widget.Button({
on_clicked: () => player.previous(),
visible: player.bind("can_go_prev"),
child: Widget.Icon(PREV_ICON),
})
const next = Widget.Button({
on_clicked: () => player.next(),
visible: player.bind("can_go_next"),
child: Widget.Icon(NEXT_ICON),
})
return Widget.Box(
{ class_name: "player" },
img,
Widget.Box(
{
vertical: true,
hexpand: true,
},
Widget.Box([
title,
icon,
]),
artist,
Widget.Box({ vexpand: true }),
positionSlider,
Widget.CenterBox({
start_widget: positionLabel,
center_widget: Widget.Box([
prev,
playPause,
next,
]),
end_widget: lengthLabel,
}),
),
)
}
export function Media() {
return Widget.Box({
vertical: true,
css: "min-height: 2px; min-width: 2px;", // small hack to make it visible
visible: players.as(p => p.length > 0),
children: players.as(p => p.map(Player)),
})
}

View File

@@ -0,0 +1,18 @@
# Media Widget
setup
```bash
mkdir -p ~/.config/ags
git clone https://github.com/Aylur/ags.git /tmp/ags
cp -r /tmp/ags/example/media-widget/* ~/.config/ags
# optionally setup types
ags --init -c ~/.config/ags/config.js
```
running
```bash
ags -c ~/.config/ags/config.js &
```

View File

@@ -0,0 +1,12 @@
import { Media } from "./Media.js"
const win = Widget.Window({
name: "mpris",
anchor: ["top", "right"],
child: Media(),
})
App.config({
style: "./style.css",
windows: [win],
})

View File

@@ -0,0 +1,49 @@
.player {
padding: 10px;
min-width: 350px;
}
.player .img {
min-width: 100px;
min-height: 100px;
background-size: cover;
background-position: center;
border-radius: 13px;
margin-right: 1em;
}
.player .title {
font-size: 1.2em;
}
.player .artist {
font-size: 1.1em;
color: @insensitive_fg_color;
}
.player scale.position {
padding: 0;
margin-bottom: .3em;
}
.player scale.position trough {
min-height: 8px;
}
.player scale.position highlight {
background-color: @theme_fg_color;
}
.player scale.position slider {
all: unset;
}
.player button {
min-height: 1em;
min-width: 1em;
padding: .3em;
}
.player button.play-pause {
margin: 0 .3em;
}

View File

@@ -0,0 +1,18 @@
# Notification Popups
setup
```bash
mkdir -p ~/.config/ags
git clone https://github.com/Aylur/ags.git /tmp/ags
cp -r /tmp/ags/example/notification-popups/* ~/.config/ags
# optionally setup types
ags --init -c ~/.config/ags/config.js
```
running
```bash
ags -c ~/.config/ags/config.js &
```

View File

@@ -0,0 +1,18 @@
import { NotificationPopups } from "./notificationPopups.js"
Utils.timeout(100, () => Utils.notify({
summary: "Notification Popup Example",
iconName: "info-symbolic",
body: "Lorem ipsum dolor sit amet, qui minim labore adipisicing "
+ "minim sint cillum sint consectetur cupidatat.",
actions: {
"Cool": () => print("pressed Cool"),
},
}))
App.config({
style: App.configDir + "/style.css",
windows: [
NotificationPopups(),
],
})

View File

@@ -0,0 +1,130 @@
const notifications = await Service.import("notifications")
/** @param {import('resource:///com/github/Aylur/ags/service/notifications.js').Notification} n */
function NotificationIcon({ app_entry, app_icon, image }) {
if (image) {
return Widget.Box({
css: `background-image: url("${image}");`
+ "background-size: contain;"
+ "background-repeat: no-repeat;"
+ "background-position: center;",
})
}
let icon = "dialog-information-symbolic"
if (Utils.lookUpIcon(app_icon))
icon = app_icon
if (app_entry && Utils.lookUpIcon(app_entry))
icon = app_entry
return Widget.Box({
child: Widget.Icon(icon),
})
}
/** @param {import('resource:///com/github/Aylur/ags/service/notifications.js').Notification} n */
function Notification(n) {
const icon = Widget.Box({
vpack: "start",
class_name: "icon",
child: NotificationIcon(n),
})
const title = Widget.Label({
class_name: "title",
xalign: 0,
justification: "left",
hexpand: true,
max_width_chars: 24,
truncate: "end",
wrap: true,
label: n.summary,
use_markup: true,
})
const body = Widget.Label({
class_name: "body",
hexpand: true,
use_markup: true,
xalign: 0,
justification: "left",
label: n.body,
wrap: true,
})
const actions = Widget.Box({
class_name: "actions",
children: n.actions.map(({ id, label }) => Widget.Button({
class_name: "action-button",
on_clicked: () => {
n.invoke(id)
n.dismiss()
},
hexpand: true,
child: Widget.Label(label),
})),
})
return Widget.EventBox(
{
attribute: { id: n.id },
on_primary_click: n.dismiss,
},
Widget.Box(
{
class_name: `notification ${n.urgency}`,
vertical: true,
},
Widget.Box([
icon,
Widget.Box(
{ vertical: true },
title,
body,
),
]),
actions,
),
)
}
export function NotificationPopups(monitor = 0) {
const list = Widget.Box({
vertical: true,
children: notifications.popups.map(Notification),
})
function onNotified(_, /** @type {number} */ id) {
const n = notifications.getNotification(id)
if (n)
list.children = [Notification(n), ...list.children]
}
function onDismissed(_, /** @type {number} */ id) {
list.children.find(n => n.attribute.id === id)?.destroy()
}
list.hook(notifications, onNotified, "notified")
.hook(notifications, onDismissed, "dismissed")
return Widget.Window({
monitor,
name: `notifications${monitor}`,
class_name: "notification-popups",
anchor: ["top", "right"],
child: Widget.Box({
css: "min-width: 2px; min-height: 2px;",
class_name: "notifications",
vertical: true,
child: list,
/** this is a simple one liner that could be used instead of
hooking into the 'notified' and 'dismissed' signals.
but its not very optimized becuase it will recreate
the whole list everytime a notification is added or dismissed */
// children: notifications.bind('popups')
// .as(popups => popups.map(Notification))
}),
})
}

View File

@@ -0,0 +1,57 @@
window.notification-popups box.notifications {
padding: .5em;
}
.icon {
min-width: 68px;
min-height: 68px;
margin-right: 1em;
}
.icon image {
font-size: 58px;
/* to center the icon */
margin: 5px;
color: @theme_fg_color;
}
.icon box {
min-width: 68px;
min-height: 68px;
border-radius: 7px;
}
.notification {
min-width: 350px;
border-radius: 11px;
padding: 1em;
margin: .5em;
border: 1px solid @wm_borders_edge;
background-color: @theme_bg_color;
}
.notification.critical {
border: 1px solid lightcoral;
}
.title {
color: @theme_fg_color;
font-size: 1.4em;
}
.body {
color: @theme_unfocused_fg_color;
}
.actions .action-button {
margin: 0 .4em;
margin-top: .8em;
}
.actions .action-button:first-child {
margin-left: 0;
}
.actions .action-button:last-child {
margin-right: 0;
}

View File

@@ -0,0 +1,18 @@
# Simple Bar
setup
```bash
mkdir -p ~/.config/ags
git clone https://github.com/Aylur/ags.git /tmp/ags
cp -r /tmp/ags/example/simple-bar/* ~/.config/ags
# optionally setup types
ags --init -c ~/.config/ags/config.js
```
running
```bash
ags -c ~/.config/ags/config.js &
```

View File

@@ -0,0 +1,219 @@
const hyprland = await Service.import("hyprland")
const notifications = await Service.import("notifications")
const mpris = await Service.import("mpris")
const audio = await Service.import("audio")
const battery = await Service.import("battery")
const systemtray = await Service.import("systemtray")
const date = Variable("", {
poll: [1000, 'date "+%H:%M:%S %b %e."'],
})
// widgets can be only assigned as a child in one container
// so to make a reuseable widget, make it a function
// then you can simply instantiate one by calling it
function Workspaces() {
const activeId = hyprland.active.workspace.bind("id")
const workspaces = hyprland.bind("workspaces")
.as(ws => ws.map(({ id }) => Widget.Button({
on_clicked: () => hyprland.messageAsync(`dispatch workspace ${id}`),
child: Widget.Label(`${id}`),
class_name: activeId.as(i => `${i === id ? "focused" : ""}`),
})))
return Widget.Box({
class_name: "workspaces",
children: workspaces,
})
}
function ClientTitle() {
return Widget.Label({
class_name: "client-title",
label: hyprland.active.client.bind("title"),
})
}
function Clock() {
return Widget.Label({
class_name: "clock",
label: date.bind(),
})
}
// we don't need dunst or any other notification daemon
// because the Notifications module is a notification daemon itself
function Notification() {
const popups = notifications.bind("popups")
return Widget.Box({
class_name: "notification",
visible: popups.as(p => p.length > 0),
children: [
Widget.Icon({
icon: "preferences-system-notifications-symbolic",
}),
Widget.Label({
label: popups.as(p => p[0]?.summary || ""),
}),
],
})
}
function Media() {
const label = Utils.watch("", mpris, "player-changed", () => {
if (mpris.players[0]) {
const { track_artists, track_title } = mpris.players[0]
return `${track_artists.join(", ")} - ${track_title}`
} else {
return "Nothing is playing"
}
})
return Widget.Button({
class_name: "media",
on_primary_click: () => mpris.getPlayer("")?.playPause(),
on_scroll_up: () => mpris.getPlayer("")?.next(),
on_scroll_down: () => mpris.getPlayer("")?.previous(),
child: Widget.Label({ label }),
})
}
function Volume() {
const icons = {
101: "overamplified",
67: "high",
34: "medium",
1: "low",
0: "muted",
}
function getIcon() {
const icon = audio.speaker.is_muted ? 0 : [101, 67, 34, 1, 0].find(
threshold => threshold <= audio.speaker.volume * 100)
return `audio-volume-${icons[icon]}-symbolic`
}
const icon = Widget.Icon({
icon: Utils.watch(getIcon(), audio.speaker, getIcon),
})
const slider = Widget.Slider({
hexpand: true,
draw_value: false,
on_change: ({ value }) => audio.speaker.volume = value,
setup: self => self.hook(audio.speaker, () => {
self.value = audio.speaker.volume || 0
}),
})
return Widget.Box({
class_name: "volume",
css: "min-width: 180px",
children: [icon, slider],
})
}
function BatteryLabel() {
const value = battery.bind("percent").as(p => p > 0 ? p / 100 : 0)
const icon = battery.bind("percent").as(p =>
`battery-level-${Math.floor(p / 10) * 10}-symbolic`)
return Widget.Box({
class_name: "battery",
visible: battery.bind("available"),
children: [
Widget.Icon({ icon }),
Widget.LevelBar({
widthRequest: 140,
vpack: "center",
value,
}),
],
})
}
function SysTray() {
const items = systemtray.bind("items")
.as(items => items.map(item => Widget.Button({
child: Widget.Icon({ icon: item.bind("icon") }),
on_primary_click: (_, event) => item.activate(event),
on_secondary_click: (_, event) => item.openMenu(event),
tooltip_markup: item.bind("tooltip_markup"),
})))
return Widget.Box({
children: items,
})
}
// layout of the bar
function Left() {
return Widget.Box({
spacing: 8,
children: [
Workspaces(),
ClientTitle(),
],
})
}
function Center() {
return Widget.Box({
spacing: 8,
children: [
Media(),
Notification(),
],
})
}
function Right() {
return Widget.Box({
hpack: "end",
spacing: 8,
children: [
Volume(),
BatteryLabel(),
Clock(),
SysTray(),
],
})
}
function Bar(monitor = 0) {
return Widget.Window({
name: `bar-${monitor}`, // name has to be unique
class_name: "bar",
monitor,
anchor: ["top", "left", "right"],
exclusivity: "exclusive",
child: Widget.CenterBox({
start_widget: Left(),
center_widget: Center(),
end_widget: Right(),
}),
})
}
App.config({
style: "./style.css",
windows: [
Bar(),
// you can call it, for each monitor
// Bar(0),
// Bar(1)
],
})
export { }

View File

@@ -0,0 +1,40 @@
window.bar {
background-color: @theme_bg_color;
color: @theme_fg_color;
}
button {
min-width: 0;
padding-top: 0;
padding-bottom: 0;
background-color: transparent;
}
button:active {
background-color: @theme_selected_bg_color;
}
button:hover {
border-bottom: 3px solid @theme_fg_color;
}
label {
font-weight: bold;
}
.workspaces button.focused {
border-bottom: 3px solid @theme_selected_bg_color;
}
.client-title {
color: @theme_selected_bg_color;
}
.notification {
color: yellow;
}
levelbar block,
highlight {
min-height: 10px;
}

View File

@@ -0,0 +1,21 @@
# TypeScript Starter Config
Dependency: `bun`
```bash
mkdir -p ~/.config/ags
git clone https://github.com/Aylur/ags.git /tmp/ags
cp -r /tmp/ags/example/ts-starter-config/* ~/.config/ags
```
optionally setup types
```bash
ags --init -c ~/.config/ags/config.js
```
running
```bash
ags -c ~/.config/ags/config.js &
```

View File

@@ -0,0 +1,15 @@
const main = '/tmp/ags/main.js';
try {
await Utils.execAsync([
'bun', 'build', `${App.configDir}/main.ts`,
'--outfile', main,
'--external', 'resource://*',
'--external', 'gi://*',
'--external', 'file://*',
]);
await import(`file://${main}`);
} catch (error) {
console.error(error);
App.quit();
}

View File

@@ -0,0 +1,26 @@
const time = Variable('', {
poll: [1000, function() {
return Date().toString();
}],
});
const Bar = (monitor: number) => Widget.Window({
monitor,
name: `bar${monitor}`,
anchor: ['top', 'left', 'right'],
exclusivity: 'exclusive',
child: Widget.CenterBox({
start_widget: Widget.Label({
hpack: 'center',
label: 'Welcome to AGS!',
}),
end_widget: Widget.Label({
hpack: 'center',
label: time.bind(),
}),
}),
});
App.config({
windows: [Bar(0)],
});