Files
glassMxrph/quickshell/controlcenter/CCSlider.qml
T
mxandClaude Opus 5.5 11bdc4c751 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>
2026-10-17 20:52:14 +02:00

218 lines
7.1 KiB
QML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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
}
}