From 823d0b9225bed02e66512ddefa5d71212f8d3860 Mon Sep 17 00:00:00 2001 From: Lemmy Date: Sun, 28 Dec 2025 14:47:02 -0500 Subject: [PATCH] Panels&IPC: attempt to figure #1166 --- Modules/MainScreen/SmartPanel.qml | 63 ++++++++++++---------- Services/Control/CurrentScreenDetector.qml | 11 +++- 2 files changed, 44 insertions(+), 30 deletions(-) diff --git a/Modules/MainScreen/SmartPanel.qml b/Modules/MainScreen/SmartPanel.qml index f0e13b51c..0f7c58f31 100644 --- a/Modules/MainScreen/SmartPanel.qml +++ b/Modules/MainScreen/SmartPanel.qml @@ -149,38 +149,45 @@ Item { buttonItem = BarService.lookupWidget(buttonName, screen.name); } - if (buttonItem) { - root.buttonItem = buttonItem; - // Map button position within its window - var buttonLocal = buttonItem.mapToItem(null, 0, 0); + // Validate buttonItem is a valid QML Item with mapToItem function + if (buttonItem && typeof buttonItem.mapToItem === "function") { + try { + root.buttonItem = buttonItem; + // Map button position within its window + var buttonLocal = buttonItem.mapToItem(null, 0, 0); - // Calculate the bar window's position on screen based on bar settings - // The BarContentWindow uses anchors, so we need to compute its position - var barWindowX = 0; - var barWindowY = 0; - var screenWidth = root.screen?.width || 0; - var screenHeight = root.screen?.height || 0; + // Calculate the bar window's position on screen based on bar settings + // The BarContentWindow uses anchors, so we need to compute its position + var barWindowX = 0; + var barWindowY = 0; + var screenWidth = root.screen?.width || 0; + var screenHeight = root.screen?.height || 0; - if (root.barPosition === "right") { - barWindowX = screenWidth - root.barMarginH - Style.barHeight; - } else if (root.barPosition === "left") { - barWindowX = root.barMarginH; + if (root.barPosition === "right") { + barWindowX = screenWidth - root.barMarginH - Style.barHeight; + } else if (root.barPosition === "left") { + barWindowX = root.barMarginH; + } + // For top/bottom bars, barWindowX stays 0 (full width window) + + if (root.barPosition === "bottom") { + barWindowY = screenHeight - root.barMarginV - Style.barHeight; + } else if (root.barPosition === "top") { + barWindowY = root.barMarginV; + } + // For left/right bars, barWindowY stays 0 (full height window) + + root.buttonPosition = Qt.point(barWindowX + buttonLocal.x, barWindowY + buttonLocal.y); + root.buttonWidth = buttonItem.width; + root.buttonHeight = buttonItem.height; + root.useButtonPosition = true; + } catch (e) { + Logger.w("SmartPanel", "Failed to get button position, using default positioning:", e); + root.buttonItem = null; + root.useButtonPosition = false; } - // For top/bottom bars, barWindowX stays 0 (full width window) - - if (root.barPosition === "bottom") { - barWindowY = screenHeight - root.barMarginV - Style.barHeight; - } else if (root.barPosition === "top") { - barWindowY = root.barMarginV; - } - // For left/right bars, barWindowY stays 0 (full height window) - - root.buttonPosition = Qt.point(barWindowX + buttonLocal.x, barWindowY + buttonLocal.y); - root.buttonWidth = buttonItem.width; - root.buttonHeight = buttonItem.height; - root.useButtonPosition = true; } else { - // No button provided: reset button position mode + // No valid button provided: reset button position mode root.buttonItem = null; root.useButtonPosition = false; } diff --git a/Services/Control/CurrentScreenDetector.qml b/Services/Control/CurrentScreenDetector.qml index 5173ea722..2915ce1fa 100644 --- a/Services/Control/CurrentScreenDetector.qml +++ b/Services/Control/CurrentScreenDetector.qml @@ -60,7 +60,7 @@ Item { Timer { id: screenDetectorDebounce running: false - interval: 20 + interval: 40 onTriggered: { Logger.d("CurrentScreenDetector", "Screen debounced to:", root.detectedScreen?.name || "null"); @@ -77,8 +77,15 @@ Item { } Logger.d("CurrentScreenDetector", "Executing callback on screen:", root.detectedScreen.name); - root.pendingCallback(root.detectedScreen); + // Store callback locally and clear pendingCallback first to prevent deadlock + // if the callback throws an error + var callback = root.pendingCallback; root.pendingCallback = null; + try { + callback(root.detectedScreen); + } catch (e) { + Logger.e("CurrentScreenDetector", "Callback failed:", e); + } } // Clean up