From 751c3bc78970e76dcf341f57f5f0c42915ab5b97 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Mon, 27 Jan 2025 12:40:15 +1100 Subject: popupwindow: fix offscreen popup Force window to appear fully on screen by clamping margin --- src/widgets/popupwindow.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/widgets/popupwindow.ts b/src/widgets/popupwindow.ts index bbc6053..39fff5e 100644 --- a/src/widgets/popupwindow.ts +++ b/src/widgets/popupwindow.ts @@ -30,11 +30,19 @@ export default class PopupWindow extends Widget.Window { popup_at_widget(widget: JSX.Element, event: Gdk.Event | Astal.ClickEvent) { const { width, height } = widget.get_allocation(); + const mWidth = AstalHyprland.get_default().get_focused_monitor().get_width(); + const pWidth = this.get_preferred_width()[1]; const [, x, y] = event instanceof Gdk.Event ? event.get_coords() : [null, event.x, event.y]; const { x: cx, y: cy } = AstalHyprland.get_default().get_cursor_position(); + + let marginLeft = cx + ((width - pWidth) / 2 - x); + if (marginLeft < 0) marginLeft = 0; + else if (marginLeft + pWidth > mWidth) marginLeft = mWidth - pWidth; + this.anchor = Astal.WindowAnchor.TOP | Astal.WindowAnchor.LEFT; - this.marginLeft = cx + ((width - this.get_preferred_width()[1]) / 2 - x); + this.marginLeft = marginLeft; this.marginTop = cy + (height - y); + this.show(); } } -- cgit v1.2.3-freya