From 34ddab9d5452da695a3cb1d61f8b754082fc81ee Mon Sep 17 00:00:00 2001 From: nico Date: Wed, 16 Sep 2026 22:52:21 +0200 Subject: [PATCH] Show now-playing track on the unfocused monitor, fix clock tooltip clipping Bar.qml: added an MPRIS now-playing display (Quickshell.Services.Mpris). The bar's center already showed nothing on whichever monitor isn't focused (only the focused one gets the active window's title) - that space now shows the currently playing track (title in the main text color/bold, artist in blue, separated by an accent-colored dash) instead when a player is active. Long text scrolls as a marquee rather than getting truncated, since the bar is a fixed-size layer surface and can't just let text overflow. Positioning defaults to centered in the whole bar, only shifting toward the gap between the pill groups if bar-centered would actually overlap one of them (their widths aren't equal). Also fixed the clock tooltip clipping: it had a fixed 230px width, too narrow for the German long-form date line ("Donnerstag, 11. September 2026"). Now grows to fit like its height already did. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01Dujsk9jYfxUVLtb5B8eC94 --- quickshell/default/Bar.qml | 79 +++++++++++++++++++++++++++++++++----- 1 file changed, 70 insertions(+), 9 deletions(-) diff --git a/quickshell/default/Bar.qml b/quickshell/default/Bar.qml index e8c547a..d0a7db1 100644 --- a/quickshell/default/Bar.qml +++ b/quickshell/default/Bar.qml @@ -5,6 +5,7 @@ import Quickshell.Io import Quickshell.Wayland import Quickshell.Hyprland import Quickshell.Services.SystemTray +import Quickshell.Services.Mpris Variants { id: root @@ -71,6 +72,17 @@ Variants { readonly property var activeToplevel: Hyprland.activeToplevel readonly property string titleText: (activeToplevel && activeToplevel.monitor && activeToplevel.monitor.name === modelData.name) ? activeToplevel.title : "" + // Prefer whichever MPRIS player (Spotify, a browser tab playing + // YT Music, etc.) is actually playing; fall back to the first one + // so a paused track still shows. + readonly property var activePlayer: { + var players = Mpris.players.values + for (var i = 0; i < players.length; i++) { + if (players[i].isPlaying) return players[i] + } + return players.length > 0 ? players[0] : null + } + Loader { active: modelData === Quickshell.screens[0] sourceComponent: IpcHandler { @@ -356,15 +368,64 @@ Variants { } // ================= CENTER ================= - Text { + // The focused monitor shows the active window's title; other + // monitors have nothing better to show there, so use that space + // for the currently playing track instead. + Item { + id: centerContainer visible: !bar.taskbarMode - anchors.centerIn: parent - width: Math.min(implicitWidth, 500) - elide: Text.ElideRight - text: bar.titleText - font.family: "JetBrainsMono Nerd Font" - font.pixelSize: 13 - color: "#c0caf5" + // Center in the whole bar by default; only shift off that if it + // would actually overlap the left or right pill group (their + // widths aren't equal, so bar-centering isn't always safe). + readonly property real barCenteredX: (bar.width - width) / 2 + x: Math.min(Math.max(centerContainer.barCenteredX, leftRow.x + leftRow.width), rightRow.x - width) + anchors.verticalCenter: parent.verticalCenter + width: Math.min(centerRow.implicitWidth, 500) + height: centerRow.implicitHeight + clip: true + + readonly property bool isFocusedMonitor: Hyprland.focusedMonitor !== null && Hyprland.focusedMonitor.name === bar.modelData.name + readonly property bool showingMedia: !centerContainer.isFocusedMonitor && bar.activePlayer !== null && bar.activePlayer.trackTitle !== "" + readonly property string mainText: centerContainer.isFocusedMonitor ? bar.titleText : (centerContainer.showingMedia ? bar.activePlayer.trackTitle : "") + readonly property string artistText: centerContainer.showingMedia ? (bar.activePlayer.trackArtist || "") : "" + + Row { + id: centerRow + spacing: 6 + + Text { + text: centerContainer.mainText + font.family: "JetBrainsMono Nerd Font" + font.pixelSize: 13 + font.bold: centerContainer.showingMedia + color: "#c0caf5" + } + Text { + visible: centerContainer.artistText !== "" + text: "—" + font.family: "JetBrainsMono Nerd Font" + font.pixelSize: 13 + color: "#1793d1" + } + Text { + visible: centerContainer.artistText !== "" + text: centerContainer.artistText + font.family: "JetBrainsMono Nerd Font" + font.pixelSize: 13 + color: "#7aa2f7" + } + } + + NumberAnimation { + target: centerRow + property: "x" + running: centerRow.implicitWidth > centerContainer.width + loops: Animation.Infinite + from: centerContainer.width + to: -centerRow.implicitWidth + duration: Math.max(4000, centerRow.implicitWidth * 20) + onRunningChanged: if (!running) centerRow.x = 0 + } } // ================= TASKBAR (toggled via Arch logo) ================= @@ -1146,7 +1207,7 @@ Variants { screen: bar.modelData anchors { top: true; right: true } margins { top: 34; right: bar.width - (rightRow.x + clockPill.x + clockPill.width) } - implicitWidth: 230 + implicitWidth: Math.max(230, clockTooltipCol.implicitWidth + 20) implicitHeight: clockTooltipCol.implicitHeight + 20 color: "transparent" WlrLayershell.namespace: "clock-tooltip"