summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-02-11 20:53:56 +1100
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-02-11 20:53:56 +1100
commitaf927d12a3594a37a0c8582d76fade54d9b9e58d (patch)
tree8db27eeb2bf667cebeacb38157678c9164e4b49f /src
parenttooltip: ensure fully visible (diff)
downloadcaelestia-shell-af927d12a3594a37a0c8582d76fade54d9b9e58d.tar.gz
caelestia-shell-af927d12a3594a37a0c8582d76fade54d9b9e58d.tar.bz2
caelestia-shell-af927d12a3594a37a0c8582d76fade54d9b9e58d.zip
tooltip: position at cursor not widget
Diffstat (limited to 'src')
-rw-r--r--src/modules/launcher.tsx4
-rw-r--r--src/utils/widgets.ts31
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;
});