diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-02-11 20:53:56 +1100 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-02-11 20:53:56 +1100 |
| commit | af927d12a3594a37a0c8582d76fade54d9b9e58d (patch) | |
| tree | 8db27eeb2bf667cebeacb38157678c9164e4b49f /src/utils | |
| parent | tooltip: ensure fully visible (diff) | |
| download | caelestia-shell-af927d12a3594a37a0c8582d76fade54d9b9e58d.tar.gz caelestia-shell-af927d12a3594a37a0c8582d76fade54d9b9e58d.tar.bz2 caelestia-shell-af927d12a3594a37a0c8582d76fade54d9b9e58d.zip | |
tooltip: position at cursor not widget
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/widgets.ts | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/src/utils/widgets.ts b/src/utils/widgets.ts index 365116b..fe7ff3e 100644 --- a/src/utils/widgets.ts +++ b/src/utils/widgets.ts @@ -16,14 +16,12 @@ export const setupCustomTooltip = (self: any, text: string | Binding<string>) => }); self.set_tooltip_window(window); - let dirty = true; let lastX = 0; - self.connect("size-allocate", () => (dirty = true)); window.connect("size-allocate", () => { 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; + let marginLeft = lastX - pWidth / 2; if (marginLeft < 0) marginLeft = 0; else if (marginLeft + pWidth > mWidth) marginLeft = mWidth - pWidth; @@ -31,24 +29,23 @@ export const setupCustomTooltip = (self: any, text: string | Binding<string>) => }); if (text instanceof Binding) self.hook(text, (_: any, v: string) => !v && window.hide()); - self.connect("query-tooltip", (_: any, x: number, y: number) => { + self.connect("query-tooltip", () => { 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(); + if (window.visible) return true; - let marginLeft = cx + ((width - pWidth) / 2 - x); - if (marginLeft < 0) marginLeft = 0; - else if (marginLeft + pWidth > mWidth) marginLeft = mWidth - pWidth; + const mWidth = AstalHyprland.get_default().get_focused_monitor().get_width(); + const pWidth = window.get_preferred_width()[1]; + const { x, y } = AstalHyprland.get_default().get_cursor_position(); + const cursorSize = Gtk.Settings.get_default()?.gtkCursorThemeSize ?? 0; + + let marginLeft = x - pWidth / 2; + if (marginLeft < 0) marginLeft = 0; + else if (marginLeft + pWidth > mWidth) marginLeft = mWidth - pWidth; - window.marginLeft = marginLeft; - window.marginTop = cy + (height - y); - lastX = cx - x; + window.marginLeft = marginLeft; + window.marginTop = y + cursorSize; + lastX = x; - dirty = false; - } return true; }); |