pragma Singleton import QtQuick import Quickshell import Quickshell.Io import "../services" // Shared bar hover popout (Caelestia-style): one surface that morphs between // anchors. The first hover waits for the hover delay; once a popout or tray menu // is open, hovering another anchor switches to it immediately. Singleton { id: root property bool open: false property Item anchor: null property string kind: "" property string text: "" // Kind-specific data, e.g. the window a preview shows. property var payload: null property bool popoutHovered: false property Item hoveredAnchor: null property var pending: null property var window: null // A popout or a tray menu is already showing, so the next hover is instant. readonly property bool warm: open || TrayService.opened readonly property int delay: TrayService.options.hoverDelay function hover(anchor, kind, text, payload) { hoveredAnchor = anchor; leave.stop(); pending = { anchor: anchor, kind: kind, text: text || "", payload: payload === undefined ? null : payload }; if (!kind) { intent.stop(); if (open) close(); } else if (warm) show(); else intent.restart(); } function unhover(anchor) { if (hoveredAnchor === anchor) hoveredAnchor = null; if (pending && pending.anchor === anchor && !open) intent.stop(); leave.restart(); } function toggle(anchor, kind, text, payload) { if (open && root.anchor === anchor) return close(); pending = { anchor: anchor, kind: kind, text: text || "", payload: payload === undefined ? null : payload }; show(); } function show() { const p = pending; intent.stop(); if (!p || !p.anchor || !p.kind) return; anchor = p.anchor; kind = p.kind; text = p.text; payload = p.payload; open = true; TrayService.close(); } function close() { open = false; intent.stop(); leave.stop(); } function setPopoutHovered(inside) { popoutHovered = inside; if (inside) leave.stop(); else leave.restart(); } onAnchorChanged: if (!anchor) close() Timer { id: intent interval: root.delay onTriggered: if (root.hoveredAnchor && root.pending && root.pending.anchor === root.hoveredAnchor) root.show() } // Grace period for crossing the gap between the bar and the popout. Timer { id: leave interval: 260 onTriggered: if (!root.hoveredAnchor && !root.popoutHovered) root.close() } Connections { target: TrayService function onOpenedChanged() { if (TrayService.opened) root.close(); } } Connections { target: ShellState function onControlCenterOpenChanged() { if (ShellState.controlCenterOpen) root.close(); } function onSettingsOpenChanged() { if (ShellState.settingsOpen) root.close(); } function onLauncherOpenChanged() { if (ShellState.launcherOpen) root.close(); } } IpcHandler { target: "popout" function close(): void { root.close(); } function status(): string { return JSON.stringify({ open: root.open, kind: root.kind, text: root.text, anchor: root.anchor ? root.anchor.objectName : "", visible: !!root.window && root.window.visible, screen: root.window && root.window.screen ? root.window.screen.name : "", width: root.window ? root.window.implicitWidth : 0, height: root.window ? root.window.implicitHeight : 0 }); } } }