import QtQuick import Quickshell import Quickshell.Hyprland import "../services" // Closes an overlay when you click anywhere outside it. Hyprland does not // route clicks outside a layer to it, even with exclusive keyboard focus, so // a focus grab does it: clicking another window, the desktop or another // monitor clears the grab. The bars count as inside, so the bar button that // opened a panel still toggles it instead of reopening it. // // The grab starts once the overlay holds the keyboard; started together with // the focus change, Hyprland clears it at once. Item { id: root required property var window property bool active: false // More windows that count as inside (e.g. the bar a popup hangs from). property var extraWindows: [] signal outside property bool grabbing: false function sync() { grabbing = false; if (active) start.restart(); else start.stop(); } onActiveChanged: sync() Component.onCompleted: sync() Timer { id: start interval: 150 onTriggered: root.grabbing = root.active } HyprlandFocusGrab { windows: [root.window].concat(TrayService.barWindows, root.extraWindows).filter((w, i, all) => !!w && all.indexOf(w) === i) active: root.grabbing onCleared: if (root.grabbing) { root.grabbing = false; root.outside(); } } }