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
+407 -152

No files matched your search

+4 -2
View File
@@ -180,8 +180,10 @@ Control Center opens at the active monitor's upper-right. Its modules sit on a
brightness, Night Light, DND, Caffeine (keeps the system awake via `systemd-inhibit`), brightness, Night Light, DND, Caffeine (keeps the system awake via `systemd-inhibit`),
power profile, Now Playing, power actions and system metrics, with Notifications power profile, Now Playing, power actions and system metrics, with Notifications
below. Each tile can be any size from 1×1 to 4×4 and adapts its layout to it. below. Each tile can be any size from 1×1 to 4×4 and adapts its layout to it.
**Edit Controls** at the bottom of the panel lets you drag tiles to reorder them, Tiles sit wherever you put them, gaps included. **Edit Controls** at the bottom
resize them from the corner handle, remove them with the badge and add others. of the panel lets you drag tiles to any cell, resize them from the corner handle
(tiles in the way are pushed down), remove them with the badge and add others.
Plugins with a Noctalia `controlCenterWidget` entry point appear there as tiles too.
Right-click Sound to extend it with a volume slider per app (the players Right-click Sound to extend it with a volume slider per app (the players
EasyEffects processes); right-click a toggle to open its settings. EasyEffects processes); right-click a toggle to open its settings.
Logout, reboot and shutdown require explicit confirmation. Logout, reboot and shutdown require explicit confirmation.
+7 -4
View File
@@ -114,10 +114,13 @@ failures do not cause restart loops. Song artwork never changes the global accen
## Phase 7 system controls ## Phase 7 system controls
`ControlCenter` is an active-monitor overlay with a registry-driven module layout. `ControlCenter` is an active-monitor overlay with a registry-driven module layout.
Modules are `CCModule` tiles on a 4-column grid (`controlcenter/GridLogic.js` packs Modules are `CCModule` tiles placed freely on a 4-column grid
them first-fit in configured order); each has a default size in `ControlRegistry` (`controlcenter/GridLogic.js`): each entry in `controlCenter.modules` may store its
and an optional per-module `w`/`h` (1–4) in `controlCenter.modules`, set from the cell (`x` 0–3, `y`) and size (`w`/`h` 1–4, else the `ControlRegistry` default).
panel's edit mode. Tiles adapt their layout to their size. A tile can extend below Tiles without a cell take the first free spot; moving or resizing one in the
panel's edit mode pushes overlapped tiles straight down and saves every cell, so
gaps persist. Enabled plugins with a Noctalia `controlCenterWidget` entry point
add `plugin:<id>` tiles hosted by `modules/Plugin.qml`. Tiles adapt their layout to their size. A tile can extend below
its cells (`extraHeight`: the Sound mixer, power confirmation) and the grid moves its cells (`extraHeight`: the Sound mixer, power confirmation) and the grid moves
the tiles underneath down. Config version 2 split the old Connectivity and Audio the tiles underneath down. Config version 2 split the old Connectivity and Audio
cards into Wi-Fi/Bluetooth/Network and Output/Input. `CaffeineService` holds a cards into Wi-Fi/Bluetooth/Network and Output/Input. `CaffeineService` holds a
+2
View File
@@ -9,6 +9,8 @@ import "../theme"
Item { Item {
id: root id: root
default property alias content: body.data 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 cols: 4
property int rows: 1 property int rows: 1
// Height of the cells, without the extension; the grid sets it. // Height of the cells, without the extension; the grid sets it.
+122 -54
View File
@@ -46,9 +46,11 @@ PanelWindow {
Component.onCompleted: ShellState.controlCenterWindow = root Component.onCompleted: ShellState.controlCenterWindow = root
Component.onDestruction: ShellState.controlCenterWindow = null Component.onDestruction: ShellState.controlCenterWindow = null
// Modules on a 4-column grid, packed first-fit in the configured order; // Modules sit freely on a 4-column grid at their saved cell, so gaps stay
// Notifications is a section under it. Edit mode reorders by dragging, // where they are left; tiles without a position take the first free spot.
// resizes from the corner handle, removes with the badge and adds from a tray. // 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 gap: 10
readonly property int cellHeight: 68 readonly property int cellHeight: 68
readonly property real gridWidth: panel.targetWidth - 28 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 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 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 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 property bool editing: false
// Live edit previews: the order while a tile is dragged, a size while resized. // Live edit preview while a tile is dragged or resized.
property var dragOrder: null property var preview: null
property string dragId: "" property string dragId: ""
property point dragPoint property point dragPoint
property point grabOffset property point grabOffset
property string resizeId: "" property string resizeId: ""
property var resizeSize: null
// Tile id -> pixels a tile extends below its cells. // Tile id -> pixels a tile extends below its cells.
property var extras: ({}) 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 savedPlan: Grid.layout(tiles.map(m => {
readonly property var plan: Grid.pack(order.map(id => { const size = ControlRegistry.size(m);
const m = tiles.find(t => t.id === id);
const size = id === resizeId && resizeSize ? resizeSize : ControlRegistry.size(m);
return { return {
id: id, id: m.id,
w: size.w, 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) readonly property var geometry: Grid.geometry(plan, cellWidth, cellHeight, gap, editing ? {} : extras)
function setExtra(id, value) { function setExtra(id, value) {
if ((extras[id] || 0) === value) if ((extras[id] || 0) === value)
@@ -85,30 +89,58 @@ PanelWindow {
next[id] = value; next[id] = value;
extras = next; extras = next;
} }
function cellAt(p) { // Writes every tile's cell (and changed sizes) back, so nothing repacks
return Qt.point(Math.floor(p.x / (cellWidth + gap)), Math.floor(p.y / (cellHeight + gap))); // 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;
} }
// 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) { if (patch && patch[m.id])
ConfigService.setValue("controlCenter.modules", entries.map(m => m.id === id ? Object.assign({}, m, { next = patch[m.id](next);
w: size.w, return next;
h: size.h }));
}) : m));
} }
function setEnabled(id, on) { function setEnabled(id, on) {
const known = entries.some(m => m.id === id); if (!on) {
ConfigService.setValue("controlCenter.modules", known ? entries.map(m => m.id === id ? Object.assign({}, m, { // The rest keep their cells; the removed tile forgets its own.
enabled: on save(savedPlan, {
}) : m) : entries.concat([ [id]: m => {
{ const next = Object.assign({}, m, {
id: id, enabled: false
enabled: on });
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() { function reset() {
ConfigService.setValue("controlCenter.modules", ConfigService.defaults.controlCenter.modules); ConfigService.setValue("controlCenter.modules", ConfigService.defaults.controlCenter.modules);
@@ -297,8 +329,8 @@ PanelWindow {
id: grid id: grid
objectName: "controlGrid" objectName: "controlGrid"
Layout.fillWidth: true Layout.fillWidth: true
implicitHeight: root.geometry.height implicitHeight: root.geometry.height + (root.editing ? root.cellHeight + root.gap : 0)
visible: root.tiles.length > 0 visible: root.tiles.length > 0 || root.editing
Behavior on implicitHeight { Behavior on implicitHeight {
enabled: panel.settled && !root.dragId enabled: panel.settled && !root.dragId
NumberAnimation { NumberAnimation {
@@ -306,6 +338,36 @@ PanelWindow {
easing.type: Easing.OutCubic 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 { Repeater {
// Keyed by id so moving or resizing keeps each module alive. // Keyed by id so moving or resizing keeps each module alive.
model: ScriptModel { model: ScriptModel {
@@ -368,6 +430,12 @@ PanelWindow {
// Edit mode shows every tile at rest. // Edit mode shows every tile at rest.
opacity: root.editing ? 0.85 : 1 opacity: root.editing ? 0.85 : 1
} }
Binding {
target: loader.item
when: !!loader.item
property: "moduleId"
value: slot.modelData
}
Binding { Binding {
target: loader.item target: loader.item
when: !!loader.item && !!slot.cell when: !!loader.item && !!slot.cell
@@ -434,12 +502,12 @@ PanelWindow {
hoverEnabled: true hoverEnabled: true
preventStealing: true preventStealing: true
cursorShape: pressed ? Qt.ClosedHandCursor : Qt.OpenHandCursor cursorShape: pressed ? Qt.ClosedHandCursor : Qt.OpenHandCursor
property point lastCell: Qt.point(-1, -1) property var lastCell: null
onPressed: mouse => { onPressed: mouse => {
const p = mapToItem(grid, mouse.x, mouse.y); const p = mapToItem(grid, mouse.x, mouse.y);
root.grabOffset = Qt.point(p.x - slot.x, p.y - slot.y); root.grabOffset = Qt.point(p.x - slot.x, p.y - slot.y);
root.dragPoint = p; root.dragPoint = p;
lastCell = Qt.point(-1, -1); lastCell = null;
} }
onPositionChanged: mouse => { onPositionChanged: mouse => {
if (!pressed) if (!pressed)
@@ -448,27 +516,28 @@ PanelWindow {
if (!root.dragId) { if (!root.dragId) {
if (Math.hypot(p.x - root.dragPoint.x, p.y - root.dragPoint.y) < 6) if (Math.hypot(p.x - root.dragPoint.x, p.y - root.dragPoint.y) < 6)
return; return;
root.dragOrder = root.order.slice();
root.dragId = slot.modelData; root.dragId = slot.modelData;
} }
root.dragPoint = p; root.dragPoint = p;
const c = root.cellAt(p); // The cell nearest the tile's top-left corner, at most one row below the rest.
if (c.x === lastCell.x && c.y === lastCell.y) 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; return;
lastCell = c; 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: { onReleased: {
const order = root.dragOrder; const plan = root.preview;
const moved = !!root.dragId && order && order.join() !== root.tiles.map(m => m.id).join();
root.dragId = ""; root.dragId = "";
if (moved) root.preview = null;
root.saveOrder(order); if (plan)
root.dragOrder = null; root.save(plan);
} }
onCanceled: { onCanceled: {
root.dragId = ""; root.dragId = "";
root.dragOrder = null; root.preview = null;
} }
} }
Badge { Badge {
@@ -523,7 +592,6 @@ PanelWindow {
w: slot.cell.w, w: slot.cell.w,
h: slot.cell.h h: slot.cell.h
}; };
root.resizeSize = startSize;
root.resizeId = slot.modelData; root.resizeId = slot.modelData;
} }
onPositionChanged: mouse => { onPositionChanged: mouse => {
@@ -531,19 +599,19 @@ PanelWindow {
return; return;
const p = mapToItem(grid, mouse.x, mouse.y); 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); 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) if (next.w !== slot.cell.w || next.h !== slot.cell.h)
root.resizeSize = next; root.preview = Grid.moveTo(root.savedPlan, slot.modelData, next);
} }
onReleased: { onReleased: {
const size = root.resizeSize; const plan = root.preview;
root.resizeId = ""; root.resizeId = "";
root.resizeSize = null; root.preview = null;
if (size && (size.w !== startSize.w || size.h !== startSize.h)) if (plan)
root.saveSize(slot.modelData, size); root.save(plan);
} }
onCanceled: { onCanceled: {
root.resizeId = ""; root.resizeId = "";
root.resizeSize = null; root.preview = null;
} }
} }
} }
+15 -1
View File
@@ -1,12 +1,26 @@
pragma Singleton pragma Singleton
import QtQuick import QtQuick
import Quickshell import Quickshell
import "../services"
// Control Center modules. Grid tiles have a default size in cells (w × h, // 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 // 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 { Singleton {
readonly property var ids: Object.keys(modules).concat(PluginService.controlModules)
function entry(id) { 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; return Object.prototype.hasOwnProperty.call(modules, id) ? modules[id] : null;
} }
// Configured size, else the module's default. // Configured size, else the module's default.
+79 -52
View File
@@ -1,6 +1,7 @@
// Pure helpers for the Control Center grid: packing, drag reordering and // Pure helpers for the Control Center grid: free placement, moving with
// resizing. // push-down, resizing and pixel geometry.
// Tiles are {id, w, h} in grid cells; the grid is `cols` wide and grows down. // 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 COLS = 4;
var MAX = 4; var MAX = 4;
@@ -10,66 +11,92 @@ function clampSize(n) {
return Number.isFinite(n) ? Math.max(1, Math.min(MAX, n)) : 1; 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 function overlaps(a, b) {
// rows top to bottom and columns left to right, so small tiles backfill gaps. 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 pack(tiles, cols) { }
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; cols = cols || COLS;
const occ = [], items = []; const placed = [];
let rows = 0; const free = t => !placed.some(p => overlaps(p, t));
function free(r, c, w, h) { const sized = t => {
for (let y = r; y < r + h; y++) const w = Math.min(cols, clampSize(t.w)), h = clampSize(t.h);
for (let x = c; x < c + w; x++) return {id: t.id, col: 0, row: 0, w: w, h: h};
if (occ[y] && occ[y][x]) };
return false; for (const t of tiles) {
return true; 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) { for (const t of tiles) {
const w = Math.min(cols, clampSize(t.w)), h = clampSize(t.h); if (Number.isInteger(t.x) && Number.isInteger(t.y))
let placed = false;
for (let r = 0; !placed; r++) {
for (let c = 0; c + w <= cols; c++) {
if (!free(r, c, w, h))
continue; continue;
for (let y = r; y < r + h; y++) { const item = sized(t);
occ[y] = occ[y] || []; let done = false;
for (let x = c; x < c + w; x++) for (let r = 0; !done; r++)
occ[y][x] = true; for (let c = 0; c + item.w <= cols && !done; c++) {
item.col = c;
item.row = r;
done = free(item);
} }
items.push({id: t.id, col: c, row: r, w: w, h: h}); placed.push(item);
rows = Math.max(rows, r + h); }
placed = true; // 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; 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. // Cell for a tile whose top-left corner is at pixel (x, y).
function at(plan, col, row) { function cellAt(x, y, cellW, cellH, gap) {
return plan.items.find(i => col >= i.col && col < i.col + i.w && row >= i.row && row < i.row + i.h) || null; return {col: Math.round(x / (cellW + gap)), row: Math.round(y / (cellH + gap))};
}
// 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;
} }
// Cells for a tile resized by a pixel delta from its start size. // 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
}
}
+1 -1
View File
@@ -89,7 +89,7 @@ function validate(c) {
if(!notes || ["enabled","doNotDisturb","criticalInDnd"].some(k=>typeof notes[k]!=="boolean") || !["slide","drop","fade","shrink"].includes(notes.animation) || !["top-right","top-center"].includes(notes.position) || !Number.isInteger(notes.timeout) || notes.timeout<1000 || notes.timeout>30000 || !Number.isInteger(notes.maxPopups) || notes.maxPopups<1 || notes.maxPopups>6)throw Error("Invalid notification preferences"); if(!notes || ["enabled","doNotDisturb","criticalInDnd"].some(k=>typeof notes[k]!=="boolean") || !["slide","drop","fade","shrink"].includes(notes.animation) || !["top-right","top-center"].includes(notes.position) || !Number.isInteger(notes.timeout) || notes.timeout<1000 || notes.timeout>30000 || !Number.isInteger(notes.maxPopups) || notes.maxPopups<1 || notes.maxPopups>6)throw Error("Invalid notification preferences");
if(c.controlCenter.version !== 2 || !Number.isFinite(c.controlCenter.width) || c.controlCenter.width < 320 || c.controlCenter.width > 600 || !Array.isArray(c.controlCenter.modules))throw Error("Invalid Control Center configuration"); if(c.controlCenter.version !== 2 || !Number.isFinite(c.controlCenter.width) || c.controlCenter.width < 320 || c.controlCenter.width > 600 || !Array.isArray(c.controlCenter.modules))throw Error("Invalid Control Center configuration");
const controlIds=new Set(); const controlIds=new Set();
for(const m of c.controlCenter.modules) { if(!m || typeof m.id!=="string" || controlIds.has(m.id) || typeof m.enabled!=="boolean" || ["w","h"].some(k=>m[k]!==undefined && (!Number.isInteger(m[k]) || m[k]<1 || m[k]>4)))throw Error("Invalid Control Center module"); controlIds.add(m.id); } for(const m of c.controlCenter.modules) { if(!m || typeof m.id!=="string" || controlIds.has(m.id) || typeof m.enabled!=="boolean" || ["w","h"].some(k=>m[k]!==undefined && (!Number.isInteger(m[k]) || m[k]<1 || m[k]>4)) || [["x",3],["y",63]].some(([k,max])=>m[k]!==undefined && (!Number.isInteger(m[k]) || m[k]<0 || m[k]>max)))throw Error("Invalid Control Center module"); controlIds.add(m.id); }
for(const group of [c.system.brightness,c.system.nightLight]) for(const key of ["statusCommand","setCommand"])if(!Array.isArray(group[key]) || group[key].some(v=>typeof v!=="string" || !v.length))throw Error("Provider command must be an argument array"); for(const group of [c.system.brightness,c.system.nightLight]) for(const key of ["statusCommand","setCommand"])if(!Array.isArray(group[key]) || group[key].some(v=>typeof v!=="string" || !v.length))throw Error("Provider command must be an argument array");
if(typeof c.system.brightness.device!=="string" || !c.system.brightness.device || !Number.isInteger(c.system.nightLight.temperature) || c.system.nightLight.temperature<1000 || c.system.nightLight.temperature>6500 || !Array.isArray(c.system.power.lockCommand) || c.system.power.lockCommand.some(v=>typeof v!=="string" || !v.length))throw Error("Invalid system provider settings"); if(typeof c.system.brightness.device!=="string" || !c.system.brightness.device || !Number.isInteger(c.system.nightLight.temperature) || c.system.nightLight.temperature<1000 || c.system.nightLight.temperature>6500 || !Array.isArray(c.system.power.lockCommand) || c.system.power.lockCommand.some(v=>typeof v!=="string" || !v.length))throw Error("Invalid system provider settings");
if(!Number.isInteger(c.metrics.interval) || c.metrics.interval<1 || c.metrics.interval>30)throw Error("Invalid metrics geometry or interval"); if(!Number.isInteger(c.metrics.interval) || c.metrics.interval<1 || c.metrics.interval>30)throw Error("Invalid metrics geometry or interval");
+2
View File
@@ -60,6 +60,8 @@ Singleton {
} }
// Enabled plugins offering a bar widget, as bar module ids. // Enabled plugins offering a bar widget, as bar module ids.
readonly property var barModules: plugins.filter(p => isEnabled(p.id) && kinds(p.id).includes("bar-widget")).map(p => "plugin:" + p.id) readonly property var barModules: plugins.filter(p => isEnabled(p.id) && kinds(p.id).includes("bar-widget")).map(p => "plugin:" + p.id)
// Enabled plugins offering a Control Center widget, as Control Center module ids.
readonly property var controlModules: plugins.filter(p => isEnabled(p.id) && kinds(p.id).includes("control-center-widget")).map(p => "plugin:" + p.id)
function schema(id) { function schema(id) {
const p = plugin(id); const p = plugin(id);
if (p && p.ecosystem === "noctalia") if (p && p.ecosystem === "noctalia")
+3 -3
View File
@@ -86,7 +86,7 @@ SettingsPage {
} }
SettingsSection { SettingsSection {
title: "Modules" title: "Modules"
description: "Drag modules to reorder them; the switch shows or hides each one. Resize tiles from Edit Controls in the Control Center" description: "The switch shows or hides each module. Move and resize tiles from Edit Controls in the Control Center; order here only decides where new tiles go"
ColumnLayout { ColumnLayout {
id: rows id: rows
objectName: "controlModuleList" objectName: "controlModuleList"
@@ -180,10 +180,10 @@ SettingsPage {
visible: addRepeater.count > 0 visible: addRepeater.count > 0
Repeater { Repeater {
id: addRepeater id: addRepeater
model: Object.keys(ControlRegistry.modules).filter(id => !ConfigService.data.controlCenter.modules.some(m => m.id === id)) model: ControlRegistry.ids.filter(id => !ConfigService.data.controlCenter.modules.some(m => m.id === id))
GlassButton { GlassButton {
required property string modelData required property string modelData
text: "+ " + ControlRegistry.modules[modelData].title text: "+ " + ControlRegistry.entry(modelData).title
onClicked: ConfigService.setValue("controlCenter.modules", ConfigService.data.controlCenter.modules.concat([ onClicked: ConfigService.setValue("controlCenter.modules", ConfigService.data.controlCenter.modules.concat([
{ {
id: modelData, id: modelData,
+5
View File
@@ -242,6 +242,11 @@ Item {
input.mouseClick(item, item.width / 2, item.height / 2); input.mouseClick(item, item.width / 2, item.height / 2);
return true; return true;
} }
// A property of a named item, as JSON (plugin fixtures).
function itemValue(name: string, key: string): string {
const item = root.child(name);
return item ? JSON.stringify(item[key]) : "";
}
function value(name: string): real { function value(name: string): real {
const item = root.child(name); const item = root.child(name);
return item ? item.value : -1; return item ? item.value : -1;
+2 -1
View File
@@ -74,12 +74,13 @@ assert.equal(phase7.controlCenter.version,2);assert(phase7.controlCenter.modules
assert.equal(api.load(defaults,{controlCenter:{version:1,modules:[]}}).controlCenter.modules.length,0); assert.equal(api.load(defaults,{controlCenter:{version:1,modules:[]}}).controlCenter.modules.length,0);
const customCenter=api.load(defaults,{controlCenter:{modules:[{id:'custom',enabled:false,metadata:'preserved'}]}}); const customCenter=api.load(defaults,{controlCenter:{modules:[{id:'custom',enabled:false,metadata:'preserved'}]}});
assert.equal(customCenter.controlCenter.modules[0].metadata,'preserved');assert.equal(customCenter.controlCenter.modules.map(m=>m.id).join(),'custom,caffeine'); assert.equal(customCenter.controlCenter.modules[0].metadata,'preserved');assert.equal(customCenter.controlCenter.modules.map(m=>m.id).join(),'custom,caffeine');
for(const controlCenter of [{version:3},{version:1,width:100},{version:2,modules:[{id:'output',enabled:true},{id:'output',enabled:false}]},{version:2,modules:[{id:'wifi',enabled:true,w:5}]},{version:2,modules:[{id:'wifi',enabled:true,h:0}]},{version:2,modules:[{id:'wifi',enabled:true,w:1.5}]}])assert.throws(()=>api.load(defaults,{controlCenter})); for(const controlCenter of [{version:3},{version:1,width:100},{version:2,modules:[{id:'output',enabled:true},{id:'output',enabled:false}]},{version:2,modules:[{id:'wifi',enabled:true,w:5}]},{version:2,modules:[{id:'wifi',enabled:true,h:0}]},{version:2,modules:[{id:'wifi',enabled:true,w:1.5}]},{version:2,modules:[{id:'wifi',enabled:true,x:4}]},{version:2,modules:[{id:'wifi',enabled:true,y:-1}]},{version:2,modules:[{id:'wifi',enabled:true,y:64}]}])assert.throws(()=>api.load(defaults,{controlCenter}));
// Version 1 splits the combined cards in place, keeps enabled state and offers Caffeine. // Version 1 splits the combined cards in place, keeps enabled state and offers Caffeine.
const v1=api.load(defaults,{controlCenter:{version:1,modules:[{id:'connectivity',enabled:true},{id:'media',enabled:true},{id:'audio',enabled:false},{id:'notifications',enabled:true}]}}).controlCenter; const v1=api.load(defaults,{controlCenter:{version:1,modules:[{id:'connectivity',enabled:true},{id:'media',enabled:true},{id:'audio',enabled:false},{id:'notifications',enabled:true}]}}).controlCenter;
assert.equal(v1.version,2);assert.equal(v1.modules.map(m=>m.id+':'+m.enabled).join(),'wifi:true,bluetooth:true,network:true,media:true,output:false,input:false,notifications:true,caffeine:true'); assert.equal(v1.version,2);assert.equal(v1.modules.map(m=>m.id+':'+m.enabled).join(),'wifi:true,bluetooth:true,network:true,media:true,output:false,input:false,notifications:true,caffeine:true');
assert.equal(JSON.stringify(api.load(defaults,{controlCenter:{version:2,modules:[{id:'wifi',enabled:true,w:4,h:1}]}}).controlCenter.modules),'[{"id":"wifi","enabled":true,"w":4,"h":1}]'); assert.equal(JSON.stringify(api.load(defaults,{controlCenter:{version:2,modules:[{id:'wifi',enabled:true,w:4,h:1}]}}).controlCenter.modules),'[{"id":"wifi","enabled":true,"w":4,"h":1}]');
assert.equal(api.load(defaults,{controlCenter:{version:2,modules:[]}}).controlCenter.modules.length,0); assert.equal(api.load(defaults,{controlCenter:{version:2,modules:[]}}).controlCenter.modules.length,0);
assert.equal(api.load(defaults,{controlCenter:{version:2,modules:[{id:'wifi',enabled:true,x:3,y:63}]}}).controlCenter.modules[0].y,63);
for(const system of [{brightness:{setCommand:'sh -c'}},{nightLight:{temperature:0}},{power:{lockCommand:['']}}])assert.throws(()=>api.load(defaults,{system})); for(const system of [{brightness:{setCommand:'sh -c'}},{nightLight:{temperature:0}},{power:{lockCommand:['']}}])assert.throws(()=>api.load(defaults,{system}));
console.log('Phase 7 one-time module migration, intentional empty layouts, provider validation and preservation passed.'); console.log('Phase 7 one-time module migration, intentional empty layouts, provider validation and preservation passed.');
+42 -25
View File
@@ -1,35 +1,52 @@
const assert = require('assert'), fs = require('fs'), path = require('path'), vm = require('vm'); const assert = require('assert'), fs = require('fs'), path = require('path'), vm = require('vm');
const api = vm.createContext({}); const api = vm.createContext({});
vm.runInContext(fs.readFileSync(path.join(__dirname, '../quickshell/controlcenter/GridLogic.js'), 'utf8'), api); vm.runInContext(fs.readFileSync(path.join(__dirname, '../quickshell/controlcenter/GridLogic.js'), 'utf8'), api);
const ids = plan => plan.items.map(i => i.id + '@' + i.col + ',' + i.row + ':' + i.w + 'x' + i.h).join(' '); const show = plan => plan.items.map(i => i.id + '@' + i.col + ',' + i.row + ':' + i.w + 'x' + i.h).join(' ');
// First fit in list order; small tiles backfill gaps beside larger ones. const at = (plan, col, row) => (plan.items.find(i => col >= i.col && col < i.col + i.w && row >= i.row && row < i.row + i.h) || {}).id;
let plan = api.pack([{id: 'wifi', w: 2, h: 1}, {id: 'media', w: 2, h: 2}, {id: 'bt', w: 1, h: 1}, {id: 'dnd', w: 1, h: 1}, {id: 'sound', w: 4, h: 1}]); // Without positions: first free spot in order, so small tiles backfill gaps.
assert.equal(ids(plan), 'wifi@0,0:2x1 media@2,0:2x2 bt@0,1:1x1 dnd@1,1:1x1 sound@0,2:4x1'); let plan = api.layout([{id: 'wifi', w: 2, h: 1}, {id: 'media', w: 2, h: 2}, {id: 'bt', w: 1, h: 1}, {id: 'dnd', w: 1, h: 1}, {id: 'sound', w: 4, h: 1}]);
assert.equal(show(plan), 'wifi@0,0:2x1 media@2,0:2x2 bt@0,1:1x1 dnd@1,1:1x1 sound@0,2:4x1');
assert.equal(plan.rows, 3); assert.equal(plan.rows, 3);
plan = api.pack([{id: 'a', w: 3, h: 1}, {id: 'b', w: 2, h: 1}, {id: 'c', w: 1, h: 1}]); assert.equal(show(api.layout([{id: 'x', w: 9, h: 0}, {id: 'y', w: 1.4, h: 4.6}])), 'x@0,0:4x1 y@0,1:1x4');
assert.equal(ids(plan), 'a@0,0:3x1 b@0,1:2x1 c@3,0:1x1'); assert.equal(api.layout([]).rows, 0);
// Sizes clamp to 1..4 cells. // Positions are kept, gaps included; unpositioned tiles fill free spots.
assert.equal(ids(api.pack([{id: 'x', w: 9, h: 0}, {id: 'y', w: 1.4, h: 4.6}])), 'x@0,0:4x1 y@0,1:1x4'); plan = api.layout([{id: 'a', w: 1, h: 1, x: 3, y: 2}, {id: 'b', w: 2, h: 1, x: 0, y: 0}, {id: 'c', w: 1, h: 1}]);
assert.equal(api.pack([]).rows, 0); assert.equal(show(plan), 'a@3,2:1x1 b@0,0:2x1 c@2,0:1x1');
// Hit testing covers spanned cells. assert.equal(plan.rows, 3);
plan = api.pack([{id: 'wifi', w: 2, h: 1}, {id: 'media', w: 2, h: 2}, {id: 'bt', w: 1, h: 1}]); assert.equal(at(plan, 0, 1), undefined);
assert.equal(api.at(plan, 3, 1).id, 'media'); // Overlapping saved positions: the earlier entry wins, the later one moves down.
assert.equal(api.at(plan, 3, 2), null); assert.equal(show(api.layout([{id: 'a', w: 2, h: 2, x: 0, y: 0}, {id: 'b', w: 1, h: 1, x: 1, y: 1}])), 'a@0,0:2x2 b@1,2:1x1');
// Dragging onto a tile takes its place in either direction; onto itself is a no-op. // Positions clamp inside the grid.
const order = ['wifi', 'media', 'bt']; assert.equal(show(api.layout([{id: 'a', w: 3, h: 1, x: 3, y: -2}])), 'a@1,0:3x1');
assert.equal(api.reorder(order, plan, 'bt', 0, 0).join(), 'bt,wifi,media'); // A free spot for a new tile.
assert.equal(api.reorder(order, plan, 'wifi', 0, 1).join(), 'media,bt,wifi'); plan = api.layout([{id: 'a', w: 4, h: 1, x: 0, y: 0}, {id: 'b', w: 1, h: 1, x: 0, y: 1}]);
assert.equal(api.reorder(order, plan, 'wifi', 1, 0).join(), 'wifi,media,bt'); assert.equal(JSON.stringify(api.freeSpot(plan, 2, 1)), '{"id":"\\u0000new","col":1,"row":1,"w":2,"h":1}');
// Empty space puts it after the last tile before that cell. // Moving into empty space leaves the old spot empty.
assert.equal(api.reorder(order, plan, 'wifi', 1, 1).join(), 'media,bt,wifi'); plan = api.layout([{id: 'wifi', w: 2, h: 1}, {id: 'bt', w: 1, h: 1}, {id: 'sound', w: 4, h: 1}]);
assert.equal(api.reorder(order, plan, 'bt', 0, 5).join(), 'wifi,media,bt'); let moved = api.moveTo(plan, 'bt', {col: 3, row: 3});
assert.equal(api.reorder(order, plan, 'nope', 0, 0).join(), order.join()); assert.equal(show(moved), 'wifi@0,0:2x1 bt@3,3:1x1 sound@0,1:4x1');
// Resizing rounds to whole cells within 1..4. assert.equal(at(moved, 2, 0), undefined);
assert.equal(moved.rows, 4);
assert.equal(show(plan), 'wifi@0,0:2x1 bt@2,0:1x1 sound@0,1:4x1', 'moveTo leaves the input plan alone');
// Landing on tiles pushes them straight down, cascading; nothing moves up.
moved = api.moveTo(plan, 'bt', {col: 0, row: 0});
assert.equal(show(moved), 'wifi@0,1:2x1 bt@0,0:1x1 sound@0,2:4x1');
// Resizing pushes the same way.
moved = api.moveTo(plan, 'wifi', {w: 3, h: 2});
assert.equal(show(moved), 'wifi@0,0:3x2 bt@2,2:1x1 sound@0,3:4x1');
// A tile pushed onto the moved one goes below it instead.
plan = api.layout([{id: 'tall', w: 1, h: 3, x: 0, y: 0}, {id: 'top', w: 2, h: 1, x: 1, y: 0}]);
moved = api.moveTo(plan, 'top', {col: 0, row: 1});
assert.equal(show(moved), 'tall@0,2:1x3 top@0,1:2x1');
// Moves clamp to the grid.
assert.equal(show(api.moveTo(plan, 'top', {col: 9, row: -4})), 'tall@0,0:1x3 top@2,0:2x1');
// Pixel corner to the nearest cell; resizing rounds to whole cells within 1..4.
assert.equal(JSON.stringify(api.cellAt(130, 40, 80, 68, 10)), '{"col":1,"row":1}');
assert.equal(JSON.stringify(api.resize({w: 1, h: 1}, 50, 0, 80, 68, 10)), '{"w":2,"h":1}'); assert.equal(JSON.stringify(api.resize({w: 1, h: 1}, 50, 0, 80, 68, 10)), '{"w":2,"h":1}');
assert.equal(JSON.stringify(api.resize({w: 2, h: 2}, -30, 400, 80, 68, 10)), '{"w":2,"h":4}'); assert.equal(JSON.stringify(api.resize({w: 2, h: 2}, -30, 400, 80, 68, 10)), '{"w":2,"h":4}');
assert.equal(JSON.stringify(api.resize({w: 1, h: 1}, -500, -500, 80, 68, 10)), '{"w":1,"h":1}'); assert.equal(JSON.stringify(api.resize({w: 1, h: 1}, -500, -500, 80, 68, 10)), '{"w":1,"h":1}');
// Geometry: an expanded tile pushes down everything from its bottom row. // Geometry: an expanded tile pushes down everything from its bottom row.
plan = api.pack([{id: 'out', w: 2, h: 1}, {id: 'media', w: 2, h: 2}, {id: 'a', w: 1, h: 1}, {id: 'b', w: 4, h: 1}]); plan = api.layout([{id: 'out', w: 2, h: 1}, {id: 'media', w: 2, h: 2}, {id: 'a', w: 1, h: 1}, {id: 'b', w: 4, h: 1}]);
let g = api.geometry(plan, 80, 68, 10); let g = api.geometry(plan, 80, 68, 10);
assert.equal(JSON.stringify(g.tiles.media), '{"x":180,"y":0,"w":170,"h":146}'); assert.equal(JSON.stringify(g.tiles.media), '{"x":180,"y":0,"w":170,"h":146}');
assert.equal(g.height, 3 * 78 - 10); assert.equal(g.height, 3 * 78 - 10);
@@ -39,4 +56,4 @@ assert.equal(g.tiles.media.y, 0);
assert.equal(g.tiles.a.y, 78 + 110); assert.equal(g.tiles.a.y, 78 + 110);
assert.equal(g.tiles.b.y, 156 + 110); assert.equal(g.tiles.b.y, 156 + 110);
assert.equal(g.height, 3 * 78 - 10 + 110); assert.equal(g.height, 3 * 78 - 10 + 110);
console.log('Control Center grid packing, hit testing, reordering, resizing and expansion geometry passed.'); console.log('Control Center free placement, push-down moves and resizes, free spots and expansion geometry passed.');
+32 -9
View File
@@ -22,9 +22,13 @@ log=ROOT/'.cache/controlcenter-runtime.log';log.parent.mkdir(exist_ok=True)
monitors=json.loads(subprocess.check_output(['hyprctl','monitors','-j'],text=True));original=next((m['name'] for m in monitors if m['focused']),None) monitors=json.loads(subprocess.check_output(['hyprctl','monitors','-j'],text=True));original=next((m['name'] for m in monitors if m['focused']),None)
with tempfile.TemporaryDirectory(prefix='glassmxrph-controls-') as tmp: with tempfile.TemporaryDirectory(prefix='glassmxrph-controls-') as tmp:
events=Path(tmp)/'events';cfg=Path(tmp)/'config/glassMxrph/config.json';cfg.parent.mkdir(parents=True) events=Path(tmp)/'events';cfg=Path(tmp)/'config/glassMxrph/config.json';cfg.parent.mkdir(parents=True)
# A Noctalia-style plugin offering a Control Center widget.
fixture=Path(tmp)/'data/glassMxrph/plugins/cc-fixture';fixture.mkdir(parents=True)
(fixture/'manifest.json').write_text(json.dumps({'id':'cc-fixture','name':'CC Fixture','version':'1.0.0','minNoctaliaVersion':'3.6.0','author':'tests','description':'Control Center widget fixture','entryPoints':{'controlCenterWidget':'ControlCenterWidget.qml'}}))
(fixture/'ControlCenterWidget.qml').write_text('import QtQuick\nItem {\n property var pluginApi: null\n property var screen: null\n property int clicks: 0\n property string tooltipText: "Fixture hint"\n objectName: "fixtureCcButton"\n implicitWidth: 30\n implicitHeight: 30\n MouseArea { anchors.fill: parent; onClicked: parent.clicks++ }\n}\n')
# The user's live shell owns the notification bus name; a second server would warn. # The user's live shell owns the notification bus name; a second server would warn.
cfg.write_text(json.dumps({'schemaVersion':3,'media':{'enabled':False},'dock':{'enabled':False},'notifications':{'enabled':False}})) cfg.write_text(json.dumps({'schemaVersion':3,'media':{'enabled':False},'dock':{'enabled':False},'notifications':{'enabled':False},'plugins':{'enabled':['cc-fixture']}}))
env=dict(os.environ,XDG_CONFIG_HOME=tmp+'/config',XDG_STATE_HOME=tmp+'/state',XDG_CACHE_HOME=tmp+'/cache',GLASSMXRPH_CONTROL_TESTING='1',GLASSMXRPH_SYSTEM_EVENTS=str(events),QT_QPA_PLATFORMTHEME='',QT_NO_XDG_DESKTOP_PORTAL='1') env=dict(os.environ,XDG_CONFIG_HOME=tmp+'/config',XDG_DATA_HOME=tmp+'/data',XDG_STATE_HOME=tmp+'/state',XDG_CACHE_HOME=tmp+'/cache',GLASSMXRPH_CONTROL_TESTING='1',GLASSMXRPH_SYSTEM_EVENTS=str(events),QT_QPA_PLATFORMTHEME='',QT_NO_XDG_DESKTOP_PORTAL='1')
with log.open('w') as output: with log.open('w') as output:
shell=subprocess.Popen([str(ROOT/'scripts/glassmxrph'),'run'],env=env,stdout=output,stderr=subprocess.STDOUT) shell=subprocess.Popen([str(ROOT/'scripts/glassmxrph'),'run'],env=env,stdout=output,stderr=subprocess.STDOUT)
try: try:
@@ -77,7 +81,7 @@ with tempfile.TemporaryDirectory(prefix='glassmxrph-controls-') as tmp:
assert ipc('controlTest','click','power-reboot');assert ipc('controlTest','click','powerConfirm') assert ipc('controlTest','click','power-reboot');assert ipc('controlTest','click','powerConfirm')
wait(lambda:not state()['busy'],'recorded confirmation') wait(lambda:not state()['busy'],'recorded confirmation')
actions=[json.loads(line) for line in events.read_text().splitlines()] actions=[json.loads(line) for line in events.read_text().splitlines()]
power=[a for a in actions if a['action']=='power'];assert len(power)==1 and power[0]['value']=='reboot' and power[0]['confirmed'] is True power=[a for a in actions if a['action']=='power'];assert len(power)==1 and power[0]['value']=='reboot' and power[0]['confirmed'] is True,str(actions)
ipc('controlcenter','close');time.sleep(.3);ipc('controlcenter','open');time.sleep(.35) ipc('controlcenter','close');time.sleep(.3);ipc('controlcenter','open');time.sleep(.35)
assert ipc('controlTest','screenshot',str(ROOT/'.cache/controlcenter-preview.png')) assert ipc('controlTest','screenshot',str(ROOT/'.cache/controlcenter-preview.png'))
ipc('controlTest','outside');wait(lambda:not state()['windowVisible'],'outside closes') ipc('controlTest','outside');wait(lambda:not state()['windowVisible'],'outside closes')
@@ -99,25 +103,44 @@ with tempfile.TemporaryDirectory(prefix='glassmxrph-controls-') as tmp:
assert ipc('controlTest','click','controlEdit');wait(lambda:state()['editing'],'edit mode') assert ipc('controlTest','click','controlEdit');wait(lambda:state()['editing'],'edit mode')
time.sleep(.6);assert ipc('controlTest','screenshot',str(ROOT/'.cache/controlcenter-editing.png')) time.sleep(.6);assert ipc('controlTest','screenshot',str(ROOT/'.cache/controlcenter-editing.png'))
s=state();tiles={t['id']:t for t in s['tiles']};step=s['cellWidth']+10 s=state();tiles={t['id']:t for t in s['tiles']};step=s['cellWidth']+10
bt,wifi=tiles['bluetooth'],tiles['wifi'] bt,wifi,caf=tiles['bluetooth'],tiles['wifi'],tiles['caffeine']
assert ipc('controlTest','drag','controlMove-bluetooth',(wifi['col']-bt['col'])*step,(wifi['row']-bt['row'])*78)
ids=lambda:[m['id'] for m in state()['modules']] ids=lambda:[m['id'] for m in state()['modules']]
wait(lambda:ids().index('bluetooth')<ids().index('wifi'),'drag reorders') pos=lambda i:next((t for t in state()['tiles'] if t['id']==i),None)
cfgpos=lambda i:next(m for m in state()['modules'] if m['id']==i)
# Dropping on a tile takes its cell and pushes it straight down.
assert ipc('controlTest','drag','controlMove-bluetooth',(wifi['col']-bt['col'])*step,(wifi['row']-bt['row'])*78)
wait(lambda:cfgpos('bluetooth').get('x')==wifi['col'] and cfgpos('bluetooth').get('y')==wifi['row'],'drag places the tile')
assert pos('wifi')['row']>wifi['row'] and pos('wifi')['col']==wifi['col'],'tile underneath is pushed down: '+str(pos('wifi'))
# Dropping into empty space leaves an air gap where it was.
time.sleep(.3);s=state();caf=pos('caffeine');rows=max(t['row']+t['h'] for t in s['tiles'])
assert ipc('controlTest','drag','controlMove-caffeine',(3-caf['col'])*step,(rows-caf['row'])*78)
wait(lambda:pos('caffeine')['row']==rows and pos('caffeine')['col']==3,'drop into empty row')
cell=lambda c,r:[t['id'] for t in state()['tiles'] if t['col']<=c<t['col']+t['w'] and t['row']<=r<t['row']+t['h']]
assert cell(caf['col'],caf['row'])==[],'air gap kept: '+str(cell(caf['col'],caf['row']))
time.sleep(.3) time.sleep(.3)
assert ipc('controlTest','drag','controlResize-wifi',step,78) assert ipc('controlTest','drag','controlResize-wifi',step,78)
wait(lambda:any(m['id']=='wifi' and m.get('w')==3 and m.get('h')==2 for m in state()['modules']),'resize to 3x2') wait(lambda:any(m['id']=='wifi' and m.get('w')==3 and m.get('h')==2 for m in state()['modules']),'resize to 3x2')
assert next(t for t in state()['tiles'] if t['id']=='wifi')['w']==3 assert next(t for t in state()['tiles'] if t['id']=='wifi')['w']==3
time.sleep(.3);dnd=pos('dnd')
assert ipc('controlTest','click','controlRemove-dnd') assert ipc('controlTest','click','controlRemove-dnd')
wait(lambda:not next(m for m in state()['modules'] if m['id']=='dnd')['enabled'],'remove badge') wait(lambda:not next(m for m in state()['modules'] if m['id']=='dnd')['enabled'],'remove badge')
assert not any(t['id']=='dnd' for t in state()['tiles']) assert not any(t['id']=='dnd' for t in state()['tiles'])
assert cell(dnd['col'],dnd['row'])==[],'removing leaves a gap'
# Plugin Control Center widgets are offered as tiles and keep their own clicks.
assert ipc('controlTest','click','controlAdd-plugin:cc-fixture')
wait(lambda:pos('plugin:cc-fixture'),'plugin tile added')
assert ipc('controlTest','click','controlEdit');wait(lambda:not state()['editing'],'leave edit for plugin click')
time.sleep(.4);assert ipc('controlTest','click','fixtureCcButton')
wait(lambda:ipc('controlTest','itemValue','fixtureCcButton','clicks')==1,'plugin widget click')
assert ipc('controlTest','click','controlEdit');wait(lambda:state()['editing'],'edit again')
assert ipc('controlTest','click','controlAdd-dnd') assert ipc('controlTest','click','controlAdd-dnd')
wait(lambda:any(t['id']=='dnd' for t in state()['tiles']),'add from tray') wait(lambda:any(t['id']=='dnd' for t in state()['tiles']),'add from tray')
ipc('controlTest','pressEscape');wait(lambda:not state()['editing'],'Escape leaves edit mode') ipc('controlTest','pressEscape');wait(lambda:not state()['editing'],'Escape leaves edit mode')
assert ipc('controlcenter','status')['opened'] assert ipc('controlcenter','status')['opened']
time.sleep(.6);assert ipc('controlTest','screenshot',str(ROOT/'.cache/controlcenter-edited.png')) time.sleep(.6);assert ipc('controlTest','screenshot',str(ROOT/'.cache/controlcenter-edited.png'))
assert ipc('controlTest','click','controlEdit');wait(lambda:state()['editing'],'edit mode again') assert ipc('controlTest','click','controlEdit');wait(lambda:state()['editing'],'edit mode again')
assert ipc('controlTest','click','controlReset') time.sleep(.5);assert ipc('controlTest','click','controlReset')
wait(lambda:all('w' not in m for m in state()['modules']) and ids()[0]=='wifi','reset layout') wait(lambda:all('w' not in m and 'x' not in m for m in state()['modules']) and ids()[0]=='wifi','reset layout')
assert ipc('controlTest','click','controlEdit');wait(lambda:not state()['editing'],'done') assert ipc('controlTest','click','controlEdit');wait(lambda:not state()['editing'],'done')
ipc('controlcenter','close');wait(lambda:not state()['windowVisible'],'close after editing') ipc('controlcenter','close');wait(lambda:not state()['windowVisible'],'close after editing')
ipc('shell','openSettings','controlcenter');wait(lambda:state()['settingsVisible'],'module editor opens');time.sleep(.3) ipc('shell','openSettings','controlcenter');wait(lambda:state()['settingsVisible'],'module editor opens');time.sleep(.3)
@@ -137,4 +160,4 @@ with tempfile.TemporaryDirectory(prefix='glassmxrph-controls-') as tmp:
shell.terminate();shell.wait(timeout=5) shell.terminate();shell.wait(timeout=5)
if original:subprocess.run(['hyprctl','dispatch','focusmonitor',original],capture_output=True) if original:subprocess.run(['hyprctl','dispatch','focusmonitor',original],capture_output=True)
text=log.read_text();assert 'WARN' not in text and 'ERROR' not in text,text text=log.read_text();assert 'WARN' not in text and 'ERROR' not in text,text
print('PASS: native read-only discovery, active-monitor placement, system pill, recording audio/per-app volume/Caffeine/network/Bluetooth/display/DND actions, grid edit mode (drag, resize, remove, add, reset), power confirmation/cancel, outside/Escape/exclusivity, settings, clean logs.') print('PASS: native read-only discovery, active-monitor placement, system pill, recording audio/per-app volume/Caffeine/network/Bluetooth/display/DND actions, free grid edit mode (place, push down, air gaps, resize, remove, add, plugin tiles, reset), power confirmation/cancel, outside/Escape/exclusivity, settings, clean logs.')