diff --git a/Modules/MainScreen/PanelPlaceholder.qml b/Modules/MainScreen/PanelPlaceholder.qml index af50d4c4..3cd68d85 100644 --- a/Modules/MainScreen/PanelPlaceholder.qml +++ b/Modules/MainScreen/PanelPlaceholder.qml @@ -56,6 +56,48 @@ Item { // Expose panelBackground as panelItem for AllBackgrounds readonly property var panelItem: panelBackground + // Primary anchor edge for window positioning + readonly property string primaryAnchorEdge: { + if (effectivePanelAnchorTop) + return "top" + if (effectivePanelAnchorBottom) + return "bottom" + if (effectivePanelAnchorLeft) + return "left" + if (effectivePanelAnchorRight) + return "right" + return "top" + // default + } + + // Calculate window margins for content-sized panel windows + function getWindowMargins() { + if (!root.width || !root.height) + return { + "top": 0, + "bottom": 0, + "left": 0, + "right": 0 + } + + // Determine which edges are anchored (matching SmartPanelWindow logic) + var isPrimaryVertical = primaryAnchorEdge === "top" || primaryAnchorEdge === "bottom" + var isPrimaryHorizontal = primaryAnchorEdge === "left" || primaryAnchorEdge === "right" + + // Anchor the primary edge + opposite edges of the other axis + var useTop = effectivePanelAnchorTop || primaryAnchorEdge === "top" || isPrimaryHorizontal + var useBottom = effectivePanelAnchorBottom || primaryAnchorEdge === "bottom" || isPrimaryHorizontal + var useLeft = effectivePanelAnchorLeft || primaryAnchorEdge === "left" || isPrimaryVertical + var useRight = effectivePanelAnchorRight || primaryAnchorEdge === "right" || isPrimaryVertical + + return { + "top": useTop ? panelBackground.targetY : 0, + "bottom": useBottom ? (root.height - panelBackground.targetY - panelBackground.targetHeight) : 0, + "left": useLeft ? panelBackground.targetX : 0, + "right": useRight ? (root.width - panelBackground.targetX - panelBackground.targetWidth) : 0 + } + } + // Bar configuration readonly property string barPosition: Settings.data.bar.position readonly property bool barIsVertical: barPosition === "left" || barPosition === "right" diff --git a/Modules/MainScreen/SmartPanelWindow.qml b/Modules/MainScreen/SmartPanelWindow.qml index 40a52a90..2023abdb 100644 --- a/Modules/MainScreen/SmartPanelWindow.qml +++ b/Modules/MainScreen/SmartPanelWindow.qml @@ -48,6 +48,10 @@ PanelWindow { property bool closeWatchdogActive: false property bool openWatchdogActive: false + // Cached window size (only update when content size changes, not during animation) + property real cachedWindowWidth: 0 + property real cachedWindowHeight: 0 + // Signals signal panelOpened signal panelClosed @@ -57,18 +61,44 @@ PanelWindow { mask: null // No mask - content window is rectangular visible: isPanelOpen - // Wayland layer shell configuration - fullscreen window + // Wayland layer shell configuration - content-sized window WlrLayershell.layer: WlrLayer.Top WlrLayershell.namespace: "noctalia-panel-content-" + placeholder.panelName + "-" + (placeholder.screen?.name || "unknown") WlrLayershell.exclusionMode: ExclusionMode.Ignore WlrLayershell.keyboardFocus: !root.isPanelOpen ? WlrKeyboardFocus.None : (exclusiveKeyboard ? WlrKeyboardFocus.Exclusive : WlrKeyboardFocus.OnDemand) - // Anchor to all edges to make fullscreen - anchors { - top: true - bottom: true - left: true - right: true + // Dynamic anchoring based on panel position + // For correct positioning with Wayland layer shell: + // - Anchor the primary edge (top/bottom/left/right) + // - Also anchor the opposite edge of the OTHER axis (both horizontal edges if panel is vertical, both vertical edges if panel is horizontal) + // This prevents unwanted centering and allows margins to position the panel correctly + readonly property bool isPrimaryVertical: placeholder.primaryAnchorEdge === "top" || placeholder.primaryAnchorEdge === "bottom" + readonly property bool isPrimaryHorizontal: placeholder.primaryAnchorEdge === "left" || placeholder.primaryAnchorEdge === "right" + + anchors.top: placeholder.effectivePanelAnchorTop || placeholder.primaryAnchorEdge === "top" || isPrimaryHorizontal + anchors.bottom: placeholder.effectivePanelAnchorBottom || placeholder.primaryAnchorEdge === "bottom" || isPrimaryHorizontal + anchors.left: placeholder.effectivePanelAnchorLeft || placeholder.primaryAnchorEdge === "left" || isPrimaryVertical + anchors.right: placeholder.effectivePanelAnchorRight || placeholder.primaryAnchorEdge === "right" || isPrimaryVertical + + // Size to content (cached to avoid resizing during animations) + implicitWidth: cachedWindowWidth + implicitHeight: cachedWindowHeight + + // Position via margins (calculated from target position, not animated position) + readonly property var windowMargins: placeholder.getWindowMargins() + margins.top: windowMargins.top + margins.bottom: windowMargins.bottom + margins.left: windowMargins.left + margins.right: windowMargins.right + + // Debug logging for positioning + Component.onCompleted: { + Logger.d("SmartPanelWindow", "Panel positioning:", placeholder.panelName) + Logger.d("SmartPanelWindow", " primaryAnchorEdge:", placeholder.primaryAnchorEdge) + Logger.d("SmartPanelWindow", " isPrimaryVertical:", isPrimaryVertical, "isPrimaryHorizontal:", isPrimaryHorizontal) + Logger.d("SmartPanelWindow", " anchors:", anchors.top, anchors.bottom, anchors.left, anchors.right) + Logger.d("SmartPanelWindow", " margins (TLBR):", windowMargins.top, windowMargins.left, windowMargins.bottom, windowMargins.right) + Logger.d("SmartPanelWindow", " size:", cachedWindowWidth, "x", cachedWindowHeight) } // Sync state to placeholder @@ -82,6 +112,19 @@ PanelWindow { placeholder.opacityFadeComplete = opacityFadeComplete } + // Update cached window size (only when target size changes) + function updateWindowSize() { + var targetWidth = placeholder.panelItem.targetWidth + var targetHeight = placeholder.panelItem.targetHeight + + // Only update if size actually changed + if (cachedWindowWidth !== targetWidth || cachedWindowHeight !== targetHeight) { + cachedWindowWidth = targetWidth + cachedWindowHeight = targetHeight + Logger.d("SmartPanelWindow", "Window size updated:", targetWidth, "x", targetHeight, placeholder.panelName) + } + } + // Panel control functions function toggle(buttonItem, buttonName) { if (!isPanelOpen) { @@ -110,6 +153,9 @@ PanelWindow { placeholder.useButtonPosition = false } + // Initialize cached window size + updateWindowSize() + // Set isPanelOpen to trigger content loading isPanelOpen = true @@ -164,12 +210,13 @@ PanelWindow { Logger.d("SmartPanelWindow", "Panel close finalized", placeholder.panelName) } - // Fullscreen container for click-to-close and content + // Content wrapper with opacity animation (fills content-sized window) Item { + id: contentWrapper anchors.fill: parent - focus: true // Enable keyboard event handling + focus: true - // Handle keyboard events directly via Keys handler + // Keyboard event handling Keys.onPressed: event => { Logger.d("SmartPanelWindow", "Key pressed:", event.key, "for panel:", placeholder.panelName) if (event.key === Qt.Key_Escape) { @@ -228,143 +275,120 @@ PanelWindow { } } - // Background MouseArea for click-to-close (behind content) - MouseArea { - anchors.fill: parent - enabled: root.isPanelOpen && !root.isClosing - acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton - onClicked: mouse => { - root.close() - mouse.accepted = true - } - z: 0 + // Opacity animation + opacity: { + if (isClosing) + return 0.0 + if (isPanelVisible && sizeAnimationComplete) + return 1.0 + return 0.0 } - // Content wrapper with opacity animation - Item { - id: contentWrapper - // Position at placeholder location within fullscreen window - x: placeholder.panelItem.x - y: placeholder.panelItem.y - width: placeholder.panelItem.width - height: placeholder.panelItem.height - z: 1 // Above click-to-close MouseArea + Behavior on opacity { + NumberAnimation { + id: opacityAnimation + duration: root.isClosing ? Style.animationFaster : Style.animationFast + easing.type: Easing.OutQuad - // Opacity animation - opacity: { - if (isClosing) - return 0.0 - if (isPanelVisible && sizeAnimationComplete) - return 1.0 - return 0.0 - } - - Behavior on opacity { - NumberAnimation { - id: opacityAnimation - duration: root.isClosing ? Style.animationFaster : Style.animationFast - easing.type: Easing.OutQuad - - onRunningChanged: { - // Safety: Zero-duration animation handling - if (!running && duration === 0) { - if (root.isClosing && contentWrapper.opacity === 0.0) { - root.opacityFadeComplete = true - var shouldFinalizeNow = placeholder.panelItem && !placeholder.panelItem.shouldAnimateWidth && !placeholder.panelItem.shouldAnimateHeight - if (shouldFinalizeNow) { - Logger.d("SmartPanelWindow", "Zero-duration opacity + no size animation - finalizing", placeholder.panelName) - Qt.callLater(root.finalizeClose) - } - } else if (root.isPanelVisible && contentWrapper.opacity === 1.0) { - root.openWatchdogActive = false - openWatchdogTimer.stop() - } - return - } - - // When opacity fade completes during close, trigger size animation - if (!running && root.isClosing && contentWrapper.opacity === 0.0) { + onRunningChanged: { + // Safety: Zero-duration animation handling + if (!running && duration === 0) { + if (root.isClosing && contentWrapper.opacity === 0.0) { root.opacityFadeComplete = true var shouldFinalizeNow = placeholder.panelItem && !placeholder.panelItem.shouldAnimateWidth && !placeholder.panelItem.shouldAnimateHeight if (shouldFinalizeNow) { - Logger.d("SmartPanelWindow", "No animation - finalizing immediately", placeholder.panelName) + Logger.d("SmartPanelWindow", "Zero-duration opacity + no size animation - finalizing", placeholder.panelName) Qt.callLater(root.finalizeClose) - } else { - Logger.d("SmartPanelWindow", "Animation will run - waiting for size animation", placeholder.panelName) } - } // When opacity fade completes during open, stop watchdog - else if (!running && root.isPanelVisible && contentWrapper.opacity === 1.0) { + } else if (root.isPanelVisible && contentWrapper.opacity === 1.0) { root.openWatchdogActive = false openWatchdogTimer.stop() } + return } - } - } - // Panel content loader - Loader { - id: contentLoader - active: isPanelOpen - anchors.fill: parent - sourceComponent: root.panelContent - - // When content finishes loading, trigger positioning and visibility - onLoaded: { - // Capture initial content-driven size if available - if (contentLoader.item) { - var hasWidthProp = contentLoader.item.hasOwnProperty('contentPreferredWidth') - var hasHeightProp = contentLoader.item.hasOwnProperty('contentPreferredHeight') - - if (hasWidthProp || hasHeightProp) { - var initialWidth = hasWidthProp ? contentLoader.item.contentPreferredWidth : 0 - var initialHeight = hasHeightProp ? contentLoader.item.contentPreferredHeight : 0 - placeholder.updateContentSize(initialWidth, initialHeight) - Logger.d("SmartPanelWindow", "Initial content size:", initialWidth, "x", initialHeight, placeholder.panelName) + // When opacity fade completes during close, trigger size animation + if (!running && root.isClosing && contentWrapper.opacity === 0.0) { + root.opacityFadeComplete = true + var shouldFinalizeNow = placeholder.panelItem && !placeholder.panelItem.shouldAnimateWidth && !placeholder.panelItem.shouldAnimateHeight + if (shouldFinalizeNow) { + Logger.d("SmartPanelWindow", "No animation - finalizing immediately", placeholder.panelName) + Qt.callLater(root.finalizeClose) + } else { + Logger.d("SmartPanelWindow", "Animation will run - waiting for size animation", placeholder.panelName) } + } // When opacity fade completes during open, stop watchdog + else if (!running && root.isPanelVisible && contentWrapper.opacity === 1.0) { + root.openWatchdogActive = false + openWatchdogTimer.stop() } - - // Calculate position in placeholder - placeholder.setPosition() - - // Make panel visible on the next frame - Qt.callLater(function () { - root.isPanelVisible = true - opacityTrigger.start() - - // Start open watchdog timer - root.openWatchdogActive = true - openWatchdogTimer.start() - - panelOpened() - }) } } + } - // MouseArea to prevent clicks on panel content from closing it - MouseArea { - anchors.fill: parent - acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton - onClicked: mouse => { - mouse.accepted = true // Eat the click to prevent propagation to background - } - z: -1 // Behind content but above background click-to-close - } + // Panel content loader + Loader { + id: contentLoader + active: isPanelOpen + anchors.fill: parent + sourceComponent: root.panelContent - // Watch for changes in content-driven sizes - Connections { - target: contentLoader.item - ignoreUnknownSignals: true + // When content finishes loading, trigger positioning and visibility + onLoaded: { + // Capture initial content-driven size if available + if (contentLoader.item) { + var hasWidthProp = contentLoader.item.hasOwnProperty('contentPreferredWidth') + var hasHeightProp = contentLoader.item.hasOwnProperty('contentPreferredHeight') - function onContentPreferredWidthChanged() { - if (root.isPanelOpen && root.isPanelVisible && contentLoader.item) { - placeholder.updateContentSize(contentLoader.item.contentPreferredWidth, placeholder.contentPreferredHeight) + if (hasWidthProp || hasHeightProp) { + var initialWidth = hasWidthProp ? contentLoader.item.contentPreferredWidth : 0 + var initialHeight = hasHeightProp ? contentLoader.item.contentPreferredHeight : 0 + placeholder.updateContentSize(initialWidth, initialHeight) + Logger.d("SmartPanelWindow", "Initial content size:", initialWidth, "x", initialHeight, placeholder.panelName) } } - function onContentPreferredHeightChanged() { - if (root.isPanelOpen && root.isPanelVisible && contentLoader.item) { - placeholder.updateContentSize(placeholder.contentPreferredWidth, contentLoader.item.contentPreferredHeight) - } + // Calculate position in placeholder + placeholder.setPosition() + + // Make panel visible on the next frame + Qt.callLater(function () { + root.isPanelVisible = true + opacityTrigger.start() + + // Start open watchdog timer + root.openWatchdogActive = true + openWatchdogTimer.start() + + panelOpened() + }) + } + } + + // MouseArea to prevent clicks on panel content from closing it + MouseArea { + anchors.fill: parent + acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton + onClicked: mouse => { + mouse.accepted = true // Eat the click to prevent propagation to background + } + z: -1 // Behind content but above background click-to-close + } + + // Watch for changes in content-driven sizes + Connections { + target: contentLoader.item + ignoreUnknownSignals: true + + function onContentPreferredWidthChanged() { + if (root.isPanelOpen && root.isPanelVisible && contentLoader.item) { + placeholder.updateContentSize(contentLoader.item.contentPreferredWidth, placeholder.contentPreferredHeight) + } + } + + function onContentPreferredHeightChanged() { + if (root.isPanelOpen && root.isPanelVisible && contentLoader.item) { + placeholder.updateContentSize(placeholder.contentPreferredWidth, contentLoader.item.contentPreferredHeight) } } } @@ -416,6 +440,16 @@ PanelWindow { Connections { target: placeholder.panelItem + function onTargetWidthChanged() { + // Update cached window size when target changes (not during animation) + root.updateWindowSize() + } + + function onTargetHeightChanged() { + // Update cached window size when target changes (not during animation) + root.updateWindowSize() + } + function onWidthChanged() { // When width shrinks to 0 during close and we're animating width, finalize if (root.isClosing && placeholder.panelItem.width === 0 && placeholder.panelItem.shouldAnimateWidth) {