chore: migrate shell to ags v3 and gtk4

This commit is contained in:
retrozinndev
2025-07-06 19:57:28 -03:00
parent b90a799a89
commit 246698c642
10 changed files with 169 additions and 128 deletions
+10 -7
View File
@@ -8,7 +8,7 @@ import GLib from "gi://GLib?version=2.0";
import Gio from "gi://Gio?version=2.0";
import AstalIO from "gi://AstalIO";
import AstalNotifd from "gi://AstalNotifd";
import { Accessor, createConnection } from "ags";
import { Accessor } from "ags";
export { Config };
@@ -46,14 +46,15 @@ export type ConfigEntries = Partial<{
type ValueTypes = "string" | "boolean" | "object" | "number" | "undefined" | "any";
interface ConfigSignals extends GObject.Object.SignalSignatures {
"notify::entries": (entries: ConfigEntries) => void;
}
@register({ GTypeName: "Config" })
class Config extends GObject.Object {
private static instance: Config;
$signals = {
"notify": () => {},
"notify::entries": (_: ConfigEntries) => {}
};
declare $signals: ConfigSignals;
private readonly defaultFile = Gio.File.new_for_path(
`${GLib.get_user_config_dir()}/colorshell/config.json`);
@@ -196,8 +197,10 @@ class Config extends GObject.Object {
}
public bindProperty(propertyPath: (keyof ConfigEntries|string), expectType?: ValueTypes): Accessor<any|undefined> {
return createConnection(this.getProperty(propertyPath), [(this as typeof Config.instance), "notify::entries", () =>
this.getProperty(propertyPath, expectType)]);
return new Accessor<ConfigEntries>(() => this.getProperty(propertyPath, expectType), (callback: () => void) => {
const id = this.connect("notify::entries", () => callback());
return () => this.disconnect(id);
});
}
public getProperty(path: string, expectType?: ValueTypes): (any|undefined) {
+86 -2
View File
@@ -2,6 +2,13 @@ import { createPoll } from "ags/time";
import { exec, execAsync } from "ags/process";
import GLib from "gi://GLib?version=2.0";
import Gio from "gi://Gio?version=2.0";
import { Accessor, For, With } from "ags";
import GObject from "gi://GObject?version=2.0";
import { Astal, Gtk } from "ags/gtk4";
/** gnim doesn't export this, so we need to do it again */
export type WidgetNodeType = Array<GObject.Object> | GObject.Object | number | string | boolean | null | undefined;
export const decoder = new TextDecoder("utf-8"),
encoder = new TextEncoder();
@@ -18,9 +25,63 @@ export function getHyprlandVersion(): string {
}
export function omitObjectKeys<ObjT = object>(obj: ObjT, keys: keyof ObjT|Array<keyof ObjT>): ObjT {
for(const objKey of Object.keys(obj)) {
for(const omitKey of keys) {}
const finalObject = obj;
for(const objKey of Object.keys(obj as object)) {
if(!Array.isArray(keys)) {
if(objKey === keys) {
delete finalObject[keys as keyof typeof finalObject];
break;
}
continue;
}
for(const omitKey of keys) {
if(objKey === omitKey) {
delete finalObject[objKey as keyof typeof finalObject];
break;
}
}
}
return finalObject;
}
export function variableToBoolean(variable: any|Accessor<any>|Accessor<Array<any>>): boolean|Accessor<boolean> {
return (variable instanceof Accessor) ?
variable.as(v => Array.isArray(v) ?
(v as Array<any>).length > 0
: Boolean(v))
: Boolean(variable);
}
export function transform<ValueType = any|Array<any>, RType = any>(
v: Accessor<ValueType>|ValueType, fn: (v: ValueType) => RType
): RType|Accessor<RType> {
return (v instanceof Accessor) ?
v.as(fn)
: fn(v);
}
export function transformWidget<ValueType = unknown>(
v: Accessor<ValueType|Array<ValueType>>|ValueType|Array<ValueType>,
fn: (v: ValueType, i?: Accessor<number>|number) => JSX.Element
): WidgetNodeType {
return (v instanceof Accessor) ?
Array.isArray(v.get()) ?
For({
each: v as Accessor<Array<ValueType>>,
children: (cval, i) => fn(cval, i)
})
: With({
value: v as Accessor<ValueType>,
children: fn
})
: (Array.isArray(v) ?
v.map(val => fn(val))
: fn(v));
}
export function makeDirectory(dir: string): void {
@@ -41,3 +102,26 @@ export function isInstalled(commandName: string): boolean {
return false;
}
export function addSliderMarksFromMinMax(slider: Astal.Slider, amountOfMarks: number = 2, markup?: (string | null)) {
if(markup && !markup.includes("{}"))
markup = `${markup}{}`
slider.add_mark(slider.min, Gtk.PositionType.BOTTOM, markup ?
markup.replaceAll("{}", `${slider.min}`) : null);
const num = (amountOfMarks - 1);
for(let i = 1; i <= num; i++) {
const part = (slider.max / num) | 0;
if(i > num) {
slider.add_mark(slider.max, Gtk.PositionType.BOTTOM, `${slider.max}K`);
break;
}
slider.add_mark(part*i, Gtk.PositionType.BOTTOM, markup ?
markup.replaceAll("{}", `${part*i}`) : null);
}
return slider;
}
-24
View File
@@ -1,24 +0,0 @@
import { Gtk, Astal } from "ags/gtk4";
export function addSliderMarksFromMinMax(slider: Astal.Slider, amountOfMarks: number = 2, markup?: (string | null)) {
if(markup && !markup.includes("{}"))
markup = `${markup}{}`
slider.add_mark(slider.min, Gtk.PositionType.BOTTOM, markup ?
markup.replaceAll("{}", `${slider.min}`) : null);
const num = (amountOfMarks - 1);
for(let i = 1; i <= num; i++) {
const part = (slider.max / num) | 0;
if(i > num) {
slider.add_mark(slider.max, Gtk.PositionType.BOTTOM, `${slider.max}K`);
break;
}
slider.add_mark(part*i, Gtk.PositionType.BOTTOM, markup ?
markup.replaceAll("{}", `${part*i}`) : null);
}
return slider;
}