diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/modules/launcher.tsx | 4 | ||||
| -rw-r--r-- | src/utils/widgets.ts | 31 |
2 files changed, 16 insertions, 19 deletions
diff --git a/src/modules/launcher.tsx b/src/modules/launcher.tsx index 8949444..5462067 100644 --- a/src/modules/launcher.tsx +++ b/src/modules/launcher.tsx @@ -160,13 +160,13 @@ const Result = ({ <button className="result" cursor="pointer" - tooltipText={tooltip} onClicked={onClicked} onClick={(self, event) => { if (event.button === Astal.MouseButton.SECONDARY) onSecondaryClick?.(self); else if (event.button === Astal.MouseButton.MIDDLE) onMiddleClick?.(self); }} onDestroy={onDestroy} + setup={self => tooltip && setupCustomTooltip(self, tooltip)} > <box> {icon && @@ -399,7 +399,7 @@ const WindowResult = ({ client, reload }: { client: Client; reload: () => void } close(result); execAsync(`wl-copy -- ${value}`).catch(console.error); }, - tooltipText: String(value), + tooltipText: String(value), // Cannot use custom tooltip cause it'll be below menu }) ); 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; }); |