summaryrefslogtreecommitdiff
path: root/src/utils/widgets.ts
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-02-09 17:16:53 +1100
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-02-09 17:16:53 +1100
commit09d4e4810803f6679ee9f2b44f8e0880a1197105 (patch)
treefb8e3631035dedf4599ee0cd12f05c0addc2cb32 /src/utils/widgets.ts
parentsideright: weather wind & rain tooltips (diff)
downloadcaelestia-shell-09d4e4810803f6679ee9f2b44f8e0880a1197105.tar.gz
caelestia-shell-09d4e4810803f6679ee9f2b44f8e0880a1197105.tar.bz2
caelestia-shell-09d4e4810803f6679ee9f2b44f8e0880a1197105.zip
tooltip: ensure fully visible
Diffstat (limited to 'src/utils/widgets.ts')
-rw-r--r--src/utils/widgets.ts20
1 files changed, 18 insertions, 2 deletions
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<string>) =>
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<string>) =>
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<string>) =>
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;