effects/{private,desktopgrid,overview}: Guard against function execution when component is being destroyed

Accept drop events correctly and use returned value (action) of
Drag.drop() to guard against the situation where the delegate is about
to be destroyed.

This does not fix any bugs per se, except suppressing a warning about
undefined targetScreen being printed to a console on every window dropped
onto a different virtual desktop.
This commit is contained in:
ivan tkachenko 2022-08-02 11:44:01 +03:00
parent c3f9aab329
commit 3197c7892f
No known key found for this signature in database
GPG key ID: AF72731B7C654CB3
3 changed files with 25 additions and 7 deletions

View file

@ -30,15 +30,21 @@ FocusScope {
onEntered: {
drag.accepted = true;
}
onDropped: {
onDropped: drop => {
drop.accepted = true;
if (drag.source instanceof DesktopView) {
// dragging a desktop as a whole
if (desktopView === drag.source) {
if (drag.source === desktopView) {
drop.action = Qt.IgnoreAction;
return;
}
effect.swapDesktops(drag.source.desktop.x11DesktopNumber, desktop.x11DesktopNumber);
} else {
// dragging a KWin::Window
if (drag.source.desktop === desktopView.desktop.x11DesktopNumber) {
drop.action = Qt.IgnoreAction;
return;
}
drag.source.desktop = desktopView.desktop.x11DesktopNumber;
}
}
@ -96,6 +102,8 @@ FocusScope {
y = 0;
}
Drag.active: dragHandler.active
Drag.proposedAction: Qt.MoveAction
Drag.supportedActions: Qt.MoveAction
Drag.source: desktopView
Drag.hotSpot: Qt.point(width * 0.5, height * 0.5)
width: parent.width

View file

@ -199,10 +199,13 @@ Item {
id: dropArea
anchors.fill: parent
onEntered: {
drag.accepted = true;
}
onDropped: {
onDropped: drop => {
drop.accepted = true;
// dragging a KWin::Window
if (drag.source.desktop === delegate.desktop.x11DesktopNumber) {
drop.action = Qt.IgnoreAction;
return;
}
drag.source.desktop = delegate.desktop.x11DesktopNumber;
}
}

View file

@ -92,6 +92,8 @@ Item {
state: thumb.activeDragHandler.active ? "drag" : "normal"
Drag.active: thumb.activeDragHandler.active
Drag.proposedAction: Qt.MoveAction
Drag.supportedActions: Qt.MoveAction
Drag.source: thumb.client
Drag.hotSpot: Qt.point(
thumb.activeDragHandler.centroid.pressPosition.x * thumb.targetScale,
@ -324,7 +326,12 @@ Item {
if (active) {
thumb.activeDragHandler = this;
} else {
thumbSource.Drag.drop();
var action = thumbSource.Drag.drop();
if (action === Qt.MoveAction) {
// this whole component is in the process of being destroyed due to drop onto
// another virtual desktop (not another screen).
return;
}
var globalPos = targetScreen.mapToGlobal(centroid.scenePosition);
effect.checkItemDroppedOutOfScreen(globalPos, thumbSource);
}