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>
1140 lines
54 KiB
QML
1140 lines
54 KiB
QML
pragma ComponentBehavior: Bound
|
||
import QtQuick
|
||
import QtQuick.Controls
|
||
import Quickshell
|
||
import Quickshell.Io
|
||
import Quickshell.Wayland
|
||
import "../components"
|
||
import "../bar"
|
||
import "../controlcenter"
|
||
import "../controlcenter/GridLogic.js" as Grid
|
||
import "../core"
|
||
import "../dashboard"
|
||
import "../services"
|
||
import "../theme"
|
||
import "../widgets/faces" as Faces
|
||
|
||
// Notch mode's open panel (pocket-dots style). It grows out of the collapsed
|
||
// notch at the top edge into three columns: a dashboard pager on the left
|
||
// (Media, Performance, Calendar; the wheel moves between them), the Control
|
||
// Center tiles and weather in the middle, and notifications on the right.
|
||
// Clicking Performance swaps in the full "Your computer" view, and clicking
|
||
// the album art swaps in the EasyEffects equalizer.
|
||
// The layer is sized to the shape so HyprGlass follows its outline.
|
||
// qmllint disable uncreatable-type
|
||
PanelWindow {
|
||
// qmllint enable uncreatable-type
|
||
id: root
|
||
screen: ScreenService.current(ShellState.notchScreen)
|
||
readonly property real screenWidth: screen ? screen.width : 1920
|
||
readonly property real screenHeight: screen ? screen.height : 1080
|
||
readonly property var options: ConfigService.ready ? ConfigService.data.notch : null
|
||
readonly property bool computer: ShellState.notchView === "computer"
|
||
readonly property bool equalizer: ShellState.notchView === "equalizer"
|
||
// A full view replaces the three columns.
|
||
readonly property bool detail: computer || equalizer
|
||
readonly property bool equalizerShown: ShellState.notchOpen && equalizer
|
||
onEqualizerShownChanged: if (equalizerShown)
|
||
EasyEffectsService.refresh()
|
||
readonly property real ear: BarDrawers.ear
|
||
readonly property real band: BarDrawers.bottom
|
||
readonly property int pad: 22
|
||
readonly property int sideWidth: 330
|
||
readonly property int middleWidth: 440
|
||
readonly property int columnGap: 44
|
||
// The open notch's header: the band plus room for the divider below it.
|
||
readonly property real header: band + 8
|
||
readonly property int gutter: 16
|
||
|
||
// Open size of each view, then the morph between the pill and that size.
|
||
readonly property real mainWidth: 2 * sideWidth + middleWidth + 2 * columnGap + 2 * pad
|
||
readonly property real mainHeight: Math.max(600, middle.contentHeight + header + gutter + pad)
|
||
readonly property Item detailItem: (equalizer ? equalizerView.item : computerView.item) as Item
|
||
readonly property real detailWidth: (detailItem ? detailItem.implicitWidth : equalizer ? 400 : 800) + 2 * pad
|
||
readonly property real detailHeight: band + 44 + (detailItem ? detailItem.implicitHeight : 400) + pad
|
||
readonly property real openWidth: Math.min(screenWidth - 2 * (BarDrawers.margin + ear) - 40, detail ? detailWidth : mainWidth)
|
||
readonly property real openHeight: Math.min(screenHeight - 40, detail ? detailHeight : mainHeight)
|
||
property real progress: ShellState.notchOpen ? 1 : 0
|
||
Behavior on progress {
|
||
NumberAnimation {
|
||
id: morph
|
||
duration: ShellState.notchOpen ? Theme.notchOpenDuration * 2 : Theme.notchCloseDuration * 1.3
|
||
easing.type: Easing.BezierSpline
|
||
easing.bezierCurve: ShellState.notchOpen ? [0.2, 0, 0, 1, 1, 1] : [0.3, 0, 0.8, 0.15, 1, 1]
|
||
}
|
||
}
|
||
readonly property bool settled: ShellState.notchOpen && !morph.running
|
||
// Width leads the height a little, like a notch unfolding.
|
||
readonly property real wp: Math.min(1, progress * 1.15)
|
||
property real targetWidth: openWidth
|
||
property real targetHeight: openHeight
|
||
Behavior on targetWidth {
|
||
enabled: root.settled
|
||
NumberAnimation {
|
||
duration: Theme.notchDuration * 1.4
|
||
easing.type: Easing.BezierSpline
|
||
easing.bezierCurve: [0.2, 0, 0, 1, 1, 1]
|
||
}
|
||
}
|
||
Behavior on targetHeight {
|
||
enabled: root.settled
|
||
NumberAnimation {
|
||
duration: Theme.notchDuration * 1.4
|
||
easing.type: Easing.BezierSpline
|
||
easing.bezierCurve: [0.2, 0, 0, 1, 1, 1]
|
||
}
|
||
}
|
||
readonly property real bodyWidth: ShellState.notchPillWidth + (targetWidth - ShellState.notchPillWidth) * wp
|
||
readonly property real bodyHeight: band + (targetHeight - band) * progress
|
||
// Content fades in once the shape has mostly opened, and out first.
|
||
readonly property real contentOpacity: Math.max(0, Math.min(1, (progress - 0.55) / 0.4))
|
||
|
||
anchors.top: true
|
||
// Screen x of this centred layer, so bar popouts (plugin tooltips) anchored
|
||
// in the strip land under their module.
|
||
readonly property real screenOffsetX: Math.round((screenWidth - implicitWidth) / 2)
|
||
implicitWidth: Math.round(bodyWidth + 2 * ear)
|
||
implicitHeight: Math.max(1, Math.round(bodyHeight))
|
||
visible: ShellState.notchOpen || progress > 0.001
|
||
color: Theme.transparent
|
||
exclusionMode: ExclusionMode.Ignore
|
||
WlrLayershell.layer: WlrLayer.Overlay
|
||
// Shares the dashboard's HyprGlass namespace (already whitelisted).
|
||
WlrLayershell.namespace: "glassMxrph-dashboard"
|
||
// A plugin panel opened from the strip takes focus (and the pointer) while it is open.
|
||
WlrLayershell.keyboardFocus: ShellState.notchOpen && !PluginService.activePopout ? WlrKeyboardFocus.Exclusive : WlrKeyboardFocus.None
|
||
Component.onCompleted: ShellState.notchWindow = root
|
||
Component.onDestruction: ShellState.notchWindow = null
|
||
|
||
// Pill button for the tile editor.
|
||
component Pill: Rectangle {
|
||
id: pill
|
||
property string text
|
||
property bool strong: false
|
||
signal clicked
|
||
implicitWidth: pillLabel.implicitWidth + 28
|
||
implicitHeight: 30
|
||
radius: 15
|
||
color: strong ? (pillArea.containsMouse ? Theme.accentHover : Theme.accent) : pillArea.containsMouse ? Theme.hover : Theme.fill
|
||
border.width: strong ? 0 : 1
|
||
border.color: Theme.hairline
|
||
Accessible.role: Accessible.Button
|
||
Accessible.name: text
|
||
Text {
|
||
id: pillLabel
|
||
anchors.centerIn: parent
|
||
text: pill.text
|
||
color: pill.strong ? Theme.accentText : Theme.text
|
||
font.pixelSize: 12
|
||
font.weight: Font.Medium
|
||
}
|
||
MouseArea {
|
||
id: pillArea
|
||
anchors.fill: parent
|
||
hoverEnabled: true
|
||
cursorShape: Qt.PointingHandCursor
|
||
onClicked: pill.clicked()
|
||
}
|
||
}
|
||
|
||
// Opening with audio playing always lands on Media.
|
||
Connections {
|
||
target: ShellState
|
||
function onNotchOpenChanged() {
|
||
if (ShellState.notchOpen) {
|
||
if (MediaService.playing && (!root.options || root.options.mediaFirst))
|
||
pager.page = 0;
|
||
body.forceActiveFocus();
|
||
}
|
||
}
|
||
}
|
||
|
||
// Keyboard focus comes back once a plugin panel from the strip closes.
|
||
Connections {
|
||
target: PluginService
|
||
function onActivePopoutChanged() {
|
||
if (!PluginService.activePopout && ShellState.notchOpen)
|
||
body.forceActiveFocus();
|
||
}
|
||
}
|
||
|
||
OutsideClick {
|
||
window: root
|
||
active: ShellState.notchOpen && !PluginService.activePopout
|
||
onOutside: ShellState.notchOpen = false
|
||
}
|
||
// Fallback outside-click catcher (see ControlCenter).
|
||
MouseArea {
|
||
objectName: "notchOutside"
|
||
x: -20000
|
||
y: -20000
|
||
width: 40000
|
||
height: 40000
|
||
onPressed: ShellState.notchOpen = false
|
||
}
|
||
|
||
DrawerShape {
|
||
bodyWidth: root.bodyWidth
|
||
bodyHeight: root.bodyHeight
|
||
ear: root.ear
|
||
radius: Math.min(Theme.radius + 8, root.bodyHeight / 2)
|
||
// Fades between the docked and open fill at its own speed; closing, it
|
||
// never outlasts the shrink so it docks in the docked colour.
|
||
fillColor: ShellState.notchOpen ? Theme.notchOpenFill : Theme.notchFill
|
||
Behavior on fillColor {
|
||
ColorAnimation {
|
||
duration: ShellState.notchOpen ? Theme.notchColorDuration : Math.min(Theme.notchColorDuration, Theme.notchCloseDuration * 1.3)
|
||
}
|
||
}
|
||
}
|
||
|
||
Item {
|
||
id: body
|
||
objectName: "notchSurface"
|
||
x: root.ear
|
||
width: root.bodyWidth
|
||
height: root.bodyHeight
|
||
clip: true
|
||
focus: ShellState.notchOpen
|
||
Keys.onEscapePressed: {
|
||
if (middle.editing)
|
||
middle.editing = false;
|
||
else if (root.detail)
|
||
ShellState.notchView = "main";
|
||
else
|
||
ShellState.notchOpen = false;
|
||
}
|
||
Keys.onUpPressed: pager.go(pager.page - 1)
|
||
Keys.onDownPressed: pager.go(pager.page + 1)
|
||
MouseArea {
|
||
anchors.fill: parent
|
||
} // Inside clicks must not dismiss.
|
||
|
||
// The clock stays put in the band while the notch opens around it.
|
||
SystemClock {
|
||
id: clock
|
||
precision: SystemClock.Minutes
|
||
}
|
||
Row {
|
||
id: clockRow
|
||
anchors.horizontalCenter: parent.horizontalCenter
|
||
y: (root.band - height) / 2
|
||
spacing: 8
|
||
Text {
|
||
text: Qt.formatDateTime(clock.date, ConfigService.ready && !ConfigService.data.bar.clock.use24Hour ? "h:mm" : "HH:mm")
|
||
color: Theme.text
|
||
font.pixelSize: 14
|
||
font.weight: Font.DemiBold
|
||
font.features: {
|
||
"tnum": 1
|
||
}
|
||
}
|
||
Text {
|
||
opacity: root.contentOpacity
|
||
text: "· " + Qt.formatDateTime(clock.date, "ddd d MMMM")
|
||
color: Theme.textSecondary
|
||
font.pixelSize: 14
|
||
}
|
||
}
|
||
|
||
// Header: chosen bar modules left of the clock (the wheel scrolls them
|
||
// sideways), the tile editor cog, and a divider under it all.
|
||
readonly property bool headerShown: !root.detail && root.contentOpacity > 0
|
||
Flickable {
|
||
id: strip
|
||
objectName: "notchStrip"
|
||
x: main.x
|
||
width: Math.max(0, clockRow.x - 24 - main.x)
|
||
height: root.band
|
||
visible: body.headerShown
|
||
opacity: root.contentOpacity
|
||
contentWidth: stripRow.implicitWidth
|
||
contentHeight: height
|
||
flickableDirection: Flickable.HorizontalFlick
|
||
boundsBehavior: Flickable.StopAtBounds
|
||
clip: true
|
||
ModuleRow {
|
||
id: stripRow
|
||
position: "center"
|
||
active: ShellState.notchOpen
|
||
modules: BarLayout.notchModules(root.screen ? root.screen.name : "", "strip")
|
||
barScreen: root.screen
|
||
anchors.verticalCenter: parent.verticalCenter
|
||
}
|
||
}
|
||
// Empty strip: a shortcut to pick its modules.
|
||
Rectangle {
|
||
objectName: "notchStripAdd"
|
||
x: main.x
|
||
y: (root.band - height) / 2
|
||
width: addLabel.implicitWidth + 24
|
||
height: 28
|
||
radius: 14
|
||
visible: body.headerShown && stripRow.modules.length === 0
|
||
opacity: root.contentOpacity
|
||
color: addArea.containsMouse ? Theme.hover : Theme.fill
|
||
border.width: 1
|
||
border.color: Theme.hairline
|
||
Text {
|
||
id: addLabel
|
||
anchors.centerIn: parent
|
||
text: "+ Add bar modules"
|
||
color: Theme.textSecondary
|
||
font.pixelSize: 12
|
||
}
|
||
MouseArea {
|
||
id: addArea
|
||
anchors.fill: parent
|
||
hoverEnabled: true
|
||
cursorShape: Qt.PointingHandCursor
|
||
onClicked: ShellState.revealSetting("notch", "Notch strip")
|
||
}
|
||
}
|
||
MouseArea {
|
||
anchors.fill: strip
|
||
visible: strip.visible
|
||
acceptedButtons: Qt.NoButton
|
||
onWheel: wheel => {
|
||
const delta = wheel.angleDelta.y !== 0 ? wheel.angleDelta.y : wheel.angleDelta.x;
|
||
strip.contentX = Math.max(0, Math.min(strip.contentWidth - strip.width, strip.contentX - delta * 0.6));
|
||
}
|
||
}
|
||
Rectangle {
|
||
objectName: "notchEditControls"
|
||
x: main.x + root.sideWidth + root.columnGap + root.middleWidth - width
|
||
y: (root.band - height) / 2
|
||
width: 30
|
||
height: 30
|
||
radius: 15
|
||
visible: body.headerShown
|
||
opacity: root.contentOpacity
|
||
color: middle.editing ? Theme.accent : cogArea.containsMouse ? Theme.hover : Theme.transparent
|
||
Accessible.role: Accessible.Button
|
||
Accessible.name: "Edit controls"
|
||
Text {
|
||
anchors.centerIn: parent
|
||
text: Icons.available ? "" : "⚙"
|
||
font.family: Icons.available ? Icons.family : ""
|
||
font.pixelSize: 16
|
||
color: middle.editing ? Theme.accentText : Theme.textSecondary
|
||
}
|
||
MouseArea {
|
||
id: cogArea
|
||
anchors.fill: parent
|
||
hoverEnabled: true
|
||
cursorShape: Qt.PointingHandCursor
|
||
onClicked: middle.editing = !middle.editing
|
||
}
|
||
}
|
||
Rectangle {
|
||
x: main.x
|
||
y: root.header
|
||
width: main.width
|
||
height: 1
|
||
visible: body.headerShown
|
||
opacity: root.contentOpacity
|
||
color: Theme.hairline
|
||
}
|
||
|
||
// Main view ----------------------------------------------------------
|
||
Item {
|
||
id: main
|
||
x: (root.bodyWidth - root.mainWidth) / 2 + root.pad
|
||
y: root.header + root.gutter
|
||
width: root.mainWidth - 2 * root.pad
|
||
height: root.targetHeight - root.header - root.gutter - root.pad
|
||
visible: opacity > 0
|
||
opacity: root.detail ? 0 : root.contentOpacity
|
||
Behavior on opacity {
|
||
enabled: root.settled
|
||
NumberAnimation {
|
||
duration: Theme.notchDuration
|
||
}
|
||
}
|
||
|
||
// Left: dashboard pager.
|
||
Item {
|
||
id: pager
|
||
objectName: "notchPager"
|
||
width: root.sideWidth
|
||
height: parent.height
|
||
clip: true
|
||
property int page: 0
|
||
readonly property int count: 3
|
||
function go(i) {
|
||
page = Math.max(0, Math.min(count - 1, i));
|
||
}
|
||
property real wheelAccum: 0
|
||
Timer {
|
||
id: wheelLock
|
||
interval: 320
|
||
}
|
||
Column {
|
||
y: -pager.page * pager.height
|
||
Behavior on y {
|
||
NumberAnimation {
|
||
duration: Theme.notchDuration * 1.6
|
||
easing.type: Easing.BezierSpline
|
||
easing.bezierCurve: [0.2, 0, 0, 1, 1, 1]
|
||
}
|
||
}
|
||
// Media
|
||
NotchMedia {
|
||
width: pager.width - 16
|
||
height: pager.height
|
||
active: ShellState.notchOpen && pager.page === 0
|
||
}
|
||
// Performance: click for the full view.
|
||
Item {
|
||
id: perf
|
||
width: pager.width - 16
|
||
height: pager.height
|
||
readonly property var disk: (MetricsService.snapshot.storage || []).find(s => s.available) || ({})
|
||
readonly property var gpu: MetricsService.gpu || ({})
|
||
readonly property var rows: [["CPU", [MetricsService.value(MetricsService.cpu.temperature, " °C"), MetricsService.value(MetricsService.cpu.frequency / 1000, " GHz", 2)].filter(v => v !== "—").join(" · ") || "—"], ["GPU", Number.isFinite(gpu.percent) ? Math.round(gpu.percent) + "%" + (Number.isFinite(gpu.temperature) ? " · " + Math.round(gpu.temperature) + " °C" : "") : "—"], ["Memory", MetricsService.bytes(MetricsService.ram.used) + " / " + MetricsService.bytes(MetricsService.ram.total)], ["Network", "↓ " + MetricsService.bytes(MetricsService.network.download) + "/s ↑ " + MetricsService.bytes(MetricsService.network.upload) + "/s"]]
|
||
Demand {
|
||
service: MetricsService
|
||
active: ShellState.notchOpen && pager.page === 1
|
||
}
|
||
Rectangle {
|
||
anchors.fill: parent
|
||
anchors.topMargin: 6
|
||
anchors.bottomMargin: 6
|
||
radius: Math.max(16, Theme.radius)
|
||
color: perfArea.containsMouse ? Theme.hover : Theme.surfaceVariant
|
||
border.width: 1
|
||
border.color: Theme.hairline
|
||
Behavior on color {
|
||
ColorAnimation {
|
||
duration: Theme.notchDuration / 2
|
||
}
|
||
}
|
||
Column {
|
||
anchors.centerIn: parent
|
||
width: parent.width - 40
|
||
spacing: 22
|
||
Item {
|
||
width: parent.width
|
||
height: 24
|
||
Text {
|
||
text: "Your computer"
|
||
color: Theme.text
|
||
font.pixelSize: 17
|
||
font.weight: Font.DemiBold
|
||
}
|
||
Text {
|
||
anchors.right: parent.right
|
||
text: Icons.available ? "" : "›"
|
||
font.family: Icons.available ? Icons.family : ""
|
||
color: Theme.textSecondary
|
||
font.pixelSize: 20
|
||
}
|
||
}
|
||
Row {
|
||
anchors.horizontalCenter: parent.horizontalCenter
|
||
spacing: 10
|
||
Gauge {
|
||
size: (perf.width - 40 - 20) / 3
|
||
value: MetricsService.cpu.percent
|
||
caption: "CPU"
|
||
}
|
||
Gauge {
|
||
size: (perf.width - 40 - 20) / 3
|
||
value: MetricsService.ram.percent
|
||
caption: "Memory"
|
||
}
|
||
Gauge {
|
||
size: (perf.width - 40 - 20) / 3
|
||
value: perf.disk.percent
|
||
caption: "Disk"
|
||
}
|
||
}
|
||
Column {
|
||
width: parent.width
|
||
Repeater {
|
||
model: perf.rows
|
||
Item {
|
||
required property var modelData
|
||
required property int index
|
||
width: parent.width
|
||
height: 38
|
||
Rectangle {
|
||
visible: parent.index > 0
|
||
width: parent.width
|
||
height: 1
|
||
color: Theme.hairline
|
||
}
|
||
Text {
|
||
anchors.verticalCenter: parent.verticalCenter
|
||
text: parent.modelData[0]
|
||
color: Theme.textSecondary
|
||
font.pixelSize: 13
|
||
}
|
||
Text {
|
||
anchors.right: parent.right
|
||
anchors.verticalCenter: parent.verticalCenter
|
||
text: parent.modelData[1]
|
||
color: Theme.text
|
||
font.pixelSize: 13
|
||
font.features: {
|
||
"tnum": 1
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
MouseArea {
|
||
id: perfArea
|
||
objectName: "notchComputer"
|
||
anchors.fill: parent
|
||
hoverEnabled: true
|
||
cursorShape: Qt.PointingHandCursor
|
||
onClicked: ShellState.notchView = "computer"
|
||
}
|
||
}
|
||
}
|
||
// Calendar
|
||
Item {
|
||
width: pager.width - 16
|
||
height: pager.height
|
||
Column {
|
||
id: dateHead
|
||
anchors.horizontalCenter: parent.horizontalCenter
|
||
y: 6
|
||
Text {
|
||
anchors.horizontalCenter: parent.horizontalCenter
|
||
text: Qt.formatDateTime(clock.date, ConfigService.ready && !ConfigService.data.bar.clock.use24Hour ? "h:mm" : "HH:mm")
|
||
color: Theme.text
|
||
font.pixelSize: 54
|
||
font.weight: Font.Light
|
||
font.features: {
|
||
"tnum": 1
|
||
}
|
||
}
|
||
Text {
|
||
anchors.horizontalCenter: parent.horizontalCenter
|
||
text: Qt.formatDateTime(clock.date, "dddd, d MMMM")
|
||
color: Theme.textSecondary
|
||
font.pixelSize: 14
|
||
}
|
||
}
|
||
Faces.CalendarFace {
|
||
anchors.left: parent.left
|
||
anchors.right: parent.right
|
||
anchors.top: dateHead.bottom
|
||
anchors.topMargin: 14
|
||
anchors.bottom: parent.bottom
|
||
}
|
||
}
|
||
}
|
||
// Wheel moves one page per notch; touchpads are rate-limited.
|
||
MouseArea {
|
||
anchors.fill: parent
|
||
acceptedButtons: Qt.NoButton
|
||
onWheel: wheel => {
|
||
pager.wheelAccum += wheel.angleDelta.y;
|
||
if (Math.abs(pager.wheelAccum) < 120 || wheelLock.running)
|
||
return;
|
||
pager.go(pager.page + (pager.wheelAccum < 0 ? 1 : -1));
|
||
pager.wheelAccum = 0;
|
||
wheelLock.restart();
|
||
}
|
||
}
|
||
Column {
|
||
anchors.right: parent.right
|
||
anchors.verticalCenter: parent.verticalCenter
|
||
spacing: 8
|
||
Repeater {
|
||
model: pager.count
|
||
Rectangle {
|
||
required property int index
|
||
width: 6
|
||
height: pager.page === index ? 20 : 6
|
||
radius: 3
|
||
color: pager.page === index ? Theme.accent : Qt.alpha(Theme.text, 0.25)
|
||
Behavior on height {
|
||
NumberAnimation {
|
||
duration: Theme.notchDuration
|
||
easing.type: Easing.OutCubic
|
||
}
|
||
}
|
||
MouseArea {
|
||
anchors.fill: parent
|
||
anchors.margins: -4
|
||
cursorShape: Qt.PointingHandCursor
|
||
onClicked: pager.go(parent.index)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
Rectangle {
|
||
x: root.sideWidth + root.columnGap / 2
|
||
y: -root.gutter
|
||
width: 1
|
||
height: parent.height + root.gutter
|
||
color: Theme.hairline
|
||
}
|
||
|
||
// Middle: the notch's own Control Center tiles, then the weather.
|
||
// The header cog edits them in place (notch.controls); until first
|
||
// edited they follow the Control Center's order, packed, without
|
||
// Now Playing (the left column shows media).
|
||
Flickable {
|
||
id: middle
|
||
objectName: "notchControls"
|
||
x: root.sideWidth + root.columnGap
|
||
width: root.middleWidth
|
||
height: parent.height
|
||
contentWidth: width
|
||
contentHeight: middleColumn.implicitHeight
|
||
clip: true
|
||
interactive: !editing
|
||
boundsBehavior: Flickable.StopAtBounds
|
||
ScrollBar.vertical: ScrollBar {
|
||
policy: ScrollBar.AsNeeded
|
||
}
|
||
readonly property int gap: 10
|
||
readonly property int cellHeight: 68
|
||
readonly property real cellWidth: (width - 3 * gap) / Grid.COLS
|
||
readonly property bool ownLayout: ConfigService.ready && ConfigService.data.notch.controls.length > 0
|
||
readonly property var entries: ControlRegistry.notchModules
|
||
readonly property var tiles: entries.filter(m => m.enabled && m.id !== "media" && !!ControlRegistry.entry(m.id) && !ControlRegistry.entry(m.id).section).slice().sort((a, b) => ((Number.isInteger(a.y) ? a.y : 99) - (Number.isInteger(b.y) ? b.y : 99)) || ((Number.isInteger(a.x) ? a.x : 0) - (Number.isInteger(b.x) ? b.x : 0)))
|
||
readonly property var savedPlan: Grid.layout(tiles.map(m => {
|
||
const size = ControlRegistry.size(m);
|
||
return middle.ownLayout ? {
|
||
id: m.id,
|
||
w: size.w,
|
||
h: size.h,
|
||
x: m.x,
|
||
y: m.y
|
||
} : {
|
||
id: m.id,
|
||
w: size.w,
|
||
h: size.h
|
||
};
|
||
}))
|
||
// Edit mode, as in the Control Center: drag to move, corner to
|
||
// resize (tiles in the way are pushed down), badge to remove.
|
||
property bool editing: false
|
||
property var preview: null
|
||
property string dragId: ""
|
||
property point dragPoint
|
||
property point grabOffset
|
||
property string resizeId: ""
|
||
readonly property var plan: preview || savedPlan
|
||
readonly property int shownRows: plan.rows + (editing ? 1 : 0)
|
||
readonly property var addable: ControlRegistry.ids.filter(id => id !== "media" && id !== "notifications" && !tiles.some(m => m.id === id))
|
||
property var extras: ({})
|
||
function setExtra(id, value) {
|
||
if ((extras[id] || 0) === value)
|
||
return;
|
||
const next = Object.assign({}, extras);
|
||
next[id] = value;
|
||
extras = next;
|
||
}
|
||
readonly property var geometry: Grid.geometry(plan, cellWidth, cellHeight, gap, editing ? {} : extras)
|
||
// Writes every tile's cell back to the notch's own layout.
|
||
function save(plan, patch) {
|
||
const list = entries.map(m => Object.assign({}, m));
|
||
for (const i of plan.items)
|
||
if (!list.some(m => m.id === i.id))
|
||
list.push({
|
||
id: i.id,
|
||
enabled: true
|
||
});
|
||
ConfigService.setValue("notch.controls", list.map(m => {
|
||
const i = plan.items.find(t => t.id === m.id);
|
||
let next = m;
|
||
if (i) {
|
||
next.x = i.col;
|
||
next.y = i.row;
|
||
next.w = i.w;
|
||
next.h = i.h;
|
||
}
|
||
if (patch && patch[m.id])
|
||
next = patch[m.id](next);
|
||
return next;
|
||
}));
|
||
}
|
||
function setEnabled(id, on) {
|
||
if (!on) {
|
||
save(savedPlan, {
|
||
[id]: m => {
|
||
const next = Object.assign({}, m, {
|
||
enabled: false
|
||
});
|
||
delete next.x;
|
||
delete next.y;
|
||
return next;
|
||
}
|
||
});
|
||
return;
|
||
}
|
||
const known = entries.find(m => m.id === id);
|
||
const size = ControlRegistry.size(known || {
|
||
id: id
|
||
});
|
||
const spot = Grid.freeSpot(savedPlan, size.w, size.h);
|
||
save(savedPlan, {
|
||
[id]: m => Object.assign({}, m, {
|
||
enabled: true,
|
||
x: spot.col,
|
||
y: spot.row
|
||
})
|
||
});
|
||
if (!known)
|
||
ConfigService.setValue("notch.controls", ConfigService.data.notch.controls.concat([{
|
||
id: id,
|
||
enabled: true,
|
||
x: spot.col,
|
||
y: spot.row
|
||
}]));
|
||
}
|
||
Connections {
|
||
target: ShellState
|
||
function onNotchOpenChanged() {
|
||
if (!ShellState.notchOpen)
|
||
middle.editing = false;
|
||
}
|
||
}
|
||
readonly property var weatherOptions: {
|
||
const items = ConfigService.ready ? ConfigService.data.desktopWidgets.items : [];
|
||
const w = items.find(i => i.type === "weather");
|
||
return w && w.options ? w.options : {};
|
||
}
|
||
Column {
|
||
id: middleColumn
|
||
width: middle.width
|
||
spacing: 14
|
||
Item {
|
||
id: tileGrid
|
||
width: parent.width
|
||
height: middle.geometry.height + (middle.editing ? middle.cellHeight + middle.gap : 0)
|
||
// Edit mode: faint empty cells, and where a dragged tile lands.
|
||
Repeater {
|
||
model: middle.editing ? Array.from({
|
||
length: Grid.COLS * middle.shownRows
|
||
}, (_, i) => i).filter(i => !middle.plan.items.some(t => i % Grid.COLS >= t.col && i % Grid.COLS < t.col + t.w && Math.floor(i / Grid.COLS) >= t.row && Math.floor(i / Grid.COLS) < t.row + t.h)) : []
|
||
Rectangle {
|
||
required property int modelData
|
||
x: (modelData % Grid.COLS) * (middle.cellWidth + middle.gap)
|
||
y: Math.floor(modelData / Grid.COLS) * (middle.cellHeight + middle.gap)
|
||
width: middle.cellWidth
|
||
height: middle.cellHeight
|
||
radius: 16
|
||
color: Qt.alpha(Theme.text, 0.03)
|
||
border.width: 1
|
||
border.color: Qt.alpha(Theme.text, 0.07)
|
||
}
|
||
}
|
||
Rectangle {
|
||
readonly property var target: middle.dragId ? middle.geometry.tiles[middle.dragId] : null
|
||
visible: !!target
|
||
x: target ? target.x : 0
|
||
y: target ? target.y : 0
|
||
width: target ? target.w : 0
|
||
height: target ? target.h : 0
|
||
radius: Math.min(30, height / 2, width / 2)
|
||
color: Qt.alpha(Theme.accent, 0.12)
|
||
border.width: 2
|
||
border.color: Qt.alpha(Theme.accent, 0.6)
|
||
}
|
||
Repeater {
|
||
model: ScriptModel {
|
||
values: middle.tiles.map(m => m.id)
|
||
}
|
||
Item {
|
||
id: slot
|
||
required property string modelData
|
||
readonly property var cell: middle.plan.items.find(i => i.id === modelData) || null
|
||
readonly property var rect: middle.geometry.tiles[modelData] || null
|
||
readonly property bool dragging: middle.dragId === modelData
|
||
readonly property real extra: loader.item ? loader.item.extraHeight : 0
|
||
readonly property var shape: loader.item ? loader.item.background : null
|
||
readonly property bool circle: !!loader.item && loader.item.circle
|
||
objectName: "notchTile-" + modelData
|
||
visible: !!rect
|
||
x: dragging ? middle.dragPoint.x - middle.grabOffset.x : rect ? rect.x : 0
|
||
y: dragging ? middle.dragPoint.y - middle.grabOffset.y : rect ? rect.y : 0
|
||
width: rect ? rect.w : 0
|
||
height: rect ? rect.h : 0
|
||
z: dragging ? 10 : 0
|
||
scale: dragging ? 1.04 : 1
|
||
onExtraChanged: middle.setExtra(modelData, extra)
|
||
Behavior on x {
|
||
enabled: root.settled && !slot.dragging
|
||
NumberAnimation {
|
||
duration: Theme.notchDuration
|
||
easing.type: Easing.OutCubic
|
||
}
|
||
}
|
||
Behavior on y {
|
||
enabled: root.settled && !slot.dragging
|
||
NumberAnimation {
|
||
duration: Theme.notchDuration
|
||
easing.type: Easing.OutCubic
|
||
}
|
||
}
|
||
Loader {
|
||
id: loader
|
||
anchors.fill: parent
|
||
active: ShellState.notchOpen
|
||
source: ControlRegistry.entry(slot.modelData).source
|
||
opacity: middle.editing ? 0.85 : 1
|
||
}
|
||
Binding {
|
||
target: loader.item
|
||
when: !!loader.item
|
||
property: "moduleId"
|
||
value: slot.modelData
|
||
}
|
||
Binding {
|
||
target: loader.item
|
||
when: !!loader.item && !!slot.cell
|
||
property: "cols"
|
||
value: slot.cell ? slot.cell.w : 1
|
||
}
|
||
Binding {
|
||
target: loader.item
|
||
when: !!loader.item && !!slot.cell
|
||
property: "rows"
|
||
value: slot.cell ? slot.cell.h : 1
|
||
}
|
||
Binding {
|
||
target: loader.item
|
||
when: !!loader.item && !!slot.cell
|
||
property: "baseHeight"
|
||
value: slot.cell ? slot.cell.h * middle.cellHeight + (slot.cell.h - 1) * middle.gap : 0
|
||
}
|
||
Connections {
|
||
target: middle
|
||
function onEditingChanged() {
|
||
if (middle.editing && loader.item && loader.item.expanded)
|
||
loader.item.expanded = false;
|
||
}
|
||
}
|
||
Rectangle {
|
||
visible: middle.editing
|
||
x: slot.shape ? slot.shape.x : 0
|
||
y: slot.shape ? slot.shape.y : 0
|
||
width: slot.shape ? slot.shape.width : parent.width
|
||
height: slot.shape ? slot.shape.height : parent.height
|
||
radius: slot.shape ? slot.shape.radius : 12
|
||
color: move.containsMouse || slot.dragging ? Qt.alpha(Theme.text, 0.06) : Theme.transparent
|
||
border.width: slot.dragging || middle.resizeId === slot.modelData ? 2 : 1
|
||
border.color: slot.dragging || middle.resizeId === slot.modelData ? Theme.accent : Qt.alpha(Theme.text, 0.3)
|
||
}
|
||
MouseArea {
|
||
id: move
|
||
objectName: "notchMove-" + slot.modelData
|
||
visible: middle.editing
|
||
anchors.fill: parent
|
||
hoverEnabled: true
|
||
preventStealing: true
|
||
cursorShape: pressed ? Qt.ClosedHandCursor : Qt.OpenHandCursor
|
||
property var lastCell: null
|
||
onPressed: mouse => {
|
||
const p = mapToItem(tileGrid, mouse.x, mouse.y);
|
||
middle.grabOffset = Qt.point(p.x - slot.x, p.y - slot.y);
|
||
middle.dragPoint = p;
|
||
lastCell = null;
|
||
}
|
||
onPositionChanged: mouse => {
|
||
if (!pressed)
|
||
return;
|
||
const p = mapToItem(tileGrid, mouse.x, mouse.y);
|
||
if (!middle.dragId) {
|
||
if (Math.hypot(p.x - middle.dragPoint.x, p.y - middle.dragPoint.y) < 6)
|
||
return;
|
||
middle.dragId = slot.modelData;
|
||
}
|
||
middle.dragPoint = p;
|
||
const c = Grid.cellAt(p.x - middle.grabOffset.x, p.y - middle.grabOffset.y, middle.cellWidth, middle.cellHeight, middle.gap);
|
||
c.row = Math.min(c.row, middle.savedPlan.rows);
|
||
if (lastCell && c.col === lastCell.col && c.row === lastCell.row)
|
||
return;
|
||
lastCell = c;
|
||
middle.preview = Grid.moveTo(middle.savedPlan, slot.modelData, c);
|
||
}
|
||
onReleased: {
|
||
const plan = middle.preview;
|
||
middle.dragId = "";
|
||
middle.preview = null;
|
||
if (plan)
|
||
middle.save(plan);
|
||
}
|
||
onCanceled: {
|
||
middle.dragId = "";
|
||
middle.preview = null;
|
||
}
|
||
}
|
||
Rectangle {
|
||
objectName: "notchRemove-" + slot.modelData
|
||
visible: middle.editing && !slot.dragging
|
||
x: slot.circle && slot.shape ? slot.shape.x + slot.shape.width * 0.146 - width / 2 : 0
|
||
y: slot.circle && slot.shape ? slot.shape.y + slot.shape.height * 0.146 - height / 2 : 0
|
||
width: 22
|
||
height: 22
|
||
radius: 11
|
||
color: removeArea.containsMouse ? Theme.accent : Theme.surface
|
||
border.width: 1
|
||
border.color: Qt.alpha(Theme.text, 0.35)
|
||
Accessible.role: Accessible.Button
|
||
Accessible.name: "Remove " + ControlRegistry.entry(slot.modelData).title
|
||
Text {
|
||
anchors.centerIn: parent
|
||
text: "−"
|
||
color: removeArea.containsMouse ? Theme.accentText : Theme.text
|
||
font.pixelSize: 15
|
||
font.weight: Font.DemiBold
|
||
}
|
||
MouseArea {
|
||
id: removeArea
|
||
anchors.fill: parent
|
||
anchors.margins: -3
|
||
hoverEnabled: true
|
||
cursorShape: Qt.PointingHandCursor
|
||
onClicked: middle.setEnabled(slot.modelData, false)
|
||
}
|
||
}
|
||
Rectangle {
|
||
visible: middle.editing && !slot.dragging
|
||
x: slot.circle && slot.shape ? slot.shape.x + slot.shape.width * 0.854 - width / 2 : parent.width - width - 2
|
||
y: slot.circle && slot.shape ? slot.shape.y + slot.shape.height * 0.854 - height / 2 : parent.height - height - 2
|
||
width: 14
|
||
height: 14
|
||
radius: 7
|
||
color: Theme.text
|
||
border.width: 2
|
||
border.color: Theme.accent
|
||
MouseArea {
|
||
objectName: "notchResize-" + slot.modelData
|
||
anchors.fill: parent
|
||
anchors.margins: -5
|
||
preventStealing: true
|
||
cursorShape: Qt.SizeFDiagCursor
|
||
property point start
|
||
property var startSize
|
||
onPressed: mouse => {
|
||
start = mapToItem(tileGrid, mouse.x, mouse.y);
|
||
startSize = {
|
||
w: slot.cell.w,
|
||
h: slot.cell.h
|
||
};
|
||
middle.resizeId = slot.modelData;
|
||
}
|
||
onPositionChanged: mouse => {
|
||
if (!pressed)
|
||
return;
|
||
const p = mapToItem(tileGrid, mouse.x, mouse.y);
|
||
const next = Grid.resize(startSize, p.x - start.x, p.y - start.y, middle.cellWidth, middle.cellHeight, middle.gap);
|
||
if (next.w !== slot.cell.w || next.h !== slot.cell.h)
|
||
middle.preview = Grid.moveTo(middle.savedPlan, slot.modelData, next);
|
||
}
|
||
onReleased: {
|
||
const plan = middle.preview;
|
||
middle.resizeId = "";
|
||
middle.preview = null;
|
||
if (plan)
|
||
middle.save(plan);
|
||
}
|
||
onCanceled: {
|
||
middle.resizeId = "";
|
||
middle.preview = null;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
// Edit mode: add tiles, reset, done.
|
||
Flow {
|
||
visible: middle.editing && middle.addable.length > 0
|
||
width: parent.width
|
||
spacing: 8
|
||
Repeater {
|
||
model: middle.editing ? middle.addable : []
|
||
Pill {
|
||
required property string modelData
|
||
objectName: "notchAdd-" + modelData
|
||
text: "+ " + (Icons.available ? ControlRegistry.entry(modelData).glyph + " " : "") + ControlRegistry.entry(modelData).title
|
||
onClicked: middle.setEnabled(modelData, true)
|
||
}
|
||
}
|
||
}
|
||
Row {
|
||
visible: middle.editing
|
||
anchors.horizontalCenter: parent.horizontalCenter
|
||
spacing: 8
|
||
Pill {
|
||
objectName: "notchReset"
|
||
text: "Follow Control Center"
|
||
onClicked: ConfigService.setValue("notch.controls", [])
|
||
}
|
||
Pill {
|
||
objectName: "notchDone"
|
||
text: "Done"
|
||
strong: true
|
||
onClicked: middle.editing = false
|
||
}
|
||
}
|
||
Rectangle {
|
||
visible: !middle.editing
|
||
width: parent.width
|
||
height: 92
|
||
radius: Math.min(30, height / 2)
|
||
color: Theme.fill
|
||
border.width: 1
|
||
border.color: Theme.hairline
|
||
Faces.WeatherFace {
|
||
anchors.fill: parent
|
||
options: middle.weatherOptions
|
||
visible: ShellState.notchOpen
|
||
}
|
||
}
|
||
}
|
||
}
|
||
Rectangle {
|
||
x: root.sideWidth + root.columnGap + root.middleWidth + root.columnGap / 2
|
||
y: -root.gutter
|
||
width: 1
|
||
height: parent.height + root.gutter
|
||
color: Theme.hairline
|
||
}
|
||
|
||
// Right: notifications.
|
||
Flickable {
|
||
x: root.sideWidth + 2 * root.columnGap + root.middleWidth
|
||
width: root.sideWidth
|
||
height: parent.height
|
||
contentWidth: width
|
||
contentHeight: notifications.implicitHeight
|
||
clip: true
|
||
boundsBehavior: Flickable.StopAtBounds
|
||
Loader {
|
||
id: notifications
|
||
width: parent.width
|
||
active: ShellState.notchOpen
|
||
source: ControlRegistry.entry("notifications").source
|
||
}
|
||
}
|
||
}
|
||
|
||
// Full views: "Your computer" (the dashboard's Performance tab) and
|
||
// the dashboard's EasyEffects equalizer ------------------------------
|
||
DetailView {
|
||
id: computerView
|
||
view: "computer"
|
||
title: "Your computer"
|
||
source: DashboardRegistry.entry("performance").source
|
||
}
|
||
DetailView {
|
||
id: equalizerView
|
||
view: "equalizer"
|
||
title: "Equalizer"
|
||
source: Qt.resolvedUrl("../dashboard/Equalizer.qml")
|
||
}
|
||
}
|
||
|
||
// A full view: a back pill over the loaded page, shown while it is the
|
||
// notch's view.
|
||
component DetailView: Item {
|
||
id: detailView
|
||
required property string view
|
||
property string title
|
||
property alias source: detailLoader.source
|
||
readonly property bool shown: ShellState.notchView === view
|
||
readonly property var item: detailLoader.item
|
||
x: root.pad
|
||
y: root.band
|
||
width: root.bodyWidth - 2 * root.pad
|
||
height: Math.max(0, root.bodyHeight - root.band - root.pad)
|
||
visible: opacity > 0
|
||
opacity: shown ? root.contentOpacity : 0
|
||
Behavior on opacity {
|
||
enabled: root.settled
|
||
NumberAnimation {
|
||
duration: Theme.notchDuration
|
||
}
|
||
}
|
||
Rectangle {
|
||
objectName: detailView.view === "computer" ? "notchBack" : "notchBack-" + detailView.view
|
||
width: backLabel.implicitWidth + 28
|
||
height: 30
|
||
radius: 15
|
||
color: backArea.containsMouse ? Theme.hover : Theme.fill
|
||
border.width: 1
|
||
border.color: Theme.hairline
|
||
Text {
|
||
id: backLabel
|
||
anchors.centerIn: parent
|
||
text: (Icons.available ? " " : "‹ ") + detailView.title
|
||
color: Theme.text
|
||
font.pixelSize: 13
|
||
font.weight: Font.DemiBold
|
||
}
|
||
MouseArea {
|
||
id: backArea
|
||
anchors.fill: parent
|
||
hoverEnabled: true
|
||
cursorShape: Qt.PointingHandCursor
|
||
onClicked: ShellState.notchView = "main"
|
||
}
|
||
}
|
||
Loader {
|
||
id: detailLoader
|
||
y: 44
|
||
anchors.horizontalCenter: parent.horizontalCenter
|
||
active: ShellState.notchOpen && detailView.shown
|
||
onLoaded: if ("current" in item)
|
||
item.current = Qt.binding(() => ShellState.notchOpen && detailView.shown)
|
||
}
|
||
}
|
||
|
||
IpcHandler {
|
||
target: "notch"
|
||
function toggle(): void {
|
||
ShellState.toggleNotch();
|
||
}
|
||
function open(): void {
|
||
ShellState.openNotch();
|
||
}
|
||
function close(): void {
|
||
ShellState.notchOpen = false;
|
||
}
|
||
function page(index: int): void {
|
||
pager.go(index);
|
||
}
|
||
function editControls(): void {
|
||
middle.editing = !middle.editing;
|
||
}
|
||
function toggleMode(): bool {
|
||
return ShellState.toggleNotchMode();
|
||
}
|
||
function view(name: string): void {
|
||
ShellState.notchView = name === "computer" || name === "equalizer" ? name : "main";
|
||
}
|
||
// Open straight onto a full view; again on that view closes the notch.
|
||
function computer(): void {
|
||
ShellState.toggleNotchView("computer");
|
||
}
|
||
function equalizer(): void {
|
||
ShellState.toggleNotchView("equalizer");
|
||
}
|
||
function status(): string {
|
||
return JSON.stringify({
|
||
mode: ShellState.notchMode,
|
||
open: ShellState.notchOpen,
|
||
visible: root.visible,
|
||
view: ShellState.notchView,
|
||
page: pager.page,
|
||
screen: root.screen ? root.screen.name : "",
|
||
width: root.implicitWidth,
|
||
height: root.implicitHeight
|
||
});
|
||
}
|
||
}
|
||
}
|