From 343c3b95ae8a3e54bcc890191b7ed80a7e423e48 Mon Sep 17 00:00:00 2001 From: ItsLemmy Date: Fri, 3 Oct 2025 23:55:17 -0400 Subject: [PATCH] IPC: new approach to ensure accuate positionning once the screen variable has propagated. --- Services/IPCService.qml | 6 +++--- Widgets/NPanel.qml | 40 ++++++++++++++++++++++++++-------------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/Services/IPCService.qml b/Services/IPCService.qml index 0095705c..f37b61be 100644 --- a/Services/IPCService.qml +++ b/Services/IPCService.qml @@ -35,7 +35,7 @@ Item { target: "notifications" function toggleHistory() { // Will attempt to open the panel next to the bar button if any. - notificationHistoryPanel.toggle(BarService.lookupWidget("NotificationHistory")) + notificationHistoryPanel.toggle(null, "NotificationHistory") } function toggleDND() { Settings.data.notifications.doNotDisturb = !Settings.data.notifications.doNotDisturb @@ -139,7 +139,7 @@ Item { target: "sidePanel" function toggle() { // Will attempt to open the panel next to the bar button if any. - controlCenterPanel.toggle(BarService.lookupWidget("ControlCenter")) + controlCenterPanel.toggle(null, "ControlCenter") ToastService.showWarning("IPC", I18n.tr("toast.ipc.sidepanel-deprecated"), 8000) } } @@ -147,7 +147,7 @@ Item { target: "controlCenter" function toggle() { // Will attempt to open the panel next to the bar button if any. - controlCenterPanel.toggle(BarService.lookupWidget("ControlCenter")) + controlCenterPanel.toggle(null, "ControlCenter") } } diff --git a/Widgets/NPanel.qml b/Widgets/NPanel.qml index d56f7be1..bc21248f 100644 --- a/Widgets/NPanel.qml +++ b/Widgets/NPanel.qml @@ -17,6 +17,8 @@ Loader { property real preferredHeightRatio property color panelBackgroundColor: Color.mSurface property bool draggable: false + property var buttonItem: null + property string buttonName: "" property bool panelAnchorHorizontalCenter: false property bool panelAnchorVerticalCenter: false @@ -72,27 +74,18 @@ Loader { } // ----------------------------------------- - function toggle(buttonItem) { + function toggle(buttonItem, buttonName) { if (!active) { - open(buttonItem) + open(buttonItem, buttonName) } else { close() } } // ----------------------------------------- - function open(buttonItem) { - - // Get the button position if provided - if (buttonItem !== undefined && buttonItem !== null) { - useButtonPosition = true - var itemPos = buttonItem.mapToItem(null, 0, 0) - buttonPosition = Qt.point(itemPos.x, itemPos.y) - buttonWidth = buttonItem.width - buttonHeight = buttonItem.height - } else { - useButtonPosition = false - } + function open(buttonItem, buttonName) { + root.buttonItem = buttonItem + root.buttonName = buttonName || "" PanelService.willOpenPanel(root) @@ -149,6 +142,25 @@ Loader { // It's mandatory to force refresh the subloader to ensure the scaling is properly dispatched panelContentLoader.active = false panelContentLoader.active = true + + // If we have a button name, we are landing here from an IPC call. + // IPC calls have no idead on which screen they panel will spawn. + // Resolve the button name to a proper button item now that we have a screen. + if (buttonName !== "") { + buttonItem = BarService.lookupWidget(buttonName, root.screen.name) + } + + // Get the button position if provided + if (buttonItem !== undefined && buttonItem !== null) { + useButtonPosition = true + var itemPos = buttonItem.mapToItem(null, 0, 0) + buttonPosition = Qt.point(itemPos.x, itemPos.y) + buttonWidth = buttonItem.width + buttonHeight = buttonItem.height + } else { + useButtonPosition = false + } + //Logger.log("NPanel", "OnScreenChanged", root.screen.name) } }