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.
This commit is contained in:
ivan tkachenko 2022-09-14 02:22:11 +03:00
parent 1f0a0c893a
commit 329731be2d
No known key found for this signature in database
GPG key ID: AF72731B7C654CB3
2 changed files with 17 additions and 3 deletions

View file

@ -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.

View file

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