pragma ComponentBehavior: Bound import QtQuick import QtQuick.Controls import QtQuick.Layouts import Quickshell import Quickshell.Io import Quickshell.Wayland import "../components" import "../services" import "../core" import "../theme" import "GridLogic.js" as Grid // macOS-style Control Center. The layer surface is sized to the panel so // compositor glass (HyprGlass) shapes its edges to the panel, not the screen. // qmllint disable uncreatable-type PanelWindow { id: root screen: ScreenService.current(ShellState.controlCenterScreen) anchors { top: true right: true } readonly property int screenWidth: screen ? screen.width : 1920 readonly property int screenHeight: screen ? screen.height : 1080 // Drops out of the bar's right side; the right ear stays on its straight edge. readonly property real rightInset: BarDrawers.margin + BarDrawers.radius // Panel position on the output, for tests and diagnostics. readonly property real panelScreenX: screenWidth - rightInset - width + panel.ear readonly property real panelScreenY: BarDrawers.bottom // The layer starts at the screen top so the bar join is inside its box. // Margins is present at runtime but unresolved in 0.3.1 qmltypes. // qmllint disable unqualified unresolved-type margins { right: root.rightInset } // qmllint enable unqualified unresolved-type implicitWidth: Math.round(panel.width) implicitHeight: Math.round(BarDrawers.bottom + panel.contentHeight) visible: ShellState.controlCenterOpen || panel.shown color: Theme.transparent exclusionMode: ExclusionMode.Ignore WlrLayershell.layer: WlrLayer.Overlay WlrLayershell.namespace: "glassMxrph-controlcenter" WlrLayershell.keyboardFocus: ShellState.controlCenterOpen ? WlrKeyboardFocus.Exclusive : WlrKeyboardFocus.None Component.onCompleted: ShellState.controlCenterWindow = root Component.onDestruction: ShellState.controlCenterWindow = null // Modules on a 4-column grid, packed first-fit in the configured order; // Notifications is a section under it. Edit mode reorders by dragging, // resizes from the corner handle, removes with the badge and adds from a tray. readonly property int gap: 10 readonly property int cellHeight: 68 readonly property real gridWidth: panel.targetWidth - 28 readonly property real cellWidth: (gridWidth - 3 * gap) / Grid.COLS readonly property var entries: ConfigService.ready ? ConfigService.data.controlCenter.modules : [] readonly property var tiles: entries.filter(m => m.enabled && !!ControlRegistry.entry(m.id) && !ControlRegistry.entry(m.id).section) readonly property bool notifications: entries.some(m => m.id === "notifications" && m.enabled) readonly property var addable: Object.keys(ControlRegistry.modules).filter(id => !entries.some(m => m.id === id && m.enabled)) property bool editing: false // Live edit previews: the order while a tile is dragged, a size while resized. property var dragOrder: null property string dragId: "" property point dragPoint property point grabOffset property string resizeId: "" property var resizeSize: null // Tile id -> pixels a tile extends below its cells. property var extras: ({}) readonly property var order: dragOrder ? dragOrder.filter(id => tiles.some(m => m.id === id)) : tiles.map(m => m.id) readonly property var plan: Grid.pack(order.map(id => { const m = tiles.find(t => t.id === id); const size = id === resizeId && resizeSize ? resizeSize : ControlRegistry.size(m); return { id: id, w: size.w, h: size.h }; })) readonly property var geometry: Grid.geometry(plan, cellWidth, cellHeight, gap, editing ? {} : extras) function setExtra(id, value) { if ((extras[id] || 0) === value) return; const next = Object.assign({}, extras); next[id] = value; extras = next; } function cellAt(p) { return Qt.point(Math.floor(p.x / (cellWidth + gap)), Math.floor(p.y / (cellHeight + gap))); } // Writes the module list back, keeping entries that are not grid tiles. function saveOrder(ids) { const rest = entries.filter(m => !ids.includes(m.id)); ConfigService.setValue("controlCenter.modules", ids.map(id => entries.find(m => m.id === id)).concat(rest)); } function saveSize(id, size) { ConfigService.setValue("controlCenter.modules", entries.map(m => m.id === id ? Object.assign({}, m, { w: size.w, h: size.h }) : m)); } function setEnabled(id, on) { const known = entries.some(m => m.id === id); ConfigService.setValue("controlCenter.modules", known ? entries.map(m => m.id === id ? Object.assign({}, m, { enabled: on }) : m) : entries.concat([ { id: id, enabled: on } ])); } function reset() { ConfigService.setValue("controlCenter.modules", ConfigService.defaults.controlCenter.modules); } Connections { target: ShellState function onControlCenterOpenChanged() { if (!ShellState.controlCenterOpen) root.editing = false; } } component ModuleSlot: Loader { property string moduleId Layout.fillWidth: true Layout.preferredWidth: 1 active: ShellState.controlCenterOpen source: moduleId ? ControlRegistry.entry(moduleId).source : "" } component Badge: Rectangle { id: badge property string glyph signal clicked width: 22 height: 22 radius: 11 color: badgeArea.containsMouse ? Theme.accent : Theme.surface border.width: 1 border.color: Qt.alpha(Theme.text, 0.35) Accessible.role: Accessible.Button Text { anchors.centerIn: parent text: badge.glyph color: badgeArea.containsMouse ? Theme.accentText : Theme.text font.pixelSize: 15 font.weight: Font.DemiBold } MouseArea { id: badgeArea anchors.fill: parent anchors.margins: -3 hoverEnabled: true cursorShape: Qt.PointingHandCursor onClicked: badge.clicked() } } 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() } } component HeaderButton: Rectangle { id: headerButton property string glyph property string fallback signal clicked implicitWidth: 28 implicitHeight: 28 radius: 14 color: headerArea.containsMouse ? Qt.alpha(Theme.text, 0.12) : Theme.transparent Accessible.role: Accessible.Button GlassIcon { anchors.centerIn: parent size: 28 glyphSize: 14 glyph: headerButton.glyph fallback: headerButton.fallback color: Theme.transparent border.width: 0 glyphColor: Theme.textSecondary } MouseArea { id: headerArea anchors.fill: parent hoverEnabled: true cursorShape: Qt.PointingHandCursor onClicked: headerButton.clicked() } } // Hyprland routes every pointer event to a layer with exclusive keyboard // focus, so clicks outside the panel arrive here with out-of-bounds // coordinates. Qt Quick still delivers them to items extending past the // window, so this catcher (behind the panel) dismisses on outside clicks. MouseArea { objectName: "controlCenterOutside" x: -20000 y: -20000 width: 40000 height: 40000 onPressed: ShellState.controlCenterOpen = false } BarDrawer { id: panel objectName: "controlCenterSurface" readonly property real targetWidth: Math.min(ConfigService.ready ? ConfigService.data.controlCenter.width : 400, root.screenWidth - 2 * root.rightInset - 2 * ear) readonly property real targetHeight: Math.min(content.implicitHeight + 28, root.screenHeight - BarDrawers.bottom - 20) y: BarDrawers.bottom open: ShellState.controlCenterOpen contentWidth: targetWidth contentHeight: targetHeight drawerId: "controlcenter" screenName: root.screen ? root.screen.name : "" screenX: root.screenWidth - root.rightInset - width focus: open onOpenChanged: if (open) forceActiveFocus() Keys.onEscapePressed: { if (PowerService.pending) PowerService.cancel(); else if (root.editing) root.editing = false; else ShellState.controlCenterOpen = false; } Behavior on contentHeight { enabled: panel.settled NumberAnimation { duration: Theme.duration easing.type: Easing.OutCubic } } MouseArea { anchors.fill: parent } ScrollView { anchors.fill: parent anchors.margins: 14 clip: true contentWidth: panel.targetWidth - 28 ColumnLayout { id: content width: panel.targetWidth - 28 spacing: 10 RowLayout { Layout.fillWidth: true Layout.leftMargin: 4 spacing: 2 Text { text: root.editing ? "Edit Controls" : "Control Center" color: Theme.text font.pixelSize: 14 font.weight: Font.DemiBold Layout.fillWidth: true } HeaderButton { visible: root.editing glyph: "󰒓" fallback: "⚙" onClicked: ShellState.openSettings("controlcenter") Accessible.name: "Control Center settings" } HeaderButton { glyph: "󰅖" fallback: "×" onClicked: ShellState.controlCenterOpen = false Accessible.name: "Close Control Center" } } Item { id: grid objectName: "controlGrid" Layout.fillWidth: true implicitHeight: root.geometry.height visible: root.tiles.length > 0 Behavior on implicitHeight { enabled: panel.settled && !root.dragId NumberAnimation { duration: Theme.duration easing.type: Easing.OutCubic } } Repeater { // Keyed by id so moving or resizing keeps each module alive. model: ScriptModel { values: root.tiles.map(m => m.id) } Item { id: slot required property string modelData readonly property var cell: root.plan.items.find(i => i.id === modelData) || null readonly property var rect: root.geometry.tiles[modelData] || null readonly property bool dragging: root.dragId === modelData readonly property real extra: loader.item ? loader.item.extraHeight : 0 objectName: "controlTile-" + modelData visible: !!rect x: dragging ? root.dragPoint.x - root.grabOffset.x : rect ? rect.x : 0 y: dragging ? root.dragPoint.y - root.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: root.setExtra(modelData, extra) Behavior on x { enabled: panel.settled && !slot.dragging NumberAnimation { duration: Theme.duration easing.type: Easing.OutCubic } } Behavior on y { enabled: panel.settled && !slot.dragging NumberAnimation { duration: Theme.duration easing.type: Easing.OutCubic } } Behavior on width { enabled: panel.settled NumberAnimation { duration: Theme.duration easing.type: Easing.OutCubic } } Behavior on height { enabled: panel.settled NumberAnimation { duration: Theme.duration easing.type: Easing.OutCubic } } Behavior on scale { NumberAnimation { duration: Theme.duration / 2 } } Loader { id: loader anchors.fill: parent active: ShellState.controlCenterOpen source: ControlRegistry.entry(slot.modelData).source // Edit mode shows every tile at rest. opacity: root.editing ? 0.85 : 1 } 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 * root.cellHeight + (slot.cell.h - 1) * root.gap : 0 } // One extended tile at a time, none while editing. Connections { target: loader.item function onExpandedChanged() { if (!loader.item.expanded) return; for (let i = 0; i < grid.children.length; ++i) { const other = grid.children[i]; if (other !== slot && other.collapse) other.collapse(); } } } function collapse() { if (loader.item && loader.item.expanded) loader.item.expanded = false; } Connections { target: root function onEditingChanged() { if (root.editing) slot.collapse(); } } // The tile's drawn shape: a 1×1 circle is smaller than its cell. readonly property var shape: loader.item ? loader.item.background : null readonly property bool circle: !!loader.item && loader.item.circle // Edit mode: this layer takes the clicks, so pressing drags. Rectangle { visible: root.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 || root.resizeId === slot.modelData ? 2 : 1 border.color: slot.dragging || root.resizeId === slot.modelData ? Theme.accent : Qt.alpha(Theme.text, 0.3) } MouseArea { id: move objectName: "controlMove-" + slot.modelData visible: root.editing anchors.fill: parent hoverEnabled: true preventStealing: true cursorShape: pressed ? Qt.ClosedHandCursor : Qt.OpenHandCursor property point lastCell: Qt.point(-1, -1) onPressed: mouse => { const p = mapToItem(grid, mouse.x, mouse.y); root.grabOffset = Qt.point(p.x - slot.x, p.y - slot.y); root.dragPoint = p; lastCell = Qt.point(-1, -1); } onPositionChanged: mouse => { if (!pressed) return; const p = mapToItem(grid, mouse.x, mouse.y); if (!root.dragId) { if (Math.hypot(p.x - root.dragPoint.x, p.y - root.dragPoint.y) < 6) return; root.dragOrder = root.order.slice(); root.dragId = slot.modelData; } root.dragPoint = p; const c = root.cellAt(p); if (c.x === lastCell.x && c.y === lastCell.y) return; lastCell = c; root.dragOrder = Grid.reorder(root.order, root.plan, slot.modelData, Math.max(0, Math.min(Grid.COLS - 1, c.x)), Math.max(0, c.y)); } onReleased: { const order = root.dragOrder; const moved = !!root.dragId && order && order.join() !== root.tiles.map(m => m.id).join(); root.dragId = ""; if (moved) root.saveOrder(order); root.dragOrder = null; } onCanceled: { root.dragId = ""; root.dragOrder = null; } } Badge { objectName: "controlRemove-" + slot.modelData visible: root.editing && !slot.dragging // On the shape's top-left curve, inside the scroll clip. 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 glyph: "−" onClicked: root.setEnabled(slot.modelData, false) Accessible.name: "Remove " + ControlRegistry.entry(slot.modelData).title } // Size while resizing. Rectangle { visible: root.resizeId === slot.modelData anchors.centerIn: parent implicitWidth: sizeLabel.implicitWidth + 16 implicitHeight: 22 radius: 11 color: Theme.accent Text { id: sizeLabel anchors.centerIn: parent text: slot.cell ? slot.cell.w + "×" + slot.cell.h : "" color: Theme.accentText font.pixelSize: 11 font.weight: Font.DemiBold } } Rectangle { id: handle visible: root.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: "controlResize-" + slot.modelData anchors.fill: parent anchors.margins: -5 preventStealing: true cursorShape: Qt.SizeFDiagCursor property point start property var startSize onPressed: mouse => { start = mapToItem(grid, mouse.x, mouse.y); startSize = { w: slot.cell.w, h: slot.cell.h }; root.resizeSize = startSize; root.resizeId = slot.modelData; } onPositionChanged: mouse => { if (!pressed) return; const p = mapToItem(grid, mouse.x, mouse.y); const next = Grid.resize(startSize, p.x - start.x, p.y - start.y, root.cellWidth, root.cellHeight, root.gap); if (next.w !== root.resizeSize.w || next.h !== root.resizeSize.h) root.resizeSize = next; } onReleased: { const size = root.resizeSize; root.resizeId = ""; root.resizeSize = null; if (size && (size.w !== startSize.w || size.h !== startSize.h)) root.saveSize(slot.modelData, size); } onCanceled: { root.resizeId = ""; root.resizeSize = null; } } } } } } Text { visible: root.tiles.length === 0 && !root.editing text: "No controls. Use Edit Controls to add some." color: Theme.textSecondary font.pixelSize: 12 horizontalAlignment: Text.AlignHCenter wrapMode: Text.Wrap Layout.fillWidth: true Layout.topMargin: 8 Layout.bottomMargin: 8 } Text { visible: SystemService.acting text: "Updating system controls…" color: Theme.textSecondary font.pixelSize: 11 Layout.fillWidth: true Layout.leftMargin: 4 } Text { visible: !!SystemService.error text: SystemService.error color: Theme.urgent font.pixelSize: 11 wrapMode: Text.Wrap Layout.fillWidth: true Layout.leftMargin: 4 } ModuleSlot { moduleId: "notifications" visible: root.notifications && !root.editing active: visible && ShellState.controlCenterOpen } // Edit mode stands the Notifications section in as a bar. Item { visible: root.notifications && root.editing Layout.fillWidth: true implicitHeight: 44 Rectangle { anchors.fill: parent radius: 22 color: Theme.fill border.width: 1 border.color: Qt.alpha(Theme.text, 0.3) Text { anchors.centerIn: parent text: "Notifications" color: Theme.textSecondary font.pixelSize: 12 font.weight: Font.DemiBold } } Badge { objectName: "controlRemove-notifications" glyph: "−" onClicked: root.setEnabled("notifications", false) Accessible.name: "Remove Notifications" } } ColumnLayout { visible: root.editing && root.addable.length > 0 Layout.fillWidth: true Layout.topMargin: 4 spacing: 8 Text { text: "Add Controls" color: Theme.textSecondary font.pixelSize: 12 font.weight: Font.DemiBold Layout.leftMargin: 4 } Flow { Layout.fillWidth: true spacing: 8 Repeater { model: root.editing ? root.addable : [] Pill { required property string modelData objectName: "controlAdd-" + modelData text: "+ " + (Icons.available ? ControlRegistry.entry(modelData).glyph + " " : "") + ControlRegistry.entry(modelData).title onClicked: root.setEnabled(modelData, true) } } } } RowLayout { Layout.alignment: Qt.AlignHCenter Layout.topMargin: 2 spacing: 8 Pill { objectName: "controlReset" visible: root.editing text: "Reset" onClicked: root.reset() } Pill { objectName: "controlEdit" text: root.editing ? "Done" : "Edit Controls" strong: root.editing onClicked: root.editing = !root.editing } } } } } IpcHandler { target: "controlcenter" function toggle(): void { ShellState.toggleControlCenter(); } function open(): void { ShellState.openControlCenter(); } function close(): void { ShellState.controlCenterOpen = false; } function status(): string { return JSON.stringify({ opened: ShellState.controlCenterOpen, screen: root.screen ? root.screen.name : "", busy: SystemService.busy, error: SystemService.error, pendingPower: PowerService.pending }); } } }