Initial commit of the Quickshell desktop suite: bar, dock, launcher, settings, Control Center, dashboard, OSD, lock screen, desktop widgets, plugin host with the vendored Noctalia/Omarchy compatibility layer, helpers, packaging, tests and phase documentation. Includes the optimization work so far: usage widgets and dashboard gauges no longer animate continuously, desktop widgets pause while covered, system controls stop flickering on background polls, dock app matching uses an indexed catalog, and workspace ghosts are created only for occupied slots. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
115 lines
4.0 KiB
QML
115 lines
4.0 KiB
QML
pragma Singleton
|
|
import QtQuick
|
|
import Quickshell
|
|
import Quickshell.Io
|
|
import Quickshell.Services.Mpris
|
|
|
|
Singleton {
|
|
id: root
|
|
readonly property var players: Mpris.players.values
|
|
property string selected: ""
|
|
readonly property string preferred: ConfigService.ready ? ConfigService.data.media.preferredPlayer : "automatic"
|
|
readonly property var player: players.find(p => p.dbusName === selected) || players.find(p => p.dbusName === preferred || p.desktopEntry === preferred) || players.find(p => p.isPlaying) || players[0] || null
|
|
readonly property bool playing: !!player && player.isPlaying
|
|
readonly property string title: player ? (player.trackTitle || "Untitled track") : "Nothing playing"
|
|
readonly property string artist: player ? player.trackArtist : "Open a music or video player"
|
|
readonly property string album: player ? player.trackAlbum : ""
|
|
readonly property string artwork: player ? player.trackArtUrl : ""
|
|
readonly property real length: player && player.lengthSupported ? Math.max(0, player.length) : 0
|
|
property real position: 0
|
|
property int progressConsumers: 0
|
|
readonly property bool seekable: !!player && player.canControl && player.canSeek && player.positionSupported && length > 0
|
|
onPreferredChanged: selected = ""
|
|
onPlayerChanged: refreshPosition()
|
|
onPlayingChanged: refreshPosition()
|
|
onLengthChanged: refreshPosition()
|
|
function refreshPosition() {
|
|
position = player && player.positionSupported ? Math.max(0, Math.min(length || Infinity, player.position)) : 0;
|
|
}
|
|
function choose(name) {
|
|
if (name && !players.some(p => p.dbusName === name))
|
|
return false;
|
|
selected = name;
|
|
return true;
|
|
}
|
|
function toggle() {
|
|
if (!player || !player.canControl || !player.canTogglePlaying)
|
|
return false;
|
|
player.togglePlaying();
|
|
return true;
|
|
}
|
|
function previous() {
|
|
if (!player || !player.canControl || !player.canGoPrevious)
|
|
return false;
|
|
player.previous();
|
|
return true;
|
|
}
|
|
function next() {
|
|
if (!player || !player.canControl || !player.canGoNext)
|
|
return false;
|
|
player.next();
|
|
return true;
|
|
}
|
|
function seek(value) {
|
|
if (!seekable || !Number.isFinite(value))
|
|
return false;
|
|
player.position = Math.max(0, Math.min(length, value));
|
|
refreshPosition();
|
|
return true;
|
|
}
|
|
function time(value) {
|
|
const s = Math.max(0, Math.floor(value));
|
|
return Math.floor(s / 60) + ":" + String(s % 60).padStart(2, "0");
|
|
}
|
|
Timer {
|
|
interval: 500
|
|
repeat: true
|
|
running: root.playing && root.progressConsumers > 0
|
|
onTriggered: root.refreshPosition()
|
|
}
|
|
Connections {
|
|
target: root.player
|
|
function onPositionChanged() {
|
|
root.refreshPosition();
|
|
}
|
|
function onTrackChanged() {
|
|
root.refreshPosition();
|
|
}
|
|
}
|
|
IpcHandler {
|
|
target: "media"
|
|
function status(): string {
|
|
return JSON.stringify({
|
|
players: root.players.map(p => ({
|
|
id: p.dbusName,
|
|
name: p.identity
|
|
})),
|
|
selected: root.player ? root.player.dbusName : "",
|
|
title: root.title,
|
|
artist: root.artist,
|
|
album: root.album,
|
|
artwork: root.artwork,
|
|
playing: root.playing,
|
|
position: root.position,
|
|
length: root.length,
|
|
seekable: root.seekable
|
|
});
|
|
}
|
|
function select(name: string): bool {
|
|
return root.choose(name);
|
|
}
|
|
function toggle(): bool {
|
|
return root.toggle();
|
|
}
|
|
function next(): bool {
|
|
return root.next();
|
|
}
|
|
function previous(): bool {
|
|
return root.previous();
|
|
}
|
|
function seek(seconds: real): bool {
|
|
return root.seek(seconds);
|
|
}
|
|
}
|
|
}
|