diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-03-25 22:01:31 +1100 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-03-25 22:01:31 +1100 |
| commit | 603ee96750ba3342fe1060e9629cfe35ff97b839 (patch) | |
| tree | 3c2e1233fa9865e2b5a79414be633f0d32e618e0 /src/utils | |
| parent | sidebar: create upcoming module (diff) | |
| download | caelestia-shell-603ee96750ba3342fe1060e9629cfe35ff97b839.tar.gz caelestia-shell-603ee96750ba3342fe1060e9629cfe35ff97b839.tar.bz2 caelestia-shell-603ee96750ba3342fe1060e9629cfe35ff97b839.zip | |
tooltip: show above cursor if offscreen
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/widgets.ts | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/src/utils/widgets.ts b/src/utils/widgets.ts index ef952f2..e0e512d 100644 --- a/src/utils/widgets.ts +++ b/src/utils/widgets.ts @@ -23,35 +23,35 @@ export const setupCustomTooltip = ( }); self.set_tooltip_window(window); - let lastX = 0; - window.connect("size-allocate", () => { - const mWidth = AstalHyprland.get_default().get_focused_monitor().get_width(); - const pWidth = window.get_preferred_width()[1]; + if (text instanceof Binding) self.hook(text, (_, v) => !v && window.hide()); + + const positionWindow = ({ x, y }: { x: number; y: number }) => { + const { width: mWidth, height: mHeight } = AstalHyprland.get_default().get_focused_monitor(); + const { width: pWidth, height: pHeight } = window.get_preferred_size()[1]!; + const cursorSize = Gtk.Settings.get_default()?.gtkCursorThemeSize ?? 0; - let marginLeft = lastX - pWidth / 2; + let marginLeft = x - pWidth / 2; if (marginLeft < 0) marginLeft = 0; else if (marginLeft + pWidth > mWidth) marginLeft = mWidth - pWidth; + let marginTop = y + cursorSize; + if (marginTop < 0) marginTop = 0; + else if (marginTop + pHeight > mHeight) marginTop = y - pHeight; + window.marginLeft = marginLeft; - }); - if (text instanceof Binding) self.hook(text, (_, v) => !v && window.hide()); + window.marginTop = marginTop; + }; + + let lastPos = { x: 0, y: 0 }; + window.connect("size-allocate", () => positionWindow(lastPos)); self.connect("query-tooltip", () => { if (text instanceof Binding && !text.get()) return false; if (window.visible) return true; - 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 = y + cursorSize; - lastX = x; + const cPos = AstalHyprland.get_default().get_cursor_position(); + positionWindow(cPos); + lastPos = cPos; return true; }); |