diff options
Diffstat (limited to 'bar')
| -rw-r--r-- | bar/Bar.qml | 3 | ||||
| -rw-r--r-- | bar/Mpris.qml | 57 | ||||
| -rw-r--r-- | bar/Workspace.qml | 18 |
3 files changed, 71 insertions, 7 deletions
diff --git a/bar/Bar.qml b/bar/Bar.qml index 4bb56e5..8bef666 100644 --- a/bar/Bar.qml +++ b/bar/Bar.qml @@ -43,16 +43,19 @@ Scope { id: leftRow Layout.preferredWidth: 1 Layout.fillWidth: true + spacing: 40 // Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter Workspace { id: workspace Layout.preferredWidth: 3 + Layout.fillHeight: true Layout.fillWidth: true } Mpris { id: mpris Layout.fillWidth: true + Layout.fillHeight: true Layout.preferredWidth: 1 } } diff --git a/bar/Mpris.qml b/bar/Mpris.qml new file mode 100644 index 0000000..880456b --- /dev/null +++ b/bar/Mpris.qml @@ -0,0 +1,57 @@ +import QtQuick.Layouts +import QtQuick +import Quickshell +import Quickshell.Services.Mpris +import qs.services + +// import Quickshell.Utils + +Item { + id: root + implicitWidth: parent.width + height: Bar.height + readonly property MprisPlayer activePlayer: SMpris.activePlayer + readonly property string cleanedTitle: cleanMusicTitle(activePlayer?.trackTitle) || qsTr("No media") + // length broken (https://github.com/quickshell-mirror/quickshell/issues/109) + readonly property string position: friendlyTimeForSeconds(activePlayer?.position) || "0:00" + readonly property string length: friendlyTimeForSeconds(activePlayer?.length) || "0:00" + readonly property string progress: activePlayer.positionSupported && position != length ? position + "/" + length : activePlayer.positionSupported && !activePlayer.lengthSupported ? !activePlayer.positionSupported && activePlayer.lengthSupported ? "" : position : activePlayer.lengthSupported ? length : "" + readonly property string state: activePlayer?.isPlaying ? "Playing" : "Paused" + + function cleanMusicTitle(title: string): string { + if (!title) + return ""; + title = title.replace(/\s*\([^)]*\)/g, " "); // Round brackets + title = title.replace(/\s*\[[^\]]*\]/g, " "); // Square brackets + title = title.replace(/\s*\{[^\}]*\}/g, " "); // Curly brackets + title = title.replace(/\s*【[^】]*】/g, " "); // Touhou + title = title.replace(/\s*《[^》]*》/g, " "); + title = title.replace(/\s*「[^」]*」/g, " "); + title = title.replace(/\s*『[^』]*』/g, " "); + + return title.trim(); + } + + function friendlyTimeForSeconds(seconds) { + if (isNaN(seconds) || seconds < 0) + return "0:00"; + seconds = Math.floor(seconds); + const h = Math.floor(seconds / 3600); + const m = Math.floor((seconds % 3600) / 60); + const s = seconds % 60; + if (h > 0) { + return `${h}:${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}`; + } else { + return `${m}:${s.toString().padStart(2, '0')}`; + } + } + + Text { + anchors.centerIn: parent + text: root.state + " " + root.cleanedTitle + " [" + root.progress + "]" + } + // hover + // Text { + // text: root.activePlayer.trackTitle + " by " + root.activePlayer.trackArtist + " - " + root.activePlayer.trackAlbum + root.activePlayer.position + "/" + root.activePlayer.length + // } +} diff --git a/bar/Workspace.qml b/bar/Workspace.qml index fd9d521..de63eba 100644 --- a/bar/Workspace.qml +++ b/bar/Workspace.qml @@ -5,29 +5,29 @@ import qs.services import qs.config Item { - Layout.fillHeight: true + id: root property list<bool> workspaceOccupied: [] function updateWorkspaceOccupied() { // workspaceOccupied = Array.from({ length: Config.options.bar.workspaces.shown }, (_, i) => { - // return Hyprland.workspaces.values.some(ws => ws.id === workspaceGroup * Config.options.bar.workspaces.shown + i + 1); + // return SHyprland.workspaces.values.some(ws => ws.id === workspaceGroup * Config.options.bar.workspaces.shown + i + 1); // }) workspaceOccupied = Array.from({ length: Bar.workspaces }, (_, i) => { - return Hyprland.workspaces.values.some(ws => ws.id === (i + 1)); + return SHyprland.workspaces.values.some(ws => ws.id === (i + 1)); }); } function isActive(index: int): bool { - Hyprland.focusedWorkspace.id.toString() == (index + 1).toString(); + SHyprland.focusedWorkspace.id.toString() == (index + 1).toString(); } function isOccupied(index: int): bool { return workspaceOccupied[index] === true; } Connections { - target: Hyprland.workspaces + target: SHyprland.workspaces function onValuesChanged() { updateWorkspaceOccupied(); } @@ -36,14 +36,18 @@ Item { Component.onCompleted: updateWorkspaceOccupied() RowLayout { - anchors.fill: parent + id: layout + implicitWidth: parent.width + height: Bar.height + spacing: 0 + Repeater { model: Bar.workspaces Rectangle { Text { - text: Hyprland.focusedWorkspace?.id.toString() == (index + 1).toString() + text: SHyprland.focusedWorkspace?.id.toString() == (index + 1).toString() // text: isActive(index) } implicitWidth: 10 |
