Files
glassMxrph/quickshell/compat/omarchy/Ui/GlassPopupBase.qml
T
mxandClaude Opus 5.5 e4ca1f5d9c Add notch opacity and colour; open plugin panels from the notch strip
- Settings → Notch → Look: opacity (0% glass to 100% solid) and colour
  for the notch, the open notch and the notch-mode launcher.
- Bar popouts and plugin panels add the open notch's screen offset, so
  tooltips and panels from the strip land under their module.
- Opening a plugin panel keeps the notch open; the notch hands keyboard
  focus to the panel and takes it back when it closes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 17:18:58 +01:00

176 lines
6.9 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)
}
}
// Keyboard mode: Hyprland routes every click to the exclusive layer, so
// outside clicks arrive here with out-of-bounds coordinates (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
}
}
}