Settings → Notch switches it on. The bar becomes left and right islands with a notch at the top centre. Super+C, Super+X and a click on the notch open a three-column panel: dashboard pages on the left (Media, Performance, Calendar; the wheel switches them), the Control Center tiles and weather in the middle, and notifications on the right. The Performance card opens the full "Your computer" view. The launcher drops out of the notch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
316 lines
12 KiB
QML
316 lines
12 KiB
QML
pragma ComponentBehavior: Bound
|
||
import QtQuick
|
||
import QtQuick.Controls
|
||
import QtQuick.Layouts
|
||
import Quickshell
|
||
import Quickshell.Io
|
||
import Quickshell.Wayland
|
||
import "../components"
|
||
import "../services"
|
||
import "../core"
|
||
import "../theme"
|
||
|
||
// macOS-style level HUD: a compact glass capsule for volume, microphone and
|
||
// brightness. It follows changes from any source (keys, wpctl, the bar), can be
|
||
// dragged, and stays while hovered. The surface is sized to the capsule so
|
||
// compositor glass shapes its edges to it.
|
||
// qmllint disable uncreatable-type
|
||
PanelWindow {
|
||
id: root
|
||
readonly property var options: ConfigService.ready ? ConfigService.data.osd : ({
|
||
enabled: false,
|
||
position: "top-right",
|
||
timeout: 1600,
|
||
step: 5
|
||
})
|
||
property var targetScreen: null
|
||
screen: ScreenService.current(targetScreen)
|
||
property bool shown: false
|
||
property string kind: "volume"
|
||
readonly property var node: kind === "microphone" ? AudioService.source : AudioService.sink
|
||
readonly property var brightness: SystemService.state.brightness || ({
|
||
available: false
|
||
})
|
||
readonly property bool muted: kind !== "brightness" && !!node && !!node.audio && node.audio.muted
|
||
readonly property real level: kind === "brightness" ? (brightness.value || 0) / 100 : node && node.audio ? node.audio.volume : 0
|
||
readonly property string title: kind === "brightness" ? "Display" : kind === "microphone" ? "Microphone" : "Sound"
|
||
readonly property string detail: kind === "brightness" ? (brightness.device || "Brightness") : node ? (node.description || node.name || "") : ""
|
||
readonly property string glyph: kind === "brightness" ? "" : kind === "microphone" ? (muted ? "" : "") : muted || level === 0 ? "" : level < 0.34 ? "" : level < 0.67 ? "" : ""
|
||
|
||
// Top positions drop out of the bar as a drawer; bottom-center floats.
|
||
readonly property bool attached: options.position !== "bottom-center"
|
||
anchors {
|
||
top: root.attached
|
||
bottom: !root.attached
|
||
right: root.options.position === "top-right"
|
||
}
|
||
// Margins is present at runtime but unresolved in 0.3.1 qmltypes.
|
||
// qmllint disable unqualified unresolved-type
|
||
margins {
|
||
right: BarDrawers.margin + BarDrawers.radius
|
||
bottom: 96
|
||
}
|
||
// qmllint enable unqualified unresolved-type
|
||
implicitWidth: Math.round(card.width)
|
||
implicitHeight: (attached ? BarDrawers.bottom : 0) + 74
|
||
// Only the capsule takes input; the strip over the bar passes through.
|
||
mask: Region {
|
||
item: card.body
|
||
}
|
||
visible: shown || card.shown
|
||
color: Theme.transparent
|
||
exclusionMode: ExclusionMode.Ignore
|
||
WlrLayershell.layer: WlrLayer.Overlay
|
||
WlrLayershell.namespace: "glassMxrph-osd"
|
||
WlrLayershell.keyboardFocus: WlrKeyboardFocus.None
|
||
Component.onCompleted: ShellState.osdWindow = root
|
||
Component.onDestruction: ShellState.osdWindow = null
|
||
|
||
// Initial values and default-device switches are not user changes.
|
||
property bool armed: false
|
||
function rearm() {
|
||
armed = false;
|
||
armTimer.restart();
|
||
}
|
||
Timer {
|
||
id: armTimer
|
||
running: true
|
||
interval: 1500
|
||
onTriggered: root.armed = true
|
||
}
|
||
function show(next) {
|
||
// Control Center already shows these levels.
|
||
if (!options.enabled || !armed || ShellState.controlCenterOpen || ShellState.notchOpen)
|
||
return;
|
||
if (!shown)
|
||
targetScreen = ScreenService.active;
|
||
kind = next;
|
||
shown = true;
|
||
hideTimer.restart();
|
||
}
|
||
Timer {
|
||
id: hideTimer
|
||
interval: root.options.timeout
|
||
onTriggered: {
|
||
if (hover.hovered || bar.pressed)
|
||
restart();
|
||
else
|
||
root.shown = false;
|
||
}
|
||
}
|
||
Connections {
|
||
target: AudioService
|
||
function onSinkChanged() {
|
||
root.rearm();
|
||
}
|
||
function onSourceChanged() {
|
||
root.rearm();
|
||
}
|
||
}
|
||
Connections {
|
||
target: AudioService.sink ? AudioService.sink.audio : null
|
||
function onVolumeChanged() {
|
||
root.show("volume");
|
||
}
|
||
function onMutedChanged() {
|
||
root.show("volume");
|
||
}
|
||
}
|
||
Connections {
|
||
target: AudioService.source ? AudioService.source.audio : null
|
||
function onMutedChanged() {
|
||
root.show("microphone");
|
||
}
|
||
}
|
||
property var lastBrightness: undefined
|
||
Connections {
|
||
target: SystemService
|
||
function onStateChanged() {
|
||
const value = SystemService.state.brightness ? SystemService.state.brightness.value : undefined;
|
||
if (value !== undefined && root.lastBrightness !== undefined && value !== root.lastBrightness)
|
||
root.show("brightness");
|
||
root.lastBrightness = value;
|
||
}
|
||
}
|
||
|
||
function step(direction) {
|
||
return direction * root.options.step / 100;
|
||
}
|
||
function changeVolume(input, direction) {
|
||
const target = input ? AudioService.source : AudioService.sink;
|
||
if (target && target.audio) {
|
||
if (direction > 0)
|
||
target.audio.muted = false;
|
||
AudioService.volume(input, target.audio.volume + step(direction));
|
||
}
|
||
show(input ? "microphone" : "volume");
|
||
}
|
||
function changeBrightness(direction) {
|
||
if (brightness.available)
|
||
SystemService.action("brightness", Math.max(1, Math.min(100, Math.round((brightness.value || 0) + step(direction) * 100))), false);
|
||
show("brightness");
|
||
}
|
||
|
||
BarDrawer {
|
||
id: card
|
||
objectName: "osdSurface"
|
||
y: root.attached ? BarDrawers.bottom : 0
|
||
open: root.shown
|
||
attached: root.attached
|
||
style: root.options.animation || "slide"
|
||
contentWidth: 320
|
||
contentHeight: 74
|
||
drawerId: "osd"
|
||
screenName: root.screen ? root.screen.name : ""
|
||
screenX: root.options.position === "top-right" ? (root.screen ? root.screen.width : 1920) - BarDrawers.margin - BarDrawers.radius - width : ((root.screen ? root.screen.width : 1920) - width) / 2
|
||
HoverHandler {
|
||
id: hover
|
||
}
|
||
RowLayout {
|
||
anchors.fill: parent
|
||
anchors.leftMargin: 14
|
||
anchors.rightMargin: 18
|
||
spacing: 12
|
||
GlassIcon {
|
||
size: 42
|
||
radius: 21
|
||
glyph: root.glyph
|
||
fallback: root.kind === "brightness" ? "☀" : root.muted ? "×" : "♪"
|
||
glyphSize: 20
|
||
active: root.muted
|
||
color: root.muted ? Qt.alpha(Theme.urgent, 0.85) : Theme.surfaceVariant
|
||
glyphColor: root.muted ? Theme.surface : Theme.text
|
||
}
|
||
ColumnLayout {
|
||
Layout.fillWidth: true
|
||
spacing: 4
|
||
RowLayout {
|
||
Layout.fillWidth: true
|
||
spacing: 8
|
||
ColumnLayout {
|
||
Layout.fillWidth: true
|
||
spacing: 0
|
||
Text {
|
||
text: root.title
|
||
color: Theme.text
|
||
font.pixelSize: 13
|
||
font.weight: Font.DemiBold
|
||
}
|
||
Text {
|
||
text: root.detail
|
||
visible: text !== ""
|
||
color: Theme.textSecondary
|
||
font.pixelSize: 10
|
||
elide: Text.ElideRight
|
||
Layout.fillWidth: true
|
||
}
|
||
}
|
||
Text {
|
||
objectName: "osdValue"
|
||
text: root.muted ? "Muted" : Math.round(root.level * 100) + "%"
|
||
color: root.muted ? Theme.urgent : Theme.textSecondary
|
||
font.pixelSize: 12
|
||
font.features: {
|
||
"tnum": 1
|
||
}
|
||
}
|
||
}
|
||
// Thin level bar; dragging adjusts the level directly.
|
||
Slider {
|
||
id: bar
|
||
objectName: "osdSlider"
|
||
Layout.fillWidth: true
|
||
implicitHeight: 14
|
||
padding: 0
|
||
from: 0
|
||
to: 1
|
||
value: root.level
|
||
enabled: root.kind !== "brightness" || !!root.brightness.available
|
||
onMoved: {
|
||
if (root.kind !== "brightness")
|
||
AudioService.volume(root.kind === "microphone", value);
|
||
hideTimer.restart();
|
||
}
|
||
onPressedChanged: if (!pressed && root.kind === "brightness") {
|
||
SystemService.action("brightness", Math.max(1, Math.round(value * 100)), false);
|
||
value = Qt.binding(() => root.level);
|
||
}
|
||
background: Rectangle {
|
||
y: bar.availableHeight / 2 - height / 2
|
||
width: bar.availableWidth
|
||
height: 6
|
||
radius: 3
|
||
color: Theme.surfaceVariant
|
||
border.width: 1
|
||
border.color: Theme.hairline
|
||
Rectangle {
|
||
width: bar.visualPosition * parent.width
|
||
height: parent.height
|
||
radius: 3
|
||
color: root.muted ? Qt.alpha(Theme.text, 0.35) : Theme.text
|
||
Behavior on width {
|
||
enabled: !bar.pressed
|
||
NumberAnimation {
|
||
duration: Theme.duration / 2
|
||
easing.type: Easing.OutCubic
|
||
}
|
||
}
|
||
}
|
||
}
|
||
handle: Rectangle {
|
||
x: bar.visualPosition * (bar.availableWidth - width)
|
||
y: bar.availableHeight / 2 - height / 2
|
||
width: 14
|
||
height: 14
|
||
radius: 7
|
||
color: Theme.text
|
||
opacity: hover.hovered || bar.pressed ? 1 : 0
|
||
Behavior on opacity {
|
||
NumberAnimation {
|
||
duration: Theme.duration / 2
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
IpcHandler {
|
||
target: "osd"
|
||
function volumeUp(): void {
|
||
root.changeVolume(false, 1);
|
||
}
|
||
function volumeDown(): void {
|
||
root.changeVolume(false, -1);
|
||
}
|
||
function mute(): void {
|
||
AudioService.mute(false);
|
||
root.show("volume");
|
||
}
|
||
function micMute(): void {
|
||
AudioService.mute(true);
|
||
root.show("microphone");
|
||
}
|
||
function brightnessUp(): void {
|
||
root.changeBrightness(1);
|
||
}
|
||
function brightnessDown(): void {
|
||
root.changeBrightness(-1);
|
||
}
|
||
// Not "show": that name collides with the `quickshell ipc show` subcommand.
|
||
function open(kind: string): void {
|
||
root.show(["volume", "microphone", "brightness"].includes(kind) ? kind : "volume");
|
||
}
|
||
function status(): string {
|
||
return JSON.stringify({
|
||
shown: root.shown,
|
||
kind: root.kind,
|
||
level: root.level,
|
||
muted: root.muted,
|
||
screen: root.screen ? root.screen.name : ""
|
||
});
|
||
}
|
||
}
|
||
}
|