From 09d4e4810803f6679ee9f2b44f8e0880a1197105 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Sun, 9 Feb 2025 17:16:53 +1100 Subject: tooltip: ensure fully visible --- src/utils/widgets.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/utils') diff --git a/src/utils/widgets.ts b/src/utils/widgets.ts index 454a7a6..365116b 100644 --- a/src/utils/widgets.ts +++ b/src/utils/widgets.ts @@ -8,6 +8,7 @@ export const setupCustomTooltip = (self: any, text: string | Binding) => const window = new Widget.Window({ visible: false, namespace: "caelestia-tooltip", + layer: Astal.Layer.OVERLAY, keymode: Astal.Keymode.NONE, exclusivity: Astal.Exclusivity.IGNORE, anchor: Astal.WindowAnchor.TOP | Astal.WindowAnchor.LEFT, @@ -19,7 +20,14 @@ export const setupCustomTooltip = (self: any, text: string | Binding) => let lastX = 0; self.connect("size-allocate", () => (dirty = true)); window.connect("size-allocate", () => { - window.marginLeft = lastX + (self.get_allocated_width() - window.get_preferred_width()[1]) / 2; + const mWidth = AstalHyprland.get_default().get_focused_monitor().get_width(); + const pWidth = window.get_preferred_width()[1]; + + let marginLeft = lastX + (self.get_allocated_width() - pWidth) / 2; + if (marginLeft < 0) marginLeft = 0; + else if (marginLeft + pWidth > mWidth) marginLeft = mWidth - pWidth; + + window.marginLeft = marginLeft; }); if (text instanceof Binding) self.hook(text, (_: any, v: string) => !v && window.hide()); @@ -27,10 +35,18 @@ export const setupCustomTooltip = (self: any, text: string | Binding) => if (text instanceof Binding && !text.get()) return false; if (dirty) { const { width, height } = self.get_allocation(); + const mWidth = AstalHyprland.get_default().get_focused_monitor().get_width(); + const pWidth = window.get_preferred_width()[1]; const { x: cx, y: cy } = AstalHyprland.get_default().get_cursor_position(); - window.marginLeft = cx + ((width - window.get_preferred_width()[1]) / 2 - x); + + let marginLeft = cx + ((width - pWidth) / 2 - x); + if (marginLeft < 0) marginLeft = 0; + else if (marginLeft + pWidth > mWidth) marginLeft = mWidth - pWidth; + + window.marginLeft = marginLeft; window.marginTop = cy + (height - y); lastX = cx - x; + dirty = false; } return true; -- cgit v1.2.3-freya