Lay the Control Center out as a resizable, editable grid
Modules are tiles on a 4-column grid, each 1x1 to 4x4 and adapting its layout to its size. Edit Controls in the panel reorders by dragging, resizes from a corner handle, removes with a badge and adds from a tray. Connectivity splits into Wi-Fi, Bluetooth and Network tiles and Audio into Sound and Microphone; right-clicking Sound extends it with output devices and a volume slider per app. Adds a Caffeine tile. Config version 2 migrates existing layouts in place. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0dcf37346c
commit
11bdc4c751
32 files changed
+2147
-355
No files matched your search
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user