diff --git a/Modules/MainScreen/PanelPlaceholder.qml b/Modules/MainScreen/PanelPlaceholder.qml index 3cd68d85..af50d4c4 100644 --- a/Modules/MainScreen/PanelPlaceholder.qml +++ b/Modules/MainScreen/PanelPlaceholder.qml @@ -56,48 +56,6 @@ 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 2023abdb..40a52a90 100644 --- a/Modules/MainScreen/SmartPanelWindow.qml +++ b/Modules/MainScreen/SmartPanelWindow.qml @@ -48,10 +48,6 @@ 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 @@ -61,44 +57,18 @@ PanelWindow { mask: null // No mask - content window is rectangular visible: isPanelOpen - // Wayland layer shell configuration - content-sized window + // Wayland layer shell configuration - fullscreen 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) - // 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) + // Anchor to all edges to make fullscreen + anchors { + top: true + bottom: true + left: true + right: true } // Sync state to placeholder @@ -112,19 +82,6 @@ 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) { @@ -153,9 +110,6 @@ PanelWindow { placeholder.useButtonPosition = false } - // Initialize cached window size - updateWindowSize() - // Set isPanelOpen to trigger content loading isPanelOpen = true @@ -210,13 +164,12 @@ PanelWindow { Logger.d("SmartPanelWindow", "Panel close finalized", placeholder.panelName) } - // Content wrapper with opacity animation (fills content-sized window) + // Fullscreen container for click-to-close and content Item { - id: contentWrapper anchors.fill: parent - focus: true + focus: true // Enable keyboard event handling - // Keyboard event handling + // Handle keyboard events directly via Keys handler Keys.onPressed: event => { Logger.d("SmartPanelWindow", "Key pressed:", event.key, "for panel:", placeholder.panelName) if (event.key === Qt.Key_Escape) { @@ -275,120 +228,143 @@ PanelWindow { } } - // Opacity animation - opacity: { - if (isClosing) - return 0.0 - if (isPanelVisible && sizeAnimationComplete) - return 1.0 - return 0.0 + // 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 } - Behavior on opacity { - NumberAnimation { - id: opacityAnimation - duration: root.isClosing ? Style.animationFaster : Style.animationFast - easing.type: Easing.OutQuad + // 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 - onRunningChanged: { - // Safety: Zero-duration animation handling - if (!running && duration === 0) { - if (root.isClosing && contentWrapper.opacity === 0.0) { + // 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) { 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) + 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) } - } else if (root.isPanelVisible && contentWrapper.opacity === 1.0) { + } // When opacity fade completes during open, stop watchdog + else if (!running && 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) { - 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) + // 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 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() + }) } } - } - // Panel content loader - Loader { - id: contentLoader - active: isPanelOpen - anchors.fill: parent - sourceComponent: root.panelContent + // 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 + } - // 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') + // Watch for changes in content-driven sizes + Connections { + target: contentLoader.item + ignoreUnknownSignals: true - 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 onContentPreferredWidthChanged() { + if (root.isPanelOpen && root.isPanelVisible && contentLoader.item) { + placeholder.updateContentSize(contentLoader.item.contentPreferredWidth, placeholder.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) + function onContentPreferredHeightChanged() { + if (root.isPanelOpen && root.isPanelVisible && contentLoader.item) { + placeholder.updateContentSize(placeholder.contentPreferredWidth, contentLoader.item.contentPreferredHeight) + } } } } @@ -440,16 +416,6 @@ 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) {