Files
glassMxrph/quickshell/menus/TrayMenu.qml
T
mxandClaude Opus 5.5 b03bd77941 Give notch-mode panels their own liquid drop animation
With no bar to unroll from, attached drawers in notch mode now open as a
glass bead that swells out under the clicked island icon on a tapered
neck, flips the wallpaper behind it like a lens, then widens into the
panel and lets go. NotchDrop draws it with a signed-distance shader;
BarDrawer swaps to it in notch mode, and hosts pass the icon's screen x.
The notch-shaped wallpaper picker keeps its own motion.

Notch settings gain panel opening and closing speeds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 14:06:14 +01:00

185 lines
9.7 KiB
QML

pragma ComponentBehavior: Bound
import QtQuick
import QtQuick.Controls
import Quickshell
import Quickshell.Wayland
import "../components"
import "../core"
import "../services"
import "../theme"
// A layer surface is required for HyprGlass; xdg popups bypass its layer renderer.
// qmllint disable uncreatable-type
PanelWindow {
// qmllint enable uncreatable-type
id: root
property var menuHandle: null
property Item anchorItem: null
property bool isRoot: true
property bool opened: false
property int depth: 0
property var parentMenu: null
property int selectedIndex: -1
property var childEntry: null
property Item childAnchor: null
property bool contentOpen: false
readonly property var entries: opener.children.values
readonly property var anchorWindow: anchorItem ? anchorItem.QsWindow.window : null
screen: anchorWindow ? anchorWindow.screen : null
anchors { top: true; left: true }
exclusionMode: ExclusionMode.Ignore
WlrLayershell.namespace: "glassMxrph-tray"
WlrLayershell.layer: WlrLayer.Overlay
WlrLayershell.keyboardFocus: WlrKeyboardFocus.OnDemand
readonly property point anchorPoint: anchorItem && anchorWindow
? anchorItem.mapToItem(anchorWindow.contentItem, 0, 0) : Qt.point(0, 0)
// Root menus centre under the icon's placement item (the whole tray pill).
readonly property var anchorObject: anchorItem
readonly property Item placementItem: anchorObject ? (anchorObject.placement || anchorObject) : null
readonly property real placementCenter: placementItem && anchorWindow
? placementItem.mapToItem(anchorWindow.contentItem, placementItem.width / 2, 0).x : 0
readonly property real availableWidth: screen ? screen.width : 1280
readonly property real availableHeight: screen ? screen.height : 720
readonly property real desiredX: {
if (!parentMenu) return placementCenter - implicitWidth / 2;
// A drawer parent's ears are not part of its body.
const inset = parentMenu.isRoot ? BarDrawers.ear : 0;
const right = parentMenu.margins.left + parentMenu.width - inset - 4;
return right + implicitWidth <= availableWidth - 4
? right : parentMenu.margins.left + inset - implicitWidth + 4;
}
// Quickshell 0.3.1 qmllint cannot resolve the exported Margins value type.
// qmllint disable unqualified unresolved-type
margins.left: Math.round(animX)
// The root menu is a drawer hanging from the bar; its layer starts at the screen top.
margins.top: isRoot ? 0 : Math.round(Math.max(4, Math.min(
parentMenu ? parentMenu.margins.top + anchorPoint.y
: anchorPoint.y + (anchorItem ? anchorItem.height : 0),
availableHeight - implicitHeight - 4)))
// qmllint enable unqualified unresolved-type
color: Theme.transparent
readonly property int menuWidth: 280
implicitWidth: isRoot ? menuWidth + 2 * BarDrawers.ear : menuWidth + 8
// Switching icons while open glides the menu over instead of reopening it;
// the previous height is held while the next DBus menu is still loading.
readonly property bool morph: isRoot && contentOpen && drawerSurface.progress > 0.05 && Theme.duration > 0
readonly property real targetX: isRoot ? BarDrawers.clampX(desiredX + implicitWidth / 2, implicitWidth, availableWidth) : Math.max(4, Math.min(desiredX, availableWidth - implicitWidth - 4))
readonly property real contentTarget: Math.min((screen ? screen.height : 720) - 80 - (isRoot ? BarDrawers.bottom : 0), Math.max(50, list.contentHeight + 16))
property real heldHeight: 58
readonly property real targetHeight: entries.length === 0 && emptyTimer.running && morph ? heldHeight : contentTarget
onContentTargetChanged: if (entries.length > 0) heldHeight = contentTarget
property real animX: targetX
property real animH: targetHeight
Behavior on animX { enabled: root.morph; NumberAnimation { duration: Theme.duration * 1.2; easing.type: Easing.OutCubic } }
Behavior on animH { enabled: root.morph; NumberAnimation { duration: Theme.duration; easing.type: Easing.OutCubic } }
implicitHeight: Math.round(animH + (isRoot ? BarDrawers.bottom : 8))
Region {
id: drawerMask
item: drawerSurface.body
}
mask: isRoot ? drawerMask : null
onMenuHandleChanged: if (opened && isRoot) { emptyTimer.restart(); swap.restart(); }
visible: opened || surface.visible || drawerSurface.shown
onOpenedChanged: {
if (opened) { selectedIndex = -1; childEntry = null; emptyTimer.restart(); Qt.callLater(() => { contentOpen = true; menuBody.forceActiveFocus(); }); }
else { contentOpen = false; childEntry = null; submenuTimer.stop(); emptyTimer.stop(); }
}
Component.onCompleted: { TrayService.registerWindow(root); if (opened) { contentOpen = true; emptyTimer.restart(); } }
Component.onDestruction: TrayService.unregisterWindow(root)
onEntriesChanged: { childEntry = null; selectedIndex = -1; }
function dismissChild() { childEntry = null; menuBody.forceActiveFocus(); }
function select(index, keyboard) {
selectedIndex = index;
const entry = entries[index];
if (childEntry !== entry) childEntry = null;
submenuTimer.stop();
if (entry && entry.enabled && entry.hasChildren && !keyboard) submenuTimer.restart();
}
function move(direction) {
for (let i = 1; i <= entries.length; ++i) {
const next = (selectedIndex + direction * i + entries.length) % entries.length;
if (entries[next].enabled && !entries[next].isSeparator) { select(next, true); list.positionViewAtIndex(next, ListView.Contain); return; }
}
}
function invoke(index) {
const entry = entries[index];
if (!entry || entry.isSeparator || !entry.enabled) return false;
if (entry.hasChildren) { openChild(index); return true; }
entry.triggered(); TrayService.close(); return true;
}
function openChild(index) {
const entry = entries[index];
if (!entry || !entry.enabled || !entry.hasChildren) return;
list.positionViewAtIndex(index, ListView.Contain);
childAnchor = list.itemAtIndex(index);
if (childAnchor) childEntry = entry;
}
function snapshot() { return {depth:depth, screen:screen ? screen.name : "", entries:entries.map(e => ({text:e.text, enabled:e.enabled, separator:e.isSeparator, buttonType:e.buttonType, checkState:e.checkState, hasChildren:e.hasChildren, icon:e.icon !== ""}))}; }
QsMenuOpener { id: opener; menu: root.opened ? root.menuHandle : null }
Timer { id: submenuTimer; interval: 180; onTriggered: root.openChild(root.selectedIndex) }
Timer { id: emptyTimer; interval: 1500 }
NumberAnimation { id: swap; target: list; property: "opacity"; from: 0.2; to: 1; duration: Theme.duration; easing.type: Easing.OutCubic }
// Submenus float beside their parent as glass cards.
GlassMenu {
id: surface; objectName: root.isRoot ? "" : "trayMenuSurface"
visible: !root.isRoot && (opened || opacity > 0.01)
anchors.fill: parent; anchors.margins: 4
opened: root.contentOpen && !root.isRoot
transformOrigin: Item.TopLeft
}
BarDrawer {
id: drawerSurface; objectName: root.isRoot ? "trayMenuSurface" : ""
visible: root.isRoot
y: BarDrawers.bottom
// Open (and take input) at once: a click-opened menu's focus grab needs
// an input region as soon as the menu maps.
open: root.opened && root.isRoot
contentWidth: root.menuWidth
contentHeight: Math.round(root.animH)
drawerId: root.isRoot ? "tray" : ""
screenName: root.screen ? root.screen.name : ""
screenX: root.animX
sourceScreenX: root.isRoot ? root.placementCenter : -1
onHoveredChanged: if (root.isRoot) TrayService.setHovered(root, hovered)
}
// Shared menu body, placed in whichever surface this menu uses.
Item {
id: menuBody
parent: root.isRoot ? drawerSurface.container : surface.contentItem
anchors.fill: parent
anchors.margins: root.isRoot ? 8 : 0
focus: true
Keys.onEscapePressed: TrayService.close()
Keys.onDownPressed: root.move(1)
Keys.onUpPressed: root.move(-1)
Keys.onReturnPressed: root.invoke(root.selectedIndex)
Keys.onEnterPressed: root.invoke(root.selectedIndex)
Keys.onRightPressed: root.openChild(root.selectedIndex)
Keys.onLeftPressed: if (root.parentMenu) root.parentMenu.dismissChild()
HoverHandler { enabled: !root.isRoot; onHoveredChanged: TrayService.setHovered(root, hovered) }
ListView {
id: list; objectName: "trayMenuList"; anchors.fill: parent; clip: true
model: opener.children; boundsBehavior: Flickable.StopAtBounds
ScrollBar.vertical: ScrollBar {}
onContentYChanged: root.childEntry = null
delegate: TrayMenuItem {
required property var modelData
required property int index
entry: modelData; width: list.width
selected: root.selectedIndex === index
onEntered: root.select(index, false)
onInvoked: root.invoke(index)
}
}
Text { anchors.centerIn: parent; visible: root.entries.length === 0; text: emptyTimer.running ? "Loading application menu…" : "No menu entries"; color: Theme.textSecondary; font.pixelSize: 12 }
}
Loader {
active: root.opened && root.childEntry !== null
source: active ? Qt.resolvedUrl("TraySubMenu.qml") : ""
onLoaded: {
item.menuHandle = Qt.binding(() => root.childEntry);
item.anchorItem = Qt.binding(() => root.childAnchor);
item.parentMenu = root; item.depth = root.depth + 1; item.opened = true;
}
}
}