Lay the Control Center out as a resizable, editable grid

Modules are tiles on a 4-column grid, each 1x1 to 4x4 and adapting its
layout to its size. Edit Controls in the panel reorders by dragging,
resizes from a corner handle, removes with a badge and adds from a tray.
Connectivity splits into Wi-Fi, Bluetooth and Network tiles and Audio
into Sound and Microphone; right-clicking Sound extends it with output
devices and a volume slider per app. Adds a Caffeine tile. Config
version 2 migrates existing layouts in place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mxandClaude Opus 5.5 committed 2026-10-17 20:52:14 +02:00
1 parent 0dcf37346c
commit 11bdc4c751
32 files changed
+2147 -355

No files matched your search

+465 -88
View File
@@ -9,6 +9,7 @@ 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.
@@ -45,44 +46,79 @@ PanelWindow {
Component.onCompleted: ShellState.controlCenterWindow = root
Component.onDestruction: ShellState.controlCenterWindow = null
// Connectivity and the small tiles share one block (connectivity left, tiles
// stacked right), placed where the first of them appears; other modules
// span the full width in their configured order.
readonly property var smallTiles: ["dnd", "nightLight", "profiles"]
readonly property var blocks: {
if (!ConfigService.ready)
return [];
const ids = ConfigService.data.controlCenter.modules.filter(m => m.enabled && !!ControlRegistry.entry(m.id)).map(m => m.id);
const grouped = ids.filter(id => id === "connectivity" || smallTiles.includes(id));
const result = [];
let placed = false;
for (const id of ids) {
if (!grouped.includes(id)) {
result.push({
kind: "full",
ids: [id]
});
} else if (!placed) {
placed = true;
const tiles = grouped.filter(g => g !== "connectivity");
if (!grouped.includes("connectivity"))
result.push({
kind: "grid",
ids: tiles
});
else if (tiles.length === 0)
result.push({
kind: "full",
ids: ["connectivity"]
});
else
result.push({
kind: "split",
ids: tiles
});
// 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;
}
return result;
}
component ModuleSlot: Loader {
@@ -92,6 +128,62 @@ PanelWindow {
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
@@ -152,6 +244,8 @@ PanelWindow {
Keys.onEscapePressed: {
if (PowerService.pending)
PowerService.cancel();
else if (root.editing)
root.editing = false;
else
ShellState.controlCenterOpen = false;
}
@@ -179,13 +273,14 @@ PanelWindow {
Layout.leftMargin: 4
spacing: 2
Text {
text: "Control Center"
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")
@@ -198,61 +293,274 @@ PanelWindow {
Accessible.name: "Close Control Center"
}
}
Repeater {
model: root.blocks
Item {
id: block
required property var modelData
Layout.fillWidth: true
implicitHeight: block.modelData.kind === "full" ? full.implicitHeight : block.modelData.kind === "split" ? split.implicitHeight : grid.implicitHeight
ModuleSlot {
id: full
visible: block.modelData.kind === "full"
width: parent.width
moduleId: block.modelData.kind === "full" ? block.modelData.ids[0] : ""
active: visible && ShellState.controlCenterOpen
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
}
RowLayout {
id: split
visible: block.modelData.kind === "split"
width: parent.width
spacing: 10
ModuleSlot {
moduleId: "connectivity"
active: split.visible && ShellState.controlCenterOpen
Layout.fillHeight: true
}
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
}
}
ColumnLayout {
Layout.fillWidth: true
Layout.preferredWidth: 1
Layout.alignment: Qt.AlignTop
spacing: 10
Repeater {
model: block.modelData.kind === "split" ? block.modelData.ids : []
ModuleSlot {
required property string modelData
moduleId: modelData
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;
}
}
}
}
GridLayout {
id: grid
visible: block.modelData.kind === "grid"
width: parent.width
columns: 2
columnSpacing: 10
rowSpacing: 10
Repeater {
model: block.modelData.kind === "grid" ? block.modelData.ids : []
ModuleSlot {
required property string modelData
moduleId: modelData
}
}
}
}
}
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…"
@@ -270,10 +578,79 @@ PanelWindow {
Layout.fillWidth: true
Layout.leftMargin: 4
}
GlassButton {
visible: root.blocks.length === 0
text: "Add modules"
onClicked: ShellState.openSettings("controlcenter")
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
}
}
}
}