rags: format and fix monitor
crispy-caesus crispy@crispy-caesus.eu
Sat, 28 Feb 2026 00:08:53 +0100
2 files changed,
174 insertions(+),
275 deletions(-)
D
rags/.config/ags/cava.js
@@ -1,92 +0,0 @@
-import Gio from 'gi://Gio'; -import GLib from 'gi://GLib'; - -const confPath = `/tmp/ags/cava.conf`; -async function readCavaAsync(barNumber, bitFormat, callback, onError) { - try { - const conf = -`[general] -framerate = 30 -bars = ${barNumber} -[output] -method = raw -bit_format = ${bitFormat}`; - - Utils.writeFileSync(conf, confPath); - - const cava = Gio.Subprocess.new( - [`cava`, `-p`, confPath], - Gio.SubprocessFlags.STDOUT_PIPE | - Gio.SubprocessFlags.STDERR_PIPE, - ); - - const pipe = cava.get_stdout_pipe(); - if (!pipe) { - onError(Error(`cava stdout pipe is null`)); - return null; - } - - const read8bit = (stream) => { - stream.read_bytes_async(barNumber, GLib.PRIORITY_LOW, null, (stream, res) => { - try { - let data = stream.read_bytes_finish(res).get_data(); - const output = new Float64Array(data).map(d => d / 255); - callback(output); - read8bit(stream); - } catch (e) { - onError(e); - } - }); - }; - const read16bit = (stream) => { - stream.read_bytes_async(barNumber * 2, GLib.PRIORITY_LOW, null, (stream, res) => { - try { - const data = stream.read_bytes_finish(res).get_data(); - const output = new Float64Array(new Uint16Array(data.buffer)).map(d => d / 65535); - callback(output); - read16bit(stream); - } catch (e) { - onError(e); - } - }); - }; - - if (bitFormat === '8bit') { - read8bit(pipe); - } else if (bitFormat === '16bit'){ - read16bit(pipe); - } - - } catch (e) { - logError(e); - return null; - } -} - -export class Cava extends Service { - static { - Service.register(this, {}, { - 'bar-value': ['float[]', 'r'], - }); - } - - #barValues = []; - get bar_value() { - return this.#barValues; - } - - constructor(barNumber, bitFormat) { - super(); - readCavaAsync( - barNumber, bitFormat, (barValues) => { - this.#barValues = barValues; - this.#onChange(); - } - ) - } - - #onChange() { - this.emit('changed'); - this.notify('bar-value'); - } -}
M
rags/.config/ags/config.js
→
rags/.config/ags/config.js
@@ -1,241 +1,232 @@
-const mpris = await Service.import("mpris") -const audio = await Service.import("audio") -const battery = await Service.import("battery") -const systemtray = await Service.import("systemtray") -import brightness from "./brightness.js" - +const mpris = await Service.import("mpris"); +const audio = await Service.import("audio"); +const battery = await Service.import("battery"); +const systemtray = await Service.import("systemtray"); +import brightness from "./brightness.js"; const time = Variable("", { - poll: [1000, `date +'%H\n%M'`], -}) + poll: [1000, `date +'%H\n%M'`], +}); const date = Variable("", { - poll: [1000, `date +'%d'`], -}) + poll: [1000, `date +'%d'`], +}); const day = Variable("", { - poll: [1000, `date +'%d'`], -}) + poll: [1000, `date +'%d'`], +}); const month = Variable("", { - poll: [1000, `date +'%m'`], -}) + poll: [1000, `date +'%m'`], +}); function Clock() { - return Widget.Label({ - class_name: "clock", - vpack: "center", - label: time.bind(), - }) + return Widget.Label({ + class_name: "clock", + vpack: "center", + label: time.bind(), + }); } function Date() { - return Widget.Label({ - class_name: "date", - vpack: "center", - label: date.bind(), - }) + return Widget.Label({ + class_name: "date", + vpack: "center", + label: date.bind(), + }); } function DateTime() { - return Widget.Box({ - vertical: true, + return Widget.Box({ + vertical: true, + vpack: "center", + children: [ + Widget.Label({ + class_name: "time", + vpack: "center", + label: time.bind(), + }), + Widget.Label({ + class_name: "date2", vpack: "center", - children: [ - Widget.Label({ - class_name: "time", - vpack: "center", - label: time.bind(), - }), - Widget.Label({ - class_name: "date2", - vpack: "center", - label: date.bind(), - }), - - ] - }) + label: date.bind(), + }), + ], + }); } - function Media() { - return Widget.Button({ - class_name: "media", - on_primary_click: () => mpris.getPlayer("")?.playPause(), - on_scroll_up: () => mpris.getPlayer("")?.next(), - on_scroll_down: () => mpris.getPlayer("")?.previous(), - }) + return Widget.Button({ + class_name: "media", + on_primary_click: () => mpris.getPlayer("")?.playPause(), + on_scroll_up: () => mpris.getPlayer("")?.next(), + on_scroll_down: () => mpris.getPlayer("")?.previous(), + }); } - function Volume() { - const icons = { - 101: "overamplified", - 67: "high", - 34: "medium", - 1: "low", - 0: "muted", - } + 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) + 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` - } + return `audio-volume-${icons[icon]}-symbolic`; + } - const icon = Widget.Icon({ - icon: Utils.watch(getIcon(), audio.speaker, getIcon), - }) + const icon = Widget.Icon({ + icon: Utils.watch(getIcon(), audio.speaker, getIcon), + }); - const slider = Widget.Slider({ - vertical: true, - inverted: true, - expand: true, - draw_value: false, - on_change: ({ value }) => audio.speaker.volume = value, - setup: self => self.hook(audio.speaker, () => { - self.value = audio.speaker.volume || 0 - }), - }) + const slider = Widget.Slider({ + vertical: true, + inverted: true, + expand: 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({ - vertical: true, - vpack: "start", - class_name: "volume", - children: [icon, slider], - }) + return Widget.Box({ + vertical: true, + vpack: "start", + class_name: "volume", + children: [icon, slider], + }); } function Brightness() { - const slider = Widget.Slider({ - vertical: true, - inverted: true, - expand: true, - draw_value: false, - class_name: "brightness", - on_change: self => brightness.screen_value = self.value, - value: brightness.bind('screen-value'), - }); - return slider + const slider = Widget.Slider({ + vertical: true, + inverted: true, + expand: true, + draw_value: false, + class_name: "brightness", + on_change: (self) => (brightness.screen_value = self.value), + value: brightness.bind("screen-value"), + }); + return 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`) + 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", + return Widget.Box({ + class_name: "battery", + vertical: true, + visible: battery.bind("available"), + children: [ + Widget.Icon({ class_name: "icon", icon }), + Widget.LevelBar({ vertical: true, - visible: battery.bind("available"), - children: [ - Widget.Icon({ class_name: "icon", icon }), - Widget.LevelBar({ - vertical: true, - inverted: true, - heightRequest: 140, - vpack: "center", - value, - }), - ], - }) + inverted: true, + heightRequest: 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"), - }))) + 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({ - vertical: true, - children: items, - }) + return Widget.Box({ + vertical: true, + children: items, + }); } const Separator = Widget.Separator({ - vertical: true, - class_name: "separator", -}) + vertical: true, + class_name: "separator", +}); function Dnd() { - return Widget.Button({ - child: Widget.Label('dnd'), - onClicked: () => { - console.log('DND button clicked'); // Add debugging - Utils.exec(`${Utils.HOME}/.config/hypr/scripts/dnd.sh`); - } - }) + return Widget.Button({ + child: Widget.Label("dnd"), + onClicked: () => { + console.log("DND button clicked"); // Add debugging + Utils.exec(`${Utils.HOME}/.config/hypr/scripts/dnd.sh`); + }, + }); } // layout of the bar function Top() { - return Widget.Box({ - vertical: true, - spacing: 8, - children: [ - //ClientTitle(), - //Volume(), - Volume(), - Brightness(), - ], - }) + return Widget.Box({ + vertical: true, + spacing: 8, + children: [ + //ClientTitle(), + //Volume(), + Volume(), + Brightness(), + ], + }); } function Center() { - return Widget.Box({ - vertical: true, - spacing: 8, - children: [ - //Media(), - //Notification(), - //Workspaces(), - ], - }) + return Widget.Box({ + vertical: true, + spacing: 8, + children: [ + //Media(), + //Notification(), + //Workspaces(), + ], + }); } function Bottom() { - return Widget.Box({ - vertical: true, - vpack: "end", - spacing: 8, - children: [ - BatteryLabel(), - Dnd(), - SysTray(), - DateTime(), - ], - }) + return Widget.Box({ + vertical: true, + vpack: "end", + spacing: 8, + children: [BatteryLabel(), Dnd(), SysTray(), DateTime()], + }); } function Bar(monitor = 0) { - return Widget.Window({ - name: `bar-${monitor}`, // name has to be unique - class_name: "bar", - monitor, - anchor: ["right", "top", "bottom"], - exclusivity: "exclusive", - margins: [0, 0, 0, 0], - child: Widget.CenterBox({ - vertical: true, - start_widget: Top(), - center_widget: Center(), - end_widget: Bottom(), - }), - }) + return Widget.Window({ + name: `bar-${monitor}`, // name has to be unique + class_name: "bar", + monitor, + anchor: ["right", "top", "bottom"], + exclusivity: "exclusive", + margins: [0, 0, 0, 0], + child: Widget.CenterBox({ + vertical: true, + start_widget: Top(), + center_widget: Center(), + end_widget: Bottom(), + }), + }); } App.config({ - style: "./style.css", - windows: [ - Bar(3), + style: "./style.css", + windows: [Bar(2)], +}); - // you can call it, for each monitor - // Bar(0), - // Bar(1) - ], -}) - -export { } +export {};