Do not destroy drag after launchDrag()

On X11 we need to keep the QDrag around a little longer.

Right now, drag is scoped local to launchDrag() and will be destroyed
immediately when launchDrag() finishes. However for X11 we must keep the
drag object alive a little longer. It may only be destroyed once the
drag operation has been accepted by another window, otherwise drag and
drop is broken on Linux and no action happens when something is dragged
from Telegram into another window.

This is because there is still communication happening in the XDND
protocol once QDrag::exec() finishes. See the documentation for
reference: https://freedesktop.org/wiki/Specifications/XDND/

Fixes #17291
This commit is contained in:
Magnus Groß 2021-12-08 00:40:44 +01:00 committed by John Preston
parent b341dddbb9
commit c2b2d0a92a

View file

@ -964,7 +964,9 @@ int MainWindow::tryToExtendWidthBy(int addToWidth) {
void MainWindow::launchDrag(
std::unique_ptr<QMimeData> data,
Fn<void()> &&callback) {
auto drag = std::make_unique<QDrag>(this);
// Qt destroys this QDrag automatically after the drag is finished
// We must not delete this at the end of this function, as this breaks DnD on Linux
auto drag = new QDrag(this);
drag->setMimeData(data.release());
drag->exec(Qt::CopyAction);