Tooltip: no longer needed to pass a screen explicitely

This commit is contained in:
ItsLemmy
2025-11-17 22:02:10 -05:00
parent 81c0c302d4
commit 66770625dd
19 changed files with 59 additions and 60 deletions

View File

@@ -255,7 +255,7 @@ Item {
onEntered: {
hovered = true;
root.entered();
TooltipService.show(screen, pill, root.tooltipText, BarService.getTooltipDirection(), Style.tooltipDelayLong);
TooltipService.show(pill, root.tooltipText, BarService.getTooltipDirection(), Style.tooltipDelayLong);
if (forceClose) {
return;
}

View File

@@ -297,7 +297,7 @@ Item {
onEntered: {
hovered = true;
root.entered();
TooltipService.show(screen, pill, root.tooltipText, BarService.getTooltipDirection(), Style.tooltipDelayLong);
TooltipService.show(pill, root.tooltipText, BarService.getTooltipDirection(), Style.tooltipDelayLong);
if (forceClose) {
return;
}

View File

@@ -412,7 +412,7 @@ Item {
acceptedButtons: Qt.LeftButton
onEntered: {
if ((windowTitle !== "") && isVerticalBar || (scrollingMode === "never")) {
TooltipService.show(screen, root, windowTitle, BarService.getTooltipDirection());
TooltipService.show(root, windowTitle, BarService.getTooltipDirection());
}
}
onExited: {

View File

@@ -122,7 +122,7 @@ Rectangle {
hoverEnabled: true
onEntered: {
if (!PanelService.getPanel("calendarPanel", screen)?.active) {
TooltipService.show(screen, root, I18n.tr("clock.tooltip"), BarService.getTooltipDirection());
TooltipService.show(root, I18n.tr("clock.tooltip"), BarService.getTooltipDirection());
}
}
onExited: {

View File

@@ -484,7 +484,7 @@ Item {
onEntered: {
var textToShow = hasActivePlayer ? tooltipText : placeholderText;
if ((textToShow !== "") && isVerticalBar || (scrollingMode === "never")) {
TooltipService.show(screen, root, textToShow, BarService.getTooltipDirection());
TooltipService.show(root, textToShow, BarService.getTooltipDirection());
}
}
onExited: {

View File

@@ -524,7 +524,7 @@ Rectangle {
anchors.fill: parent
hoverEnabled: true
onEntered: {
TooltipService.show(screen, diskContent, diskPath, BarService.getTooltipDirection());
TooltipService.show(diskContent, diskPath, BarService.getTooltipDirection());
}
onExited: {
TooltipService.hide();

View File

@@ -177,7 +177,7 @@ Rectangle {
}
}
}
onEntered: TooltipService.show(screen, taskbarItem, taskbarItem.modelData.title || taskbarItem.modelData.appId || "Unknown app.", BarService.getTooltipDirection())
onEntered: TooltipService.show(taskbarItem, taskbarItem.modelData.title || taskbarItem.modelData.appId || "Unknown app.", BarService.getTooltipDirection())
onExited: TooltipService.hide()
}
}

View File

@@ -306,7 +306,7 @@ Item {
}
onEntered: {
taskbarItem.itemHovered = true;
TooltipService.show(screen, taskbarItem, model.title || model.appId || "Unknown app.", BarService.getTooltipDirection());
TooltipService.show(taskbarItem, model.title || model.appId || "Unknown app.", BarService.getTooltipDirection());
}
onExited: {
taskbarItem.itemHovered = false;

View File

@@ -379,7 +379,7 @@ Rectangle {
if (popupMenuWindow) {
popupMenuWindow.close();
}
TooltipService.show(screen, trayIcon, modelData.tooltipTitle || modelData.name || modelData.id || "Tray Item", BarService.getTooltipDirection());
TooltipService.show(trayIcon, modelData.tooltipTitle || modelData.name || modelData.id || "Tray Item", BarService.getTooltipDirection());
}
onExited: TooltipService.hide()
}

View File

@@ -500,7 +500,7 @@ Loader {
const appName = appButton.appTitle || appButton.appId || "Unknown";
const tooltipText = appName.length > 40 ? appName.substring(0, 37) + "..." : appName;
if (!contextMenu.visible) {
TooltipService.show(screen, appButton, tooltipText, "top");
TooltipService.show(appButton, tooltipText, "top");
}
if (autoHide) {
showTimer.stop();

View File

@@ -617,7 +617,7 @@ SmartPanel {
return `${startFormatted}-${endFormatted} ${event.summary}`;
}
}).join('\n');
TooltipService.show(screen, parent, summaries, "auto", Style.tooltipDelay, Settings.data.ui.fontFixed);
TooltipService.show(parent, summaries, "auto", Style.tooltipDelay, Settings.data.ui.fontFixed);
}
}

View File

@@ -82,7 +82,7 @@ ColumnLayout {
enabled: !valueTextStream
Layout.alignment: Qt.AlignRight | Qt.AlignBottom
Layout.bottomMargin: Style.marginS
onEntered: TooltipService.show(screen, leftClickUpdateText, I18n.tr("bar.widget-settings.custom-button.left-click.update-text"), "auto")
onEntered: TooltipService.show(leftClickUpdateText, I18n.tr("bar.widget-settings.custom-button.left-click.update-text"), "auto")
onExited: TooltipService.hide()
checked: widgetData?.leftClickUpdateText ?? widgetMetadata.leftClickUpdateText
onToggled: isChecked => checked = isChecked
@@ -106,7 +106,7 @@ ColumnLayout {
enabled: !valueTextStream
Layout.alignment: Qt.AlignRight | Qt.AlignBottom
Layout.bottomMargin: Style.marginS
onEntered: TooltipService.show(screen, rightClickUpdateText, I18n.tr("bar.widget-settings.custom-button.right-click.update-text"), "auto")
onEntered: TooltipService.show(rightClickUpdateText, I18n.tr("bar.widget-settings.custom-button.right-click.update-text"), "auto")
onExited: TooltipService.hide()
checked: widgetData?.rightClickUpdateText ?? widgetMetadata.rightClickUpdateText
onToggled: isChecked => checked = isChecked
@@ -130,7 +130,7 @@ ColumnLayout {
enabled: !valueTextStream
Layout.alignment: Qt.AlignRight | Qt.AlignBottom
Layout.bottomMargin: Style.marginS
onEntered: TooltipService.show(screen, middleClickUpdateText, I18n.tr("bar.widget-settings.custom-button.middle-click.update-text"), "auto")
onEntered: TooltipService.show(middleClickUpdateText, I18n.tr("bar.widget-settings.custom-button.middle-click.update-text"), "auto")
onExited: TooltipService.hide()
checked: widgetData?.middleClickUpdateText ?? widgetMetadata.middleClickUpdateText
onToggled: isChecked => checked = isChecked

View File

@@ -235,7 +235,7 @@ SmartPanel {
if (popupMenuWindow) {
popupMenuWindow.close();
}
TooltipService.show(screen, trayIcon, modelData.tooltipTitle || modelData.name || modelData.id || "Tray Item", BarService.getTooltipDirection());
TooltipService.show(trayIcon, modelData.tooltipTitle || modelData.name || modelData.id || "Tray Item", BarService.getTooltipDirection());
}
onExited: TooltipService.hide()
}

View File

@@ -1,5 +1,4 @@
import QtQuick
// import QtQuick.Layouts
import Quickshell
import qs.Commons
import qs.Widgets
@@ -7,9 +6,6 @@ import qs.Widgets
PopupWindow {
id: root
property int screenWidth: 0
property int screenHeight: 0
property string text: ""
property string direction: "auto" // "auto", "left", "right", "top", "bottom"
property int margin: Style.marginXS // distance from target
@@ -26,8 +22,9 @@ PopupWindow {
property real anchorX: 0
property real anchorY: 0
property bool isPositioned: false
property bool pendingShow: false
property bool animatingOut: true
property int screenWidth: 1920
property int screenHeight: 1080
visible: false
color: Color.transparent
@@ -108,11 +105,9 @@ PopupWindow {
}
// Function to show tooltip
function show(screen, target, tipText, customDirection, showDelay, fontFamily) {
if (!screen || !target || !tipText || tipText === "")
function show(target, tipText, customDirection, showDelay, fontFamily) {
if (!target || !tipText || tipText === "")
return;
root.screenWidth = screen.width;
root.screenHeight = screen.height;
root.delay = showDelay;
@@ -128,9 +123,32 @@ PopupWindow {
}
// Set properties
targetItem = target;
text = tipText;
pendingShow = true;
targetItem = target;
// Find the correct screen dimensions based on target's global position
// Respect all screens positionning
const targetGlobal = target.mapToGlobal(target.width / 2, target.height / 2);
let foundScreen = false;
for (let i = 0; i < Quickshell.screens.length; i++) {
const s = Quickshell.screens[i];
if (targetGlobal.x >= s.x && targetGlobal.x < s.x + s.width && targetGlobal.y >= s.y && targetGlobal.y < s.y + s.height) {
screenWidth = s.width;
screenHeight = s.height;
foundScreen = true;
break;
}
}
if (!foundScreen) {
Logger.w("Tooltip", "No screen found for target position!");
}
// Initialize animation state (hidden)
tooltipContainer.opacity = 0.0;
tooltipContainer.scale = root.animationScale;
// Start show timer (will position and then make visible)
showTimer.start();
if (customDirection !== undefined) {
direction = customDirection;
@@ -139,17 +157,16 @@ PopupWindow {
}
tooltipText.family = fontFamily ? fontFamily : Settings.data.ui.fontDefault;
// Start show timer
showTimer.start();
}
// Function to position and display the tooltip
function positionAndShow() {
if (!targetItem || !targetItem.parent || !pendingShow) {
if (!targetItem || !targetItem.parent) {
return;
}
console.log(screenWidth, screenHeight);
// Calculate tooltip dimensions
const tipWidth = Math.min(tooltipText.implicitWidth + (padding * 2), maxWidth);
root.implicitWidth = tipWidth;
@@ -256,35 +273,20 @@ PopupWindow {
}
}
// Apply position
// Apply position first (before making visible)
anchorX = newAnchorX;
anchorY = newAnchorY;
isPositioned = true;
pendingShow = false;
// Show tooltip and start animation
visible = true;
// Initialize animation state
tooltipContainer.opacity = 0.0;
tooltipContainer.scale = animationScale;
// Start show animation
// Now make visible and start animation
root.visible = true;
showAnimation.start();
// Force anchor update after showing
Qt.callLater(() => {
if (root.anchor && root.visible) {
root.anchor.updateAnchor();
}
});
}
// Function to hide tooltip
function hide() {
// Stop show timer if it's running
showTimer.stop();
pendingShow = false;
// Stop hide timer if it's running
hideTimer.stop();
@@ -307,7 +309,6 @@ PopupWindow {
function completeHide() {
visible = false;
animatingOut = false;
pendingShow = false;
text = "";
isPositioned = false;
tooltipContainer.opacity = 1.0;
@@ -320,7 +321,6 @@ PopupWindow {
hideTimer.stop();
showAnimation.stop();
hideAnimation.stop();
pendingShow = false;
animatingOut = false;
completeHide();
}
@@ -345,8 +345,8 @@ PopupWindow {
const globalX = targetGlobal.x + anchorX;
if (globalX < 0) {
anchorX = -targetGlobal.x + margin;
} else if (globalX + tipWidth > screenWidth) {
anchorX = screenWidth - targetGlobal.x - tipWidth - margin;
} else if (globalX + tipWidth > root.screen.width) {
anchorX = root.screen.width - targetGlobal.x - tipWidth - margin;
}
// Force anchor update
@@ -368,7 +368,6 @@ PopupWindow {
// Clear all state
visible = false;
pendingShow = false;
animatingOut = false;
text = "";
isPositioned = false;

View File

@@ -15,13 +15,13 @@ Singleton {
Tooltip {}
}
function show(screen, target, text, direction, delay, fontFamily) {
function show(target, text, direction, delay, fontFamily) {
if (!Settings.data.ui.tooltipsEnabled) {
return;
}
// Don't create if no text
if (!screen || !target || !text) {
if (!target || !text) {
Logger.i("Tooltip", "No target or text");
return;
}
@@ -78,7 +78,7 @@ Singleton {
});
// Show the tooltip
newTooltip.show(screen, target, text, direction || "auto", delay || Style.tooltipDelay, fontFamily);
newTooltip.show(target, text, direction || "auto", delay || Style.tooltipDelay, fontFamily);
return newTooltip;
} else {

View File

@@ -144,7 +144,7 @@ Rectangle {
root.hovered = true;
root.entered();
if (tooltipText) {
TooltipService.show(screen, root, root.tooltipText);
TooltipService.show(root, root.tooltipText);
}
}
onExited: {

View File

@@ -83,7 +83,7 @@ Rectangle {
onEntered: {
hovering = root.enabled ? true : false;
if (tooltipText) {
TooltipService.show(screen, parent, tooltipText, tooltipDirection);
TooltipService.show(parent, tooltipText, tooltipDirection);
}
root.entered();
}

View File

@@ -119,7 +119,7 @@ Rectangle {
onEntered: {
hovering = root.enabled ? true : false;
if (tooltipText) {
TooltipService.show(screen, parent, tooltipText, tooltipDirection);
TooltipService.show(parent, tooltipText, tooltipDirection);
}
root.entered();
}

View File

@@ -117,7 +117,7 @@ Slider {
onEntered: {
root.hovering = true;
if (root.tooltipText) {
TooltipService.show(screen, knob, root.tooltipText, root.tooltipDirection);
TooltipService.show(knob, root.tooltipText, root.tooltipDirection);
}
}