IPC: new approach to ensure accuate positionning once the screen variable has propagated.

This commit is contained in:
ItsLemmy
2025-10-03 23:55:17 -04:00
parent 86127660fe
commit 343c3b95ae
2 changed files with 29 additions and 17 deletions

View File

@@ -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")
}
}

View File

@@ -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)
}
}