Panels relied on Hyprland sending every click to a layer with exclusive keyboard focus; it does not, so clicking another window or monitor left the Control Center, Dashboard, notch, Overview, Settings, wallpaper picker, launcher and plugin panels open. A shared OutsideClick holds a Hyprland focus grab while a panel is open and closes it when the grab is cleared. The bars count as inside, so a bar button still toggles its panel. The old catchers stay as a fallback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
181 lines
7.0 KiB
QML
181 lines
7.0 KiB
QML
import QtQuick
|
|
import Quickshell
|
|
import Quickshell.Hyprland
|
|
import Quickshell.Wayland
|
|
import qs.compat.omarchy.Commons
|
|
import "../../../components" as C
|
|
import "../../../core" as Core
|
|
import "../../../theme" as G
|
|
|
|
// glassMxrph base for Omarchy's PopupCard and KeyboardPanel: the popup is a
|
|
// glassMxrph bar drawer that grows out of the bar under its anchor, with the
|
|
// same glass, ears and animation as the shell's own panels. The public API
|
|
// (sizes, fitted*/capped* helpers, open/close, owner, focusTarget, popout
|
|
// coordination) matches Omarchy so plugins work unchanged.
|
|
//
|
|
// mode: "keyboard" — exclusive keyboard focus, outside clicks close (like the
|
|
// Control Center); "click" — focus grab, outside clicks
|
|
// close; "hover" — passive, the owner opens/closes it.
|
|
PanelWindow {
|
|
id: root
|
|
|
|
required property Item anchorItem
|
|
required property QtObject bar
|
|
property var owner: null
|
|
property string mode: "keyboard"
|
|
property int margin: 8
|
|
property int padding: Style.spacing.popupPadding
|
|
property int contentWidth: Style.space(280)
|
|
property int contentHeight: Style.space(200)
|
|
property var borderSpec: Border.none()
|
|
property color borderColor: G.Theme.border
|
|
property bool centerOnBar: false
|
|
property bool open: false
|
|
property int gap: 0
|
|
property bool popoutSwitching: false
|
|
property bool popoutSwitchClosing: false
|
|
property bool focusPrimed: true
|
|
property Item focusTarget: null
|
|
|
|
default property alias contentItem: contentHolder.children
|
|
|
|
readonly property var coordinatorKey: owner || root
|
|
readonly property var anchorWindow: anchorItem ? anchorItem.QsWindow.window : null
|
|
readonly property string barPos: "top"
|
|
readonly property bool containsMouse: drawer.hovered
|
|
|
|
function close() {
|
|
if (owner && "close" in owner) owner.close()
|
|
else root.open = false
|
|
}
|
|
function beginFocusPrime() {
|
|
}
|
|
|
|
screen: anchorWindow ? anchorWindow.screen : null
|
|
readonly property real screenW: screen ? screen.width : 0
|
|
readonly property real screenH: screen ? screen.height : 0
|
|
readonly property real sideSpace: 2 * (Core.BarDrawers.margin + Core.BarDrawers.radius + Core.BarDrawers.ear)
|
|
readonly property real availableCardWidth: screenW > 0 ? Math.max(120, screenW - sideSpace) : 0
|
|
readonly property real availableCardHeight: screenH > 0 ? Math.max(120, screenH - Core.BarDrawers.bottom - 20) : 0
|
|
readonly property real verticalContentInset: padding * 2
|
|
|
|
function fittedContentWidth(width, cap) {
|
|
var desired = Math.max(1, Number(width) || 1)
|
|
var maxWidth = root.availableCardWidth > 0 ? root.availableCardWidth : desired
|
|
if (cap !== undefined && Number(cap) > 0) maxWidth = Math.min(maxWidth, Number(cap))
|
|
return Math.round(Math.min(desired, maxWidth))
|
|
}
|
|
function fittedContentHeight(implicitHeight, cap) {
|
|
var desired = Math.max(root.verticalContentInset, (Number(implicitHeight) || 0) + root.verticalContentInset)
|
|
var maxHeight = root.availableCardHeight > 0 ? root.availableCardHeight : desired
|
|
if (cap !== undefined && Number(cap) > 0) maxHeight = Math.min(maxHeight, Number(cap))
|
|
return Math.round(Math.min(desired, maxHeight))
|
|
}
|
|
function cappedContentHeight(height) {
|
|
var desired = Math.max(root.padding * 2, Number(height) || root.padding * 2)
|
|
var maxHeight = root.availableCardHeight > 0 ? root.availableCardHeight : desired
|
|
return Math.round(Math.min(desired, maxHeight))
|
|
}
|
|
|
|
readonly property real barW: anchorWindow ? anchorWindow.width : screenW
|
|
readonly property real barH: Core.BarDrawers.bottom
|
|
// Re-read on open: mapToItem is not reactive to layout changes.
|
|
readonly property point anchorScreenPos: {
|
|
root.open
|
|
if (!anchorItem || !anchorWindow) return Qt.point(0, 0)
|
|
const p = anchorItem.mapToItem(anchorWindow.contentItem, 0, 0)
|
|
// Centred layers (the open notch) report their screen offset.
|
|
const offset = anchorWindow.screenOffsetX !== undefined ? anchorWindow.screenOffsetX : 0
|
|
return Qt.point(p.x + offset, p.y)
|
|
}
|
|
readonly property real anchorW: anchorItem ? anchorItem.width : 0
|
|
readonly property real anchorH: anchorItem ? anchorItem.height : 0
|
|
readonly property real outerWidth: drawer.width
|
|
readonly property real drawerX: centerOnBar
|
|
? Math.round((screenW - outerWidth) / 2)
|
|
: Core.BarDrawers.clampX(anchorScreenPos.x + anchorW / 2, outerWidth, screenW)
|
|
readonly property point cardOrigin: Qt.point(drawerX + drawer.ear, Core.BarDrawers.bottom)
|
|
|
|
// Hang from the bar: the layer starts at the screen top so the join with
|
|
// the bar is inside its box (no HyprGlass edge there).
|
|
anchors {
|
|
top: true
|
|
left: true
|
|
}
|
|
// qmllint disable unqualified unresolved-type
|
|
margins.left: root.drawerX
|
|
// qmllint enable unqualified unresolved-type
|
|
implicitWidth: Math.max(1, Math.round(drawer.width))
|
|
implicitHeight: Math.max(1, Math.round(Core.BarDrawers.bottom + drawer.contentHeight))
|
|
visible: open || drawer.shown || popoutSwitching
|
|
color: "transparent"
|
|
exclusionMode: ExclusionMode.Ignore
|
|
WlrLayershell.namespace: "glassMxrph-plugin-popup"
|
|
WlrLayershell.layer: WlrLayer.Overlay
|
|
WlrLayershell.keyboardFocus: !open ? WlrKeyboardFocus.None : mode === "keyboard" ? WlrKeyboardFocus.Exclusive : mode === "click" ? WlrKeyboardFocus.OnDemand : WlrKeyboardFocus.None
|
|
// Passive popups only take input on the drawer itself.
|
|
Region {
|
|
id: bodyMask
|
|
item: drawer.body
|
|
}
|
|
mask: mode === "keyboard" ? null : bodyMask
|
|
|
|
onOpenChanged: {
|
|
if (open && focusTarget) Qt.callLater(function() {
|
|
if (root.open && root.focusTarget) root.focusTarget.forceActiveFocus()
|
|
})
|
|
if (!bar) return
|
|
if (open) {
|
|
popoutSwitchClosing = false
|
|
if (bar.requestPopout) bar.requestPopout(coordinatorKey)
|
|
} else {
|
|
popoutSwitchClosing = !!(owner && owner.popoutSwitchClosing)
|
|
if (bar.activePopout === coordinatorKey && bar.releasePopout) bar.releasePopout(coordinatorKey)
|
|
}
|
|
}
|
|
|
|
C.OutsideClick {
|
|
window: root
|
|
active: root.open && root.mode === "keyboard"
|
|
extraWindows: root.anchorWindow ? [root.anchorWindow] : []
|
|
onOutside: root.close()
|
|
}
|
|
// Keyboard mode: fallback outside-click catcher (see ControlCenter).
|
|
MouseArea {
|
|
x: -20000
|
|
y: -20000
|
|
width: 40000
|
|
height: 40000
|
|
enabled: root.open && root.mode === "keyboard"
|
|
acceptedButtons: Qt.AllButtons
|
|
onPressed: root.close()
|
|
}
|
|
HyprlandFocusGrab {
|
|
active: root.open && root.mode === "click"
|
|
windows: root.anchorWindow ? [root, root.anchorWindow] : [root]
|
|
onCleared: root.close()
|
|
}
|
|
|
|
C.BarDrawer {
|
|
id: drawer
|
|
y: Core.BarDrawers.bottom
|
|
open: root.open
|
|
contentWidth: root.contentWidth
|
|
contentHeight: root.contentHeight
|
|
drawerId: "plugin-popup-" + (root.owner && root.owner.moduleName ? root.owner.moduleName : "")
|
|
screenName: root.screen ? root.screen.name : ""
|
|
screenX: root.drawerX
|
|
|
|
// Swallow clicks on the card so they never reach the outside catcher.
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
acceptedButtons: Qt.AllButtons
|
|
}
|
|
Item {
|
|
id: contentHolder
|
|
anchors.fill: parent
|
|
anchors.margins: root.padding
|
|
}
|
|
}
|
|
}
|