💥 ags(popup-window, ask-popup): fix unexpected behaviors, removed onClose() and closeAction() support

This commit is contained in:
retrozinndev
2025-04-16 19:44:18 -03:00
parent cc043e4e55
commit 5376eb6576
7 changed files with 39 additions and 45 deletions
+5 -6
View File
@@ -47,11 +47,7 @@ export namespace Runner {
}; };
export function close() { export function close() {
[...plugins.values()].map(plugin =>
plugin && plugin.onClose && plugin.onClose());
runnerInstance?.close(); runnerInstance?.close();
runnerInstance = null;
} }
const plugins = new Set<Runner.Plugin>([]); const plugins = new Set<Runner.Plugin>([]);
@@ -181,9 +177,12 @@ export namespace Runner {
event.get_keyval()[1] === Gdk.KEY_F5 && event.get_keyval()[1] === Gdk.KEY_F5 &&
updateApps(); updateApps();
}, },
closeAction: () => { onDestroy: () => {
subs.map(sub => sub()); subs.map(sub => sub());
close();
[...plugins.values()].map(plugin =>
plugin && plugin.onClose && plugin.onClose());
runnerInstance = null;
}, },
child: new Widget.Box({ child: new Widget.Box({
className: "runner main", className: "runner main",
+4 -4
View File
@@ -16,16 +16,16 @@
* { * {
@include mixins.reset-props; @include mixins.reset-props;
/*&:selected {
box-shadow: inset 0 0 0 2px colors.$fg-primary;
}*/
} }
window * { window * {
@include mixins.default-styles; @include mixins.default-styles;
} }
window.ask-popup {
background: rgba(black, .4);
}
.ask-popup-box { .ask-popup-box {
background: colors.$bg-translucent; background: colors.$bg-translucent;
padding: 18px; padding: 18px;
+15 -17
View File
@@ -5,6 +5,7 @@ import { Separator } from "./Separator";
import { tr } from "../i18n/intl"; import { tr } from "../i18n/intl";
import { Windows } from "../windows"; import { Windows } from "../windows";
export type AskPopupProps = { export type AskPopupProps = {
title?: string | Binding<string | undefined>; title?: string | Binding<string | undefined>;
text: string | Binding<string | undefined>; text: string | Binding<string | undefined>;
@@ -15,29 +16,27 @@ export type AskPopupProps = {
}; };
/** /**
* A Popup Widget that asks yes or no to a certain question. * A Popup Widget that asks yes or no to a defined promt.
* Runs onAccept() when user accepts or else onDecline() when * Runs onAccept() when user accepts, or else onDecline() when
* user doesn't accept or closes window. * user doesn't accept / closes window.
* This window isn't registered in this shell windowing stuff. * This window isn't usually registered in this shell windowing
* system.
*/ */
export function AskPopup(props: AskPopupProps): Gtk.Window { export function AskPopup(props: AskPopupProps): Widget.Window {
const buttons = [ const buttons = [
new Widget.Button({ new Widget.Button({
className: "cancel", className: "cancel",
hexpand: true, hexpand: true,
label: props.cancelText || tr("ask_popup.options.cancel") || "Cancel", label: props.cancelText || tr("ask_popup.options.cancel") || "Cancel",
onClick: (_) => { onClick: () => window.close(),
window.close();
props.onCancel && props.onCancel();
}
} as Widget.ButtonProps), } as Widget.ButtonProps),
new Widget.Button({ new Widget.Button({
className: "accept", className: "accept",
hexpand: true, hexpand: true,
label: props.acceptText || tr("ask_popup.options.accept") || "Ok", label: props.acceptText || tr("ask_popup.options.accept") || "Ok",
onClick: (_) => { onClick: () => {
window.close(); window.close();
props.onAccept && props.onAccept(); props.onAccept?.();
} }
} as Widget.ButtonProps) } as Widget.ButtonProps)
]; ];
@@ -46,13 +45,12 @@ export function AskPopup(props: AskPopupProps): Gtk.Window {
namespace: "ask-popup", namespace: "ask-popup",
className: "ask-popup", className: "ask-popup",
monitor: mon, monitor: mon,
cssBackgroundWindow: "background: rgba(0, 0, 0, .3);",
exclusivity: Astal.Exclusivity.IGNORE, exclusivity: Astal.Exclusivity.IGNORE,
widthRequest: 350, layer: Astal.Layer.OVERLAY,
heightRequest: 200, widthRequest: 400,
onClose: (_) => { heightRequest: 220,
props.onCancel && props.onCancel(); onDestroy: () => props.onCancel?.(),
_.destroy();
},
child: new Widget.Box({ child: new Widget.Box({
className: "ask-popup-box", className: "ask-popup-box",
orientation: Gtk.Orientation.VERTICAL, orientation: Gtk.Orientation.VERTICAL,
+6 -2
View File
@@ -1,13 +1,16 @@
import { Binding } from "astal";
import { Astal, Gdk, Widget } from "astal/gtk3"; import { Astal, Gdk, Widget } from "astal/gtk3";
const { TOP, LEFT, RIGHT, BOTTOM } = Astal.WindowAnchor; const { TOP, LEFT, RIGHT, BOTTOM } = Astal.WindowAnchor;
export type BackgroundWindowProps = { export type BackgroundWindowProps = {
/** GtkWindow Layer */
layer?: Astal.Layer | Binding<Astal.Layer | undefined>;
/** Monitor number where the window should open */ /** Monitor number where the window should open */
monitor: number; monitor: number | Binding<number | undefined>;
/** Custom stylesheet used in the window. default: `background: rgba(0, 0, 0, .2)` */ /** Custom stylesheet used in the window. default: `background: rgba(0, 0, 0, .2)` */
css?: string; css?: string | Binding<string | undefined>;
/** Function that is called when the user clicks on the window (any mouse button) */ /** Function that is called when the user clicks on the window (any mouse button) */
onClick?: (window: Widget.Window) => void; onClick?: (window: Widget.Window) => void;
/** Function that is called when the user clicks on the window with primary mouse button */ /** Function that is called when the user clicks on the window with primary mouse button */
@@ -29,6 +32,7 @@ export function BackgroundWindow(props: BackgroundWindowProps) {
namespace: "background-window", namespace: "background-window",
css: props.css ?? "background: rgba(0, 0, 0, .2);", css: props.css ?? "background: rgba(0, 0, 0, .2);",
monitor: props.monitor, monitor: props.monitor,
layer: props.layer ?? Astal.Layer.OVERLAY,
anchor: TOP | LEFT | BOTTOM | RIGHT, anchor: TOP | LEFT | BOTTOM | RIGHT,
exclusivity: Astal.Exclusivity.IGNORE, exclusivity: Astal.Exclusivity.IGNORE,
onButtonPressEvent: (window, event: Gdk.Event) => { onButtonPressEvent: (window, event: Gdk.Event) => {
+8 -15
View File
@@ -1,17 +1,10 @@
import { Binding } from "astal"; import { Binding } from "astal";
import { Astal, Gdk, Widget } from "astal/gtk3"; import { Astal, Gdk, Widget } from "astal/gtk3";
import { BackgroundWindow } from "./BackgroundWindow"; import { BackgroundWindow } from "./BackgroundWindow";
import { Windows } from "../windows";
type PopupWindowSpecificProps = { type PopupWindowSpecificProps = {
onDestroy?: (self: Widget.Window) => void; onDestroy?: (self: Widget.Window) => void;
onKeyPressEvent?: (win: Widget.Window, event: Gdk.Event) => void; onKeyPressEvent?: (win: Widget.Window, event: Gdk.Event) => void;
/** Do something else instead of closing window on close action(clicking outside conent/pressing Escape)
* Observation: onClose() will still be called after close action, if defined.
*/
closeAction?: (self: Widget.Window) => void;
/** Do something when window closes */
onClose?: (self: Widget.Window) => void;
/** Stylesheet for the background of the popup-window */ /** Stylesheet for the background of the popup-window */
cssBackgroundWindow?: string; cssBackgroundWindow?: string;
}; };
@@ -19,14 +12,15 @@ type PopupWindowSpecificProps = {
export type PopupWindowProps = Omit<Widget.WindowProps, "keymode"> & PopupWindowSpecificProps; export type PopupWindowProps = Omit<Widget.WindowProps, "keymode"> & PopupWindowSpecificProps;
export function PopupWindow(props: PopupWindowProps): Widget.Window { export function PopupWindow(props: PopupWindowProps): Widget.Window {
props.closeAction = props.closeAction ?? ((window) => window.close()); props.layer = props.layer ?? Astal.Layer.OVERLAY;
const bgWindow = BackgroundWindow({ const bgWindow = BackgroundWindow({
monitor: Windows.getFocusedMonitorId() ?? 0, monitor: props.monitor ?? 0,
layer: props.layer!,
css: props.cssBackgroundWindow ?? "", css: props.cssBackgroundWindow ?? "",
onClick: () => { onClick: (bgWin) => {
props.closeAction!(window); bgWin.close();
props.onClose?.(window); window.close();
} }
}); });
@@ -36,16 +30,15 @@ export function PopupWindow(props: PopupWindowProps): Widget.Window {
className: `popup-window ${(props.namespace instanceof Binding ? className: `popup-window ${(props.namespace instanceof Binding ?
props.namespace.get() : props.namespace) || ""}`, props.namespace.get() : props.namespace) || ""}`,
keymode: Astal.Keymode.EXCLUSIVE, keymode: Astal.Keymode.EXCLUSIVE,
layer: props.layer!,
onDestroy: (self) => { onDestroy: (self) => {
bgWindow.close(); bgWindow.close();
props.closeAction!(self);
props.onClose?.(self);
props.onDestroy?.(self); props.onDestroy?.(self);
}, },
onKeyPressEvent: (self, event: Gdk.Event) => { onKeyPressEvent: (self, event: Gdk.Event) => {
if(event.get_keyval()[1] === Gdk.KEY_Escape) { if(event.get_keyval()[1] === Gdk.KEY_Escape) {
props.closeAction!(self);
bgWindow.close(); bgWindow.close();
self.close();
return; return;
} }
+1 -1
View File
@@ -16,7 +16,7 @@ export const LogoutMenu = (mon: number) => new Widget.Window({
monitor: mon, monitor: mon,
onKeyPressEvent: (_, event: Gdk.Event) => { onKeyPressEvent: (_, event: Gdk.Event) => {
event.get_keyval()[1] === Gdk.KEY_Escape && event.get_keyval()[1] === Gdk.KEY_Escape &&
_.hide(); _.close();
}, },
child: new Widget.EventBox({ child: new Widget.EventBox({
className: "logout-menu", className: "logout-menu",