From 11bdc4c75135bfbb60dbc5f1ba30e0122aa91463 Mon Sep 17 00:00:00 2001 From: mx Date: Sat, 17 Oct 2026 20:52:14 +0200 Subject: [PATCH] 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 --- README.md | 12 +- docs/architecture.md | 9 + quickshell/config/defaults.json | 64 +- quickshell/controlcenter/AudioMixer.qml | 170 ++++++ quickshell/controlcenter/CCModule.qml | 50 ++ quickshell/controlcenter/CCSlider.qml | 217 +++++++ quickshell/controlcenter/CCTile.qml | 144 ++++- quickshell/controlcenter/ControlCenter.qml | 553 +++++++++++++++--- quickshell/controlcenter/ControlRegistry.qml | 96 ++- quickshell/controlcenter/GridLogic.js | 110 ++++ .../controlcenter/modules/Bluetooth.qml | 16 + .../controlcenter/modules/Brightness.qml | 50 +- quickshell/controlcenter/modules/Caffeine.qml | 15 + .../controlcenter/modules/Connectivity.qml | 97 --- quickshell/controlcenter/modules/Dnd.qml | 2 + quickshell/controlcenter/modules/Input.qml | 26 + quickshell/controlcenter/modules/Metrics.qml | 99 +++- quickshell/controlcenter/modules/Network.qml | 42 ++ .../controlcenter/modules/NightLight.qml | 2 + .../controlcenter/modules/NowPlaying.qml | 268 +++++++++ quickshell/controlcenter/modules/Output.qml | 24 + quickshell/controlcenter/modules/Power.qml | 240 ++++++-- quickshell/controlcenter/modules/Profiles.qml | 2 + quickshell/controlcenter/modules/Wifi.qml | 16 + quickshell/controlcenter/qmldir | 3 + quickshell/services/ConfigLogic.js | 22 +- quickshell/settings/pages/ControlCenter.qml | 4 +- quickshell/testing/ControlDriver.qml | 50 +- scripts/validate | 1 + tests/config.test.cjs | 11 +- tests/controlcenter.test.cjs | 42 ++ tests/controlcenter_runtime.py | 45 +- 32 files changed, 2147 insertions(+), 355 deletions(-) create mode 100644 quickshell/controlcenter/AudioMixer.qml create mode 100644 quickshell/controlcenter/CCModule.qml create mode 100644 quickshell/controlcenter/CCSlider.qml create mode 100644 quickshell/controlcenter/GridLogic.js create mode 100644 quickshell/controlcenter/modules/Bluetooth.qml create mode 100644 quickshell/controlcenter/modules/Caffeine.qml delete mode 100644 quickshell/controlcenter/modules/Connectivity.qml create mode 100644 quickshell/controlcenter/modules/Input.qml create mode 100644 quickshell/controlcenter/modules/Network.qml create mode 100644 quickshell/controlcenter/modules/NowPlaying.qml create mode 100644 quickshell/controlcenter/modules/Output.qml create mode 100644 quickshell/controlcenter/modules/Wifi.qml create mode 100644 tests/controlcenter.test.cjs diff --git a/README.md b/README.md index e6a464f..e858701 100644 --- a/README.md +++ b/README.md @@ -175,9 +175,15 @@ without replacing your saved layout. Cava is optional and off by default. ## Control Center Click the right-hand system pill or run `./scripts/glassmxrph controlcenter`. -Control Center opens at the active monitor's upper-right, with configurable modules -for connectivity, audio/microphone, brightness, Night Light, DND, power profiles, -shared media and power actions. Settings → Control Center enables/reorders modules. +Control Center opens at the active monitor's upper-right. Its modules sit on a +4-column grid: Wi-Fi, Bluetooth, network throughput, sound, microphone, display +brightness, Night Light, DND, Caffeine (keeps the system awake via `systemd-inhibit`), +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. +**Edit Controls** at the bottom of the panel lets you drag tiles to reorder them, +resize them from the corner handle, remove them with the badge and add others. +Right-click Sound to extend it with output devices and a volume slider per app +(the players EasyEffects processes); right-click a toggle to open its settings. Logout, reboot and shutdown require explicit confirmation. NetworkManager, BlueZ and PipeWire use native Quickshell models. Other controls reuse diff --git a/docs/architecture.md b/docs/architecture.md index 337b6d6..829bf08 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -114,6 +114,15 @@ failures do not cause restart loops. Song artwork never changes the global accen ## Phase 7 system controls `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 +them first-fit in configured order); each has a default size in `ControlRegistry` +and an optional per-module `w`/`h` (1–4) in `controlCenter.modules`, set from the +panel's edit mode. Tiles adapt their layout to their size. A tile can extend below +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 +cards into Wi-Fi/Bluetooth/Network and Output/Input. `CaffeineService` holds a +`systemd-inhibit` idle/sleep lock while on; `AudioService.streams` lists app +playback streams, tracked only while a mixer holds a `Demand`. `ShellState` coordinates its visibility with existing shell popups. `AudioService`, `NetworkService` and `BluetoothService` adapt native Quickshell event-driven models. `SystemService` serializes one-shot JSON provider jobs for visible display/DND/power diff --git a/quickshell/config/defaults.json b/quickshell/config/defaults.json index 57f156b..2738856 100644 --- a/quickshell/config/defaults.json +++ b/quickshell/config/defaults.json @@ -150,41 +150,61 @@ "history": [] }, "controlCenter": { - "version": 1, + "version": 2, "width": 400, "modules": [ { - "id": "connectivity", - "enabled": true - }, - { - "id": "audio", - "enabled": true - }, - { - "id": "brightness", - "enabled": true - }, - { - "id": "nightLight", - "enabled": true - }, - { - "id": "dnd", - "enabled": true - }, - { - "id": "profiles", + "id": "wifi", "enabled": true }, { "id": "media", "enabled": true }, + { + "id": "bluetooth", + "enabled": true + }, + { + "id": "dnd", + "enabled": true + }, + { + "id": "nightLight", + "enabled": true + }, + { + "id": "caffeine", + "enabled": true + }, + { + "id": "profiles", + "enabled": true + }, + { + "id": "output", + "enabled": true + }, + { + "id": "input", + "enabled": true + }, + { + "id": "brightness", + "enabled": true + }, { "id": "power", "enabled": true }, + { + "id": "network", + "enabled": false + }, + { + "id": "metrics", + "enabled": false + }, { "id": "notifications", "enabled": true diff --git a/quickshell/controlcenter/AudioMixer.qml b/quickshell/controlcenter/AudioMixer.qml new file mode 100644 index 0000000..9fcaebb --- /dev/null +++ b/quickshell/controlcenter/AudioMixer.qml @@ -0,0 +1,170 @@ +pragma ComponentBehavior: Bound +import QtQuick +import QtQuick.Layouts +import Quickshell.Widgets +import "../components" +import "../services" +import "../theme" + +// Extension of the Output and Input tiles: device choice, and for output a +// volume slider per app stream (the players EasyEffects processes). +ColumnLayout { + id: root + property bool input: false + readonly property var nodes: input ? AudioService.inputs : AudioService.outputs + readonly property var current: input ? AudioService.source : AudioService.sink + spacing: 2 + Demand { + service: AudioService + counter: "streamConsumers" + active: !root.input + } + component Heading: Text { + color: Theme.textSecondary + font.pixelSize: 10 + font.weight: Font.DemiBold + font.letterSpacing: 1.1 + Layout.topMargin: 4 + Layout.bottomMargin: 2 + } + + Heading { + text: root.input ? "INPUT DEVICE" : "OUTPUT DEVICE" + } + Repeater { + model: root.nodes + Rectangle { + id: device + required property var modelData + required property int index + readonly property bool selected: modelData === root.current + Layout.fillWidth: true + implicitHeight: 28 + radius: 8 + color: deviceArea.containsMouse ? Qt.alpha(Theme.text, 0.08) : Theme.transparent + RowLayout { + anchors.fill: parent + anchors.leftMargin: 6 + anchors.rightMargin: 6 + spacing: 8 + Text { + text: device.selected ? "✓" : "" + color: Theme.accent + font.pixelSize: 12 + Layout.preferredWidth: 12 + } + Text { + text: device.modelData.description || device.modelData.name + color: device.selected ? Theme.text : Qt.alpha(Theme.text, 0.8) + font.pixelSize: 12 + font.weight: device.selected ? Font.DemiBold : Font.Normal + elide: Text.ElideRight + Layout.fillWidth: true + } + } + MouseArea { + id: deviceArea + anchors.fill: parent + hoverEnabled: true + cursorShape: Qt.PointingHandCursor + onClicked: AudioService.select(root.input, device.index) + } + } + } + + Heading { + visible: !root.input + text: "APPLICATIONS" + Layout.topMargin: 8 + } + Text { + visible: !root.input && AudioService.streams.length === 0 + text: "No apps are playing audio" + color: Theme.textSecondary + font.pixelSize: 11 + Layout.leftMargin: 6 + } + Repeater { + model: root.input ? [] : AudioService.streams + RowLayout { + id: stream + required property var modelData + readonly property bool muted: !!modelData.audio && modelData.audio.muted + readonly property string icon: AudioService.streamIcon(modelData) + objectName: "appVolume-" + AudioService.streamName(modelData) + Layout.fillWidth: true + Layout.preferredHeight: 30 + spacing: 8 + // The app icon doubles as its mute button. + Item { + implicitWidth: 22 + implicitHeight: 22 + opacity: stream.muted ? 0.4 : 1 + Accessible.role: Accessible.Button + Accessible.name: (stream.muted ? "Unmute " : "Mute ") + AudioService.streamName(stream.modelData) + IconImage { + anchors.fill: parent + visible: stream.icon !== "" + source: stream.icon + asynchronous: true + } + GlassIcon { + anchors.fill: parent + visible: stream.icon === "" + size: 22 + glyphSize: 11 + fallback: AudioService.streamName(stream.modelData).charAt(0).toUpperCase() + } + Text { + visible: stream.muted + anchors.right: parent.right + anchors.bottom: parent.bottom + anchors.margins: -3 + text: Icons.available ? "󰖁" : "×" + font.family: Icons.available ? Icons.family : "" + font.pixelSize: 11 + color: Theme.text + } + MouseArea { + objectName: "appMute-" + AudioService.streamName(stream.modelData) + anchors.fill: parent + cursorShape: Qt.PointingHandCursor + onClicked: AudioService.streamMute(stream.modelData) + } + } + ColumnLayout { + Layout.fillWidth: true + spacing: 2 + Text { + text: AudioService.streamName(stream.modelData) + color: Theme.text + font.pixelSize: 11 + elide: Text.ElideRight + Layout.fillWidth: true + } + GlassBarSlider { + id: level + objectName: "appSlider-" + AudioService.streamName(stream.modelData) + Layout.fillWidth: true + Layout.preferredHeight: 10 + from: 0 + to: 1 + stepSize: 0.01 + enabled: !!stream.modelData.audio + value: stream.modelData.audio ? stream.modelData.audio.volume : 0 + onMoved: AudioService.streamVolume(stream.modelData, value) + onPressedChanged: if (!pressed) + value = Qt.binding(() => stream.modelData.audio ? stream.modelData.audio.volume : 0) + Accessible.name: AudioService.streamName(stream.modelData) + " volume" + } + } + Text { + text: stream.modelData.audio ? Math.round(stream.modelData.audio.volume * 100) + "%" : "—" + color: Theme.textSecondary + font.pixelSize: 11 + horizontalAlignment: Text.AlignRight + Layout.preferredWidth: 32 + } + } + } +} diff --git a/quickshell/controlcenter/CCModule.qml b/quickshell/controlcenter/CCModule.qml new file mode 100644 index 0000000..d4a900d --- /dev/null +++ b/quickshell/controlcenter/CCModule.qml @@ -0,0 +1,50 @@ +pragma ComponentBehavior: Bound +import QtQuick +import "../theme" + +// Control Center grid tile. Modules fill their cells and adapt to `cols` × +// `rows` (1–4 each). A module can extend below its cells (`extraHeight`, e.g. +// per-app volume); the grid moves the tiles underneath down to make room. +// Outside the grid (Settings pages) it is a 4×1 tile that grows the same way. +Item { + id: root + default property alias content: body.data + property int cols: 4 + property int rows: 1 + // Height of the cells, without the extension; the grid sets it. + property real baseHeight: rows * 68 + (rows - 1) * 10 + // Height wanted below the cells while extended; 0 when not. + property real extraHeight: 0 + property bool expanded: false + // 1×1 toggles draw as a circle centred in their cell. + property bool round: false + property bool hovered: false + property color color: hovered ? Theme.hover : Theme.fill + readonly property bool compact: cols === 1 && rows === 1 + readonly property bool wide: cols >= 2 + readonly property bool tall: rows >= 2 + readonly property bool circle: round && compact && extraHeight <= 0 + readonly property alias background: bg + implicitWidth: 360 + implicitHeight: baseHeight + (extraHeight > 0 ? extraHeight + 10 : 0) + Rectangle { + id: bg + readonly property real d: Math.min(root.width, root.baseHeight) + x: root.circle ? (root.width - d) / 2 : 0 + width: root.circle ? d : root.width + height: root.circle ? d : root.height + radius: root.circle ? d / 2 : Math.min(30, root.baseHeight / 2, root.width / 2) + color: root.color + border.width: 1 + border.color: Theme.hairline + Behavior on color { + ColorAnimation { + duration: Theme.duration / 2 + } + } + } + Item { + id: body + anchors.fill: parent + } +} diff --git a/quickshell/controlcenter/CCSlider.qml b/quickshell/controlcenter/CCSlider.qml new file mode 100644 index 0000000..af4fda8 --- /dev/null +++ b/quickshell/controlcenter/CCSlider.qml @@ -0,0 +1,217 @@ +pragma ComponentBehavior: Bound +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts +import "../components" +import "../theme" + +// Level tile (volume, microphone, brightness). One row is a title over a +// slider; 1 wide and taller is a vertical slider; 1×1 is a round button that +// shows the level, toggles mute and scrolls to adjust. An `extension` (e.g. +// the per-app mixer) fills spare rows of wide tall tiles, and right click +// extends the tile down to show it at other sizes. +CCModule { + id: root + property string title + property string glyph + property string fallback + property string mutedGlyph: glyph + property real value: 0 + property real from: 0 + property real to: 1 + property real stepSize: 0.01 + property bool muted: false + property bool muteable: false + property string sliderName + property string muteName + property string notice + property Component extension: null + readonly property alias slider: horizontal + readonly property bool inline: !!extension && wide && tall + // Whether `value` is real; it can be while the slider is briefly disabled. + property bool known: enabled + readonly property string percent: known ? Math.round((value - from) / Math.max(1e-9, to - from) * 100) + "%" : "—" + // Live changes while dragging, and the final value on release. + signal moved(real value) + signal committed(real value) + signal muteClicked + round: true + hovered: area.containsMouse + extraHeight: expanded && outer.item ? outer.implicitHeight + 24 : 0 + function nudge(steps) { + const next = Math.max(from, Math.min(to, value + steps * (to - from) / 20)); + moved(next); + committed(next); + } + + component Level: GlassBarSlider { + from: root.from + to: root.to + stepSize: root.stepSize + value: root.value + enabled: root.enabled + // The mute button carries the icon when there is one. + glyph: root.muteable ? "" : root.glyph + fallback: root.muteable ? "" : root.fallback + onMoved: root.moved(value) + // Dragging writes `value`; follow the source again once released. + onPressedChanged: if (!pressed) { + root.committed(value); + value = Qt.binding(() => root.value); + } + Keys.onReleased: event => { + if (event.key === Qt.Key_Left || event.key === Qt.Key_Right || event.key === Qt.Key_Up || event.key === Qt.Key_Down) + root.committed(value); + } + Accessible.name: root.title + } + component Mute: CCToggle { + visible: root.muteable + size: 26 + glyph: root.muted ? root.mutedGlyph : root.glyph + fallback: root.muted ? "×" : root.fallback + checked: root.muted + enabled: root.enabled + onClicked: root.muteClicked() + Accessible.name: "Mute " + root.title + } + + MouseArea { + id: area + anchors.fill: parent + hoverEnabled: true + acceptedButtons: Qt.LeftButton | Qt.RightButton + onClicked: mouse => { + if (mouse.button === Qt.RightButton && root.extension && !root.inline) + root.expanded = !root.expanded; + else if (mouse.button === Qt.LeftButton && root.compact && root.muteable) + root.muteClicked(); + } + onWheel: wheel => { + if (root.enabled) + root.nudge(wheel.angleDelta.y > 0 ? 1 : wheel.angleDelta.y < 0 ? -1 : 0); + } + } + GlassToolTip { + visible: root.compact && area.containsMouse + delay: 500 + text: root.title + " · " + root.percent + } + + // 1×1: icon and level in a circle. + Column { + visible: root.compact + x: (root.width - width) / 2 + y: (root.baseHeight - height) / 2 + spacing: 1 + Text { + anchors.horizontalCenter: parent.horizontalCenter + text: Icons.available && root.glyph ? (root.muted ? root.mutedGlyph : root.glyph) : root.fallback + font.family: Icons.available && root.glyph ? Icons.family : "" + font.pixelSize: Math.round(root.background.width * 0.3) + color: root.muted ? Theme.textSecondary : Theme.text + } + Text { + anchors.horizontalCenter: parent.horizontalCenter + text: root.percent + color: Theme.textSecondary + font.pixelSize: 10 + font.weight: Font.DemiBold + } + } + + // One column: a vertical slider with mute above it. + ColumnLayout { + visible: !root.wide && root.tall + anchors.fill: parent + anchors.topMargin: 12 + anchors.bottomMargin: 12 + root.height - root.baseHeight + spacing: 8 + Mute { + Layout.alignment: Qt.AlignHCenter + } + Text { + visible: !root.muteable + text: root.percent + color: Theme.textSecondary + font.pixelSize: 10 + font.weight: Font.DemiBold + Layout.alignment: Qt.AlignHCenter + } + Level { + orientation: Qt.Vertical + Layout.alignment: Qt.AlignHCenter + Layout.fillHeight: true + Layout.preferredWidth: Math.min(40, root.width - 34) + } + } + + // Wide: title and level over the slider, then the extension in spare rows. + ColumnLayout { + id: wideLayout + visible: root.wide + x: 14 + y: root.tall ? 12 : (root.baseHeight - implicitHeight) / 2 + width: root.width - 28 + spacing: 6 + RowLayout { + Layout.fillWidth: true + Text { + text: root.title + color: Theme.text + font.pixelSize: 13 + font.weight: Font.DemiBold + elide: Text.ElideRight + Layout.fillWidth: true + } + Text { + text: root.notice || root.percent + color: Theme.textSecondary + font.pixelSize: 11 + elide: Text.ElideRight + Layout.maximumWidth: root.width * 0.6 + } + } + RowLayout { + Layout.fillWidth: true + spacing: 8 + Mute { + objectName: root.muteName + } + Level { + id: horizontal + objectName: root.sliderName + Layout.fillWidth: true + Layout.preferredHeight: root.tall ? 30 : 26 + } + } + } + Flickable { + visible: root.inline + x: 14 + y: wideLayout.y + wideLayout.height + 10 + width: root.width - 28 + height: root.baseHeight - y - 10 + clip: true + contentHeight: inner.implicitHeight + boundsBehavior: Flickable.StopAtBounds + ScrollBar.vertical: ScrollBar { + policy: ScrollBar.AsNeeded + } + Loader { + id: inner + width: parent.width + active: root.inline + sourceComponent: root.extension + } + } + // Extended below the cells. + Loader { + id: outer + x: 14 + y: root.baseHeight + 6 + width: root.width - 28 + active: root.expanded && !root.inline + sourceComponent: root.extension + } +} diff --git a/quickshell/controlcenter/CCTile.qml b/quickshell/controlcenter/CCTile.qml index b24f994..118a25c 100644 --- a/quickshell/controlcenter/CCTile.qml +++ b/quickshell/controlcenter/CCTile.qml @@ -1,60 +1,150 @@ +pragma ComponentBehavior: Bound import QtQuick import QtQuick.Layouts +import "../components" +import "../core" import "../theme" -// Small Control Center tile: round toggle, title and state; the whole tile toggles. -ControlCard { +// Toggle tile: icon, title and state. 1×1 is a round toggle, one row is a pill +// with labels beside the icon, taller tiles stack them. Left click toggles; +// right click opens the matching Settings page. +CCModule { id: root + property string title property string glyph property string fallback property string detail + property string page property bool checked: false + // 1×1 shows the icon; modules with their own compact face turn it off. + property bool compactGlyph: true signal clicked - padding: 10 - heading: false + signal secondaryClicked + round: true + hovered: area.containsMouse && enabled opacity: enabled ? 1 : 0.55 - color: area.containsMouse && enabled ? Theme.hover : Theme.fill + color: compact && checked ? Theme.accent : hovered ? Theme.hover : Theme.fill Accessible.role: Accessible.CheckBox Accessible.name: title Accessible.checked: checked + onSecondaryClicked: if (page) + ShellState.openSettings(page) + + component Labels: ColumnLayout { + property int align: Text.AlignLeft + property int lines: 1 + spacing: 1 + Text { + text: root.title + color: Theme.text + font.pixelSize: root.wide && root.tall ? 14 : 12 + font.weight: Font.DemiBold + elide: Text.ElideRight + horizontalAlignment: parent.align + Layout.fillWidth: true + } + Text { + text: root.detail + visible: text !== "" + color: Theme.textSecondary + font.pixelSize: 11 + elide: Text.ElideRight + wrapMode: parent.lines > 1 ? Text.Wrap : Text.NoWrap + maximumLineCount: parent.lines + horizontalAlignment: parent.align + Layout.fillWidth: true + } + } + MouseArea { id: area - parent: root - z: -1 anchors.fill: parent hoverEnabled: true + acceptedButtons: Qt.LeftButton | Qt.RightButton cursorShape: Qt.PointingHandCursor - onClicked: root.clicked() + onClicked: mouse => mouse.button === Qt.RightButton ? root.secondaryClicked() : root.clicked() } + GlassToolTip { + visible: root.compact && area.containsMouse + delay: 500 + text: root.title + (root.detail ? " · " + root.detail : "") + } + // 1×1: the circle itself is the toggle. + Text { + visible: root.compact && root.compactGlyph + x: root.background.x + (root.background.width - width) / 2 + y: root.background.y + (root.background.height - height) / 2 + text: Icons.available && root.glyph ? root.glyph : root.fallback + font.family: Icons.available && root.glyph ? Icons.family : "" + font.pixelSize: Math.round(root.background.width * 0.34) + font.weight: Font.DemiBold + color: root.checked ? Theme.accentText : Theme.text + scale: area.pressed ? 0.92 : 1 + Behavior on scale { + NumberAnimation { + duration: Theme.duration / 2 + } + } + } + // One row: icon beside the labels. RowLayout { - Layout.fillWidth: true + visible: root.wide && !root.tall + anchors.fill: parent + anchors.leftMargin: (root.baseHeight - toggleRow.size) / 2 + anchors.rightMargin: 14 spacing: 10 CCToggle { + id: toggleRow + size: Math.min(38, root.baseHeight - 20) glyph: root.glyph fallback: root.fallback checked: root.checked enabled: root.enabled onClicked: root.clicked() } - ColumnLayout { + Labels { Layout.fillWidth: true - spacing: 0 - Text { - text: root.title - color: Theme.text - font.pixelSize: 12 - font.weight: Font.DemiBold - elide: Text.ElideRight - Layout.fillWidth: true - } - Text { - text: root.detail - visible: text !== "" - color: Theme.textSecondary - font.pixelSize: 11 - elide: Text.ElideRight - Layout.fillWidth: true - } } } + // One column: icon above centred labels. + ColumnLayout { + visible: !root.wide && root.tall + anchors.centerIn: parent + width: parent.width - 16 + spacing: 8 + CCToggle { + size: Math.min(44, root.width - 24) + Layout.alignment: Qt.AlignHCenter + glyph: root.glyph + fallback: root.fallback + checked: root.checked + enabled: root.enabled + onClicked: root.clicked() + } + Labels { + align: Text.AlignHCenter + lines: Math.max(1, root.rows - 1) + Layout.fillWidth: true + } + } + // Large: icon top left, labels along the bottom. + CCToggle { + visible: root.wide && root.tall + x: 14 + y: 14 + size: 44 + glyph: root.glyph + fallback: root.fallback + checked: root.checked + enabled: root.enabled + onClicked: root.clicked() + } + Labels { + visible: root.wide && root.tall + anchors.left: parent.left + anchors.right: parent.right + anchors.bottom: parent.bottom + anchors.margins: 14 + lines: root.rows - 1 + } } diff --git a/quickshell/controlcenter/ControlCenter.qml b/quickshell/controlcenter/ControlCenter.qml index d42056d..4ec21c3 100644 --- a/quickshell/controlcenter/ControlCenter.qml +++ b/quickshell/controlcenter/ControlCenter.qml @@ -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 + } } } } diff --git a/quickshell/controlcenter/ControlRegistry.qml b/quickshell/controlcenter/ControlRegistry.qml index 956f016..e7cbc59 100644 --- a/quickshell/controlcenter/ControlRegistry.qml +++ b/quickshell/controlcenter/ControlRegistry.qml @@ -2,46 +2,122 @@ pragma Singleton import QtQuick import Quickshell +// 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. Singleton { function entry(id) { return Object.prototype.hasOwnProperty.call(modules, id) ? modules[id] : null; } + // Configured size, else the module's default. + function size(module) { + if (!module) + return { + w: 1, + h: 1 + }; + const e = entry(module.id); + return { + w: module.w || (e ? e.w : 1), + h: module.h || (e ? e.h : 1) + }; + } readonly property var modules: ({ - metrics: {title:"System Metrics", source:Qt.resolvedUrl("modules/Metrics.qml")}, - connectivity: { - title: "Connectivity", - source: Qt.resolvedUrl("modules/Connectivity.qml") + wifi: { + title: "Wi-Fi", + glyph: "󰖩", + w: 2, + h: 1, + source: Qt.resolvedUrl("modules/Wifi.qml") }, - audio: { - title: "Audio", - source: Qt.resolvedUrl("modules/Audio.qml") + bluetooth: { + title: "Bluetooth", + glyph: "󰂯", + w: 1, + h: 1, + source: Qt.resolvedUrl("modules/Bluetooth.qml") + }, + network: { + title: "Network", + glyph: "󰛳", + w: 2, + h: 1, + source: Qt.resolvedUrl("modules/Network.qml") + }, + output: { + title: "Sound", + glyph: "󰕾", + w: 4, + h: 1, + source: Qt.resolvedUrl("modules/Output.qml") + }, + input: { + title: "Microphone", + glyph: "󰍬", + w: 4, + h: 1, + source: Qt.resolvedUrl("modules/Input.qml") }, brightness: { - title: "Brightness", + title: "Display", + glyph: "󰃠", + w: 4, + h: 1, source: Qt.resolvedUrl("modules/Brightness.qml") }, nightLight: { title: "Night Light", + glyph: "󰖔", + w: 1, + h: 1, source: Qt.resolvedUrl("modules/NightLight.qml") }, dnd: { title: "Do Not Disturb", + glyph: "󰽥", + w: 1, + h: 1, source: Qt.resolvedUrl("modules/Dnd.qml") }, + caffeine: { + title: "Caffeine", + glyph: "󰅶", + w: 1, + h: 1, + source: Qt.resolvedUrl("modules/Caffeine.qml") + }, profiles: { title: "Power profile", + glyph: "󰾅", + w: 2, + h: 1, source: Qt.resolvedUrl("modules/Profiles.qml") }, media: { - title: "Media", - source: Qt.resolvedUrl("modules/Media.qml") + title: "Now Playing", + glyph: "󰝚", + w: 2, + h: 2, + source: Qt.resolvedUrl("modules/NowPlaying.qml") }, power: { title: "Power", + glyph: "󰐥", + w: 4, + h: 1, source: Qt.resolvedUrl("modules/Power.qml") }, + metrics: { + title: "System Metrics", + glyph: "󰍛", + w: 4, + h: 1, + source: Qt.resolvedUrl("modules/Metrics.qml") + }, notifications: { title: "Notifications", + glyph: "󰂚", + section: true, source: Qt.resolvedUrl("modules/Notifications.qml") } }) diff --git a/quickshell/controlcenter/GridLogic.js b/quickshell/controlcenter/GridLogic.js new file mode 100644 index 0000000..e4a06de --- /dev/null +++ b/quickshell/controlcenter/GridLogic.js @@ -0,0 +1,110 @@ +// 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. + +var COLS = 4; +var MAX = 4; + +function clampSize(n) { + n = Math.round(Number(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) { + 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; + } + 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; + break; + } + } + } + return {items: items, rows: rows}; +} + +// 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; +} + +// Cells for a tile resized by a pixel delta from its start size. +function resize(start, dx, dy, cellW, cellH, gap) { + return { + w: clampSize(start.w + dx / (cellW + gap)), + h: clampSize(start.h + dy / (cellH + gap)) + }; +} + +// Pixel geometry. `extras` maps tile id -> extra height below it (an expanded +// tile); everything starting at or below that tile's bottom row moves down. +function geometry(plan, cellW, cellH, gap, extras) { + extras = extras || {}; + const boundary = {}; + for (const i of plan.items) { + const e = extras[i.id] || 0; + if (e > 0) + boundary[i.row + i.h] = Math.max(boundary[i.row + i.h] || 0, e + gap); + } + function shift(row) { + let s = 0; + for (const b in boundary) + if (row >= Number(b)) + s += boundary[b]; + return s; + } + const out = {}; + for (const i of plan.items) + out[i.id] = { + x: i.col * (cellW + gap), + y: i.row * (cellH + gap) + shift(i.row), + w: i.w * cellW + (i.w - 1) * gap, + h: i.h * cellH + (i.h - 1) * gap + ((extras[i.id] || 0) > 0 ? extras[i.id] + gap : 0) + }; + const height = plan.rows ? plan.rows * (cellH + gap) - gap + shift(plan.rows) : 0; + return {tiles: out, height: height}; +} diff --git a/quickshell/controlcenter/modules/Bluetooth.qml b/quickshell/controlcenter/modules/Bluetooth.qml new file mode 100644 index 0000000..3c4e52e --- /dev/null +++ b/quickshell/controlcenter/modules/Bluetooth.qml @@ -0,0 +1,16 @@ +pragma ComponentBehavior: Bound +import QtQuick +import ".." +import "../../services" + +CCTile { + objectName: "bluetoothToggle" + title: "Bluetooth" + detail: !BluetoothService.adapter ? "No adapter" : !BluetoothService.canToggle ? "Hardware blocked" : BluetoothService.summary + page: "bluetooth" + glyph: BluetoothService.enabled ? "󰂯" : "󰂲" + fallback: "B" + checked: BluetoothService.enabled + enabled: BluetoothService.canToggle + onClicked: BluetoothService.toggle() +} diff --git a/quickshell/controlcenter/modules/Brightness.qml b/quickshell/controlcenter/modules/Brightness.qml index 48b4847..90dcc6b 100644 --- a/quickshell/controlcenter/modules/Brightness.qml +++ b/quickshell/controlcenter/modules/Brightness.qml @@ -1,44 +1,24 @@ +pragma ComponentBehavior: Bound import QtQuick -import QtQuick.Layouts import ".." -import "../../components" import "../../services" -import "../../theme" -ControlCard { - id: root +// Display brightness; providers apply it on release. +CCSlider { readonly property var info: SystemService.state.brightness || ({ available: false }) + objectName: "brightnessTile" title: "Display" - GlassBarSlider { - objectName: "brightnessSlider" - Layout.fillWidth: true - glyph: "󰃠" - fallback: "☀" - from: 1 - to: 100 - stepSize: 1 - value: root.info.value || 1 - enabled: !!root.info.available && !SystemService.acting - onPressedChanged: if (!pressed && enabled) { - SystemService.action("brightness", value, false); - value = Qt.binding(() => root.info.value || 1); - } - Keys.onReleased: event => { - if (event.key === Qt.Key_Left || event.key === Qt.Key_Right) { - SystemService.action("brightness", value, false); - value = Qt.binding(() => root.info.value || 1); - } - } - Accessible.name: "Display brightness" - } - Text { - visible: !root.info.available - text: root.info.notice || "No brightness provider" - color: Theme.textSecondary - font.pixelSize: 11 - wrapMode: Text.Wrap - Layout.fillWidth: true - } + glyph: "󰃠" + fallback: "☀" + sliderName: "brightnessSlider" + from: 1 + to: 100 + stepSize: 1 + value: info.value || 1 + enabled: !!info.available && !SystemService.acting + known: !!info.available + notice: info.available ? "" : info.notice || "No brightness provider" + onCommitted: value => SystemService.action("brightness", value, false) } diff --git a/quickshell/controlcenter/modules/Caffeine.qml b/quickshell/controlcenter/modules/Caffeine.qml new file mode 100644 index 0000000..dea1b85 --- /dev/null +++ b/quickshell/controlcenter/modules/Caffeine.qml @@ -0,0 +1,15 @@ +pragma ComponentBehavior: Bound +import QtQuick +import ".." +import "../../services" + +// Keeps the screen on and the system awake until turned off. +CCTile { + objectName: "caffeineToggle" + title: "Caffeine" + detail: CaffeineService.active ? "Staying awake" : "Off" + glyph: CaffeineService.active ? "󰅶" : "󰛊" + fallback: "☕" + checked: CaffeineService.active + onClicked: CaffeineService.toggle() +} diff --git a/quickshell/controlcenter/modules/Connectivity.qml b/quickshell/controlcenter/modules/Connectivity.qml deleted file mode 100644 index 5ce5fd8..0000000 --- a/quickshell/controlcenter/modules/Connectivity.qml +++ /dev/null @@ -1,97 +0,0 @@ -pragma ComponentBehavior: Bound -import QtQuick -import QtQuick.Layouts -import ".." -import "../../services" -import "../../core" -import "../../theme" - -// Wi-Fi, Bluetooth and live throughput; labels open the matching Settings page. -ControlCard { - id: root - // Tile metrics, so rows line up with the small tiles beside this card: when - // the block stretches it, the gaps grow and each row meets a tile's toggle. - readonly property int rowHeight: 34 - padding: 10 - implicitHeight: 3 * rowHeight + 2 * 10 + 2 * padding - spacing: Math.max(10, (root.height - 2 * root.padding - 3 * root.rowHeight) / 2) - Demand { - service: MetricsService - } - component Entry: RowLayout { - id: entry - property alias toggle: toggle - property string title - property string detail - property string page - Layout.fillWidth: true - Layout.preferredHeight: toggle.size - spacing: 10 - CCToggle { - id: toggle - } - Item { - Layout.fillWidth: true - implicitHeight: labels.implicitHeight - ColumnLayout { - id: labels - anchors.left: parent.left - anchors.right: parent.right - spacing: 0 - Text { - text: entry.title - color: Theme.text - font.pixelSize: 12 - font.weight: Font.DemiBold - elide: Text.ElideRight - Layout.fillWidth: true - } - Text { - text: entry.detail - color: Theme.textSecondary - font.pixelSize: 11 - elide: Text.ElideRight - Layout.fillWidth: true - } - } - MouseArea { - anchors.fill: parent - cursorShape: Qt.PointingHandCursor - onClicked: ShellState.openSettings(entry.page) - } - } - } - Entry { - title: "Wi-Fi" - detail: !NetworkService.available ? "No Wi-Fi adapter" : !NetworkService.backend.wifiHardwareEnabled ? "Hardware blocked" : NetworkService.enabled ? NetworkService.summary : "Off" - page: "network" - toggle.objectName: "wifiToggle" - toggle.glyph: NetworkService.enabled ? "󰖩" : "󰖪" - toggle.fallback: "W" - toggle.checked: NetworkService.available && NetworkService.enabled - toggle.enabled: NetworkService.available && NetworkService.backend.wifiHardwareEnabled - toggle.onClicked: NetworkService.toggle() - toggle.Accessible.name: "Wi-Fi" - } - Entry { - title: "Bluetooth" - detail: !BluetoothService.adapter ? "No adapter" : !BluetoothService.canToggle ? "Hardware blocked" : BluetoothService.summary - page: "bluetooth" - toggle.objectName: "bluetoothToggle" - toggle.glyph: BluetoothService.enabled ? "󰂯" : "󰂲" - toggle.fallback: "B" - toggle.checked: BluetoothService.enabled - toggle.enabled: BluetoothService.canToggle - toggle.onClicked: BluetoothService.toggle() - toggle.Accessible.name: "Bluetooth" - } - Entry { - title: "Network" - detail: "↓ " + MetricsService.bytes(MetricsService.network.download) + "/s ↑ " + MetricsService.bytes(MetricsService.network.upload) + "/s" - page: "metrics" - toggle.glyph: "󰛳" - toggle.fallback: "N" - toggle.onClicked: ShellState.openSettings("network") - toggle.Accessible.name: "Network settings" - } -} diff --git a/quickshell/controlcenter/modules/Dnd.qml b/quickshell/controlcenter/modules/Dnd.qml index 0d53d0f..091d55d 100644 --- a/quickshell/controlcenter/modules/Dnd.qml +++ b/quickshell/controlcenter/modules/Dnd.qml @@ -1,3 +1,4 @@ +pragma ComponentBehavior: Bound import QtQuick import ".." import "../../services" @@ -12,6 +13,7 @@ CCTile { title: "Do Not Disturb" detail: shellOwned ? (NotificationService.dnd ? "On" : "Off") : !info.available ? (info.notice || "No notification server") : info.enabled ? "On" : "Off" glyph: "󰽥" + page: "notifications" fallback: "☾" // Shows acknowledged provider state; a failed request leaves it unchanged. checked: shellOwned ? NotificationService.dnd : !!info.enabled diff --git a/quickshell/controlcenter/modules/Input.qml b/quickshell/controlcenter/modules/Input.qml new file mode 100644 index 0000000..c6ff68d --- /dev/null +++ b/quickshell/controlcenter/modules/Input.qml @@ -0,0 +1,26 @@ +pragma ComponentBehavior: Bound +import QtQuick +import ".." +import "../../services" + +// Microphone level. Right click (or spare rows) shows input devices. +CCSlider { + readonly property var node: AudioService.source + objectName: "inputTile" + title: "Microphone" + glyph: "󰍬" + mutedGlyph: "󰍭" + fallback: "M" + sliderName: "microphoneSlider" + muteName: "microphoneMute" + muteable: true + enabled: !!node && !!node.audio + muted: enabled && node.audio.muted + value: enabled ? node.audio.volume : 0 + notice: AudioService.available ? "" : "PipeWire is unavailable" + onMoved: value => AudioService.volume(true, value) + onMuteClicked: AudioService.mute(true) + extension: AudioMixer { + input: true + } +} diff --git a/quickshell/controlcenter/modules/Metrics.qml b/quickshell/controlcenter/modules/Metrics.qml index 21201ce..a2497c8 100644 --- a/quickshell/controlcenter/modules/Metrics.qml +++ b/quickshell/controlcenter/modules/Metrics.qml @@ -1,10 +1,99 @@ +pragma ComponentBehavior: Bound import QtQuick +import QtQuick.Layouts +import ".." +import "../../core" import "../../metrics" +import "../../services" import "../../theme" -MetricsCard { - compact: true - radius: Math.max(12, Theme.radius * 0.75) - color: Theme.fill - border.color: Theme.hairline +// CPU, RAM and GPU load. Small tiles show the figures as text (1×1 just CPU); +// wide tall tiles show ring gauges. Click opens the Metrics settings. +CCModule { + id: root + readonly property var stats: [ + { + label: "CPU", + value: MetricsService.cpu.percent + }, + { + label: "RAM", + value: MetricsService.ram.percent + }, + { + label: "GPU", + value: MetricsService.gpu.percent + } + ] + readonly property int shown: compact ? 1 : Math.min(stats.length, wide ? cols : rows) + readonly property bool gauges: wide && tall + objectName: "metricsTile" + hovered: area.containsMouse + Demand { + service: MetricsService + } + MouseArea { + id: area + anchors.fill: parent + hoverEnabled: true + cursorShape: Qt.PointingHandCursor + onClicked: ShellState.openSettings("metrics") + } + GridLayout { + visible: !root.gauges + anchors.fill: parent + anchors.margins: 8 + columns: root.wide ? root.shown : 1 + rowSpacing: 4 + columnSpacing: 4 + Repeater { + model: root.stats.slice(0, root.shown) + ColumnLayout { + id: stat + required property var modelData + Layout.fillWidth: true + Layout.fillHeight: true + spacing: 0 + Text { + text: MetricsService.value(stat.modelData.value, "%") + color: Theme.text + font.pixelSize: 17 + font.weight: Font.DemiBold + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignBottom + Layout.fillWidth: true + Layout.fillHeight: true + } + Text { + text: stat.modelData.label + color: Theme.textSecondary + font.pixelSize: 10 + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignTop + Layout.fillWidth: true + Layout.fillHeight: true + } + } + } + } + Row { + visible: root.gauges + anchors.centerIn: parent + Repeater { + model: root.gauges ? root.stats.slice(0, root.shown) : [] + Item { + id: cell + required property var modelData + readonly property real scaleBy: Math.min(1, (root.width - 16) / root.shown / 100, (root.baseHeight - 16) / 106) + width: 100 * scaleBy + height: 106 * scaleBy + MetricGauge { + label: cell.modelData.label + value: cell.modelData.value + scale: cell.scaleBy + transformOrigin: Item.TopLeft + } + } + } + } } diff --git a/quickshell/controlcenter/modules/Network.qml b/quickshell/controlcenter/modules/Network.qml new file mode 100644 index 0000000..7dd1be5 --- /dev/null +++ b/quickshell/controlcenter/modules/Network.qml @@ -0,0 +1,42 @@ +pragma ComponentBehavior: Bound +import QtQuick +import QtQuick.Layouts +import ".." +import "../../core" +import "../../services" +import "../../theme" + +// Live throughput. 1×1 shows just the two rates. +CCTile { + id: root + readonly property string down: "↓ " + MetricsService.bytes(MetricsService.network.download) + "/s" + readonly property string up: "↑ " + MetricsService.bytes(MetricsService.network.upload) + "/s" + objectName: "networkTile" + title: "Network" + detail: down + " " + up + page: "network" + glyph: "󰛳" + fallback: "N" + round: false + compactGlyph: false + onClicked: ShellState.openSettings("metrics") + Demand { + service: MetricsService + } + ColumnLayout { + visible: root.compact + anchors.centerIn: parent + spacing: 2 + Repeater { + model: [root.down, root.up] + Text { + required property string modelData + text: modelData + color: Theme.text + font.pixelSize: 10 + font.weight: Font.DemiBold + Layout.alignment: Qt.AlignHCenter + } + } + } +} diff --git a/quickshell/controlcenter/modules/NightLight.qml b/quickshell/controlcenter/modules/NightLight.qml index 4d3b5ef..5a0d371 100644 --- a/quickshell/controlcenter/modules/NightLight.qml +++ b/quickshell/controlcenter/modules/NightLight.qml @@ -1,3 +1,4 @@ +pragma ComponentBehavior: Bound import QtQuick import ".." import "../../services" @@ -10,6 +11,7 @@ CCTile { title: "Night Light" detail: !info.available ? "No gamma provider" : info.enabled ? "On" : "Off" glyph: "󰖔" + page: "displays" fallback: "N" // Shows acknowledged provider state; a failed request leaves it unchanged. checked: !!info.enabled diff --git a/quickshell/controlcenter/modules/NowPlaying.qml b/quickshell/controlcenter/modules/NowPlaying.qml new file mode 100644 index 0000000..ae66187 --- /dev/null +++ b/quickshell/controlcenter/modules/NowPlaying.qml @@ -0,0 +1,268 @@ +pragma ComponentBehavior: Bound +import QtQuick +import QtQuick.Layouts +import Quickshell.Widgets +import ".." +import "../../components" +import "../../services" +import "../../theme" + +// Now Playing tile. 1×1 is a round play button over the artwork; one row puts +// the artwork beside the track; taller tiles stack artwork, track and controls, +// with a progress bar from three rows. +CCModule { + id: root + readonly property bool canControl: !!MediaService.player && MediaService.player.canControl + readonly property bool showProgress: rows >= 3 && wide && MediaService.length > 0 + objectName: "nowPlayingTile" + round: true + hovered: area.containsMouse + Demand { + service: MediaService + counter: "progressConsumers" + active: root.showProgress + } + + component Art: ClippingRectangle { + id: artFrame + property real size: 48 + implicitWidth: size + implicitHeight: size + radius: Math.max(8, size * 0.18) + color: Theme.surfaceVariant + Text { + anchors.centerIn: parent + visible: art.status !== Image.Ready + text: Icons.available ? "󰝚" : "♫" + font.family: Icons.available ? Icons.family : "" + font.pixelSize: Math.round(artFrame.size * 0.4) + color: Theme.textSecondary + } + Image { + id: art + anchors.fill: parent + source: MediaService.artwork + sourceSize: Qt.size(192, 192) + asynchronous: true + retainWhileLoading: true + fillMode: Image.PreserveAspectCrop + } + } + component Track: ColumnLayout { + property int titleSize: 13 + property int align: Text.AlignLeft + spacing: 1 + Text { + text: MediaService.title + color: Theme.text + font.pixelSize: parent.titleSize + font.weight: Font.DemiBold + elide: Text.ElideRight + horizontalAlignment: parent.align + Layout.fillWidth: true + } + Text { + text: MediaService.artist + visible: text !== "" + color: Theme.textSecondary + font.pixelSize: 11 + elide: Text.ElideRight + horizontalAlignment: parent.align + Layout.fillWidth: true + } + } + component Control: Item { + id: control + property string glyph + property string fallback + property bool main: false + property bool available: true + signal clicked + implicitWidth: main ? 34 : 28 + implicitHeight: implicitWidth + enabled: root.canControl && available + opacity: enabled ? 1 : 0.4 + Accessible.role: Accessible.Button + Rectangle { + anchors.fill: parent + radius: width / 2 + color: control.main ? Qt.alpha(Theme.text, controlArea.containsMouse ? 0.2 : 0.12) : controlArea.containsMouse ? Theme.hover : Theme.transparent + } + Text { + anchors.centerIn: parent + text: Icons.available ? control.glyph : control.fallback + font.family: Icons.available ? Icons.family : "" + font.pixelSize: control.main ? 17 : 15 + color: Theme.text + scale: controlArea.pressed ? 0.9 : 1 + } + MouseArea { + id: controlArea + anchors.fill: parent + hoverEnabled: true + cursorShape: Qt.PointingHandCursor + onClicked: control.clicked() + } + } + component Controls: RowLayout { + property bool full: true + spacing: 4 + Control { + visible: parent.full + glyph: "󰒮" + fallback: "⏮" + available: !!MediaService.player && MediaService.player.canGoPrevious + onClicked: MediaService.previous() + Accessible.name: "Previous track" + } + Control { + objectName: "ccMediaToggle" + main: true + glyph: MediaService.playing ? "󰏤" : "󰐊" + fallback: MediaService.playing ? "Ⅱ" : "▶" + available: !!MediaService.player && MediaService.player.canTogglePlaying + onClicked: MediaService.toggle() + Accessible.name: MediaService.playing ? "Pause" : "Play" + } + Control { + visible: parent.full + glyph: "󰒭" + fallback: "⏭" + available: !!MediaService.player && MediaService.player.canGoNext + onClicked: MediaService.next() + Accessible.name: "Next track" + } + } + + MouseArea { + id: area + anchors.fill: parent + hoverEnabled: true + onClicked: if (root.compact && root.canControl) + MediaService.toggle() + } + GlassToolTip { + visible: root.compact && area.containsMouse + delay: 500 + text: MediaService.title + (MediaService.artist ? " · " + MediaService.artist : "") + } + + // 1×1: artwork filling the circle with the play state on top. + ClippingRectangle { + visible: root.compact + x: root.background.x + y: root.background.y + width: root.background.width + height: root.background.height + radius: width / 2 + color: Theme.transparent + Image { + anchors.fill: parent + source: root.compact ? MediaService.artwork : "" + sourceSize: Qt.size(128, 128) + asynchronous: true + fillMode: Image.PreserveAspectCrop + opacity: 0.55 + } + Text { + anchors.centerIn: parent + text: Icons.available ? (MediaService.playing ? "󰏤" : "󰐊") : (MediaService.playing ? "Ⅱ" : "▶") + font.family: Icons.available ? Icons.family : "" + font.pixelSize: Math.round(root.background.width * 0.32) + color: Theme.text + } + } + + // One row: artwork, track, controls. + RowLayout { + visible: root.wide && !root.tall + anchors.fill: parent + anchors.margins: 10 + anchors.rightMargin: 12 + spacing: 10 + Art { + size: root.baseHeight - 20 + } + Track { + Layout.fillWidth: true + } + Controls { + full: root.cols >= 3 + } + } + + // One column: artwork above the play button. + ColumnLayout { + visible: !root.wide && root.tall + anchors.fill: parent + anchors.margins: 10 + spacing: 8 + Art { + size: Math.min(root.width - 20, root.baseHeight - 64) + Layout.alignment: Qt.AlignHCenter + } + Track { + visible: root.rows >= 3 + titleSize: 11 + align: Text.AlignHCenter + Layout.fillWidth: true + } + Item { + Layout.fillHeight: true + } + Controls { + full: false + Layout.alignment: Qt.AlignHCenter + } + } + + // Large: artwork and track on top, controls along the bottom. + ColumnLayout { + visible: root.wide && root.tall + anchors.fill: parent + anchors.margins: 14 + spacing: 8 + RowLayout { + Layout.fillWidth: true + spacing: 12 + Art { + size: Math.min(root.rows >= 3 ? 96 : 56, root.width / 2 - 14) + } + Track { + titleSize: root.cols >= 3 ? 15 : 13 + Layout.fillWidth: true + Layout.alignment: Qt.AlignVCenter + } + } + Item { + Layout.fillHeight: true + } + RowLayout { + visible: root.showProgress + Layout.fillWidth: true + spacing: 6 + Text { + text: MediaService.time(MediaService.position) + color: Theme.textSecondary + font.pixelSize: 10 + } + GlassSlider { + Layout.fillWidth: true + from: 0 + to: Math.max(1, MediaService.length) + value: MediaService.position + enabled: MediaService.seekable + onMoved: MediaService.seek(value) + Accessible.name: "Track position" + } + Text { + text: "−" + MediaService.time(MediaService.length - MediaService.position) + color: Theme.textSecondary + font.pixelSize: 10 + } + } + Controls { + Layout.alignment: Qt.AlignHCenter + } + } +} diff --git a/quickshell/controlcenter/modules/Output.qml b/quickshell/controlcenter/modules/Output.qml new file mode 100644 index 0000000..9f0f6be --- /dev/null +++ b/quickshell/controlcenter/modules/Output.qml @@ -0,0 +1,24 @@ +pragma ComponentBehavior: Bound +import QtQuick +import ".." +import "../../services" + +// Output volume. Right click (or spare rows) shows devices and per-app volume. +CCSlider { + readonly property var node: AudioService.sink + objectName: "outputTile" + title: "Sound" + glyph: "󰕾" + mutedGlyph: "󰖁" + fallback: "♪" + sliderName: "volumeSlider" + muteName: "volumeMute" + muteable: true + enabled: !!node && !!node.audio + muted: enabled && node.audio.muted + value: enabled ? node.audio.volume : 0 + notice: AudioService.available ? "" : "PipeWire is unavailable" + onMoved: value => AudioService.volume(false, value) + onMuteClicked: AudioService.mute(false) + extension: AudioMixer {} +} diff --git a/quickshell/controlcenter/modules/Power.qml b/quickshell/controlcenter/modules/Power.qml index a732a4c..146be2e 100644 --- a/quickshell/controlcenter/modules/Power.qml +++ b/quickshell/controlcenter/modules/Power.qml @@ -6,55 +6,94 @@ import "../../components" import "../../services" import "../../theme" -ControlCard { +// Session actions as round buttons, wrapped to the tile. When they do not fit +// it becomes one power button that extends into a list. Confirmation for +// destructive actions extends below the tile. +CCModule { id: root + readonly property var actions: [ + { + id: "lock", + glyph: "󰌾", + label: "Lock" + }, + { + id: "logout", + glyph: "󰍃", + label: "Log out" + }, + { + id: "suspend", + glyph: "󰤄", + label: "Suspend" + }, + { + id: "reboot", + glyph: "󰜉", + label: "Reboot" + }, + { + id: "shutdown", + glyph: "󰐥", + label: "Shut down" + } + ] + readonly property real innerWidth: width - 20 + readonly property real innerHeight: baseHeight - 12 + readonly property int count: actions.length + function perRowFor(slot) { + return Math.max(1, Math.min(count, Math.floor((innerWidth + 4) / (slot + 4)))); + } + function heightFor(perRow, rowHeight) { + return Math.ceil(count / perRow) * (rowHeight + 4) - 4; + } + // Labelled buttons where they fit on four-wide or taller tiles, else plain + // 34 px buttons, else one row of smaller ones, else the menu button. + readonly property bool labels: (cols >= 4 || rows >= 2) && heightFor(perRowFor(52), 49) <= innerHeight + readonly property bool plain: !labels && heightFor(perRowFor(34), 34) <= innerHeight + readonly property real squeezed: Math.min(innerHeight, Math.floor((innerWidth - 4 * (count - 1)) / count)) + readonly property int perRow: labels ? perRowFor(52) : plain ? perRowFor(34) : count + readonly property real buttonSize: labels || plain ? 34 : squeezed + readonly property real buttonWidth: labels ? 52 : buttonSize + readonly property bool fits: labels || plain || squeezed >= 24 + readonly property bool pending: PowerService.pending !== "" + round: !fits + hovered: menuArea.containsMouse + extraHeight: (pending || (expanded && !fits)) && extension.item ? extension.implicitHeight + 20 : 0 Component.onDestruction: PowerService.cancel() - RowLayout { - Layout.fillWidth: true - spacing: 4 + function allowed(id) { + return (id === "lock" && ConfigService.ready && ConfigService.data.lock.enabled) || (!!SystemService.state.power && !!SystemService.state.power[id] && !SystemService.acting); + } + + // Everything fits: a wrapped grid of buttons. + GridLayout { + visible: root.fits + anchors.horizontalCenter: parent.horizontalCenter + y: (root.baseHeight - height) / 2 + columns: root.perRow + rowSpacing: 4 + columnSpacing: Math.max(4, (root.innerWidth - root.perRow * root.buttonWidth) / Math.max(1, root.perRow - 1) - 2) Repeater { - model: [ - { - id: "lock", - glyph: "󰌾" - }, - { - id: "logout", - glyph: "󰍃" - }, - { - id: "suspend", - glyph: "󰤄" - }, - { - id: "reboot", - glyph: "󰜉" - }, - { - id: "shutdown", - glyph: "󰐥" - } - ] + model: root.actions ColumnLayout { id: action required property var modelData - readonly property string label: modelData.id === "logout" ? "Log out" : modelData.id === "shutdown" ? "Shut down" : modelData.id.charAt(0).toUpperCase() + modelData.id.slice(1) - Layout.fillWidth: true - Layout.preferredWidth: 1 - spacing: 4 + Layout.preferredWidth: root.buttonWidth + spacing: 3 CCToggle { objectName: "power-" + action.modelData.id Layout.alignment: Qt.AlignHCenter - size: 38 + size: root.buttonSize glyph: action.modelData.glyph - fallback: action.label.charAt(0) + fallback: action.modelData.label.charAt(0) checked: PowerService.pending === action.modelData.id - enabled: (action.modelData.id === "lock" && ConfigService.ready && ConfigService.data.lock.enabled) || (!!SystemService.state.power && !!SystemService.state.power[action.modelData.id] && !SystemService.acting) + enabled: root.allowed(action.modelData.id) onClicked: PowerService.request(action.modelData.id) - Accessible.name: action.label + Accessible.name: action.modelData.label } Text { - text: action.label + visible: root.labels + text: action.modelData.label color: Theme.textSecondary font.pixelSize: 10 elide: Text.ElideRight @@ -64,28 +103,119 @@ ControlCard { } } } - RowLayout { - visible: PowerService.pending !== "" - Layout.fillWidth: true - spacing: 8 - Text { - text: "Confirm " + PowerService.pending + "? Unsaved work may be lost." - color: Theme.text - font.pixelSize: 12 - wrapMode: Text.Wrap - Layout.fillWidth: true + + // Too small: one button that extends into the list. + MouseArea { + id: menuArea + visible: !root.fits + width: parent.width + height: root.baseHeight + hoverEnabled: true + cursorShape: Qt.PointingHandCursor + onClicked: root.expanded = !root.expanded + Accessible.role: Accessible.Button + Accessible.name: "Power" + Column { + anchors.centerIn: parent + spacing: 2 + Text { + anchors.horizontalCenter: parent.horizontalCenter + text: Icons.available ? "󰐥" : "⏻" + font.family: Icons.available ? Icons.family : "" + font.pixelSize: Math.min(26, root.innerHeight * 0.5) + color: Theme.text + } + Text { + visible: root.innerHeight >= 44 + anchors.horizontalCenter: parent.horizontalCenter + text: "Power" + color: Theme.textSecondary + font.pixelSize: 10 + } } - GlassButton { - objectName: "powerCancel" - text: "Cancel" - onClicked: PowerService.cancel() + } + + Loader { + id: extension + x: 10 + y: root.baseHeight + 6 + width: root.width - 20 + active: root.pending || (root.expanded && !root.fits) + sourceComponent: root.pending ? confirm : menu + } + Component { + id: menu + ColumnLayout { + spacing: 2 + Repeater { + model: root.actions + Rectangle { + id: item + required property var modelData + Layout.fillWidth: true + implicitHeight: 30 + radius: 8 + enabled: root.allowed(modelData.id) + opacity: enabled ? 1 : 0.45 + color: itemArea.containsMouse ? Theme.hover : Theme.transparent + RowLayout { + anchors.fill: parent + anchors.leftMargin: 8 + anchors.rightMargin: 8 + spacing: 8 + Text { + text: Icons.available ? item.modelData.glyph : "" + font.family: Icons.family + font.pixelSize: 14 + color: Theme.text + } + Text { + text: item.modelData.label + color: Theme.text + font.pixelSize: 12 + elide: Text.ElideRight + Layout.fillWidth: true + } + } + MouseArea { + id: itemArea + objectName: "power-" + item.modelData.id + anchors.fill: parent + hoverEnabled: true + cursorShape: Qt.PointingHandCursor + onClicked: PowerService.request(item.modelData.id) + } + } + } } - GlassButton { - objectName: "powerConfirm" - text: "Confirm" - accented: true - enabled: !SystemService.acting - onClicked: PowerService.confirm() + } + Component { + id: confirm + ColumnLayout { + spacing: 8 + Text { + text: "Confirm " + PowerService.pending + "? Unsaved work may be lost." + color: Theme.text + font.pixelSize: 12 + wrapMode: Text.Wrap + Layout.fillWidth: true + } + RowLayout { + Layout.alignment: Qt.AlignRight + spacing: 8 + GlassButton { + objectName: "powerCancel" + text: "Cancel" + onClicked: PowerService.cancel() + } + GlassButton { + objectName: "powerConfirm" + text: "Confirm" + accented: true + enabled: !SystemService.acting + onClicked: PowerService.confirm() + } + } } } } diff --git a/quickshell/controlcenter/modules/Profiles.qml b/quickshell/controlcenter/modules/Profiles.qml index a736d0d..52a9b73 100644 --- a/quickshell/controlcenter/modules/Profiles.qml +++ b/quickshell/controlcenter/modules/Profiles.qml @@ -1,3 +1,4 @@ +pragma ComponentBehavior: Bound import QtQuick import ".." import "../../services" @@ -15,6 +16,7 @@ CCTile { title: "Power profile" detail: !info.available ? "Unavailable" : current ? current.charAt(0).toUpperCase() + current.slice(1).replace(/-/g, " ") : "—" glyph: current === "power-saver" ? "󰌪" : current === "performance" ? "󰓅" : "󰾅" + page: "power" fallback: "P" checked: info.available && current !== "" && current !== "balanced" enabled: !!info.available && profiles.length > 1 && !SystemService.acting diff --git a/quickshell/controlcenter/modules/Wifi.qml b/quickshell/controlcenter/modules/Wifi.qml new file mode 100644 index 0000000..04beac8 --- /dev/null +++ b/quickshell/controlcenter/modules/Wifi.qml @@ -0,0 +1,16 @@ +pragma ComponentBehavior: Bound +import QtQuick +import ".." +import "../../services" + +CCTile { + objectName: "wifiToggle" + title: "Wi-Fi" + detail: !NetworkService.available ? "No Wi-Fi adapter" : !NetworkService.backend.wifiHardwareEnabled ? "Hardware blocked" : NetworkService.enabled ? NetworkService.summary : "Off" + page: "network" + glyph: NetworkService.enabled ? "󰖩" : "󰖪" + fallback: "W" + checked: NetworkService.available && NetworkService.enabled + enabled: NetworkService.available && NetworkService.backend.wifiHardwareEnabled + onClicked: NetworkService.toggle() +} diff --git a/quickshell/controlcenter/qmldir b/quickshell/controlcenter/qmldir index 119645e..98cbbc0 100644 --- a/quickshell/controlcenter/qmldir +++ b/quickshell/controlcenter/qmldir @@ -4,3 +4,6 @@ ControlCard 1.0 ControlCard.qml SystemTile 1.0 SystemTile.qml CCToggle 1.0 CCToggle.qml CCTile 1.0 CCTile.qml +CCModule 1.0 CCModule.qml +CCSlider 1.0 CCSlider.qml +AudioMixer 1.0 AudioMixer.qml diff --git a/quickshell/services/ConfigLogic.js b/quickshell/services/ConfigLogic.js index b19cc99..a31611a 100644 --- a/quickshell/services/ConfigLogic.js +++ b/quickshell/services/ConfigLogic.js @@ -87,9 +87,9 @@ function validate(c) { if(typeof c.osd.enabled!=="boolean" || !["slide","drop","fade","shrink"].includes(c.osd.animation) || !["top-right","top-center","bottom-center"].includes(c.osd.position) || !Number.isInteger(c.osd.timeout) || c.osd.timeout<500 || c.osd.timeout>5000 || !Number.isInteger(c.osd.step) || c.osd.step<1 || c.osd.step>20)throw Error("Invalid OSD preferences"); const notes=c.notifications; 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 !== 1 || !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(); - for(const m of c.controlCenter.modules) { if(!m || typeof m.id!=="string" || controlIds.has(m.id) || typeof m.enabled!=="boolean")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)))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"); 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"); @@ -123,6 +123,24 @@ function load(defaults, user) { migrated.controlCenter.modules = defaults.controlCenter.modules; migrated.controlCenter.version = 1; } + // Version 2 lays modules on a grid: the combined Connectivity and Audio + // cards split into their own tiles, in place, and Caffeine is offered. + if (migrated.controlCenter.version === 1 && Array.isArray(migrated.controlCenter.modules)) { + const parts = {connectivity: ["wifi", "bluetooth", "network"], audio: ["output", "input"]}; + const old = migrated.controlCenter.modules, modules = []; + for (const m of old) { + if (!m || !parts[m.id]) { + modules.push(m); + continue; + } + for (const id of parts[m.id]) + if (!old.some(o => o && o.id === id) && !modules.some(o => o && o.id === id)) + modules.push({id: id, enabled: m.enabled}); + } + if (old.length && !modules.some(m => m && m.id === "caffeine")) + modules.push({id: "caffeine", enabled: true}); + migrated.controlCenter = Object.assign({}, migrated.controlCenter, {version: 2, modules: modules}); + } migrated.schemaVersion = 3; return validate(merge(defaults, migrated)); } diff --git a/quickshell/settings/pages/ControlCenter.qml b/quickshell/settings/pages/ControlCenter.qml index a3a7fcc..f6c018e 100644 --- a/quickshell/settings/pages/ControlCenter.qml +++ b/quickshell/settings/pages/ControlCenter.qml @@ -86,7 +86,7 @@ SettingsPage { } SettingsSection { title: "Modules" - description: "Drag modules to reorder them; the switch shows or hides each card" + description: "Drag modules to reorder them; the switch shows or hides each one. Resize tiles from Edit Controls in the Control Center" ColumnLayout { id: rows objectName: "controlModuleList" @@ -117,7 +117,7 @@ SettingsPage { y: card.offset scale: card.lifted ? 1.02 : 1 opacity: card.lifted ? 0.9 : 1 - title: card.entry ? card.entry.title : card.modelData.id + " (unavailable)" + title: !card.entry ? card.modelData.id + " (unavailable)" : card.entry.section ? card.entry.title : card.entry.title + " · " + ControlRegistry.size(card.modelData).w + "×" + ControlRegistry.size(card.modelData).h icon: "󰇙" Behavior on scale { NumberAnimation { diff --git a/quickshell/testing/ControlDriver.qml b/quickshell/testing/ControlDriver.qml index 622ce49..49b11c6 100644 --- a/quickshell/testing/ControlDriver.qml +++ b/quickshell/testing/ControlDriver.qml @@ -35,6 +35,19 @@ Item { property bool muted: false } } + property var streamNode: QtObject { + property string name: "fixture-player" + property string description: "" + property bool isSink: false + property bool isStream: true + property var properties: ({ + "application.name": "Fixture player" + }) + property QtObject audio: QtObject { + property real volume: 0.5 + property bool muted: false + } + } property QtObject audioBackend: QtObject { property bool ready: true property var defaultAudioSink: root.audioNode @@ -42,7 +55,7 @@ Item { property var preferredDefaultAudioSink: root.audioNode property var preferredDefaultAudioSource: root.audioInput property QtObject nodes: QtObject { - property var values: [root.audioNode, root.audioInput] + property var values: [root.audioNode, root.audioInput, root.streamNode] } } property QtObject wifi: QtObject { @@ -139,6 +152,7 @@ Item { NetworkService.backend = root.networkBackend; BluetoothService.backend = root.btBackend; SystemService.helper = "testing/recording_system.py"; + CaffeineService.command = ["sleep", "infinity"]; SystemService.refresh(); return true; } @@ -158,6 +172,32 @@ Item { input.mouseClick(item, item.width * .75, item.height / 2); return true; } + function rightClick(name: string): bool { + const item = root.child(name); + if (!item || !item.enabled) + return false; + root.reveal(item); + // Near the corner: clear of sliders and buttons on every layout. + input.mouseClick(item, 14, 14, Qt.RightButton); + return true; + } + // Presses an item and drags it by (dx, dy) in steps. + function drag(name: string, dx: real, dy: real): bool { + const item = root.child(name); + if (!item || !item.visible) + return false; + root.reveal(item); + // Window coordinates, like a real pointer: the item may move or grow. + const content = ShellState.controlCenterWindow.contentItem; + const p = item.mapToItem(content, item.width / 2, item.height / 2); + input.mousePress(content, p.x, p.y); + for (let i = 1; i <= 8; ++i) + input.mouseMove(content, p.x + dx * i / 8, p.y + dy * i / 8, 20); + input.wait(60); + input.mouseRelease(content, p.x + dx, p.y + dy); + input.wait(60); + return true; + } function clickSystem(): bool { const pill = ShellState.systemPills.find(p => p.barScreen === ScreenService.active) || ShellState.systemPills[0]; if (!pill) @@ -226,6 +266,14 @@ Item { muted: AudioService.sink && AudioService.sink.audio ? AudioService.sink.audio.muted : false, microphone: AudioService.source && AudioService.source.audio ? AudioService.source.audio.muted : false, scan: fixtureWifi.scannerEnabled, + editing: ShellState.controlCenterWindow.editing, + tiles: ShellState.controlCenterWindow.plan.items, + cellWidth: ShellState.controlCenterWindow.cellWidth, + extras: ShellState.controlCenterWindow.extras, + streamVolume: root.streamNode.audio.volume, + streamMuted: root.streamNode.audio.muted, + caffeine: CaffeineService.active, + caffeineRunning: CaffeineService.running, active: ScreenService.active.name, screens: Quickshell.screens.map(s => s.name), x: ShellState.controlCenterWindow.panelScreenX, diff --git a/scripts/validate b/scripts/validate index b7147b2..207c08b 100755 --- a/scripts/validate +++ b/scripts/validate @@ -6,6 +6,7 @@ node "$project_dir/tests/polish.test.cjs" node "$project_dir/tests/dock.test.cjs" node "$project_dir/tests/launcher.test.cjs" node "$project_dir/tests/widgets.test.cjs" +node "$project_dir/tests/controlcenter.test.cjs" python3 "$project_dir/tests/providers_test.py" python3 "$project_dir/tests/system_providers_test.py" python3 "$project_dir/tests/metrics_test.py" diff --git a/tests/config.test.cjs b/tests/config.test.cjs index 5859ad9..a28bb4c 100644 --- a/tests/config.test.cjs +++ b/tests/config.test.cjs @@ -70,11 +70,16 @@ console.log('Phase 5 preference merging, validation and immutable bar editing/re assert.throws(() => api.update(phase5, 'bar.modules', {}), /must be an array/); assert.equal(api.update(phase5, 'bar.modules', [{id:'nowPlaying',position:'right',enabled:true}]).bar.modules[0].id, 'nowPlaying'); const phase7=api.load(defaults,{schemaVersion:3,controlCenter:{modules:[]},dock:{pinnedApps:['keep.desktop']},future:{keep:true}}); -assert.equal(phase7.controlCenter.version,1);assert(phase7.controlCenter.modules.length>0);assert.equal(phase7.dock.pinnedApps[0],'keep.desktop');assert(phase7.future.keep); +assert.equal(phase7.controlCenter.version,2);assert(phase7.controlCenter.modules.length>0);assert.equal(phase7.dock.pinnedApps[0],'keep.desktop');assert(phase7.future.keep); 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'}]}}); -assert.equal(customCenter.controlCenter.modules[0].metadata,'preserved');assert.equal(customCenter.controlCenter.modules.length,1); -for(const controlCenter of [{version:2},{version:1,width:100},{version:1,modules:[{id:'audio',enabled:true},{id:'audio',enabled:false}]}])assert.throws(()=>api.load(defaults,{controlCenter})); +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})); +// 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; +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(api.load(defaults,{controlCenter:{version:2,modules:[]}}).controlCenter.modules.length,0); 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.'); diff --git a/tests/controlcenter.test.cjs b/tests/controlcenter.test.cjs new file mode 100644 index 0000000..2bcf56e --- /dev/null +++ b/tests/controlcenter.test.cjs @@ -0,0 +1,42 @@ +const assert = require('assert'), fs = require('fs'), path = require('path'), vm = require('vm'); +const api = vm.createContext({}); +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(' '); +// First fit in list order; small tiles backfill gaps beside larger ones. +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}]); +assert.equal(ids(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); +plan = api.pack([{id: 'a', w: 3, h: 1}, {id: 'b', w: 2, h: 1}, {id: 'c', w: 1, h: 1}]); +assert.equal(ids(plan), 'a@0,0:3x1 b@0,1:2x1 c@3,0:1x1'); +// Sizes clamp to 1..4 cells. +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'); +assert.equal(api.pack([]).rows, 0); +// Hit testing covers spanned cells. +plan = api.pack([{id: 'wifi', w: 2, h: 1}, {id: 'media', w: 2, h: 2}, {id: 'bt', w: 1, h: 1}]); +assert.equal(api.at(plan, 3, 1).id, 'media'); +assert.equal(api.at(plan, 3, 2), null); +// Dragging onto a tile takes its place in either direction; onto itself is a no-op. +const order = ['wifi', 'media', 'bt']; +assert.equal(api.reorder(order, plan, 'bt', 0, 0).join(), 'bt,wifi,media'); +assert.equal(api.reorder(order, plan, 'wifi', 0, 1).join(), 'media,bt,wifi'); +assert.equal(api.reorder(order, plan, 'wifi', 1, 0).join(), 'wifi,media,bt'); +// Empty space puts it after the last tile before that cell. +assert.equal(api.reorder(order, plan, 'wifi', 1, 1).join(), 'media,bt,wifi'); +assert.equal(api.reorder(order, plan, 'bt', 0, 5).join(), 'wifi,media,bt'); +assert.equal(api.reorder(order, plan, 'nope', 0, 0).join(), order.join()); +// Resizing rounds to whole cells within 1..4. +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: 1, h: 1}, -500, -500, 80, 68, 10)), '{"w":1,"h":1}'); +// 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}]); +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(g.height, 3 * 78 - 10); +g = api.geometry(plan, 80, 68, 10, {out: 100}); +assert.equal(g.tiles.out.h, 68 + 110); +assert.equal(g.tiles.media.y, 0); +assert.equal(g.tiles.a.y, 78 + 110); +assert.equal(g.tiles.b.y, 156 + 110); +assert.equal(g.height, 3 * 78 - 10 + 110); +console.log('Control Center grid packing, hit testing, reordering, resizing and expansion geometry passed.'); diff --git a/tests/controlcenter_runtime.py b/tests/controlcenter_runtime.py index 98892ac..9bd7470 100644 --- a/tests/controlcenter_runtime.py +++ b/tests/controlcenter_runtime.py @@ -41,6 +41,15 @@ with tempfile.TemporaryDirectory(prefix='glassmxrph-controls-') as tmp: assert ipc('controlTest','click','volumeMute');wait(lambda:state()['muted'],'mute click') assert ipc('controlTest','slider','volumeSlider');wait(lambda:state()['volume']>.6,'volume slider') assert ipc('controlTest','click','microphoneMute');wait(lambda:state()['microphone'],'microphone click') + # Per-app volume: right click extends Sound with the app streams. + assert ipc('controlTest','rightClick','outputTile');wait(lambda:state()['extras'].get('output',0)>0,'Sound extends') + time.sleep(.4) + t=next(i for i in state()['tiles'] if i['id']=='input');assert t['row']>0 + assert ipc('controlTest','slider','appSlider-Fixture player');wait(lambda:state()['streamVolume']>.6,'app volume slider') + assert ipc('controlTest','click','appMute-Fixture player');wait(lambda:state()['streamMuted'],'app mute') + assert ipc('controlTest','rightClick','outputTile');wait(lambda:not state()['extras'].get('output',0),'Sound folds back') + assert ipc('controlTest','click','caffeineToggle');wait(lambda:state()['caffeine'] and state()['caffeineRunning'],'Caffeine on') + assert ipc('controlTest','click','caffeineToggle');wait(lambda:not state()['caffeine'] and not state()['caffeineRunning'],'Caffeine off') assert ipc('controlTest','click','wifiToggle');wait(lambda:not state()['wifi'],'Wi-Fi toggle') assert ipc('controlTest','click','bluetoothToggle');wait(lambda:not state()['bluetooth'],'Bluetooth toggle') assert ipc('controlTest','click','bluetoothToggle') @@ -84,12 +93,38 @@ with tempfile.TemporaryDirectory(prefix='glassmxrph-controls-') as tmp: ipc('controlcenter','close');wait(lambda:not state()['windowVisible'],'reduced motion close') pref('animation.reducedMotion',False) ipc('controlcenter','open');ipc('launcher','open');wait(lambda:not ipc('controlcenter','status')['opened'],'launcher exclusivity');ipc('launcher','close') + # Edit mode: drag to reorder, resize from the handle, remove and add, Escape leaves it. + ipc('controlcenter','open');wait(lambda:state()['windowVisible'],'reopen for editing');time.sleep(.4) + assert ipc('controlTest','click','controlEdit');wait(lambda:state()['editing'],'edit mode') + 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 + bt,wifi=tiles['bluetooth'],tiles['wifi'] + 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']] + wait(lambda:ids().index('bluetooth')