pragma ComponentBehavior: Bound import QtQuick import Quickshell import Quickshell.Hyprland import Quickshell.Widgets import "../../components" import "../../core" import "../../services" import "../../theme" // Programs on the focused workspace, left to right. Hover one for a live // preview, click to focus it, middle-click to close it. GlassPill { id: root objectName: "activeWindowPill" property var barScreen // Layout entry; options come from the cog in Settings → Bar. property var entry: ({ id: "activeWindow" }) readonly property string transition: ModuleRegistry.option(entry, "transition") readonly property string labels: ModuleRegistry.option(entry, "labels") readonly property string collapse: ModuleRegistry.option(entry, "collapse") readonly property int labelWidth: ({ short: 90, medium: 150, long: 230 })[ModuleRegistry.option(entry, "labelWidth")] || 150 readonly property bool previews: ModuleRegistry.option(entry, "preview") !== "off" readonly property int workspace: Hyprland.focusedWorkspace ? Hyprland.focusedWorkspace.id : 0 // Workspace switches replace the whole list: animate it as one, in the // switch direction, instead of popping each pill in. property int previousWorkspace: workspace property real slideFrom: 0 property bool switching: false onWorkspaceChanged: { slideFrom = workspace > previousWorkspace ? 1 : -1; previousWorkspace = workspace; switching = true; settle.restart(); if (transition === "fade" || transition === "slide") switchAnim.restart(); } Timer { id: settle interval: Theme.duration + 50 onTriggered: root.switching = false } ParallelAnimation { id: switchAnim NumberAnimation { target: row property: "opacity" from: 0 to: 1 duration: Theme.duration * 1.2 easing.type: Easing.OutCubic } NumberAnimation { target: slide property: "x" from: root.transition === "slide" ? 14 * root.slideFrom * Math.max(0.3, Theme.intensity) : 0 to: 0 duration: Theme.duration * 1.4 easing.type: Easing.OutCubic } } // Left to right by Hyprland's last known position. Positions are not // refreshed here: Hyprland.refreshToplevels() can crash Quickshell 0.3.1 // (HyprlandToplevel::updateFromObject), so windows without one go last. // Read windows only after startup: bindings on Hyprland toplevels during // Quickshell's initial window parse make its startup crash far likelier. property bool armed: false Timer { interval: 1500 running: true onTriggered: root.armed = true } readonly property var windows: !armed ? [] : HyprlandService.windows.filter(w => w.workspace === root.workspace && !!w.handle).sort((a, b) => root.order(a) - root.order(b)) function order(w) { return w.width > 0 ? w.x * 10000 + w.y : 1e12 + HyprlandService.windows.indexOf(w); } // Crowded workspaces show the unfocused programs as icons only. readonly property bool compact: labels === "icons" || labels === "focused" || (collapse !== "never" && windows.length > Number(collapse)) function pretty(id) { const last = String(id || "").split(".").pop().replace(/[-_]+/g, " "); return last ? last.charAt(0).toUpperCase() + last.slice(1) : "Window"; } implicitHeight: ModuleRegistry.pillHeight implicitWidth: (windows.length ? row.implicitWidth : empty.implicitWidth) + 8 Behavior on implicitWidth { enabled: root.transition !== "none" NumberAnimation { duration: Theme.duration easing.type: Easing.OutCubic } } clip: true Text { id: empty anchors.centerIn: parent visible: root.windows.length === 0 leftPadding: 12 rightPadding: 12 text: "Desktop" color: Theme.textSecondary font.pixelSize: 13 } Row { id: row anchors.centerIn: parent spacing: 2 transform: Translate { id: slide } // Single new windows pop in; a workspace switch uses switchAnim. add: Transition { enabled: root.transition !== "none" && (root.transition === "pop" || !root.switching) NumberAnimation { properties: "opacity,scale" from: 0 to: 1 duration: Theme.duration easing.type: Easing.OutCubic } } move: Transition { enabled: root.transition !== "none" NumberAnimation { properties: "x" duration: Theme.duration easing.type: Easing.OutCubic } } Repeater { model: ScriptModel { values: root.windows objectProp: "address" } Rectangle { id: item required property var modelData required property int index readonly property var toplevel: modelData.handle // Previews hang under the whole list so the pane stays put. readonly property Item placement: root readonly property var entry: modelData.appId ? DesktopEntries.heuristicLookup(modelData.appId) : null readonly property string name: entry && entry.name ? entry.name : root.pretty(modelData.appId || modelData.title) readonly property bool focused: !!toplevel && toplevel.activated readonly property bool previewing: PopoutState.open && PopoutState.anchor === item readonly property bool labelled: root.labels !== "icons" && (!root.compact || focused) objectName: "windowItem-" + index implicitHeight: ModuleRegistry.pillHeight - 6 implicitWidth: content.implicitWidth + 16 radius: height / 2 color: previewing ? Qt.alpha(Theme.accent, 0.28) : focused ? Qt.alpha(Theme.text, 0.13) : hover.hovered ? Theme.hover : Theme.transparent Behavior on color { ColorAnimation { duration: Theme.duration / 2 } } Behavior on implicitWidth { NumberAnimation { duration: Theme.duration easing.type: Easing.OutCubic } } Row { id: content anchors.centerIn: parent spacing: 7 IconImage { id: icon anchors.verticalCenter: parent.verticalCenter implicitSize: Math.round(ModuleRegistry.pillHeight * 0.5) source: item.entry && item.entry.icon ? Quickshell.iconPath(item.entry.icon, true) : Quickshell.iconPath("application-x-executable", true) // Synchronous on purpose: Quickshell's icon provider loads QPixmaps, // which crash when built off the GUI thread (Quickshell 0.3.1). } Text { anchors.verticalCenter: parent.verticalCenter visible: item.labelled width: Math.min(implicitWidth, root.labelWidth) text: item.name color: item.focused ? Theme.text : Theme.textSecondary font.pixelSize: 13 font.weight: item.focused ? Font.DemiBold : Font.Normal elide: Text.ElideRight } } // Focused-window underline. Rectangle { anchors.bottom: parent.bottom anchors.horizontalCenter: parent.horizontalCenter width: item.focused ? 14 : 0 height: 2 radius: 1 color: Theme.accentVivid Behavior on width { NumberAnimation { duration: Theme.duration easing.type: Easing.OutCubic } } } HoverHandler { id: hover cursorShape: Qt.PointingHandCursor onHoveredChanged: hovered ? PopoutState.hover(item, root.previews ? "window" : "tooltip", item.modelData.title || item.name, item.toplevel) : PopoutState.unhover(item) } TapHandler { acceptedButtons: Qt.LeftButton onTapped: { PopoutState.close(); HyprlandService.focusWindow(item.modelData.address); } } TapHandler { acceptedButtons: Qt.MiddleButton onTapped: HyprlandService.closeWindow(item.modelData.address) } Accessible.role: Accessible.Button Accessible.name: item.name + (item.focused ? ", focused" : "") } } } }