mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
bar-widget: fix opening "close to button"
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user