From 329731be2d05aab4b04d35c5234e4ceed7de7e0f Mon Sep 17 00:00:00 2001 From: ivan tkachenko Date: Wed, 14 Sep 2022 02:22:11 +0300 Subject: [PATCH] effects/private: Encapsulate DND management, and clean up the store Use methods with semantic naming instead of raw data manipulation, and make sure to perform clean up of DND data, so it won't haunt us back later e.g. when a window delegate is recreated not because of a drag of itself but due to a desktops rearrangement. --- src/effects/private/qml/WindowHeap.qml | 15 ++++++++++++--- src/effects/private/qml/WindowHeapDelegate.qml | 5 +++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/effects/private/qml/WindowHeap.qml b/src/effects/private/qml/WindowHeap.qml index d95d3db790..2c59023976 100644 --- a/src/effects/private/qml/WindowHeap.qml +++ b/src/effects/private/qml/WindowHeap.qml @@ -54,6 +54,15 @@ FocusScope { function saveDND(key: int, rect: rect) { dndManagerStore[key] = rect; } + function containsDND(key: int): bool { + return key in dndManagerStore; + } + function restoreDND(key: int): rect { + return dndManagerStore[key]; + } + function deleteDND(key: int) { + delete dndManagerStore[key]; + } KWinComponents.WindowThumbnailItem { id: otherScreenThumbnail @@ -119,11 +128,11 @@ FocusScope { onItemAdded: (index, item) => { // restore/reparent from drop var key = item.client.internalId; - if (key in heap.dndManagerStore) { + if (heap.containsDND(key)) { expoLayout.forceLayout(); - var oldGlobalRect = heap.dndManagerStore[key]; + var oldGlobalRect = heap.restoreDND(key); item.restoreDND(oldGlobalRect); - delete heap.dndManagerStore[key]; + heap.deleteDND(key); } else if (heap.effectiveOrganized) { // New window has opened in the middle of a running effect. // Make sure it is positioned before enabling its animations. diff --git a/src/effects/private/qml/WindowHeapDelegate.qml b/src/effects/private/qml/WindowHeapDelegate.qml index 622b1f906f..0cd8671405 100644 --- a/src/effects/private/qml/WindowHeapDelegate.qml +++ b/src/effects/private/qml/WindowHeapDelegate.qml @@ -120,6 +120,9 @@ Item { thumb.substate = "normal"; } + function deleteDND() { + thumb.windowHeap.deleteDND(thumb.client.internalId); + } PlasmaCore.FrameSvgItem { anchors { @@ -392,6 +395,7 @@ Item { // another virtual desktop (not another screen). if (typeof thumbSource !== "undefined") { // Except the case when it was dropped on the same desktop which it's already on, so let's return to normal state anyway. + thumbSource.deleteDND(); thumb.substate = "normal"; } return; @@ -401,6 +405,7 @@ Item { effect.checkItemDroppedOutOfScreen(globalPos, thumbSource); // else, return to normal without reparenting + thumbSource.deleteDND(); thumb.substate = "normal"; } }