Files
z-bar-qt/Bar.qml
T
2026-02-14 12:54:19 +01:00

188 lines
5.5 KiB
QML

pragma ComponentBehavior: Bound
import QtQuick
import QtQuick.Effects
import QtQuick.Layouts
import Quickshell
import Quickshell.Io
import Quickshell.Wayland
import Quickshell.Hyprland
import qs.Modules
import qs.Modules.Bar
import qs.Config
import qs.Helpers
import qs.Drawers
Variants {
model: Quickshell.screens
Scope {
id: scope
required property var modelData
PanelWindow {
id: bar
property bool trayMenuVisible: false
screen: scope.modelData
color: "transparent"
property var root: Quickshell.shellDir
WlrLayershell.namespace: "ZShell-Bar"
WlrLayershell.exclusionMode: ExclusionMode.Ignore
PanelWindow {
id: exclusionZone
WlrLayershell.namespace: "ZShell-Bar-Exclusion"
screen: bar.screen
WlrLayershell.layer: WlrLayer.Bottom
anchors {
left: true
right: true
top: true
}
color: "transparent"
implicitHeight: 34
}
anchors {
top: true
left: true
right: true
bottom: true
}
mask: Region {
x: 0
y: 34
property list<Region> nullRegions: []
property bool hcurrent: ( panels.popouts.hasCurrent && panels.popouts.currentName.startsWith("traymenu") ) || visibilities.sidebar || visibilities.dashboard
width: hcurrent ? 0 : bar.width
height: hcurrent ? 0 : bar.screen.height - backgroundRect.implicitHeight
intersection: Intersection.Xor
regions: hcurrent ? nullRegions : popoutRegions.instances
}
Variants {
id: popoutRegions
model: panels.children
Region {
required property Item modelData
x: modelData.x
y: modelData.y + backgroundRect.implicitHeight
width: modelData.width
height: modelData.height
intersection: Intersection.Subtract
}
}
GlobalShortcut {
name: "toggle-nc"
appid: "zshell-nc"
onPressed: {
visibilities.sidebar = !visibilities.sidebar
}
}
PersistentProperties {
id: visibilities
property bool sidebar
property bool dashboard
Component.onCompleted: Visibilities.load(scope.modelData, this)
}
Item {
anchors.fill: parent
opacity: Config.transparency.enabled ? DynamicColors.transparency.base : 1
layer.enabled: true
layer.effect: MultiEffect {
shadowEnabled: true
blurMax: 32
shadowColor: Qt.alpha(DynamicColors.palette.m3shadow, 1)
}
Border {
bar: backgroundRect
}
Backgrounds {
panels: panels
bar: backgroundRect
}
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
onContainsMouseChanged: {
if ( !containsMouse ) {
panels.popouts.hasCurrent = false;
}
}
onPositionChanged: event => {
if ( mouseY < backgroundRect.implicitHeight ) {
barLoader.checkPopout(mouseX);
}
}
onPressed: event => {
var traywithinX = mouseX >= panels.popouts.x + 8 && mouseX < panels.popouts.x + panels.popouts.implicitWidth;
var traywithinY = mouseY >= panels.popouts.y + exclusionZone.implicitHeight && mouseY < panels.popouts.y + exclusionZone.implicitHeight + panels.popouts.implicitHeight;
var sidebarwithinX = mouseX >= bar.width - panels.sidebar.width
var dashboardWithinX = mouseX <= panels.dashboard.width + panels.dashboard.x && mouseX >= panels.dashboard.x
var dashboardWithinY = mouseY <= backgroundRect.implicitHeight + panels.dashboard.implicitHeight
if ( panels.popouts.hasCurrent ) {
if ( traywithinX && traywithinY ) {
} else {
panels.popouts.hasCurrent = false;
}
} else if ( visibilities.sidebar && !sidebarwithinX ) {
visibilities.sidebar = false;
} else if ( visibilities.dashboard && ( !dashboardWithinX || !dashboardWithinY )) {
visibilities.dashboard = false;
}
}
Panels {
id: panels
screen: scope.modelData
bar: backgroundRect
visibilities: visibilities
}
Rectangle {
id: backgroundRect
property Wrapper popouts: panels.popouts
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
implicitHeight: 34
color: "transparent"
radius: 0
Behavior on color {
CAnim {}
}
BarLoader {
id: barLoader
anchors.fill: parent
popouts: panels.popouts
bar: bar
visibilities: visibilities
screen: scope.modelData
}
}
}
}
}
}