import QtQuick import QtQuick.Controls import QtQuick.Layouts import Quickshell import Quickshell.Wayland import Quickshell.Widgets import qs.Commons import qs.Services import qs.Widgets Item { id: root property ShellScreen screen property real scaling: 1.0 // Widget properties passed from Bar.qml for per-instance settings property string widgetId: "" property string section: "" property int sectionWidgetIndex: -1 property int sectionWidgetsCount: 0 property var widgetMetadata: BarWidgetRegistry.widgetMetadata[widgetId] property var widgetSettings: { if (section && sectionWidgetIndex >= 0) { var widgets = Settings.data.bar.widgets[section] if (widgets && sectionWidgetIndex < widgets.length) { return widgets[sectionWidgetIndex] } } return {} } readonly property bool hasActiveWindow: CompositorService.getFocusedWindowTitle() !== "" readonly property string windowTitle: CompositorService.getFocusedWindowTitle() || "No active window" readonly property string fallbackIcon: "user-desktop" readonly property string barPosition: Settings.data.bar.position readonly property bool compact: (Settings.data.bar.density === "compact") // Widget settings - matching MediaMini pattern readonly property bool showIcon: (widgetSettings.showIcon !== undefined) ? widgetSettings.showIcon : widgetMetadata.showIcon readonly property bool autoHide: (widgetSettings.autoHide !== undefined) ? widgetSettings.autoHide : widgetMetadata.autoHide readonly property string scrollingMode: (widgetSettings.scrollingMode !== undefined) ? widgetSettings.scrollingMode : (widgetMetadata.scrollingMode !== undefined ? widgetMetadata.scrollingMode : "hover") readonly property int widgetWidth: (widgetSettings.width !== undefined) ? widgetSettings.width : Math.max(widgetMetadata.width, screen.width * 0.06) implicitHeight: visible ? ((barPosition === "left" || barPosition === "right") ? calculatedVerticalHeight() : Math.round(Style.barHeight * scaling)) : 0 implicitWidth: visible ? ((barPosition === "left" || barPosition === "right") ? Math.round(Style.baseWidgetSize * 0.8 * scaling) : (widgetWidth * scaling)) : 0 opacity: !autoHide || hasActiveWindow ? 1.0 : 0 Behavior on opacity { NumberAnimation { duration: Style.animationNormal easing.type: Easing.OutCubic } } function calculatedVerticalHeight() { return Math.round(Style.baseWidgetSize * 0.8 * scaling) } function getAppIcon() { try { // Try CompositorService first const focusedWindow = CompositorService.getFocusedWindow() if (focusedWindow && focusedWindow.appId) { try { const idValue = focusedWindow.appId const normalizedId = (typeof idValue === 'string') ? idValue : String(idValue) const iconResult = ThemeIcons.iconForAppId(normalizedId.toLowerCase()) if (iconResult && iconResult !== "") { return iconResult } } catch (iconError) { Logger.warn("ActiveWindow", "Error getting icon from CompositorService:", iconError) } } if (CompositorService.isHyprland) { // Fallback to ToplevelManager if (ToplevelManager && ToplevelManager.activeToplevel) { try { const activeToplevel = ToplevelManager.activeToplevel if (activeToplevel.appId) { const idValue2 = activeToplevel.appId const normalizedId2 = (typeof idValue2 === 'string') ? idValue2 : String(idValue2) const iconResult2 = ThemeIcons.iconForAppId(normalizedId2.toLowerCase()) if (iconResult2 && iconResult2 !== "") { return iconResult2 } } } catch (fallbackError) { Logger.warn("ActiveWindow", "Error getting icon from ToplevelManager:", fallbackError) } } } return ThemeIcons.iconFromName(fallbackIcon) } catch (e) { Logger.warn("ActiveWindow", "Error in getAppIcon:", e) return ThemeIcons.iconFromName(fallbackIcon) } } // Hidden text element to measure full title width NText { id: fullTitleMetrics visible: false text: windowTitle pointSize: Style.fontSizeS * scaling font.weight: Style.fontWeightMedium } Rectangle { id: windowActiveRect visible: root.visible anchors.left: parent.left anchors.verticalCenter: parent.verticalCenter width: (barPosition === "left" || barPosition === "right") ? Math.round(Style.baseWidgetSize * 0.8 * scaling) : (widgetWidth * scaling) height: (barPosition === "left" || barPosition === "right") ? Math.round(Style.baseWidgetSize * 0.8 * scaling) : Math.round(Style.capsuleHeight * scaling) radius: (barPosition === "left" || barPosition === "right") ? width / 2 : Math.round(Style.radiusM * scaling) color: Settings.data.bar.showCapsule ? Color.mSurfaceVariant : Color.transparent Item { id: mainContainer anchors.fill: parent anchors.leftMargin: (barPosition === "left" || barPosition === "right") ? 0 : Style.marginS * scaling anchors.rightMargin: (barPosition === "left" || barPosition === "right") ? 0 : Style.marginS * scaling // Horizontal layout for top/bottom bars RowLayout { id: rowLayout anchors.verticalCenter: parent.verticalCenter spacing: Style.marginS * scaling visible: barPosition === "top" || barPosition === "bottom" z: 1 // Window icon Item { Layout.preferredWidth: Math.round(18 * scaling) Layout.preferredHeight: Math.round(18 * scaling) Layout.alignment: Qt.AlignVCenter visible: showIcon IconImage { id: windowIcon anchors.fill: parent source: getAppIcon() asynchronous: true smooth: true visible: source !== "" } } // Title container with scrolling Item { id: titleContainer Layout.preferredWidth: { // Calculate available width based on other elements var iconWidth = (showIcon && windowIcon.visible ? (18 * scaling + Style.marginS * scaling) : 0) var totalMargins = Style.marginXXS * scaling * 2 var availableWidth = mainContainer.width - iconWidth - totalMargins return Math.max(20 * scaling, availableWidth) } Layout.maximumWidth: Layout.preferredWidth Layout.alignment: Qt.AlignVCenter Layout.preferredHeight: titleText.height clip: true property bool isScrolling: false property bool isResetting: false property real textWidth: fullTitleMetrics.contentWidth property real containerWidth: width property bool needsScrolling: textWidth > containerWidth // Timer for "always" mode with delay Timer { id: scrollStartTimer interval: 1000 repeat: false onTriggered: { if (scrollingMode === "always" && titleContainer.needsScrolling) { titleContainer.isScrolling = true titleContainer.isResetting = false } } } // Update scrolling state based on mode property var updateScrollingState: function () { if (scrollingMode === "never") { isScrolling = false isResetting = false } else if (scrollingMode === "always") { if (needsScrolling) { if (mouseArea.containsMouse) { isScrolling = false isResetting = true } else { scrollStartTimer.restart() } } else { scrollStartTimer.stop() isScrolling = false isResetting = false } } else if (scrollingMode === "hover") { if (mouseArea.containsMouse && needsScrolling) { isScrolling = true isResetting = false } else { isScrolling = false if (needsScrolling) { isResetting = true } } } } onWidthChanged: updateScrollingState() Component.onCompleted: updateScrollingState() // React to hover changes Connections { target: mouseArea function onContainsMouseChanged() { titleContainer.updateScrollingState() } } // Scrolling content with seamless loop Item { id: scrollContainer height: parent.height width: childrenRect.width property real scrollX: 0 x: scrollX RowLayout { spacing: 50 * scaling // Gap between text copies NText { id: titleText text: windowTitle pointSize: Style.fontSizeS * scaling font.weight: Style.fontWeightMedium verticalAlignment: Text.AlignVCenter color: Color.mOnSurface } // Second copy for seamless scrolling NText { text: windowTitle font: titleText.font verticalAlignment: Text.AlignVCenter color: Color.mOnSurface visible: titleContainer.needsScrolling && titleContainer.isScrolling } } // Reset animation NumberAnimation on scrollX { running: titleContainer.isResetting to: 0 duration: 300 easing.type: Easing.OutQuad onFinished: { titleContainer.isResetting = false } } // Seamless infinite scroll NumberAnimation on scrollX { id: infiniteScroll running: titleContainer.isScrolling && !titleContainer.isResetting from: 0 to: -(titleContainer.textWidth + 50 * scaling) duration: Math.max(4000, windowTitle.length * 100) loops: Animation.Infinite easing.type: Easing.Linear } } Behavior on Layout.preferredWidth { NumberAnimation { duration: Style.animationSlow easing.type: Easing.InOutCubic } } } } // Vertical layout for left/right bars - icon only Item { id: verticalLayout anchors.centerIn: parent width: parent.width - Style.marginM * scaling * 2 height: parent.height - Style.marginM * scaling * 2 visible: barPosition === "left" || barPosition === "right" z: 1 // Window icon Item { width: Style.baseWidgetSize * 0.5 * scaling height: Style.baseWidgetSize * 0.5 * scaling anchors.centerIn: parent visible: windowTitle !== "" IconImage { id: windowIconVertical anchors.fill: parent source: getAppIcon() asynchronous: true smooth: true visible: source !== "" } } } // Mouse area for hover detection MouseArea { id: mouseArea anchors.fill: parent hoverEnabled: true cursorShape: Qt.PointingHandCursor acceptedButtons: Qt.LeftButton onEntered: { if ((windowTitle !== "") && (barPosition === "left" || barPosition === "right") || (scrollingMode === "never")) { TooltipService.show(Screen, root, windowTitle, BarService.getTooltipDirection()) } } onExited: { TooltipService.hide() } } } } Connections { target: CompositorService function onActiveWindowChanged() { try { windowIcon.source = Qt.binding(getAppIcon) windowIconVertical.source = Qt.binding(getAppIcon) } catch (e) { Logger.warn("ActiveWindow", "Error in onActiveWindowChanged:", e) } } function onWindowListChanged() { try { windowIcon.source = Qt.binding(getAppIcon) windowIconVertical.source = Qt.binding(getAppIcon) } catch (e) { Logger.warn("ActiveWindow", "Error in onWindowListChanged:", e) } } } }