ags: make osd work, new window management system, lots of improvements

This commit is contained in:
retrozinndev
2025-02-07 16:02:58 -03:00
parent 0bd0b53589
commit b0bd785ddd
24 changed files with 559 additions and 254 deletions
+56 -18
View File
@@ -1,5 +1,7 @@
import { Windows } from "./windows";
import { Gtk } from "astal/gtk3";
import { Windows } from "../windows";
import { restartInstance } from "./reload-handler";
import { Wireplumber } from "./volume";
export function handleArguments(request: string): any {
const args: Array<string> = request.split(" ");
@@ -13,8 +15,11 @@ export function handleArguments(request: string): any {
case "h":
return getHelp(); // stop it, get some help
case "volume":
return handleVolumeArgs(args);
case "reload":
restartInstance({ log: true, instanceName: "astal" });
restartInstance({ log: false, instanceName: "astal" });
return "Reloading instance..."
default:
@@ -23,48 +28,80 @@ export function handleArguments(request: string): any {
}
// Didn't want to bloat the switch statement, so I just separated it into functions
export function handleWindowArgs(args: Array<string>): string {
const windows = Windows.getDefault().getWindows();
const window = windows[args[1] as never];
function handleWindowArgs(args: Array<string>): string {
const specifiedWindow: (Gtk.Window|undefined) = Windows.getWindow(args[1]);
if(args[1] == undefined || args[1] == "")
if(!specifiedWindow)
return "Window argument not specified!";
if(!Object.hasOwn(windows, args[1]!))
return `Window "${args[1]}" not found windows list!`
if(!Windows.getList().has(args[1]))
return `Name "${args[1]}" not found windows map! Make sure to add new Windows on the Map!`
switch(args[0]) {
case "open":
if(!Windows.getDefault().isVisible(window)) {
Windows.getDefault().open(window);
if(!Windows.isVisible(specifiedWindow)) {
Windows.open(specifiedWindow);
return `Setting visibility of window "${args[1]}" to true`;
}
return `Window is already open, ignored`;
case "close":
if(Windows.getDefault().isVisible(window)) {
Windows.getDefault().close(window);
if(Windows.isVisible(specifiedWindow)) {
Windows.close(specifiedWindow);
return `Setting visibility of window "${args[1]}" to false`
}
return `Window is already closed, ignored`
case "toggle":
if(!Windows.getDefault().isVisible(window)) {
Windows.getDefault().open(window);
if(!Windows.isVisible(specifiedWindow)) {
Windows.open(specifiedWindow);
return `Toggle opening window "${args[1]}"`;
}
Windows.getDefault().close(window);
Windows.close(specifiedWindow);
return `Toggle closing window "${args[1]}"`
}
return "Couldn't handle window management arguments"
}
export function getHelp(): string {
return `Manage Astal Windows and do more stuff. From
function handleVolumeArgs(args: Array<string>) {
if(!args[1])
return `Please specify what you want to do!\n\n${volumeHelp()}`
if(!/(sink|source)\-mute/.test(args[1]) && !args[2])
return `You forgot to add a value to be set!`;
const command: Array<string> = args[1].split('-');
switch(command[1]) {
case "set":
return `Done! Set ${command[0]} volume to ${args[2]}`;
}
return `Couldn't resolve arguments! "${args.join(' ').replace(new RegExp(`^${args[0]}`), "")}"`;
function volumeHelp(): string {
return `
Control speaker and microphone volumes easily!
Options:
sink-set [number]: set sink(speaker) volume with [number], 0 to ${Wireplumber.getDefault().getMaxSinkVolume()}.
sink-mute: toggle mute for the sink(speaker) device.
sink-increase [number]: increases sink(speaker) volume with [number].
sink-decrease [number]: decreases sink(speaker) volume with [number].
source-set [number]: set source(microphone) volume with [number], 0 to ${Wireplumber.getDefault().getMaxSourceVolume()}.
source-mute: toggle mute for the source(microphone) device.
source-increase [number]: increases source(microphone) volume with [number].
source-decrease [number]: decreases source(microphone) volume with [number]
`.trim();
}
}
function getHelp(): string {
return `
Manage Astal Windows and do more stuff. From
retrozinndev's Hyprland Dots, using Astal and AGS by Aylur.
Options:
@@ -75,5 +112,6 @@ Options:
help, -h, --help: shows this help message.
2024 (c) retrozinndev's Hyprland-Dots, licensed under the MIT License.
https://github.com/retrozinndev/Hyprland-Dots`
https://github.com/retrozinndev/Hyprland-Dots
`.trim();
}
+1 -5
View File
@@ -1,5 +1,4 @@
import AstalNotifd from "gi://AstalNotifd";
import { Windows } from "./windows";
import { timeout } from "astal/time";
const notifd: AstalNotifd.Notifd = new AstalNotifd.Notifd({
@@ -7,13 +6,10 @@ const notifd: AstalNotifd.Notifd = new AstalNotifd.Notifd({
dontDisturb: false
});
const windows = Windows.getDefault();
export let notifications: Array<AstalNotifd.Notification> = [];
export let notifications: Array<AstalNotifd.Notification> = getNotifd().notifications;
export let notificationHistory: Array<AstalNotifd.Notification> = [];
notifd.connect("notified", (_source: AstalNotifd.Notifd, id: number, _replaced: boolean) => {
windows.isVisible(windows.getWindows().floating_notifications) && windows.open(windows.getWindows().floating_notifications);
addNotification(getNotifd().get_notification(id));
});
+3 -3
View File
@@ -1,6 +1,6 @@
import { monitorFile, Process } from "astal";
import { astalInstanceName } from "../app";
import { getUserDirs } from "./user";
import { App } from "astal/gtk3";
const monitoringPaths = [ "./scripts", "./window", "./app.ts", "env.d.ts" ];
@@ -12,7 +12,7 @@ export interface InstanceProps {
export function restartInstance(props: InstanceProps = { instanceName: "astal", log: false }): void {
Process.exec_async(`astal -q ${props.instanceName}`, () => {});
Process.exec_async(`ags run ${ props.log && `--log-file
${ getUserDirs().cache}/ags-${ astalInstanceName || "astal" }.log` }`.replaceAll('\n', ' ').trim(),
${ getUserDirs().cache}/ags-${ App.instanceName || "astal" }.log` }`.replaceAll('\n', ' ').trim(),
() => {}
)
}
@@ -22,7 +22,7 @@ export function monitorPaths(): void {
monitorFile(
path,
() => restartInstance({
instanceName: astalInstanceName || "astal",
instanceName: App.instanceName || "astal",
log: true
})
)
+34 -12
View File
@@ -1,23 +1,45 @@
import { GObject } from "astal";
import AstalWp from "gi://AstalWp";
export class Wireplumber {
private astalWireplumber: (AstalWp.Wp|null) = AstalWp.get_default();
private defaultSink: AstalWp.Endpoint = this.astalWireplumber!.get_default_speaker()!;
private defaultSource: AstalWp.Endpoint = this.astalWireplumber!.get_default_microphone()!;
private static inst: Wireplumber = new Wireplumber();
export const Wireplumber = GObject.registerClass({
GTypeName: "Wireplumber",
Signals: {}
}, class WireplumberClass extends GObject.Object {
private static astalWireplumber: (AstalWp.Wp|null) = AstalWp.get_default();
private static inst: WireplumberClass;
private defaultSink: AstalWp.Endpoint = WireplumberClass.astalWireplumber!.get_default_speaker()!;
private defaultSource: AstalWp.Endpoint = WireplumberClass.astalWireplumber!.get_default_microphone()!;
private maxSinkVolume: number = 100;
private maxSourceVolume: number = 100;
constructor() {
if(!this.astalWireplumber)
_init(...props: any[]) {
super._init(props);
if(!WireplumberClass.astalWireplumber)
throw new Error("Audio features will not work correctly! Please install wireplumber first", {
cause: "Wireplumber library not found"
});
}
public static getDefault(): Wireplumber {
return Wireplumber.inst;
public static getDefault(): WireplumberClass {
if(!WireplumberClass.inst)
WireplumberClass.inst = new WireplumberClass();
return WireplumberClass.inst;
}
public static getWireplumber(): AstalWp.Wp {
return WireplumberClass.astalWireplumber!;
}
public getMaxSinkVolume(): number {
return this.maxSinkVolume;
}
public getMaxSourceVolume(): number {
return this.maxSourceVolume;
}
public getDefaultSink(): AstalWp.Endpoint {
@@ -29,11 +51,11 @@ export class Wireplumber {
}
public getSinkVolume(): number {
return this.getDefaultSink().get_volume() * 100;
return Math.floor(this.getDefaultSink().get_volume() * 100);
}
public getSourceVolume(): number {
return this.getDefaultSource().get_volume() * 100;
return Math.floor(this.getDefaultSource().get_volume() * 100);
}
public setSinkVolume(newSinkVolume: number): void {
@@ -123,4 +145,4 @@ export class Wireplumber {
return this.muteSource();
}
}
});
-34
View File
@@ -1,34 +0,0 @@
// get open windows / interact with windows(e.g.: close, open or toggle)
import { Widget } from "astal/gtk3";
import { getWindowsMap } from "../app";
export class Windows {
private static inst: Windows = new Windows();
private readonly windows = getWindowsMap();
public static getDefault(): Windows {
return Windows.inst;
}
public getWindows(): typeof this.windows {
return this.windows;
}
public open(window: Widget.Window): void {
window.show();
}
public isVisible(window: Widget.Window): boolean {
return window.get_visible();
}
public close(window: Widget.Window): void {
window.hide();
}
public toggle(window: Widget.Window): void {
window.is_visible() ? this.close(window) : this.open(window);
}
}