Initial commit

This commit is contained in:
2025-02-06 12:05:55 +01:00
commit 82da1c1ecb
24 changed files with 829 additions and 0 deletions

6
lib/icons.tsx Normal file
View File

@ -0,0 +1,6 @@
export default {
battery: {
charging: "battery-symbolic",
discharging: "battery-caution-symbolic"
}
};

16
lib/utils.ts Normal file
View File

@ -0,0 +1,16 @@
import { Gtk, Gdk } from "astal/gtk4";
export type If<Condition, Then, Else> = Condition extends true ? Then : Else;
export type Belongs<T, U> = {
[K in keyof T]: T[K] extends U ? K : never;
}[keyof T];
export const hideWindow = (self: Gtk.Window, keyval: number) => {
if (keyval === Gdk.KEY_Escape) self.hide();
}
export const openOnButton = (event: Gdk.ButtonEvent, keyval: number) => (action: () => void) => {
if (event.get_button() !== keyval) return;
action();
}

24
lib/widgets/datetime.tsx Normal file
View File

@ -0,0 +1,24 @@
import { Variable, GLib } from "astal";
import { Widget } from "astal/gtk4";
type Props = {
format: string,
interval?: number
} & Widget.LabelProps;
export default function DateTime({ format, interval, ...props }: Props) {
const shouldPoll = typeof interval === "number" && interval >= 1;
const currentTime = () => {
const dateTime = GLib.DateTime.new_now_local();
return dateTime.format(format)!;
}
if (shouldPoll) {
const pollTime = new Variable(currentTime()).poll(interval || 1000, currentTime);
return <label label={pollTime()} {...props} />
} else {
const time = new Variable(currentTime())
return <label label={time()} {...props} />
}
}