✨ ags: add ask popup, make notifications work(finally :3) and more improvements
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
import { Variable } from "astal";
|
||||
import { Astal, Gdk, Gtk, Widget } from "astal/gtk3";
|
||||
import { getAstalApps } from "../scripts/apps";
|
||||
import AstalApps from "gi://AstalApps";
|
||||
import AstalHyprland from "gi://AstalHyprland";
|
||||
|
||||
const { TOP, LEFT, RIGHT, BOTTOM } = Astal.WindowAnchor;
|
||||
const searchString = new Variable<string>("");
|
||||
const appsArray = new Variable<Array<AstalApps.Application>>([]);
|
||||
let searchSubscription: () => void;
|
||||
|
||||
export const AppsWindow = new Widget.Window({
|
||||
namespace: "apps-window",
|
||||
layer: Astal.Layer.OVERLAY,
|
||||
exclusivity: Astal.Exclusivity.IGNORE,
|
||||
anchor: TOP | LEFT | RIGHT | BOTTOM,
|
||||
visible: false,
|
||||
keymode: Astal.Keymode.EXCLUSIVE,
|
||||
onKeyPressEvent: (_, event: Gdk.Event) => {
|
||||
event.get_keyval()[1] === Gdk.KEY_Escape &&
|
||||
hideAppsWindow(_);
|
||||
},
|
||||
setup: () => {
|
||||
searchSubscription = searchString.subscribe((str: string) => {
|
||||
appsArray.set(getAstalApps().fuzzy_query(str));
|
||||
});
|
||||
},
|
||||
child: new Widget.Box({
|
||||
className: "apps-window container",
|
||||
expand: true,
|
||||
orientation: Gtk.Orientation.VERTICAL,
|
||||
children: [
|
||||
new Widget.Entry({
|
||||
className: "entry",
|
||||
hexpand: true,
|
||||
vexpand: false,
|
||||
onDraw: (_) => _.grab_focus(),
|
||||
onChanged: (entry) => {
|
||||
searchString.set(entry.text);
|
||||
}
|
||||
} as Widget.EntryProps),
|
||||
new Widget.Box({
|
||||
className: "apps",
|
||||
hexpand: true,
|
||||
vexpand: true,
|
||||
orientation: Gtk.Orientation.VERTICAL,
|
||||
children: appsArray((apps: Array<AstalApps.Application>) =>
|
||||
apps.map((app: AstalApps.Application) =>
|
||||
new Widget.Button({
|
||||
className: "app",
|
||||
onClickRelease: (_) => {
|
||||
_.get_window()?.hide();
|
||||
AstalHyprland.get_default().dispatch("exec", app.get_executable());
|
||||
},
|
||||
child: new Widget.Box({
|
||||
orientation: Gtk.Orientation.VERTICAL,
|
||||
children: [
|
||||
new Widget.Icon({
|
||||
className: "icon",
|
||||
iconName: app.get_icon_name()
|
||||
} as Widget.IconProps),
|
||||
new Widget.Label({
|
||||
className: "name",
|
||||
label: app.get_name()
|
||||
} as Widget.LabelProps)
|
||||
]
|
||||
} as Widget.BoxProps)
|
||||
} as Widget.ButtonProps)
|
||||
)
|
||||
)
|
||||
} as Widget.BoxProps)
|
||||
]
|
||||
} as Widget.BoxProps)
|
||||
} as Widget.WindowProps);
|
||||
|
||||
function hideAppsWindow(window: Widget.Window) {
|
||||
searchString.set("");
|
||||
window.hide();
|
||||
}
|
||||
@@ -6,6 +6,8 @@ import { BigMedia } from "../widget/center-window/BigMedia";
|
||||
import { Separator, SeparatorProps } from "../widget/Separator";
|
||||
import { PopupWindow, PopupWindowProps } from "../widget/PopupWindow";
|
||||
|
||||
const BigMediaWidget = BigMedia();
|
||||
|
||||
export const CenterWindow: Widget.Window = PopupWindow({
|
||||
className: "center-window",
|
||||
namespace: "center-window",
|
||||
@@ -53,7 +55,7 @@ export const CenterWindow: Widget.Window = PopupWindow({
|
||||
]
|
||||
} as Widget.BoxProps),
|
||||
Separator({
|
||||
visible: bind(BigMedia, "visible"),
|
||||
visible: bind(BigMediaWidget, "visible"),
|
||||
orientation: Gtk.Orientation.HORIZONTAL,
|
||||
alpha: .5,
|
||||
cssColor: "gray",
|
||||
@@ -63,7 +65,7 @@ export const CenterWindow: Widget.Window = PopupWindow({
|
||||
className: "vertical right",
|
||||
orientation: Gtk.Orientation.VERTICAL,
|
||||
children: [
|
||||
BigMedia
|
||||
BigMediaWidget
|
||||
]
|
||||
} as Widget.BoxProps)
|
||||
]
|
||||
|
||||
+27
-10
@@ -4,16 +4,9 @@ import { Tiles } from "../widget/control-center/Tiles";
|
||||
import { Sliders } from "../widget/control-center/Sliders";
|
||||
import { PopupWindow, PopupWindowProps } from "../widget/PopupWindow";
|
||||
import { hidePages, PagesWidget } from "../widget/control-center/Pages";
|
||||
import { NotifHistory } from "../widget/control-center/NotifHistory";
|
||||
|
||||
const widgetsContainer: Widget.Box = new Widget.Box({
|
||||
className: "control-center-container",
|
||||
orientation: Gtk.Orientation.VERTICAL,
|
||||
widthRequest: 400,
|
||||
} as Widget.BoxProps,
|
||||
QuickActions,
|
||||
Sliders,
|
||||
Tiles,
|
||||
PagesWidget);
|
||||
const connections: Array<number> = [];
|
||||
|
||||
export const ControlCenter: Widget.Window = PopupWindow({
|
||||
className: "control-center",
|
||||
@@ -25,5 +18,29 @@ export const ControlCenter: Widget.Window = PopupWindow({
|
||||
halign: Gtk.Align.END,
|
||||
valign: Gtk.Align.START,
|
||||
visible: false,
|
||||
child: widgetsContainer
|
||||
vexpand: true,
|
||||
child: new Widget.Box({
|
||||
orientation: Gtk.Orientation.VERTICAL,
|
||||
vexpand: true,
|
||||
children: [
|
||||
new Widget.Box({
|
||||
className: "control-center-container",
|
||||
orientation: Gtk.Orientation.VERTICAL,
|
||||
widthRequest: 400,
|
||||
vexpand: false,
|
||||
hexpand: true,
|
||||
children: [
|
||||
QuickActions,
|
||||
Sliders,
|
||||
Tiles,
|
||||
PagesWidget
|
||||
]
|
||||
} as Widget.BoxProps),
|
||||
NotifHistory
|
||||
]
|
||||
} as Widget.BoxProps)
|
||||
} as PopupWindowProps);
|
||||
|
||||
connections.push(ControlCenter.connect("hide", (_) => {
|
||||
hidePages();
|
||||
}));
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
import { Astal, Gtk, Widget } from "astal/gtk3";
|
||||
import AstalNotifd from "gi://AstalNotifd";
|
||||
import { Notifications } from "../scripts/notification-handler";
|
||||
import { bind } from "astal/binding";
|
||||
import { Notifications } from "../scripts/notifications";
|
||||
import { NotificationWidget } from "../widget/Notification";
|
||||
import { timeout } from "astal";
|
||||
import { VarMap } from "../scripts/varmap";
|
||||
|
||||
const connections: Array<number> = [];
|
||||
const notifWidgets = new VarMap<number, Widget.Revealer>();
|
||||
|
||||
export const FloatingNotifications: Widget.Window = new Widget.Window({
|
||||
namespace: "floating-notifications",
|
||||
@@ -9,14 +16,43 @@ export const FloatingNotifications: Widget.Window = new Widget.Window({
|
||||
monitor: 0,
|
||||
layer: Astal.Layer.OVERLAY,
|
||||
visible: false,
|
||||
width_request: 350,
|
||||
widthRequest: 450,
|
||||
exclusivity: Astal.Exclusivity.NORMAL,
|
||||
setup: (window) => {
|
||||
connections.push(
|
||||
Notifications.getDefault().connect("notification-added", (_, notif: AstalNotifd.Notification) => {
|
||||
!window.is_visible() && window.show();
|
||||
|
||||
notifWidgets.set(notif.id, new Widget.Revealer({
|
||||
revealChild: false,
|
||||
transitionDuration: 320,
|
||||
transitionType: Gtk.RevealerTransitionType.SLIDE_RIGHT,
|
||||
child: NotificationWidget(notif,
|
||||
() => Notifications.getDefault().removeNotification(notif.id)),
|
||||
} as Widget.RevealerProps));
|
||||
|
||||
notifWidgets.getValue(notif.id)!.revealChild = true;
|
||||
}),
|
||||
|
||||
Notifications.getDefault().connect("notification-removed", (_, id: number) => {
|
||||
notifWidgets.getValue(id)!.revealChild = false;
|
||||
timeout(
|
||||
(notifWidgets.getValue(id)?.get_transition_duration() || 0) + 50,
|
||||
() => {
|
||||
notifWidgets.delete(id);
|
||||
Notifications.getDefault().notifications.length === 0 &&
|
||||
window.is_visible() && window.hide();
|
||||
}
|
||||
);
|
||||
})
|
||||
);
|
||||
},
|
||||
onDestroy: () => connections.map(id => Notifications.getDefault().disconnect(id)),
|
||||
child: new Widget.Box({
|
||||
className: "floating-notifications-container",
|
||||
orientation: Gtk.Orientation.VERTICAL,
|
||||
homogeneous: false,
|
||||
children: Notifications.notifications().as((notifications: Array<AstalNotifd.Notification>) =>
|
||||
notifications.map((item: AstalNotifd.Notification) =>
|
||||
NotificationWidget(item)))
|
||||
visible: bind(Notifications.getDefault(), "notifications").as(notifs => notifs.length > 0),
|
||||
children: bind(notifWidgets).as((map) => [...map.values()].map((revealer) => revealer))
|
||||
} as Widget.BoxProps)
|
||||
} as Widget.WindowProps);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Astal, Gdk, Gtk, Widget } from "astal/gtk3";
|
||||
import { getDateTime } from "../scripts/time";
|
||||
import { execAsync, GLib } from "astal";
|
||||
import { AskPopup } from "../widget/AskPopup";
|
||||
|
||||
|
||||
const { TOP, LEFT, RIGHT, BOTTOM } = Astal.WindowAnchor;
|
||||
@@ -26,7 +27,8 @@ export const LogoutMenu: Widget.Window = new Widget.Window({
|
||||
children: [
|
||||
new Widget.Box({
|
||||
className: "top",
|
||||
expand: false,
|
||||
hexpand: true,
|
||||
vexpand: false,
|
||||
orientation: Gtk.Orientation.VERTICAL,
|
||||
valign: Gtk.Align.START,
|
||||
children: [
|
||||
@@ -45,28 +47,53 @@ export const LogoutMenu: Widget.Window = new Widget.Window({
|
||||
new Widget.Box({
|
||||
className: "button-row",
|
||||
homogeneous: true,
|
||||
expand: true,
|
||||
vexpand: true,
|
||||
valign: Gtk.Align.CENTER,
|
||||
height_request: 360,
|
||||
children: [
|
||||
new Widget.Button({
|
||||
className: "poweroff nf",
|
||||
label: "",
|
||||
onClick: () => execAsync("systemctl poweroff")
|
||||
onClick: () => AskPopup({
|
||||
title: "Power Off",
|
||||
text: "Are you sure you want to power off? Unsaved work will be lost.",
|
||||
cancelText: "No! Let me go back",
|
||||
acceptText: "Yes, shutdown",
|
||||
onAccept: () => execAsync("systemctl poweroff")
|
||||
})
|
||||
} as Widget.ButtonProps),
|
||||
new Widget.Button({
|
||||
className: "reboot nf",
|
||||
label: "",
|
||||
onClick: () => execAsync("systemctl reboot")
|
||||
onClick: () => AskPopup({
|
||||
title: "Reboot",
|
||||
text: "Are you sure you want to Reboot? Unsaved work will be lost.",
|
||||
cancelText: "No! Let me go back",
|
||||
acceptText: "Yes, reboot",
|
||||
onAccept: () => execAsync("systemctl reboot")
|
||||
})
|
||||
} as Widget.ButtonProps),
|
||||
new Widget.Button({
|
||||
className: "suspend nf",
|
||||
label: "",
|
||||
onClick: () => execAsync("systemctl suspend")
|
||||
onClick: () => AskPopup({
|
||||
title: "Suspend",
|
||||
text: "Are you sure you want to Suspend?",
|
||||
cancelText: "No! Let me go back",
|
||||
acceptText: "Yes, suspend",
|
||||
onAccept: () => execAsync("systemctl suspend")
|
||||
})
|
||||
} as Widget.ButtonProps),
|
||||
new Widget.Button({
|
||||
className: "logout nf",
|
||||
label: "",
|
||||
onClick: () => execAsync("astal close logout-menu && bash -c 'loginctl terminate-user $USER'")
|
||||
onClick: () => AskPopup({
|
||||
title: "Log out",
|
||||
text: "Are you sure you want to log out? Your session will be ended.",
|
||||
cancelText: "No! Let me go back",
|
||||
acceptText: "Yes, please log out",
|
||||
onAccept: () => execAsync(`sh -c "loginctl terminate-user ${GLib.getenv("USER") || "$USER"}"`)
|
||||
})
|
||||
} as Widget.ButtonProps),
|
||||
]
|
||||
} as Widget.BoxProps)
|
||||
|
||||
+174
-31
@@ -1,41 +1,184 @@
|
||||
import { Variable } from "astal";
|
||||
import { Astal, Gtk, Widget } from "astal/gtk3";
|
||||
import { Gdk, Gtk, Widget } from "astal/gtk3";
|
||||
import { PopupWindow, PopupWindowProps } from "../widget/PopupWindow";
|
||||
import { updateApps } from "../scripts/apps";
|
||||
import { handleShell } from "../scripts/runner/shell";
|
||||
import { handleWebSearch } from "../scripts/runner/websearch";
|
||||
import { handleApplications } from "../scripts/runner/apps";
|
||||
import { ResultWidget, ResultWidgetProps } from "../widget/runner/ResultWidget";
|
||||
import Wp05 from "gi://Wp";
|
||||
|
||||
// TODO
|
||||
export let runnerInstance: (Widget.Window|null) = null;
|
||||
|
||||
export interface RunnerProps {
|
||||
halign?: Gtk.Align;
|
||||
valign?: Gtk.Align;
|
||||
width?: number;
|
||||
height?: number;
|
||||
entryPlaceHolder?: string;
|
||||
resultsPlaceholder?: Array<Gtk.Widget>;
|
||||
export function closeRunner(gtkWindow?: Widget.Window) {
|
||||
const window = gtkWindow ? gtkWindow : runnerInstance;
|
||||
|
||||
window?.destroy();
|
||||
runnerInstance = null;
|
||||
}
|
||||
|
||||
export function Runner(props?: RunnerProps) {
|
||||
export function startRunnerDefault() {
|
||||
return Runner.RunnerWindow({
|
||||
entryPlaceHolder: "Start typing...",
|
||||
resultsPlaceholder: () => [
|
||||
new ResultWidget({
|
||||
icon: "utilities-terminal-symbolic",
|
||||
title: "Run shell commands",
|
||||
description: "Start typing with '!' prefix to run shell commands"
|
||||
} as ResultWidgetProps),
|
||||
new ResultWidget({
|
||||
icon: "application-x-executable-symbolic",
|
||||
title: "Run your applications",
|
||||
description: "Type the name of the application to search"
|
||||
} as ResultWidgetProps),
|
||||
new ResultWidget({
|
||||
icon: "applications-internet-symbolic",
|
||||
title: "Search the Web",
|
||||
description: "Start typing with '?' prefix to search the web"
|
||||
} as ResultWidgetProps)
|
||||
]
|
||||
} as Runner.RunnerProps);
|
||||
}
|
||||
|
||||
const entryText: Variable<string> = new Variable<string>("");
|
||||
export namespace Runner {
|
||||
export type RunnerProps = {
|
||||
halign?: Gtk.Align;
|
||||
valign?: Gtk.Align;
|
||||
width?: number;
|
||||
height?: number;
|
||||
entryPlaceHolder?: string;
|
||||
resultsPlaceholder?: () => Array<Gtk.Widget>;
|
||||
};
|
||||
|
||||
const resultsBox: Widget.Box = new Widget.Box({
|
||||
className: "results",
|
||||
export const prefixes = new Map<string, (entry: string) => (ResultWidget|Array<ResultWidget>|null)>([
|
||||
[ "!", handleShell ],
|
||||
[ "?", handleWebSearch ],
|
||||
]);
|
||||
|
||||
export function RunnerWindow(props?: RunnerProps): (Widget.Window|null) {
|
||||
let subs: Array<() => void> = [];
|
||||
const entryText: Variable<string> = new Variable<string>("");
|
||||
let results: (Array<ResultWidget>|null) = null;
|
||||
let selectedResultIndex = 0;
|
||||
|
||||
const searchEntry = new Widget.Entry({
|
||||
className: "search",
|
||||
onChanged: (entry) => entryText.set(entry.text),
|
||||
placeholderText: props?.entryPlaceHolder || "",
|
||||
primary_icon_name: "system-search"
|
||||
} as Widget.EntryProps);
|
||||
|
||||
const resultsList: Gtk.ListBox = new Gtk.ListBox({
|
||||
visible: true,
|
||||
expand: true
|
||||
} as Gtk.ListBox.ConstructorProps);
|
||||
|
||||
subs.push(entryText().subscribe((text: string) => {
|
||||
const trimmedText = text.trim();
|
||||
const pluginResult: (ResultWidget|Array<ResultWidget>|null|undefined) = handlePrefix(
|
||||
trimmedText)?.(trimmedText.replace(trimmedText.charAt(0), ""));
|
||||
results = Boolean(pluginResult) ?
|
||||
(!Array.isArray(pluginResult) ?
|
||||
[ pluginResult! ]
|
||||
: pluginResult)
|
||||
: null;
|
||||
|
||||
[
|
||||
new Widget.Box({
|
||||
className: "not-found",
|
||||
orientation: Gtk.Orientation.VERTICAL,
|
||||
visible: entryText((text: string) => text.trim().length > 0),
|
||||
expand: true,
|
||||
children: [
|
||||
new Widget.Icon({
|
||||
icon: "software-update-urgent-symbolic"
|
||||
} as Widget.IconProps),
|
||||
new Widget.Label({
|
||||
label: "Couldn't find any results with this search. Maybe try pressing F5 and searching again?",
|
||||
truncate: false,
|
||||
wrap: true
|
||||
} as Widget.LabelProps)
|
||||
]
|
||||
} as Widget.BoxProps),
|
||||
new Widget.Box({
|
||||
className: "placeholder",
|
||||
orientation: Gtk.Orientation.VERTICAL,
|
||||
expand: true,
|
||||
visible: Boolean(props?.resultsPlaceholder),
|
||||
children: props?.resultsPlaceholder &&
|
||||
props?.resultsPlaceholder()
|
||||
} as Widget.BoxProps)
|
||||
];
|
||||
|
||||
if(resultsList.get_children().length > 0) {
|
||||
resultsList.get_children().map((listItem: Gtk.Widget) => {
|
||||
resultsList.remove(listItem);
|
||||
listItem.destroy();
|
||||
});
|
||||
}
|
||||
|
||||
if(results && results.length > 0)
|
||||
results.map((resultWidget: ResultWidget) => {
|
||||
resultsList.insert(resultWidget, -1);
|
||||
});
|
||||
|
||||
selectedResultIndex = 0;
|
||||
resultsList.select_row(resultsList.get_row_at_index(selectedResultIndex));
|
||||
}));
|
||||
|
||||
if(!runnerInstance)
|
||||
runnerInstance = PopupWindow({
|
||||
namespace: "runner",
|
||||
halign: props?.halign || Gtk.Align.CENTER,
|
||||
valign: props?.valign || Gtk.Align.CENTER,
|
||||
widthRequest: props?.width || 750,
|
||||
heightRequest: props?.height || 450,
|
||||
onKeyPressEvent: (_, event: Gdk.Event) => {
|
||||
event.get_keyval()[1] === Gdk.KEY_F5 &&
|
||||
updateApps();
|
||||
|
||||
if(event.get_keyval()[1] === Gdk.KEY_Down) {
|
||||
resultsList.get_children().length > 0 &&
|
||||
resultsList.select_row(resultsList.get_row_at_index(
|
||||
(selectedResultIndex + 1) > (resultsList.get_children().length - 1) ?
|
||||
0
|
||||
: selectedResultIndex + 1
|
||||
));
|
||||
}
|
||||
},
|
||||
closeAction: (_) => closeRunner(_),
|
||||
onClose: () => subs.map(sub => sub()),
|
||||
child: new Widget.Box({
|
||||
className: "runner main",
|
||||
orientation: Gtk.Orientation.VERTICAL,
|
||||
children: [
|
||||
searchEntry,
|
||||
new Widget.Scrollable({
|
||||
className: "results-scrollable",
|
||||
vscroll: Gtk.PolicyType.AUTOMATIC,
|
||||
hscroll: Gtk.PolicyType.NEVER,
|
||||
expand: true,
|
||||
child: resultsList
|
||||
})
|
||||
]
|
||||
} as Widget.BoxProps)
|
||||
} as PopupWindowProps);
|
||||
|
||||
return runnerInstance;
|
||||
}
|
||||
|
||||
export function handlePrefix(text: string): (((a: string) => (Array<ResultWidget>|ResultWidget|null)) | null) {
|
||||
const prefix = text.charAt(0);
|
||||
let result: (((a: string) => ResultWidget|Array<ResultWidget>|null)|null) = null;
|
||||
|
||||
if(/([a-z]|[A-Z]|[0-9])/.test(prefix))
|
||||
result = handleApplications;
|
||||
|
||||
[...prefixes.keys()].map((curPrefix: string) => {
|
||||
if(curPrefix === prefix)
|
||||
result = prefixes.get(curPrefix)!;
|
||||
});
|
||||
|
||||
} as Widget.BoxProps);
|
||||
|
||||
return PopupWindow({
|
||||
namespace: "runner",
|
||||
halign: props?.halign || Gtk.Align.CENTER,
|
||||
valign: props?.valign || Gtk.Align.CENTER,
|
||||
widthRequest: props?.width || 600,
|
||||
heightRequest: props?.height || 500,
|
||||
child: new Widget.Box({
|
||||
className: "main",
|
||||
children: [
|
||||
new Widget.Entry({
|
||||
className: "search",
|
||||
onChanged: (entry) => entryText.set(entry.text),
|
||||
} as Widget.EntryProps),
|
||||
]
|
||||
} as Widget.BoxProps)
|
||||
} as PopupWindowProps);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,10 +24,9 @@ export const Wallpaper: Widget.Window = new Widget.Window({
|
||||
exclusivity: Astal.Exclusivity.IGNORE,
|
||||
keymode: Astal.Keymode.NONE,
|
||||
visible: true,
|
||||
style: new Gtk.Style(),
|
||||
css: ".wallpaper { all: unset; }",
|
||||
monitor: 0, //Needs rework for all monitors
|
||||
child: new Widget.Box({
|
||||
className: "wallpaper",
|
||||
} as Widget.BoxProps),
|
||||
onButtonPressEvent: (_, event: Gdk.Event) => {
|
||||
const [ , x, y ] = event.get_coords();
|
||||
if(event.get_button()[1] === Gdk.BUTTON_SECONDARY)
|
||||
|
||||
Reference in New Issue
Block a user