more fixes for menu and tooltip

This commit is contained in:
Damocles 2026-04-12 14:42:03 +02:00
parent df58449ef5
commit e7abfebe49
2 changed files with 29 additions and 52 deletions

View file

@ -43,7 +43,7 @@ PanelWindow {
Text { Text {
id: label id: label
anchors.centerIn: parent anchors.centerIn: parent
text: M.FlyoutState.text text: M.FlyoutState.text.replace(/\n/g, "<br>")
textFormat: Text.RichText textFormat: Text.RichText
color: M.Theme.base05 color: M.Theme.base05
font.pixelSize: M.Theme.fontSize font.pixelSize: M.Theme.fontSize

View file

@ -1,24 +1,24 @@
pragma ComponentBehavior: Bound
import QtQuick import QtQuick
import QtQuick.Controls
import Quickshell import Quickshell
import Quickshell.Wayland import Quickshell.Wayland
import "." as M import "." as M
// Per-icon context menu popup window. // Per-icon context menu popup window.
// Covers the full screen on the Overlay layer so clicking anywhere outside // Covers the screen on the Overlay layer so clicking anywhere outside
// the menu panel dismisses it. Created on demand by Tray.qml delegates. // the menu panel dismisses it. Created on demand by Tray.qml delegates.
PanelWindow { PanelWindow {
id: menuWindow id: menuWindow
required property QsMenuHandle handle required property var handle
required property var screen required property var screen
// Global x of the icon center (from mapToGlobal), used to position the panel
required property real anchorX required property real anchorX
signal menuClosed() signal menuClosed()
// Current menu level swapped when entering/leaving submenus
property var _currentHandle: handle
property var _handleStack: []
visible: true visible: true
color: "transparent" color: "transparent"
@ -42,15 +42,15 @@ PanelWindow {
id: panel id: panel
x: Math.max(0, Math.min( x: Math.max(0, Math.min(
Math.round(menuWindow.anchorX - menuStack.width / 2), Math.round(menuWindow.anchorX - menuCol.width / 2),
menuWindow.width - menuStack.width menuWindow.width - menuCol.width
)) ))
y: 0 y: 0
width: menuStack.width width: menuCol.width
height: menuStack.height height: menuCol.height
// Eat clicks inside the panel so they don't reach the dismiss area above // Eat clicks inside the panel
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
} }
@ -65,33 +65,8 @@ PanelWindow {
bottomRightRadius: M.Theme.radius bottomRightRadius: M.Theme.radius
} }
StackView {
id: menuStack
width: currentItem ? currentItem.width : 0
height: currentItem ? currentItem.height : 0
// Push the root page once the stack is ready
Component.onCompleted: {
menuStack.push(menuPageComp, { handle: menuWindow.handle, isRoot: true }, StackView.Immediate);
}
pushEnter: Transition {}
pushExit: Transition {}
popEnter: Transition {}
popExit: Transition {}
}
}
// Reusable menu page component used for both root and submenus
Component {
id: menuPageComp
Column { Column {
id: page id: menuCol
required property QsMenuHandle handle
property bool isRoot: false
width: 220 width: 220
topPadding: 4 topPadding: 4
@ -100,14 +75,14 @@ PanelWindow {
QsMenuOpener { QsMenuOpener {
id: opener id: opener
menu: page.handle menu: menuWindow._currentHandle
} }
// Back button (shown only in submenus) // Back button (submenus only)
Item { Item {
visible: !page.isRoot visible: menuWindow._handleStack.length > 0
width: page.width width: menuCol.width
height: 28 height: visible ? 28 : 0
Rectangle { Rectangle {
anchors.fill: parent anchors.fill: parent
@ -121,7 +96,7 @@ PanelWindow {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: 12 anchors.leftMargin: 12
text: " " + qsTr("Back") text: "\u2039 Back"
color: M.Theme.base05 color: M.Theme.base05
font.pixelSize: M.Theme.fontSize font.pixelSize: M.Theme.fontSize
font.family: M.Theme.fontFamily font.family: M.Theme.fontFamily
@ -131,7 +106,11 @@ PanelWindow {
id: backArea id: backArea
anchors.fill: parent anchors.fill: parent
hoverEnabled: true hoverEnabled: true
onClicked: menuStack.pop() onClicked: {
const stack = menuWindow._handleStack.slice();
menuWindow._currentHandle = stack.pop();
menuWindow._handleStack = stack;
}
} }
} }
@ -143,10 +122,10 @@ PanelWindow {
required property QsMenuEntry modelData required property QsMenuEntry modelData
width: page.width width: menuCol.width
height: modelData.isSeparator ? 9 : 28 height: modelData.isSeparator ? 9 : 28
// Separator line // Separator
Rectangle { Rectangle {
visible: entryItem.modelData.isSeparator visible: entryItem.modelData.isSeparator
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
@ -204,7 +183,7 @@ PanelWindow {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right anchors.right: parent.right
anchors.rightMargin: 12 anchors.rightMargin: 12
text: "" text: "\u203A"
color: entryItem.modelData.enabled ? M.Theme.base05 : M.Theme.base03 color: entryItem.modelData.enabled ? M.Theme.base05 : M.Theme.base03
font.pixelSize: M.Theme.fontSize font.pixelSize: M.Theme.fontSize
font.family: M.Theme.fontFamily font.family: M.Theme.fontFamily
@ -217,10 +196,8 @@ PanelWindow {
enabled: !entryItem.modelData.isSeparator && entryItem.modelData.enabled enabled: !entryItem.modelData.isSeparator && entryItem.modelData.enabled
onClicked: { onClicked: {
if (entryItem.modelData.hasChildren) { if (entryItem.modelData.hasChildren) {
menuStack.push(menuPageComp, { menuWindow._handleStack = menuWindow._handleStack.concat([menuWindow._currentHandle]);
handle: entryItem.modelData, menuWindow._currentHandle = entryItem.modelData;
isRoot: false
}, StackView.Immediate);
} else { } else {
entryItem.modelData.triggered(); entryItem.modelData.triggered();
menuWindow.menuClosed(); menuWindow.menuClosed();