Place Control Center tiles freely and host plugin widgets as tiles

Tiles keep the cell they are dropped in, so gaps stay where they are
left; moving or resizing onto other tiles pushes those straight down.
Enabled plugins with a Noctalia controlCenterWidget entry point are
offered as tiles in edit mode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mxandClaude Opus 5.5 committed 2026-10-17 22:02:18 +02:00
1 parent 72a21c9363
commit 7f1189606c
14 files changed
+412 -157

No files matched your search

+2
View File
@@ -9,6 +9,8 @@ import "../theme"
Item {
id: root
default property alias content: body.data
// Config id of this tile; the grid sets it (plugin tiles need it).
property string moduleId
property int cols: 4
property int rows: 1
// Height of the cells, without the extension; the grid sets it.
+125 -57
View File
@@ -46,9 +46,11 @@ PanelWindow {
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.
// Modules sit freely on a 4-column grid at their saved cell, so gaps stay
// where they are left; tiles without a position take the first free spot.
// Notifications is a section under it. Edit mode moves tiles by dragging and
// resizes them from the corner handle (tiles in the way are pushed down),
// removes them with the badge and adds them from a tray.
readonly property int gap: 10
readonly property int cellHeight: 68
readonly property real gridWidth: panel.targetWidth - 28
@@ -56,27 +58,29 @@ PanelWindow {
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))
readonly property var addable: ControlRegistry.ids.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
// Live edit preview while a tile is dragged or resized.
property var preview: 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);
readonly property var savedPlan: Grid.layout(tiles.map(m => {
const size = ControlRegistry.size(m);
return {
id: id,
id: m.id,
w: size.w,
h: size.h
h: size.h,
x: m.x,
y: m.y
};
}))
readonly property var plan: preview || savedPlan
// Edit mode shows one empty row below the tiles to drop into.
readonly property int shownRows: plan.rows + (editing ? 1 : 0)
readonly property var geometry: Grid.geometry(plan, cellWidth, cellHeight, gap, editing ? {} : extras)
function setExtra(id, value) {
if ((extras[id] || 0) === value)
@@ -85,30 +89,58 @@ PanelWindow {
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));
// Writes every tile's cell (and changed sizes) back, so nothing repacks
// and gaps stay.
function save(plan, patch) {
ConfigService.setValue("controlCenter.modules", entries.map(m => {
const i = plan.items.find(t => t.id === m.id);
let next = Object.assign({}, m);
if (i) {
const def = ControlRegistry.size({
id: m.id
});
next.x = i.col;
next.y = i.row;
if (m.w !== undefined || m.h !== undefined || i.w !== def.w || i.h !== def.h) {
next.w = i.w;
next.h = i.h;
}
}
if (patch && patch[m.id])
next = patch[m.id](next);
return next;
}));
}
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
}
]));
if (!on) {
// The rest keep their cells; the removed tile forgets its own.
save(savedPlan, {
[id]: m => {
const next = Object.assign({}, m, {
enabled: false
});
delete next.x;
delete next.y;
return next;
}
});
return;
}
const e = ControlRegistry.entry(id);
const known = entries.find(m => m.id === id);
const size = ControlRegistry.size(known || {
id: id
});
const spot = e && !e.section ? Grid.freeSpot(savedPlan, size.w, size.h) : null;
const added = Object.assign({}, known || {
id: id
}, {
enabled: true
}, spot ? {
x: spot.col,
y: spot.row
} : {});
ConfigService.setValue("controlCenter.modules", known ? entries.map(m => m.id === id ? added : m) : entries.concat([added]));
}
function reset() {
ConfigService.setValue("controlCenter.modules", ConfigService.defaults.controlCenter.modules);
@@ -297,8 +329,8 @@ PanelWindow {
id: grid
objectName: "controlGrid"
Layout.fillWidth: true
implicitHeight: root.geometry.height
visible: root.tiles.length > 0
implicitHeight: root.geometry.height + (root.editing ? root.cellHeight + root.gap : 0)
visible: root.tiles.length > 0 || root.editing
Behavior on implicitHeight {
enabled: panel.settled && !root.dragId
NumberAnimation {
@@ -306,6 +338,36 @@ PanelWindow {
easing.type: Easing.OutCubic
}
}
// Edit mode: faint cells show the grid, and where a dragged tile lands.
Repeater {
// Only the empty cells: tiles are translucent.
model: root.editing ? Array.from({
length: Grid.COLS * root.shownRows
}, (_, i) => i).filter(i => !root.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) * (root.cellWidth + root.gap)
y: Math.floor(modelData / Grid.COLS) * (root.cellHeight + root.gap)
width: root.cellWidth
height: root.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: root.dragId ? root.geometry.tiles[root.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 {
// Keyed by id so moving or resizing keeps each module alive.
model: ScriptModel {
@@ -368,6 +430,12 @@ PanelWindow {
// Edit mode shows every tile at rest.
opacity: root.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
@@ -434,12 +502,12 @@ PanelWindow {
hoverEnabled: true
preventStealing: true
cursorShape: pressed ? Qt.ClosedHandCursor : Qt.OpenHandCursor
property point lastCell: Qt.point(-1, -1)
property var lastCell: null
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);
lastCell = null;
}
onPositionChanged: mouse => {
if (!pressed)
@@ -448,27 +516,28 @@ PanelWindow {
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)
// The cell nearest the tile's top-left corner, at most one row below the rest.
const c = Grid.cellAt(p.x - root.grabOffset.x, p.y - root.grabOffset.y, root.cellWidth, root.cellHeight, root.gap);
c.row = Math.min(c.row, root.savedPlan.rows);
if (lastCell && c.col === lastCell.col && c.row === lastCell.row)
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));
// Always from the saved layout, so tiles pushed aside come back.
root.preview = Grid.moveTo(root.savedPlan, slot.modelData, c);
}
onReleased: {
const order = root.dragOrder;
const moved = !!root.dragId && order && order.join() !== root.tiles.map(m => m.id).join();
const plan = root.preview;
root.dragId = "";
if (moved)
root.saveOrder(order);
root.dragOrder = null;
root.preview = null;
if (plan)
root.save(plan);
}
onCanceled: {
root.dragId = "";
root.dragOrder = null;
root.preview = null;
}
}
Badge {
@@ -523,7 +592,6 @@ PanelWindow {
w: slot.cell.w,
h: slot.cell.h
};
root.resizeSize = startSize;
root.resizeId = slot.modelData;
}
onPositionChanged: mouse => {
@@ -531,19 +599,19 @@ PanelWindow {
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;
if (next.w !== slot.cell.w || next.h !== slot.cell.h)
root.preview = Grid.moveTo(root.savedPlan, slot.modelData, next);
}
onReleased: {
const size = root.resizeSize;
const plan = root.preview;
root.resizeId = "";
root.resizeSize = null;
if (size && (size.w !== startSize.w || size.h !== startSize.h))
root.saveSize(slot.modelData, size);
root.preview = null;
if (plan)
root.save(plan);
}
onCanceled: {
root.resizeId = "";
root.resizeSize = null;
root.preview = null;
}
}
}
+15 -1
View File
@@ -1,12 +1,26 @@
pragma Singleton
import QtQuick
import Quickshell
import "../services"
// Control Center modules. Grid tiles have a default size in cells (w × h,
// each 1–4) that the user can change in edit mode; Notifications is a section
// under the grid instead.
// under the grid instead. Enabled plugins with a Control Center widget add
// "plugin:<id>" tiles.
Singleton {
readonly property var ids: Object.keys(modules).concat(PluginService.controlModules)
function entry(id) {
if (String(id).startsWith("plugin:")) {
const plugin = String(id).slice("plugin:".length);
return PluginService.controlModules.includes(id) ? {
title: PluginService.title(plugin),
glyph: "󰏗",
w: 1,
h: 1,
plugin: plugin,
source: Qt.resolvedUrl("modules/Plugin.qml")
} : null;
}
return Object.prototype.hasOwnProperty.call(modules, id) ? modules[id] : null;
}
// Configured size, else the module's default.
+81 -54
View File
@@ -1,6 +1,7 @@
// Pure helpers for the Control Center grid: packing, drag reordering and
// resizing.
// Tiles are {id, w, h} in grid cells; the grid is `cols` wide and grows down.
// Pure helpers for the Control Center grid: free placement, moving with
// push-down, resizing and pixel geometry.
// Tiles are {id, w, h, x?, y?}: a size in cells and an optional position
// (column x, row y). The grid is `cols` wide and grows down.
var COLS = 4;
var MAX = 4;
@@ -10,66 +11,92 @@ function clampSize(n) {
return Number.isFinite(n) ? Math.max(1, Math.min(MAX, n)) : 1;
}
// Packs tiles first-fit in list order: each takes the first free spot, scanning
// rows top to bottom and columns left to right, so small tiles backfill gaps.
function pack(tiles, cols) {
function overlaps(a, b) {
return a.col < b.col + b.w && b.col < a.col + a.w && a.row < b.row + b.h && b.row < a.row + a.h;
}
function rowsOf(items) {
return items.reduce((n, i) => Math.max(n, i.row + i.h), 0);
}
// Places tiles. Positioned tiles keep their spot (an earlier one wins; a later
// one it overlaps moves straight down to the first free row). Tiles without a
// position then take the first free spot in reading order. Gaps stay as set.
function layout(tiles, cols) {
cols = cols || COLS;
const occ = [], items = [];
let rows = 0;
function free(r, c, w, h) {
for (let y = r; y < r + h; y++)
for (let x = c; x < c + w; x++)
if (occ[y] && occ[y][x])
return false;
return true;
const placed = [];
const free = t => !placed.some(p => overlaps(p, t));
const sized = t => {
const w = Math.min(cols, clampSize(t.w)), h = clampSize(t.h);
return {id: t.id, col: 0, row: 0, w: w, h: h};
};
for (const t of tiles) {
if (!Number.isInteger(t.x) || !Number.isInteger(t.y))
continue;
const item = sized(t);
item.col = Math.max(0, Math.min(cols - item.w, t.x));
item.row = Math.max(0, t.y);
while (!free(item))
item.row++;
placed.push(item);
}
for (const t of tiles) {
const w = Math.min(cols, clampSize(t.w)), h = clampSize(t.h);
let placed = false;
for (let r = 0; !placed; r++) {
for (let c = 0; c + w <= cols; c++) {
if (!free(r, c, w, h))
continue;
for (let y = r; y < r + h; y++) {
occ[y] = occ[y] || [];
for (let x = c; x < c + w; x++)
occ[y][x] = true;
}
items.push({id: t.id, col: c, row: r, w: w, h: h});
rows = Math.max(rows, r + h);
placed = true;
if (Number.isInteger(t.x) && Number.isInteger(t.y))
continue;
const item = sized(t);
let done = false;
for (let r = 0; !done; r++)
for (let c = 0; c + item.w <= cols && !done; c++) {
item.col = c;
item.row = r;
done = free(item);
}
placed.push(item);
}
// Back in list order.
const items = tiles.map(t => placed.find(p => p.id === t.id));
return {items: items, rows: rowsOf(items)};
}
// First free spot for a new tile, in reading order.
function freeSpot(plan, w, h, cols) {
return layout(plan.items.map(i => ({id: i.id, x: i.col, y: i.row, w: i.w, h: i.h})).concat([{id: "\u0000new", w: w, h: h}]), cols).items.slice(-1)[0];
}
// Moves and/or resizes one tile. Tiles it lands on are pushed straight down
// below it, cascading; nothing moves up, so gaps elsewhere are kept.
function moveTo(plan, id, target, cols) {
cols = cols || COLS;
const items = plan.items.map(i => Object.assign({}, i));
const moved = items.find(i => i.id === id);
if (!moved)
return {items: items, rows: rowsOf(items)};
moved.w = Math.min(cols, clampSize(target.w !== undefined ? target.w : moved.w));
moved.h = clampSize(target.h !== undefined ? target.h : moved.h);
moved.col = Math.max(0, Math.min(cols - moved.w, Math.round(target.col !== undefined ? target.col : moved.col)));
moved.row = Math.max(0, Math.round(target.row !== undefined ? target.row : moved.row));
const queue = [moved];
while (queue.length) {
const a = queue.shift();
for (const b of items) {
if (b === a || !overlaps(a, b))
continue;
if (b === moved) {
// A pushed tile never displaces the moved one: it goes below it.
a.row = moved.row + moved.h;
queue.push(a);
break;
}
b.row = a.row + a.h;
queue.push(b);
}
}
return {items: items, rows: rows};
return {items: items, rows: rowsOf(items)};
}
// The packed tile covering a cell, or null.
function at(plan, col, row) {
return plan.items.find(i => col >= i.col && col < i.col + i.w && row >= i.row && row < i.row + i.h) || null;
}
// Order after dragging `id` over the cell (col, row): it takes the index of the
// tile under the pointer. Over empty space it goes after the last tile that
// starts at or before that cell in reading order.
function reorder(ids, plan, id, col, row) {
if (ids.indexOf(id) < 0)
return ids.slice();
const hit = at(plan, col, row);
if (hit && hit.id === id)
return ids.slice();
const next = ids.filter(i => i !== id);
let to;
if (hit) {
// Moving forward lands after the hit tile, backward lands before it.
to = next.indexOf(hit.id) + (ids.indexOf(id) < ids.indexOf(hit.id) ? 1 : 0);
} else {
const before = plan.items.filter(i => i.id !== id && (i.row < row || (i.row === row && i.col <= col)));
to = before.length ? Math.max(...before.map(i => next.indexOf(i.id))) + 1 : 0;
}
next.splice(to, 0, id);
return next;
// Cell for a tile whose top-left corner is at pixel (x, y).
function cellAt(x, y, cellW, cellH, gap) {
return {col: Math.round(x / (cellW + gap)), row: Math.round(y / (cellH + gap))};
}
// Cells for a tile resized by a pixel delta from its start size.
@@ -0,0 +1,91 @@
pragma ComponentBehavior: Bound
import QtQuick
import QtQuick.Layouts
import ".."
import "../../core"
import "../../services"
import "../../theme"
// A plugin's Control Center widget (Noctalia `controlCenterWidget` entry point)
// in a grid tile. The plugin draws and handles its own button; the tile scales
// it to fit and, when wide enough, adds the plugin's name and tooltip text.
CCModule {
id: root
readonly property string pluginId: moduleId.startsWith("plugin:") ? moduleId.slice("plugin:".length) : ""
readonly property string source: pluginId ? PluginService.entryUrl(pluginId, "control-center-widget") : ""
readonly property Item widget: loader.item as Item
// Plugin items are untyped.
readonly property var widgetObject: loader.item
readonly property string hint: widgetObject && typeof widgetObject.tooltipText === "string" ? widgetObject.tooltipText : ""
// Room for the widget: the circle at 1×1, else the first cell.
readonly property real room: compact ? background.width * 0.6 : Math.min(baseHeight, width) - 24
objectName: "pluginTile-" + pluginId
round: true
hovered: area.containsMouse
onSourceChanged: load()
Component.onCompleted: load()
function load() {
if (!source) {
loader.source = "";
return;
}
// Noctalia widgets get their pluginApi at creation, as in Noctalia.
loader.setSource(source, {
pluginApi: PluginService.noctaliaApi(pluginId),
screen: ShellState.activeScreen()
});
}
MouseArea {
id: area
anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.NoButton
}
Item {
id: holder
readonly property real size: Math.min(root.room, 56)
x: root.wide && !root.tall ? (root.baseHeight - size) / 2 : root.wide ? 14 : (root.width - size) / 2
y: root.wide && root.tall ? 14 : !root.wide && root.tall ? 12 : (root.baseHeight - size) / 2
width: size
height: size
Loader {
id: loader
anchors.centerIn: parent
scale: root.widget && root.widget.implicitWidth > 0 ? Math.min(2.2, holder.size / Math.max(root.widget.implicitWidth, root.widget.implicitHeight)) : 1
}
}
ColumnLayout {
visible: !root.compact
x: root.wide ? (root.tall ? 14 : holder.x + holder.width + 10) : 8
y: root.wide ? (root.tall ? root.baseHeight - height - 14 : (root.baseHeight - height) / 2) : holder.y + holder.height + 8
width: root.width - x - (root.wide ? 14 : 8)
spacing: 1
Text {
text: root.pluginId ? PluginService.title(root.pluginId) : ""
color: Theme.text
font.pixelSize: 12
font.weight: Font.DemiBold
elide: Text.ElideRight
horizontalAlignment: root.wide ? Text.AlignLeft : Text.AlignHCenter
Layout.fillWidth: true
}
Text {
visible: text !== ""
text: root.hint
color: Theme.textSecondary
font.pixelSize: 11
elide: Text.ElideRight
wrapMode: root.tall ? Text.Wrap : Text.NoWrap
maximumLineCount: Math.max(1, root.rows - 1)
horizontalAlignment: root.wide ? Text.AlignLeft : Text.AlignHCenter
Layout.fillWidth: true
}
}
Text {
visible: !root.source
anchors.centerIn: parent
text: "Plugin unavailable"
color: Theme.textSecondary
font.pixelSize: 10
}
}