summaryrefslogtreecommitdiff
path: root/src/widgets/popupwindow.ts
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-01-27 12:40:15 +1100
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-01-27 12:40:15 +1100
commit751c3bc78970e76dcf341f57f5f0c42915ab5b97 (patch)
tree9913d7ca851a7c1257376536fb12c688849b08ba /src/widgets/popupwindow.ts
parentscss: darken bar and popdowns (diff)
downloadcaelestia-shell-751c3bc78970e76dcf341f57f5f0c42915ab5b97.tar.gz
caelestia-shell-751c3bc78970e76dcf341f57f5f0c42915ab5b97.tar.bz2
caelestia-shell-751c3bc78970e76dcf341f57f5f0c42915ab5b97.zip
popupwindow: fix offscreen popup
Force window to appear fully on screen by clamping margin
Diffstat (limited to 'src/widgets/popupwindow.ts')
-rw-r--r--src/widgets/popupwindow.ts10
1 files changed, 9 insertions, 1 deletions
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();
}
}