Skip to content

Commit b61d14e

Browse files
committed
fix: re-apply customization after changing order of widgets
closes: #167
1 parent e8c526a commit b61d14e

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

package/contents/ui/code/utils.js

+3
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ function toggleTransparency(containmentItem, nativePanelBackgroundEnabled) {
9090
}
9191

9292
function findWidgets(panelLayout, panelWidgets) {
93+
if (!panelLayout) return panelWidgets
9394
// console.log("Updating panel widgets list");
9495
for (let i in panelLayout.children) {
9596
const child = panelLayout.children[i];
@@ -108,6 +109,7 @@ function findWidgets(panelLayout, panelWidgets) {
108109
return panelWidgets
109110
}
110111
function findWidgetsTray(grid, panelWidgets) {
112+
if (!grid) return panelWidgets
111113
if (grid instanceof GridView) {
112114
for (let i = 0; i < grid.count; i++) {
113115
const item = grid.itemAtIndex(i);
@@ -159,6 +161,7 @@ function findWidgetsTray(grid, panelWidgets) {
159161
function getWidgetNameAndId(item) {
160162
let name = ""
161163
let id = -1
164+
if (!item) return { name, id }
162165
if (item.applet?.plasmoid?.pluginName) {
163166
name = item.applet.plasmoid.pluginName
164167
id = item.applet.plasmoid.id

package/contents/ui/main.qml

+31-12
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ PlasmoidItem {
330330
id: effectRect
331331
property bool luisbocanegraPanelColorizerEffectManaged: true
332332
property QtObject target
333-
height: target.height
334-
width: target.width
333+
height: target?.height ?? 0
334+
width: target?.width ?? 0
335335
anchors.centerIn: parent
336336
source: target
337337
colorization: 1
@@ -356,7 +356,8 @@ PlasmoidItem {
356356
property bool isTrayArrow: itemType === Enums.ItemType.TrayArrow
357357
property bool inTray: isTray || isTrayArrow
358358
property bool luisbocanegraPanelColorizerBgManaged: true
359-
property var widgetProperties: isTrayArrow ? { "id":-1, "name": "org.kde.plasma.systemtray.expand" } :
359+
property var widgetProperties: isTrayArrow ?
360+
{ "id":-1, "name": "org.kde.plasma.systemtray.expand" } :
360361
Utils.getWidgetNameAndId(target)
361362
property string widgetName: widgetProperties.name
362363
property int widgetId: widgetProperties.id
@@ -524,17 +525,17 @@ PlasmoidItem {
524525
}
525526
}
526527

527-
property int targetChildren: target.children.length
528+
property int targetChildren: target?.children.length ?? 0
528529
onTargetChildrenChanged: {
529530
// console.error("CHILDREN CHANGED", targetChildren, target)
530531
recolorTimer.restart()
531532
}
532-
property int targetVisibleChildren: target.visibleChildren.length
533+
property int targetVisibleChildren: target?.visibleChildren.length ?? 0
533534
onTargetVisibleChildrenChanged: {
534535
// console.error("CHILDREN CHANGED", targetVisibleChildren, target)
535536
recolorTimer.restart()
536537
}
537-
property int targetCount: target.count || 0
538+
property int targetCount: target?.count ?? 0
538539
onTargetCountChanged: {
539540
// console.error("COUNT CHANGED", targetCount, target)
540541
recolorTimer.restart()
@@ -584,8 +585,8 @@ PlasmoidItem {
584585
recolorTimer.start()
585586
}
586587

587-
height: isTray ? target.height : parent.height
588-
width: isTray ? target.width : parent.width
588+
height: isTray ? (target?.height ?? 0) : parent.height
589+
width: isTray ? (target?.width ?? 0 ): parent.width
589590
Behavior on height {
590591
enabled: animatePropertyChanges
591592
NumberAnimation {
@@ -654,15 +655,15 @@ PlasmoidItem {
654655
Binding {
655656
target: rect
656657
property: "width"
657-
value: parent.width + horizontalWidth
658+
value: (parent?.width ?? 0) + horizontalWidth
658659
when: isWidget
659660
delayed: true
660661
}
661662

662663
Binding {
663664
target: rect
664665
property: "height"
665-
value: parent.height + verticalWidth
666+
value: (parent?.height ?? 0) + verticalWidth
666667
when: isWidget && !horizontal
667668
delayed: true
668669
}
@@ -1009,7 +1010,7 @@ PlasmoidItem {
10091010
color: {
10101011
return getColor(shadowColorCfg, targetIndex, rect.color, itemType, dropShadow)
10111012
}
1012-
source: target.applet
1013+
source: target?.applet ?? null
10131014
visible: fgShadowEnabled
10141015
Behavior on color {
10151016
enabled: animatePropertyChanges
@@ -1448,8 +1449,20 @@ PlasmoidItem {
14481449
}
14491450

14501451
onPanelLayoutCountChanged: {
1451-
if (panelLayoutCount === 0) return
14521452
console.log("onPanelLayoutCountChanged")
1453+
initAll()
1454+
// re-apply customizations after the widget stops being dagged around
1455+
for (var i = 0; i < panelLayout.children.length; i++) {
1456+
var item = panelLayout.children[i];
1457+
if (!item || (!item.hasOwnProperty("draggingChanged"))) return
1458+
item.draggingChanged.connect(function() {
1459+
initAll()
1460+
})
1461+
}
1462+
}
1463+
1464+
function initAll() {
1465+
if (!panelLayout || panelLayoutCount === 0) return
14531466
Qt.callLater(function() {
14541467
trayInitTimer.restart()
14551468
showWidgets(panelLayout)
@@ -1458,6 +1471,11 @@ PlasmoidItem {
14581471
})
14591472
}
14601473

1474+
onEditModeChanged: {
1475+
if (editMode) return
1476+
initAll()
1477+
}
1478+
14611479
onTrayGridViewCountChanged: {
14621480
if (trayGridViewCount === 0) return
14631481
// console.error(trayGridViewCount);
@@ -1632,6 +1650,7 @@ PlasmoidItem {
16321650
}
16331651

16341652
function showWidgets(panelLayout) {
1653+
if (!panelLayout) return
16351654
console.log("showWidgets()")
16361655
for (var i in panelLayout.children) {
16371656
const child = panelLayout.children[i];

0 commit comments

Comments
 (0)