From 518b67c2d3e99e4dc9eb2726b266b17457d03b81 Mon Sep 17 00:00:00 2001 From: Lemmy Date: Fri, 6 Feb 2026 15:09:36 -0500 Subject: [PATCH] bar-widget: fix opening "close to button" --- Modules/Bar/Extras/BarWidgetLoader.qml | 35 ++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/Modules/Bar/Extras/BarWidgetLoader.qml b/Modules/Bar/Extras/BarWidgetLoader.qml index f96cdfeb8..f10374670 100644 --- a/Modules/Bar/Extras/BarWidgetLoader.qml +++ b/Modules/Bar/Extras/BarWidgetLoader.qml @@ -15,6 +15,20 @@ Item { readonly property string section: widgetProps ? (widgetProps.section || "") : "" readonly property int sectionIndex: widgetProps ? (widgetProps.sectionWidgetIndex || 0) : 0 + // Store registration key at registration time so unregistration always uses the correct key, + // even if binding properties (section, sectionIndex) have changed by destruction time + property string _regScreen: "" + property string _regSection: "" + property string _regWidgetId: "" + property int _regIndex: -1 + + function _unregister() { + if (_regScreen !== "") { + BarService.unregisterWidget(_regScreen, _regSection, _regWidgetId, _regIndex); + _regScreen = ""; + } + } + // Bar orientation and height for extended click areas readonly property string barPosition: Settings.getBarPositionForScreen(widgetScreen?.name) readonly property bool isVerticalBar: barPosition === "left" || barPosition === "right" @@ -67,6 +81,13 @@ Item { return root.checkWidgetExists() ? BarWidgetRegistry.getWidget(root.widgetId) : null; } + // Unregister when the loaded item is destroyed (Loader deactivated or sourceComponent changed) + onItemChanged: { + if (!item) { + root._unregister(); + } + } + onLoaded: { if (!item) return; @@ -109,8 +130,15 @@ Item { } } - // Register this widget instance with BarService + // Unregister any previous registration before registering the new instance + root._unregister(); + + // Register and store the key for reliable unregistration BarService.registerWidget(widgetScreen.name, section, widgetId, sectionIndex, item); + root._regScreen = widgetScreen.name; + root._regSection = section; + root._regWidgetId = widgetId; + root._regIndex = sectionIndex; // Call custom onLoaded if it exists if (item.hasOwnProperty("onLoaded")) { @@ -119,10 +147,7 @@ Item { } Component.onDestruction: { - // Unregister when destroyed - if (widgetScreen && section) { - BarService.unregisterWidget(widgetScreen.name, section, widgetId, sectionIndex); - } + root._unregister(); } }