ags: add ask popup, make notifications work(finally :3) and more improvements

This commit is contained in:
retrozinndev
2025-03-09 13:45:07 -03:00
parent 161c811841
commit 59ef5e4aa7
67 changed files with 2005 additions and 731 deletions
+83
View File
@@ -0,0 +1,83 @@
import { Binding } from "astal";
import { PopupWindow, PopupWindowProps } from "./PopupWindow";
import { Astal, Gtk, Widget } from "astal/gtk3";
import { Separator } from "./Separator";
export type AskPopupProps = {
title?: string | Binding<string | undefined>;
text: string | Binding<string | undefined>;
cancelText?: string;
acceptText?: string;
onAccept: () => void;
onCancel?: () => void;
};
/**
* A Popup Widget that asks yes or no to a certain question.
* Runs onAccept() when user accepts or else onDecline() when
* user doesn't accept or closes window.
*/
export function AskPopup(props: AskPopupProps) {
const buttons = [
new Widget.Button({
className: "cancel",
hexpand: true,
label: props.cancelText || "Cancel",
onClick: (_) => {
window.destroy();
props.onCancel && props.onCancel();
}
} as Widget.ButtonProps),
new Widget.Button({
className: "accept",
hexpand: true,
label: props.acceptText || "Ok",
onClick: (_) => {
window.destroy();
props.onAccept && props.onAccept();
}
} as Widget.ButtonProps)
];
const window = PopupWindow({
namespace: "ask-popup",
visible: true,
className: "ask-popup",
exclusivity: Astal.Exclusivity.IGNORE,
widthRequest: 350,
heightRequest: 200,
onClose: (_) => {
props.onCancel && props.onCancel();
_.destroy();
},
child: new Widget.Box({
className: "ask-popup-box",
orientation: Gtk.Orientation.VERTICAL,
children: [
new Widget.Label({
className: "title",
visible: Boolean(props.title),
label: props.title || ""
} as Widget.LabelProps),
Separator({
alpha: .2,
orientation: Gtk.Orientation.VERTICAL
}),
new Widget.Label({
className: "text",
label: props.text,
yalign: 0,
expand: true
} as Widget.LabelProps),
new Widget.Box({
className: "buttons",
orientation: Gtk.Orientation.HORIZONTAL,
hexpand: true,
heightRequest: 38,
homogeneous: true,
children: buttons
} as Widget.BoxProps)
]
} as Widget.BoxProps)
} as PopupWindowProps);
}